mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
new-poly: editor enable-disable
This commit is contained in:
parent
aab1ee18b8
commit
193eca83c7
1 changed files with 32 additions and 12 deletions
|
@ -56,7 +56,8 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
polyline._showBoundMarkers();
|
polyline._showBoundMarkers();
|
||||||
} else {
|
} else {
|
||||||
polyline._hideAll();
|
// polyline._hideAll();
|
||||||
|
this._hideAllMarkers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -67,6 +68,7 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
disable: () => {
|
disable: () => {
|
||||||
|
console.log('DISABLING EDITOR');
|
||||||
this._map.setEditablePolylinesEnabled(false);
|
this._map.setEditablePolylinesEnabled(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -230,20 +232,21 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
* bounds.
|
* bounds.
|
||||||
*/
|
*/
|
||||||
this._showBoundMarkers = () => {
|
this._showBoundMarkers = () => {
|
||||||
if (!that._map) {
|
console.log('FUCKING SHOW BOUNDS');
|
||||||
|
if (!this._map) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setBusy(false);
|
this._setBusy(false);
|
||||||
|
|
||||||
if (!that._map._editablePolylinesEnabled) return;
|
if (!this._editablePolylinesEnabled) return;
|
||||||
|
|
||||||
const bounds = that._map.getBounds();
|
const bounds = this._map.getBounds();
|
||||||
let found = 0;
|
let found = 0;
|
||||||
|
|
||||||
// todo: optimise this
|
// todo: optimise this FUCK THIS
|
||||||
for (let polylineNo in that._map._editablePolylines) {
|
for (let polylineNo in this._map._editablePolylines) {
|
||||||
const polyline = that._map._editablePolylines[polylineNo];
|
const polyline = this._map._editablePolylines[polylineNo];
|
||||||
|
|
||||||
for (let markerNo in polyline._markers) {
|
for (let markerNo in polyline._markers) {
|
||||||
const marker = polyline._markers[markerNo];
|
const marker = polyline._markers[markerNo];
|
||||||
|
@ -275,6 +278,17 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._hideAllMarkers = () => {
|
||||||
|
this._markers.map(marker => {
|
||||||
|
if (marker.newPointMarker) {
|
||||||
|
this._map.removeLayer(marker.newPointMarker);
|
||||||
|
marker.newPointMarker._visible = false;
|
||||||
|
}
|
||||||
|
marker._visible = false;
|
||||||
|
this._map.removeLayer(marker);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when adding/moving points in order to disable the user to mess
|
* Used when adding/moving points in order to disable the user to mess
|
||||||
* with other markers (+ easier to decide where to put the point
|
* with other markers (+ easier to decide where to put the point
|
||||||
|
@ -305,19 +319,19 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
|
|
||||||
const map = this._map;
|
const map = this._map;
|
||||||
if (show) {
|
if (show) {
|
||||||
if (!marker._visible) {
|
// if (!marker._visible) {
|
||||||
if (!marker._map) { // First show for this marker:
|
if (!marker._map) { // First show for this marker:
|
||||||
marker.addTo(map);
|
marker.addTo(map);
|
||||||
} else { // Marker was already shown and hidden:
|
} else { // Marker was already shown and hidden:
|
||||||
map.addLayer(marker);
|
map.addLayer(marker);
|
||||||
}
|
}
|
||||||
marker._map = map;
|
marker._map = map;
|
||||||
}
|
// }
|
||||||
marker._visible = true;
|
marker._visible = true;
|
||||||
} else {
|
} else {
|
||||||
if (marker._visible) {
|
// if (marker._visible) {
|
||||||
map.removeLayer(marker);
|
map.removeLayer(marker);
|
||||||
}
|
// }
|
||||||
marker._visible = false;
|
marker._visible = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -325,6 +339,7 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
this.setPoints = latlngs => {
|
this.setPoints = latlngs => {
|
||||||
this.setLatLngs(latlngs);
|
this.setLatLngs(latlngs);
|
||||||
|
|
||||||
|
this._hideAllMarkers();
|
||||||
this._markers = [];
|
this._markers = [];
|
||||||
|
|
||||||
for (let i = 0; i < latlngs.length; i += 1) {
|
for (let i = 0; i < latlngs.length; i += 1) {
|
||||||
|
@ -345,7 +360,12 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
||||||
|
|
||||||
if (fixAroundPointNo != null) this._fixAround(fixAroundPointNo);
|
if (fixAroundPointNo != null) this._fixAround(fixAroundPointNo);
|
||||||
|
|
||||||
|
if (this._editablePolylinesEnabled) {
|
||||||
this._showBoundMarkers();
|
this._showBoundMarkers();
|
||||||
|
} else {
|
||||||
|
this._hideAllMarkers();
|
||||||
|
}
|
||||||
|
|
||||||
this._changed = true;
|
this._changed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue