Leaflet / Leaflet.Editable

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

deleteShape does not work for circle #135

Open axelerate opened 7 years ago

axelerate commented 7 years ago

deleteShape works for every shape type except for circle. The API suggests the use of deleteShapeAt, but it does not work on any of the shapes I've attempted to draw, and throws an exception on var shape = this.feature.shapeAt(latlng);, stating shapeAt is undefined. When attempting to invoke deleteShape on circle, it fails on the following line: this.feature.setLatLngs(this.getLatLngs());, stating setLatLngs is not a property of feature.

axelerate commented 7 years ago

I think this results from the fact that the deleteShape is generic and assumes all feature has setLatLngs, which L.circle doesn't.

yohanboniface commented 7 years ago

Humm, thinking a bit about it, I think it's more the doc that needs to be fixed rather than the code.

Can you elaborate on your use case?

axelerate commented 7 years ago

The public method deleteShape invokes setLatLngs on a shape. The method setLatLngs does not exist for certain shapes, noticeably circle, which has a single latlng.

chocho11 commented 7 years ago

no delete function for markers created by editable ?

overly-engineered commented 6 years ago

@axelerate Just run into this issue today. Did find a suitable solution?

tontof commented 8 months ago

Just in case, this seems to work if you want to remove circle. I've simply modified the deleteShape function:

    var deleteShape = function (e) {
      if ((e.originalEvent.ctrlKey || e.originalEvent.metaKey) && this.editEnabled()) {
        if (this.options.radius) {
          this.remove();
        } else {
          this.editor.deleteShapeAt(e.latlng);
        }
      }
    };

Instead or removing shape, it's also possible to remove object (multi polygon) by simplifying:

    var deleteShape = function (e) {
      if ((e.originalEvent.ctrlKey || e.originalEvent.metaKey) && this.editEnabled()) {
        this.remove();
      }
    };