clean up behaviour of editButton

This commit is contained in:
Gandalf 2023-08-13 18:35:11 +02:00
parent 0b52b51d45
commit fa788644be
2 changed files with 15 additions and 15 deletions

View file

@ -17,22 +17,18 @@ function onMapClick(e){ //for adding a tree(house)
}
function onMapZoom(e){ //for deciding wether to show barrios or treehouses
if (map.getZoom() > max_barrio_zoom) {
map.addLayer(barrio_markers);
map.removeLayer(tree_markers);
map.addLayer(tree_markers);
map.removeLayer(barrio_markers);
}
if (map.getZoom() <= max_barrio_zoom) {
map.addLayer(tree_markers);
map.removeLayer(barrio_markers);
map.addLayer(barrio_markers);
map.removeLayer(tree_markers);
}
}
function onSelectAreaFeatureEnabled(e){
editing = true;
editButton.toggle_style();
}
function onSelectAreaFeatureDisabled(e){
editing = false;
editButton.toggle_style();
}
function onMapMouseDown(e){} //probably needed for Barrio creation -> nope.
function onMapMouseUp(e){
@ -67,9 +63,11 @@ map.on('contextMenu', onMapContextMenu);
map.on('selectareadisabled', onSelectAreaFeatureDisabled);
map.on('selectareaenabled', onSelectAreaFeatureEnabled);
sidebar.on('closing', function(e) {
if(document.getElementById('barrio_form'))
if(document.getElementById('barrio_form')) {
sidebar.removePanel('barrio_form');
if(!document.getElementById('barrio_form'))
// this seems redundant, but I want to check that we removed *the last* of (hopefully, but not guaranteed i guess, only one) barrio_form(s)
if(!document.getElementById('barrio_form') && editing && map.getZoom() <= max_barrio_zoom)
map.selectAreaFeature.enable();
}
});

View file

@ -25,20 +25,22 @@ L.Control.EditButton = L.Control.extend({
},
onAdd: function (map) {
let ts = this;
this.editButton = L.DomUtil.create('button', 'w3-button w3-white w3-hover-light-blue w3-small leaflet-bar');
this.editButton.innerHTML = 'edit';
this.editButton.title = this.title.inactive();
this.editButton.onclick = function(){
let zoom = map.getZoom();
if (editing) {
map.selectAreaFeature.disable();
// editing = false; // /should/ be redundand
editing = false;
} else {
map.selectAreaFeature.enable();
// editing = true; // /should/ be redundand
if(!document.getElementById('barrio_form') && zoom <= max_barrio_zoom) map.selectAreaFeature.enable();
editing = true;
}
// this.toggle_style(); // /should/ be redundand
ts.toggle_style();
};
return this.editButton;