5

I am looking for ideas/libraries that enable snapping when I create a circle with leaflet draw. There is the libaray Leaflet snap, that enables snapping of draggable markers to polylines and other layers. But I am looking for an option to snap to markers when creating a circle. So basically create a circle around the marker.
enter image description here

6

Did you find a solution?

I've created a function which does this for me.

  function mapToPosition(position){
    lon = position.coords.longitude;
    lat = position.coords.latitude;

    var marker = new L.Marker([lat,lon],{title: "Not at the right spot? Drag me!"}).addTo(map);
    marker.dragging.enable();

    marker.on('dragend', function(e){
      var coords = e.target.getLatLng();
      var lat = coords.lat;
      var lon = coords.lng;
      map.panTo({lon:lon,lat:lat})
      map.removeLayer(cir);
      cir = L.circle([lat,lon],1000).addTo(map).bindPopup("Area within 1km of your point.");
    });

    cir = L.circle([lat,lon],1000).addTo(map);
  }

I hope that helps!

| improve this answer | |

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.