Leaflet / Leaflet.Editable

Make geometries editable in Leaflet.
http://leaflet.github.io/Leaflet.Editable/doc/api.html
559 stars 197 forks source link

Disable line dragging feature #202

Closed superrache closed 3 years ago

superrache commented 4 years ago

I use Leaflet.Editable on polylines and I would like to disable the line dragging feature and only keep point adding, removing and dragging. Is it possible?

timberkeley commented 3 years ago

Yes, you can do this by overriding the onFeatureAdd method of the PolylineEditor class if you only want to effect polylines. You can change the startof the index.html example script so that it starts like:

<script type="text/javascript">
var startPoint = [43.1249, 1.254];
const MyPolylineEditor = L.Editable.PolylineEditor.extend({
  // Override to disable path dragging
  onFeatureAdd: function () {
      this.tools.editLayer.addLayer(this.editLayer);
      if (this.feature.dragging) this.feature.dragging.disable();
  },
});
var map = L.map('map', {
  editable: true,
  editOptions: {
    polylineEditorClass: MyPolylineEditor,
  }}).setView(startPoint, 16),
superrache commented 3 years ago

That's working great. Thanks a lot. Maybe this could become a parameter of Leaflet.Editable..