Mapbox-gl-native: Adding anchor points to MarkerOptions()?

Created on 30 Oct 2017  路  10Comments  路  Source: mapbox/mapbox-gl-native

So recently we have been implementing the Mapbox SDK, we are using markers on the map and have found that the MarkerOptions() doesn't have an anchor function. I would like to request this as a feature, as working with bitmaps we do require some maneuverability when placing the bitmap around the point that it is placed. Is this something that you expect to add in soon?

Alternatively like the MarkerViewOptions() whereby the anchor works perfectly but removing the title/snippet the markerClick gets intercepted as I don't want to display an infoWindow but a custom bottomsheet, is there a way to use this MarkerViewOptions() as a workaround?

Platform:

  • min sdk: 19
  • target sdk: 26

Mapbox SDK version:
5.2.0-beta2

Android

Most helpful comment

Annotations API is now deprecated as should be replaced with either the annotations plugin or the symbol layer api. Both support the concept of anchoring.

But they don't support using custom marker icons. Only predefined ones. There is no clear tutorial on how to make symbol layers work when you have more than 10 different icons which are not known at the start of the app.

All 10 comments

Any update on this feature request? My marker looks pretty much like this,

icon-ios7-location-128

So without the anchoring, the marker will just centering the location, instead of hovering above it.
Would also be cool if there is any known workaround for this.

We really need this feature too.
We're using SymbolLayer for other requirements like setting alpha or rotation, but still, we need to set anchor on the "Marker"s. I believe it's a primary option and a must.

Any news on this? Would really appreciate an effort on this. Thanks!

Guys, I am using Mapbox SDK in my project and I need this feature too.
For now I am forced to fill 0.5 of my markers height with empty pixels in order to get proper visual consistency. Alongside with this I am forced to detect marker clicks via custom overlay so that empty pixels won't register clicks because they are a simple workaround.
I have a setting in my app that allows switching between Mapbox and GoogleMaps, and all this crazy stuff is only for Mapbox markers, whereas GoogleMaps has that anchor parameter and works just fine.
We need this setting. Please.

Thanks all for feedback here. The anchoring can be easily achieved using the SymbolLayer API, or with a newly introduced Annotation Plugin. The plugin is still in an experimental phase and we welcome any feedback or comments on how we can improve it.

LukasPaczos, hello. I appreciate your answer.
But as mentioned before -- it is the markers implementation need to be complete.
It would be a mess trying to go abstract between your SymbolLayer API and Google Maps markers API.
Furthermore, SymbolLayer API seem to be more troublesome when you are using a set of markers styled differently. As I understand, if I have (for example) 15 markers colored/numbered in a particular way, I would need to create 15 separate SymbolLayers for each of them in order to show them on the map. SymbolManager looks a bit handy for this task, but still, it is what it is.
Guys, you do own a good API that is almost a reflection of the one used by Google Maps for markers, why are you trying to push people to different solutions where they just need to use markers?
Is it difficult for you to maintain markers API while moving further to improving MapBox functionality?
Declare it as deprecated in this case. Because it is really silly -- you have markers, but if you want your marker to be anchored in a way you want, drop all your code and implement our different API.
Guys, come on.

As I understand, if I have (for example) 15 markers colored/numbered in a particular way, I would need to create 15 separate SymbolLayers for each of them in order to show them on the map.

This is not correct. You can use data-driven styling and a single layer to style all of your symbols:

symbolLayer.setProperties(
  ...
  PropertyFactory.iconImage(Expression.get("image_id_property")),
  PropertyFactory.iconAnchor(Property.ICON_ANCHOR_TOP),
  ...
);
...
mapboxMap.addImage("image_id", bitmap);
feature.addStringProperty("image_id_property", "image_id");
...
geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(featureList));
...

That said, we are working on the best-possible long-term solution to make the API more straightforward, thanks again for the feedback.

Thanks dear @LukasPaczos for your response, as @JasmineMan has already mentioned, and I've already said, the use-cases of SymbolLayer API and Markers at least to us seem different.
I'm already using Symbol-Layers however for some annotations which need alpha animations or rotation.
So right now, I willingly want to try the Annotation Plugin for anchors and I hope it works fine. I'll reach out if I face anything unexpected.
Thanks again.

Annotations API is now deprecated as should be replaced with either the annotations plugin or the symbol layer api. Both support the concept of anchoring.

Annotations API is now deprecated as should be replaced with either the annotations plugin or the symbol layer api. Both support the concept of anchoring.

But they don't support using custom marker icons. Only predefined ones. There is no clear tutorial on how to make symbol layers work when you have more than 10 different icons which are not known at the start of the app.

Was this page helpful?
0 / 5 - 0 ratings