Mapbox-gl-js: how to implement "centerMarker"

Created on 1 Nov 2019  路  3Comments  路  Source: mapbox/mapbox-gl-js

how i can implement "_centerMarker_" for choose and get a location from user like that :
http://jsfiddle.net/doktormolle/jcHqt/

Most helpful comment

You can listen for map.on('drag', callbackFn) and in the callback function, use map.getCenter() to get the center coordinate of the map. You can then update the position of the marker so that it will smoothly move as the map is panned.

All 3 comments

I'm not entirely sure which part of that demo you're trying to replicate but you can create a marker with a popup like in this example. It's up to you to set where the marker is located on the map and/or get input from the user. You can use map.on('click, function () {...}) to place a marker on the map at the site of a user's click. You can see the basic idea in this example.

Please note for the future, that this issue tracker is for reporting bugs and requesting features for GL JS. We can't offer general support through this channel. For answers to "how to" questions like this, we recommend contacting Mapbox Support or asking your question on Stack Overflow. Thanks!

i want to marker is fixed and center of map and change location with drag map and not drag marker

You can listen for map.on('drag', callbackFn) and in the callback function, use map.getCenter() to get the center coordinate of the map. You can then update the position of the marker so that it will smoothly move as the map is panned.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aendrew picture aendrew  路  3Comments

rigoneri picture rigoneri  路  3Comments

foundryspatial-duncan picture foundryspatial-duncan  路  3Comments

stevage picture stevage  路  3Comments

muesliq picture muesliq  路  3Comments