HambiMap/sketch/html/editButton.js

55 lines
1.8 KiB
JavaScript

L.Control.EditButton = L.Control.extend({
title: {
inactive_treehouse: 'Add a treehouse in the current map area',
inactive_barrio: 'Add a barrio in the current map area',
active: 'Disable edit mode to drag the map',
inactive: function(){
let zoom = map.getZoom();
if (zoom <= max_barrio_zoom) return this.inactive_barrio;
// if (layer == 'treehouse') // uncomment if you ever introduce another layer or default value
return this.inactive_treehouse;
}
},
editButton: null,
toggle_style: function(){
if (editing) {
this.editButton.className = this.editButton.className.replace("w3-white", "w3-blue");
this.editButton.title = this.title.active;
} else {
this.editButton.className = this.editButton.className.replace("w3-blue", "w3-white");
this.editButton.title = this.title.inactive();
}
},
onAdd: function (map) {
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(){
if (editing) {
map.selectAreaFeature.disable();
// editing = false; // /should/ be redundand
} else {
map.selectAreaFeature.enable();
// editing = true; // /should/ be redundand
}
// this.toggle_style(); // /should/ be redundand
};
return this.editButton;
},
onRemove: function(map) {
// Nothing to do here
}
});
L.control.editButton = function(opts) {
return new L.Control.EditButton(opts);
}