clean up behaviour of editButton
This commit is contained in:
parent
0b52b51d45
commit
fa788644be
|
@ -17,22 +17,18 @@ function onMapClick(e){ //for adding a tree(house)
|
||||||
}
|
}
|
||||||
function onMapZoom(e){ //for deciding wether to show barrios or treehouses
|
function onMapZoom(e){ //for deciding wether to show barrios or treehouses
|
||||||
if (map.getZoom() > max_barrio_zoom) {
|
if (map.getZoom() > max_barrio_zoom) {
|
||||||
map.addLayer(barrio_markers);
|
map.addLayer(tree_markers);
|
||||||
map.removeLayer(tree_markers);
|
map.removeLayer(barrio_markers);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (map.getZoom() <= max_barrio_zoom) {
|
if (map.getZoom() <= max_barrio_zoom) {
|
||||||
map.addLayer(tree_markers);
|
map.addLayer(barrio_markers);
|
||||||
map.removeLayer(barrio_markers);
|
map.removeLayer(tree_markers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onSelectAreaFeatureEnabled(e){
|
function onSelectAreaFeatureEnabled(e){
|
||||||
editing = true;
|
|
||||||
editButton.toggle_style();
|
|
||||||
}
|
}
|
||||||
function onSelectAreaFeatureDisabled(e){
|
function onSelectAreaFeatureDisabled(e){
|
||||||
editing = false;
|
|
||||||
editButton.toggle_style();
|
|
||||||
}
|
}
|
||||||
function onMapMouseDown(e){} //probably needed for Barrio creation -> nope.
|
function onMapMouseDown(e){} //probably needed for Barrio creation -> nope.
|
||||||
function onMapMouseUp(e){
|
function onMapMouseUp(e){
|
||||||
|
@ -67,9 +63,11 @@ map.on('contextMenu', onMapContextMenu);
|
||||||
map.on('selectareadisabled', onSelectAreaFeatureDisabled);
|
map.on('selectareadisabled', onSelectAreaFeatureDisabled);
|
||||||
map.on('selectareaenabled', onSelectAreaFeatureEnabled);
|
map.on('selectareaenabled', onSelectAreaFeatureEnabled);
|
||||||
sidebar.on('closing', function(e) {
|
sidebar.on('closing', function(e) {
|
||||||
if(document.getElementById('barrio_form'))
|
if(document.getElementById('barrio_form')) {
|
||||||
sidebar.removePanel('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();
|
map.selectAreaFeature.enable();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,20 +25,22 @@ L.Control.EditButton = L.Control.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
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 = L.DomUtil.create('button', 'w3-button w3-white w3-hover-light-blue w3-small leaflet-bar');
|
||||||
|
|
||||||
this.editButton.innerHTML = 'edit';
|
this.editButton.innerHTML = 'edit';
|
||||||
this.editButton.title = this.title.inactive();
|
this.editButton.title = this.title.inactive();
|
||||||
|
|
||||||
this.editButton.onclick = function(){
|
this.editButton.onclick = function(){
|
||||||
|
let zoom = map.getZoom();
|
||||||
if (editing) {
|
if (editing) {
|
||||||
map.selectAreaFeature.disable();
|
map.selectAreaFeature.disable();
|
||||||
// editing = false; // /should/ be redundand
|
editing = false;
|
||||||
} else {
|
} else {
|
||||||
map.selectAreaFeature.enable();
|
if(!document.getElementById('barrio_form') && zoom <= max_barrio_zoom) map.selectAreaFeature.enable();
|
||||||
// editing = true; // /should/ be redundand
|
editing = true;
|
||||||
}
|
}
|
||||||
// this.toggle_style(); // /should/ be redundand
|
ts.toggle_style();
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.editButton;
|
return this.editButton;
|
||||||
|
|
Loading…
Reference in a new issue