Leaflet.Editable icon indicating copy to clipboard operation
Leaflet.Editable copied to clipboard

deleteShape does not work for circle

Open axelerate opened this issue 7 years ago • 6 comments

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 avatar Jul 06 '17 14:07 axelerate

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

axelerate avatar Jul 06 '17 17:07 axelerate

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?

yohanboniface avatar Jul 24 '17 20:07 yohanboniface

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.

axelerate avatar Aug 21 '17 19:08 axelerate

no delete function for markers created by editable ?

chocho11 avatar Oct 18 '17 08:10 chocho11

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

overly-engineered avatar Oct 29 '18 16:10 overly-engineered

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();
      }
    };

tontof avatar Feb 17 '24 21:02 tontof