mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

How to make Symbol added via PointAnnotationManager appear above all other Layers

Open brandon-watkins-avcrm opened this issue 1 year ago • 3 comments

I create Fill, Line and a Symbol (For text) layers on the map using GeoJson. I then have the functionality where a user clicks on the map and I add a Symbol via the PointAnnotationManager. However I can't figure out how to make sure these Symbols are displayed above all other layers I add programatically :/

Hoping to avoid having to add logic where the Symbols the user adds are SymbolLayers because of the complexities with tapping on existing symbols.

You can see the symbol with the Text 4 is underneath the Zone layer:

Screenshot 2024-10-09 at 2 40 31 PM

brandon-watkins-avcrm avatar Oct 09 '24 04:10 brandon-watkins-avcrm

`// Your geojson source // final source = GeojsonSource()

// add source to map map.style.addSource(source)

// add layers, attention the sort map.style.addLayer(FillLayer) map.style.addLayer(LineLayer) map.style.addLayer(SymbolLayer)

// or map.style.addLayerAt({above: otherLayerId})

// then add new Point with update geojson source on map click event map.style.addGeoJSONSourceFeatures(...)

// or update whole geojson final geojson = map.style.getSource(id) as GeojsonSource geojson.update(..)`

lantah-1 avatar Oct 09 '24 06:10 lantah-1

@brandon-watkins-avcrm Layers appear in the order they've been added to the style(if the ordering is not specified explicitly), annotation manager internally adds a layer upon initialization, you could either:

  • reorder your code to create point annotation manager after the rest of the layers are added to the style
  • specify layer position explicitly:
    • position parameter for layers: mapboxMap.style.addLayerAt(layer, position)
    • belowLayerId for annotation managers: mapboxMap.annotations.createPointAnnotationManager(below: layerId)

evil159 avatar Oct 09 '24 10:10 evil159

Thanks I will give these a go today!

brandon-watkins-avcrm avatar Oct 10 '24 00:10 brandon-watkins-avcrm