Select to view content in your preferred language

Create AGSClassBreak with hatch

1509
10
Jump to solution
10-24-2023 02:21 PM
RTC
by
Emerging Contributor

Is there a way to create a AGSClassBreak using a hatch type fill? Thanks!

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

Ting_0-1698276234446.png

With the change above, this is what you see.

If you want to use another type of stroke as the border, you can create another symbol, such as

// Create a stroke symbol layer to make the symbol layer.
let strokeLayer = SolidStrokeSymbolLayer(width: 2, color: .red)
// Create a hatch fill symbol layer with hatched lines at the given angle.
let hatchLayer = HatchFillSymbolLayer(
    polylineSymbol: MultilayerPolylineSymbol(symbolLayers: [strokeLayer]),
    angle: angle
)
// Set separation distance for lines.
hatchLayer.separation = 25
// Create a stroke for the outline.
let outlineStrokeLayer = SolidStrokeSymbolLayer(width: 5, color: .blue)
// Create a multilayer polygon symbol from the symbol layer list.
let polygonSymbol = MultilayerPolygonSymbol(symbolLayers: [hatchLayer, outlineStrokeLayer])

Ting_1-1698276350057.png

 

View solution in original post

0 Kudos
10 Replies
Ting
by Esri Contributor
Esri Contributor

Can you specify your question a bit more?

Generally speaking, you can use a AGSSimpleFillSymbol for a class break renderer. The fill symbol has many styles, including backwardDiagonal which is a kind of hatch fill. Then you can add a AGSClassBreak using this symbol like shown in this documentation: https://developers.arcgis.com/documentation/mapping-apis-and-services/visualization/data-driven-styl...

See another example at here.

0 Kudos
RTC
by
Emerging Contributor

Hi Ting, thanks for the quick reply. Yes, I am defining class break renderers and using simpleFillSymbol to define the fills. I tried to use the different styles, including the backwardDiagonal but didn't see anyway to modify the lines of the hatch. Is there way to do that?

 

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Thanks for the details. Runtime API does not expose the hatched symbol settings like in ArcGIS Pro, say setting the pattern with angle/separation/offset.

One potential way is to use the AGSPictureFillSymbol, where you use an image for the repeating pattern. You can try to create an image swatch from code and use it for the symbol.

I'll try tomorrow to see if there is another way to do that. Stay tuned.

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Actually, there is a more elaborated way to create the hatched fill symbol, using the AGSHatchFillSymbolLayer API. Basically, you create a hatch fill symbol layer with hatched lines at the given angle and separation, and then create a multilayer polygon symbol from the hatched line layer. Then this symbol can be used for your polygons. The gist looks like this.

 

        // Create a stroke symbol layer to make the symbol layer.
        let strokeLayer = SolidStrokeSymbolLayer(width: 2, color: .red)
        // Create a hatch fill symbol layer with hatched lines at the given angle.
        let hatchLayer = HatchFillSymbolLayer(
            polylineSymbol: MultilayerPolylineSymbol(symbolLayers: [strokeLayer]),
            angle: angle
        )
        // Set separation distance for lines.
        hatchLayer.separation = 9
        // Create a multilayer polygon symbol from the symbol layer list.
        let polygonSymbol = MultilayerPolygonSymbol(symbolLayers: [hatchLayer])

 

 You can check out an example in the new Swift API samples here. Hope it helps!

Ting_0-1698255901636.png

 

0 Kudos
RTC
by
Emerging Contributor

Thanks Ting!  Will give this a try and make your answer as the solution once I can verify it's working. Thanks!

0 Kudos
RTC
by
Emerging Contributor

Hi Ting, this is about 90% there, is there a way to add an outline (border)? 

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Yup - you can append another stroke layer to the symbolLayers array, such as

let polygonSymbol = MultilayerPolygonSymbol(symbolLayers: [hatchLayer, strokeLayer])

The stroke symbol will serve as the outline symbol.

0 Kudos
RTC
by
Emerging Contributor

I did not see a way to use the strokeLayer to act as an outline (border). Can you provide an example of how that would be done?  Thanks!

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Ting_0-1698276234446.png

With the change above, this is what you see.

If you want to use another type of stroke as the border, you can create another symbol, such as

// Create a stroke symbol layer to make the symbol layer.
let strokeLayer = SolidStrokeSymbolLayer(width: 2, color: .red)
// Create a hatch fill symbol layer with hatched lines at the given angle.
let hatchLayer = HatchFillSymbolLayer(
    polylineSymbol: MultilayerPolylineSymbol(symbolLayers: [strokeLayer]),
    angle: angle
)
// Set separation distance for lines.
hatchLayer.separation = 25
// Create a stroke for the outline.
let outlineStrokeLayer = SolidStrokeSymbolLayer(width: 5, color: .blue)
// Create a multilayer polygon symbol from the symbol layer list.
let polygonSymbol = MultilayerPolygonSymbol(symbolLayers: [hatchLayer, outlineStrokeLayer])

Ting_1-1698276350057.png

 

0 Kudos