We have migrated ArcGis library from 10x to 100.9.0.
In our app we have the functionality of change mock location using long press. Below is the code snippet of 10x which is working fine.
Graphic graphic = mGraphicsLayer.getGraphic(marker);
if (graphic != null) {
Point point = LocationUtils.convertToMapPoint(position, getSpatialReference());
final Point geometry = (Point) graphic.getGeometry();
geometry.setXY(point.getX(), point.getY());mGraphicsLayer.updateGraphic(marker, geometry);
mGraphicsLayer.bringToFront(marker);
}
After Migration we does not found any method like update graphic and change location of marker which is already drawn on Graphic layer. We have more than 1000 marker on Map so also not feasible to clear and redraw all again. I tried so much but there are no such documentation help. So we are stuck now. Please help and provide code snippet to migrate above code with new library.
The API has changed a little, but once you have understood the new concepts it will work well for you.
In your application it sounds like you are maintaining your own locations which you display in your app. If this is the case then the container you will want to use is a GraphicsOverlay. I have shown some very simple code below which creates a graphics overlay, adds it to your MapView and adds a graphic. It then goes on to move the graphic straight away. Note that the Point class is immutable.
// create a graphics overlay GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); mapView.getGraphicsOverlays().add(graphicsOverlay); // make a symbol for your graphic - this is just a dot SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFF00FF00, 10); // make a point geometry - note its immutable. Point initialPoint = new Point(1000,1000); // create your graphic from the symbol and geometry Graphic graphic = new Graphic(initialPoint, simpleMarkerSymbol); // add it to the graphics overlay - this will allow you to see the point graphicsOverlay.getGraphics().add(graphic); // this code section is for moving the graphic to a new location // start by creating a new point Point newPoint = new Point(5000,5000); // apply the new point to the graphic graphic.setGeometry(newPoint); // your graphic is now in the new location!
There is lots of documentation explaining how this work here: Add graphics and text to graphics overlays—ArcGIS Runtime SDK for Android | ArcGIS for Developers
There are also samples in gitHub. arcgis-runtime-samples-android/java at master · Esri/arcgis-runtime-samples-android · GitHub (Kotlin examples are there too if you prefer).
There is an example of a 3D app which shows how to rapidly update graphics which you can take a look at:
Does this help?
Thanks for the quick reply.
Add marker on graphic layer and the simple straight forward document I already referred but the problem is lots of methods are not available in new library. even alternate method is not mentioned anywhere in document. So if you are aware about how to update the existing marker position which already drawn on map.
The code in the example I have above explains how to move a graphic. You just need to create a new geometry and apply it to the existing graphic.
// this code section is for moving the graphic to a new location // start by creating a new point Point newPoint = new Point(5000,5000); // apply the new point to the graphic graphic.setGeometry(newPoint);
If this isn't what you are trying to achieve, then can you explain exactly what you are trying to implement.