Is there a way to create a AGSClassBreak using a hatch type fill? Thanks!
Solved! Go to Solution.
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])
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.
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?
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.
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!
Thanks Ting! Will give this a try and make your answer as the solution once I can verify it's working. Thanks!
Hi Ting, this is about 90% there, is there a way to add an outline (border)?
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.
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!
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])