Files
thetool/public/assets/js/leaflet-ext/leaflet.switch-view-button.js
2024-07-25 15:56:53 +02:00

62 lines
1.7 KiB
JavaScript

(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['leaflet'], factory);
} else if (typeof module !== 'undefined') {
// Node/CommonJS
module.exports = factory(require('leaflet'));
} else {
// Browser globals
if (typeof window.L === 'undefined') {
throw new Error('Leaflet must be loaded first');
}
factory(window.L);
}
}(function (L) {
L.Control.Switchview = L.Control.extend({
options: {
position: 'bottomleft',
title: 'Zwischen Karte und Satellitenansicht wechseln'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-switch-view leaflet-bar leaflet-control');
this.link = L.DomUtil.create('a', 'leaflet-control-switch-view-button leaflet-bar-part', container);
this.link.href = '#';
this._map = map;
this.link.title = this.options.title;
L.DomEvent.on(this.link, 'click', this._click, this);
return container;
},
_click: function (e) {
L.DomEvent.stopPropagation(e);
L.DomEvent.preventDefault(e);
this._map.toggleTileset();
},
});
L.Map.include({
toggleTileset: function() {
toggleTileset();
},
});
L.Map.addInitHook(function () {
if (this.options.switchviewControl) {
this.switchviewControl = new L.Control.Switchview(this.options.switchviewControl);
this.addControl(this.switchviewControl);
}
});
L.control.switchview = function (options) {
return new L.Control.Switchview(options);
};
}));