Reputation: 319
I'm reading the documentation of the Annotation Plugin along with the examples, but still can't quite understand how to work with Lines.
I want to create a Line, which need to be updated frequently with additional coordinates. In Google Maps is easy, since we declare a Polyline object, take the LatLng points and set the new one. Basically, I'm not going to use a lot of customization, only width and color of the line.
So do we need to define a layer, or we could just use the options for this case?
And a second question: (From the documentation, I see a lot of examples with FeatureCollection and GeoJSON) Is this the only way of updating the line?
Upvotes: 3
Views: 2243
Reputation: 2546
Tldr; There are two main options and it's basically up to you as to which route to take. Your LatLng
coordinates can be used to create a LineString
/Line
each time you want to update the visual line.
You can use a LineLayer
:
https://docs.mapbox.com/android/maps/examples/draw-a-geojson-line/
https://docs.mapbox.com/android/maps/examples/create-a-line-layer (in this example,
style.addSource(new GeoJsonSource("line-source", FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry( LineString.fromLngLats(routeCoordinates) )})));
can actually just be style.addSource(new GeoJsonSource("line-source", LineString.fromLngLats(routeCoordinates)));
.
Updating GeoJSON of the source that's being used by the LineLayer
. Create a new LineString
each time you want to update:
See second code block in the GeoJSON updates section (source.setGeoJson()
, etc.): https://docs.mapbox.com/android/java/overview/geojson/#geojson-updates
You can use a LineManager
in the Annotation Plugin:
Updating the line via LineManager
Create a new Line
each time you want to update
Upvotes: 2