64 lines
1.7 KiB
JavaScript
64 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.Center = L.Control.extend({
|
|
options: {
|
|
position: 'bottomleft',
|
|
title: 'Zentrieren'
|
|
},
|
|
|
|
onAdd: function (map) {
|
|
var container = L.DomUtil.create('div', 'leaflet-control-center leaflet-bar leaflet-control');
|
|
|
|
this.link = L.DomUtil.create('a', 'leaflet-control-center-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.centerMap();
|
|
},
|
|
|
|
});
|
|
|
|
L.Map.include({
|
|
centerMap: function() {
|
|
if(typeof mapCenterPos !== 'undefined') {
|
|
this.setView(mapCenterPos);
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
L.Map.addInitHook(function () {
|
|
if (this.options.centerControl) {
|
|
this.centerControl = new L.Control.Center(this.options.centerControl);
|
|
this.addControl(this.centerControl);
|
|
}
|
|
});
|
|
|
|
L.control.center = function (options) {
|
|
return new L.Control.Center(options);
|
|
};
|
|
})); |