Select to view content in your preferred language

Custom Vector graphics for current location

1277
8
Jump to solution
11-04-2022 02:29 PM
decay
by
Occasional Contributor

I am trying to replace the blue dot for the current location with a custom vector graphic.  I know you can replace the image with a .png or some other fixed image.

It would appear that AGSVectorMarkerSymbolElement might fit the situation, but I am having a problem constructing the object based on this statement

To create a red square, for example, construct an instance AGSVectorMarkerSymbolElement with a AGSMultilayerPolygonSymbol that contains a red AGSSolidFillSymbolLayer and a square geometry.

This appears to use layers instead of overlays, and I am not sure if layers can be animated (or converted to an overlay somehow).  It also appears that the functionality I am looking for (animated vector graphics on the map), is more of a ArcGIS pro thing where the element is created as a JSON object, but I can't be sure based on the documentation.

Thanks.

 

0 Kudos
1 Solution

Accepted Solutions
MarkDostal
Esri Regular Contributor

That's good (that it's called in `viewDidLoad()`).  Can you check what `autoPanMode`, the location display is in (some modes use different symbols)?  Or you can try setting all the `locationDisplay` symbols:

 mapView.locationDisplay.accuracySymbol = symbol
 mapView.locationDisplay.acquiringSymbol = symbol
 mapView.locationDisplay.headingSymbol = symbol
 mapView.locationDisplay.courseSymbol = symbol

 

Also, you can try setting the symbol to a basic symbol, to see if the issue is with the multi-layer symbol or not:

mapView.locationDisplay.defaultSymbol = AGSSimpleMarkerSymbol(style: .diamond, color: .green, size: 24.0)

 Mark

View solution in original post

0 Kudos
8 Replies
MarkDostal
Esri Regular Contributor

Hello and thank you for your question.  Creating a multi-layer symbol requires several steps.  Below is code to create a square polygon symbol using custom points and using that as the default location display symbol.

 

// The array of points for our shape (polygon), a 1 x 1 square
// The size is set on the final symbol, below.
let points = [
    AGSPoint(x: 0, y: 0, spatialReference: nil),
    AGSPoint(x: 0, y: 1, spatialReference: nil),
    AGSPoint(x: 1, y: 1, spatialReference: nil),
    AGSPoint(x: 1, y: 0, spatialReference: nil)
]
// Create the polygon from our points.
let polygon = AGSPolygon(points: points)
// Create a red solid fill symbol layer.
let redFill = AGSSolidFillSymbolLayer(color: .red)
// Create a multi-layer polygons ymbol from the solid fill layer.
let multiLayerPolygonSymbol = AGSMultilayerPolygonSymbol(symbolLayers: [redFill])
// Create a vector marker element using our polygon geometry and multi-layer symbol.
let vectorElement = AGSVectorMarkerSymbolElement(geometry: polygon, multilayerSymbol: multiLayerPolygonSymbol)
// Create a vector marker symbol layer from our element.
let vectorMarker = AGSVectorMarkerSymbolLayer(vectorMarkerSymbolElements: [vectorElement])
// Create the multi-layer point symbol.
let symbol = AGSMultilayerPointSymbol(symbolLayers: [vectorMarker])
// Set the size of our symbol.
symbol.size = 24.0
// Set our symbol as the location display symbol.
mapView.locationDisplay.defaultSymbol = symbol

You can modify the "points" array to get any geometry you'd like.

Regarding animation, there is no built-in animation capabilities with the Runtime as relates to the location display or graphics.  However it is possible to programmatically modify the symbol/geometry to get animation.

You can see some code to animate a graphics overlay graphic in an Esri Community response here:

https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/make-a-pulse-animation-in-agspict...

Let us know if you have more questions!

Mark

0 Kudos
decay
by
Occasional Contributor

Thanks Mark.

I did add your code in, and I am not seeing the red polygon on the map.  I still see the blue dot for current position, or nothing if I turn it off with showLocation = false.

0 Kudos
MarkDostal
Esri Regular Contributor

When are you setting the symbol on the mapView.locationDisplay?

mapView.locationDisplay.defaultSymbol = symbol

In my test code, I put it in the `viewDidLoad()` method to ensure that the mapView was visible on the screen. 

Mark

0 Kudos
decay
by
Occasional Contributor

It's in a function that gets called at as the last line in viewDidLoad()

0 Kudos
decay
by
Occasional Contributor

Mark,

The issue appeared to be using the AGSSimulatedLocationDataSource for location updates.  When I turned that off, the red square appeared.  The location indicator is totally different.  Is there any way to change the indicator for a simulated data source?

0 Kudos
MarkDostal
Esri Regular Contributor

That's good (that it's called in `viewDidLoad()`).  Can you check what `autoPanMode`, the location display is in (some modes use different symbols)?  Or you can try setting all the `locationDisplay` symbols:

 mapView.locationDisplay.accuracySymbol = symbol
 mapView.locationDisplay.acquiringSymbol = symbol
 mapView.locationDisplay.headingSymbol = symbol
 mapView.locationDisplay.courseSymbol = symbol

 

Also, you can try setting the symbol to a basic symbol, to see if the issue is with the multi-layer symbol or not:

mapView.locationDisplay.defaultSymbol = AGSSimpleMarkerSymbol(style: .diamond, color: .green, size: 24.0)

 Mark

0 Kudos
decay
by
Occasional Contributor

Setting the courseSymbol property with the AGSSimulatedLocationDataSource did the trick.  Thanks.

Is there any way to coerce an AGSModelSceneSymbol to be used as the location indicator?

0 Kudos
MarkDostal
Esri Regular Contributor

Unfortunately, the location display is only available in 2D and the `AGSModelSceneSymbol` is a 3D symbol, so that won't be possible.

If you can get the list of points out from the model, you should be able to create an `AGSPolygon` to display it as in the example above.

Mark

0 Kudos