From 56f451fff2f35ae21e6853a5b0b053d3507c8bb2 Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Tue, 25 Jul 2017 10:36:20 +0200 Subject: [PATCH 1/5] removed uncessary if statement --- src/js/L.PM.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/js/L.PM.js b/src/js/L.PM.js index 3650bd17..4267260c 100644 --- a/src/js/L.PM.js +++ b/src/js/L.PM.js @@ -39,13 +39,12 @@ L.PM = L.PM || { }, addInitHooks() { function initLayerGroup() { - if(!this.options.pmIgnore) { - this.pm = new L.PM.Edit.LayerGroup(this); - } + this.pm = new L.PM.Edit.LayerGroup(this); } L.LayerGroup.addInitHook(initLayerGroup); + function initMarker() { if(!this.options.pmIgnore) { this.pm = new L.PM.Edit.Marker(this); From b1dfa55b14c4d20f5e0e47eb09d5240916a494c6 Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Tue, 25 Jul 2017 11:07:48 +0200 Subject: [PATCH 2/5] used setLatlngs to update LInes and Polygons. Hopefully fixes #181 --- src/js/Edit/L.PM.Edit.Line.js | 15 +++++++++++++-- src/js/Edit/L.PM.Edit.Poly.js | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/js/Edit/L.PM.Edit.Line.js b/src/js/Edit/L.PM.Edit.Line.js index 4ca75757..c589bba9 100644 --- a/src/js/Edit/L.PM.Edit.Line.js +++ b/src/js/Edit/L.PM.Edit.Line.js @@ -181,6 +181,9 @@ Edit.Line = Edit.extend({ coords.splice(index, 0, latlng); + // set new latlngs to trigger bounds update + this._layer.setLatLngs(coords); + // associate polygon coordinate with marker coordinate newM._origLatLng = coords[index]; @@ -216,6 +219,9 @@ Edit.Line = Edit.extend({ // remove polygon coordinate from this marker coords.splice(index, 1); + // set new latlngs to trigger bounds update + this._layer.setLatLngs(coords); + // if the poly has no coordinates left, remove the layer // else, redraw it if(coords.length < 1) { @@ -270,9 +276,14 @@ Edit.Line = Edit.extend({ const nextMarkerIndex = marker._index + 1 >= this._markers.length ? 0 : marker._index + 1; const prevMarkerIndex = marker._index - 1 < 0 ? this._markers.length - 1 : marker._index - 1; - // update marker coordinates which will update polygon coordinates + // update marker coordinates L.extend(marker._origLatLng, marker._latlng); - this._layer.redraw(); + + // update polygon coords + const coords = this._layer._latlngs; + const index = marker._index; + coords.splice(index, 1, marker._origLatLng); + this._layer.setLatLngs(coords).redraw(); // update middle markers on the left and right // be aware that "next" and "prev" might be interchanged, depending on the geojson array diff --git a/src/js/Edit/L.PM.Edit.Poly.js b/src/js/Edit/L.PM.Edit.Poly.js index cd10e8d0..73582a91 100644 --- a/src/js/Edit/L.PM.Edit.Poly.js +++ b/src/js/Edit/L.PM.Edit.Poly.js @@ -46,6 +46,9 @@ Edit.Poly = Edit.Line.extend({ coords.splice(index, 0, latlng); + // set new latlngs to trigger bounds update + this._layer.setLatLngs(coords); + // associate polygon coordinate with marker coordinate newM._origLatLng = coords[index]; @@ -86,6 +89,9 @@ Edit.Poly = Edit.Line.extend({ // remove polygon coordinate from this marker coords.splice(index, 1); + // set new latlngs to trigger bounds update + this._layer.setLatLngs(coords); + // if the poly has no coordinates left, remove the layer // else, redraw it if(coords.length < 1) { From a0122b080cc4329bd503cdcd185ee674e0ae68ce Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Tue, 25 Jul 2017 11:46:45 +0200 Subject: [PATCH 3/5] fixed coord diff from line and poly --- package.json | 3 ++- src/js/Edit/L.PM.Edit.Line.js | 17 ++++++++++++----- src/js/Edit/L.PM.Edit.Poly.js | 9 +++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 1d46faea..335a0b0d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "start": "npm run dev", "dev": "./node_modules/.bin/webpack --config=webpack.dev.js", "test": "browserify ./spec/test.spec.js | tape-run", - "prepublish": "./node_modules/.bin/webpack --config=webpack.build.js" + "build": "./node_modules/.bin/webpack --config=webpack.build.js", + "prepublish": "npm run build" }, "repository": { "type": "git", diff --git a/src/js/Edit/L.PM.Edit.Line.js b/src/js/Edit/L.PM.Edit.Line.js index c589bba9..875566a5 100644 --- a/src/js/Edit/L.PM.Edit.Line.js +++ b/src/js/Edit/L.PM.Edit.Line.js @@ -181,6 +181,8 @@ Edit.Line = Edit.extend({ coords.splice(index, 0, latlng); + console.log(coords); + // set new latlngs to trigger bounds update this._layer.setLatLngs(coords); @@ -263,6 +265,15 @@ Edit.Line = Edit.extend({ this._fireEdit(); }, + updatePolygonCoordsFromMarker(marker) { + // update polygon coords + const coords = this._layer.getLatLngs(); + const index = marker._index; + + coords.splice(index, 1, marker.getLatLng()); + this._layer.setLatLngs(coords).redraw(); + }, + _onMarkerDrag(e) { // dragged marker const marker = e.target; @@ -279,11 +290,7 @@ Edit.Line = Edit.extend({ // update marker coordinates L.extend(marker._origLatLng, marker._latlng); - // update polygon coords - const coords = this._layer._latlngs; - const index = marker._index; - coords.splice(index, 1, marker._origLatLng); - this._layer.setLatLngs(coords).redraw(); + this.updatePolygonCoordsFromMarker(marker); // update middle markers on the left and right // be aware that "next" and "prev" might be interchanged, depending on the geojson array diff --git a/src/js/Edit/L.PM.Edit.Poly.js b/src/js/Edit/L.PM.Edit.Poly.js index 73582a91..9dcab380 100644 --- a/src/js/Edit/L.PM.Edit.Poly.js +++ b/src/js/Edit/L.PM.Edit.Poly.js @@ -33,6 +33,15 @@ Edit.Poly = Edit.Line.extend({ } }, + updatePolygonCoordsFromMarker(marker) { + // update polygon coords + const coords = this._layer.getLatLngs()[0]; + const index = marker._index; + + coords.splice(index, 1, marker.getLatLng()); + this._layer.setLatLngs(coords).redraw(); + }, + // adds a new marker from a middlemarker _addMarker(newM, leftM, rightM) { // first, make this middlemarker a regular marker From 8c4cfae3fd2e8dc8464a1f99c8736dd19435b381 Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Tue, 25 Jul 2017 11:53:37 +0200 Subject: [PATCH 4/5] clarified function name --- src/js/Edit/L.PM.Edit.Line.js | 4 ++-- src/js/Edit/L.PM.Edit.Poly.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/Edit/L.PM.Edit.Line.js b/src/js/Edit/L.PM.Edit.Line.js index 875566a5..515eac6f 100644 --- a/src/js/Edit/L.PM.Edit.Line.js +++ b/src/js/Edit/L.PM.Edit.Line.js @@ -265,7 +265,7 @@ Edit.Line = Edit.extend({ this._fireEdit(); }, - updatePolygonCoordsFromMarker(marker) { + updatePolygonCoordsFromMarkerDrag(marker) { // update polygon coords const coords = this._layer.getLatLngs(); const index = marker._index; @@ -290,7 +290,7 @@ Edit.Line = Edit.extend({ // update marker coordinates L.extend(marker._origLatLng, marker._latlng); - this.updatePolygonCoordsFromMarker(marker); + this.updatePolygonCoordsFromMarkerDrag(marker); // update middle markers on the left and right // be aware that "next" and "prev" might be interchanged, depending on the geojson array diff --git a/src/js/Edit/L.PM.Edit.Poly.js b/src/js/Edit/L.PM.Edit.Poly.js index 9dcab380..257eade8 100644 --- a/src/js/Edit/L.PM.Edit.Poly.js +++ b/src/js/Edit/L.PM.Edit.Poly.js @@ -33,7 +33,7 @@ Edit.Poly = Edit.Line.extend({ } }, - updatePolygonCoordsFromMarker(marker) { + updatePolygonCoordsFromMarkerDrag(marker) { // update polygon coords const coords = this._layer.getLatLngs()[0]; const index = marker._index; From c088f60fdfefbd19c16ca888a49371404d4ac7dc Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Tue, 25 Jul 2017 19:46:12 +0200 Subject: [PATCH 5/5] removed console.log --- src/js/Edit/L.PM.Edit.Line.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/js/Edit/L.PM.Edit.Line.js b/src/js/Edit/L.PM.Edit.Line.js index 515eac6f..93ec5401 100644 --- a/src/js/Edit/L.PM.Edit.Line.js +++ b/src/js/Edit/L.PM.Edit.Line.js @@ -181,8 +181,6 @@ Edit.Line = Edit.extend({ coords.splice(index, 0, latlng); - console.log(coords); - // set new latlngs to trigger bounds update this._layer.setLatLngs(coords);