mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +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) {
|
||||
polyline._showBoundMarkers();
|
||||
} else {
|
||||
polyline._hideAll();
|
||||
// polyline._hideAll();
|
||||
this._hideAllMarkers();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -67,6 +68,7 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
|||
},
|
||||
|
||||
disable: () => {
|
||||
console.log('DISABLING EDITOR');
|
||||
this._map.setEditablePolylinesEnabled(false);
|
||||
},
|
||||
|
||||
|
@ -230,20 +232,21 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
|||
* bounds.
|
||||
*/
|
||||
this._showBoundMarkers = () => {
|
||||
if (!that._map) {
|
||||
console.log('FUCKING SHOW BOUNDS');
|
||||
if (!this._map) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// todo: optimise this
|
||||
for (let polylineNo in that._map._editablePolylines) {
|
||||
const polyline = that._map._editablePolylines[polylineNo];
|
||||
// todo: optimise this FUCK THIS
|
||||
for (let polylineNo in this._map._editablePolylines) {
|
||||
const polyline = this._map._editablePolylines[polylineNo];
|
||||
|
||||
for (let markerNo in polyline._markers) {
|
||||
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
|
||||
* 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;
|
||||
if (show) {
|
||||
if (!marker._visible) {
|
||||
// if (!marker._visible) {
|
||||
if (!marker._map) { // First show for this marker:
|
||||
marker.addTo(map);
|
||||
} else { // Marker was already shown and hidden:
|
||||
map.addLayer(marker);
|
||||
}
|
||||
marker._map = map;
|
||||
}
|
||||
// }
|
||||
marker._visible = true;
|
||||
} else {
|
||||
if (marker._visible) {
|
||||
// if (marker._visible) {
|
||||
map.removeLayer(marker);
|
||||
}
|
||||
// }
|
||||
marker._visible = false;
|
||||
}
|
||||
};
|
||||
|
@ -325,6 +339,7 @@ L.Polyline.polylineEditor = L.Polyline.extend({
|
|||
this.setPoints = latlngs => {
|
||||
this.setLatLngs(latlngs);
|
||||
|
||||
this._hideAllMarkers();
|
||||
this._markers = [];
|
||||
|
||||
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 (this._editablePolylinesEnabled) {
|
||||
this._showBoundMarkers();
|
||||
} else {
|
||||
this._hideAllMarkers();
|
||||
}
|
||||
|
||||
this._changed = true;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue