Skip to content

Commit

Permalink
Get "Delete last point" working, this doesn't feel like the right way…
Browse files Browse the repository at this point in the history
… to do it, but it works.
  • Loading branch information
danzel committed Aug 26, 2015
1 parent d3ec83b commit 8943d99
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/draw/handler/Draw.Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({

var lastMarker = this._markers.pop(),
poly = this._poly,
latlng = this._poly.spliceLatLngs(poly.getLatLngs().length - 1, 1)[0];
latlng = this._poly._spliceLatLngs(poly.getLatLngs().length - 1, 1)[0];

this._markerGroup.removeLayer(lastMarker);

Expand Down
50 changes: 36 additions & 14 deletions src/edit/handler/Edit.Poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ L.Edit.Poly = L.Handler.extend({

this._markerGroup.removeLayer(marker);
this._markers.splice(i, 1);
this._spliceLatLngs(i, 1);
this._poly._spliceLatLngs(i, 1);
this._updateIndexes(i, -1);

marker
Expand Down Expand Up @@ -199,7 +199,7 @@ L.Edit.Poly = L.Handler.extend({

latlng.lat = marker.getLatLng().lat;
latlng.lng = marker.getLatLng().lng;
this._spliceLatLngs(i, 0, latlng);
this._poly._spliceLatLngs(i, 0, latlng);
this._markers.splice(i, 0, marker);

marker.setOpacity(1);
Expand Down Expand Up @@ -249,18 +249,6 @@ L.Edit.Poly = L.Handler.extend({
p2 = map.project(marker2.getLatLng());

return map.unproject(p1._add(p2)._divideBy(2));
},

_spliceLatLngs: function (index, count, toAdd) {
var latLngs = this._isPolygon ? this._poly._latlngs[0] : this._poly._latlngs;

if (toAdd) {
latLngs.splice(index, count, toAdd);
} else {
latLngs.splice(index, count);
}

this._poly.redraw();
}
});

Expand Down Expand Up @@ -294,3 +282,37 @@ var initHook = function () {

L.Polyline.addInitHook(initHook);
L.Polygon.addInitHook(initHook);

L.Polyline.include({
_spliceLatLngs: function (index, count, toAdd) {
var latLngs = this._latlngs,
res;

if (toAdd) {
res = latLngs.splice(index, count, toAdd);
} else {
res = latLngs.splice(index, count);
}

this.redraw();

return res;
}
});

L.Polygon.include({
_spliceLatLngs: function (index, count, toAdd) {
var latLngs = this._latlngs[0],
res;

if (toAdd) {
res = latLngs.splice(index, count, toAdd);
} else {
res = latLngs.splice(index, count);
}

this.redraw();

return res;
}
});

0 comments on commit 8943d99

Please sign in to comment.