0

I have my own Mapbox style that I build in MapBox Studio. Now I want to allow my user to move poi_label symbols. How could I do that? I am following this example Create a draggable point and also I am aware of Mapbox properties. I have added my code below where I can access the layer, now how can I make this symbol draggable/movable?

     map.on('load', function () {
      var layers = map.getStyle().layers;
      layers.forEach(function (layer) {
        if (layer.type && layer.type == "symbol"
          && layer["source-layer"] && layer["source-layer"] == "poi_label") {
          layer.draggable = true;// not working
          map.on('mouseenter', layer.id, function () {
            map.getCanvas().style.cursor = 'draggable';
          });
          map.on('mouseleave', layer.id, function () {
            map.getCanvas().style.cursor = '';
          });          
        }
      });

In the Create a draggable point example, the author is using manual geojson data. Is there any way to build this geojson programmatically based on the loaded part of the map?

1

Yes using querySourceFeatures to get the GeoJSON from there you can use the draggable point example you've linked to.

  • What do I need to pass in the querySourceFeatures to get the features in the map screen? – MJK Oct 4 at 10:29
  • Check the API docs I linked to, after all that's all I would be doing... – AndrewHarvey Oct 4 at 14:12
  • Thanks @AndrewHarvey it helped – MJK Oct 4 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.