/* * Leaflet zoom control with a home button for resetting the view. * * Distributed under the CC-BY-SA-3.0 license. See the file "LICENSE" * for details. * * Based on code by toms (https://gis.stackexchange.com/a/127383/48264). */ (function () { "use strict"; L.Control.ZoomHome = L.Control.Zoom.extend({ options: { position: 'topleft', zoomInText: '+', zoomInTitle: 'Zoom in', zoomOutText: '-', zoomOutTitle: 'Zoom out', zoomHomeIcon: 'home', zoomHomeTitle: 'Home', homeCoordinates: null, homeZoom: null }, onAdd: function (map) { var controlName = 'leaflet-control-zoomhome', container = L.DomUtil.create('div', controlName + ' leaflet-bar'), options = this.options; if (options.homeCoordinates === null) { options.homeCoordinates = map.getCenter(); } if (options.homeZoom === null) { options.homeZoom = map.getZoom(); } this._zoomInButton = this._createButton(options.zoomInText, options.zoomInTitle, controlName + '-in', container, this._zoomIn.bind(this)); var zoomHomeText = ''; this._zoomHomeButton = this._createButton(zoomHomeText, options.zoomHomeTitle, controlName + '-home', container, this._zoomHome.bind(this)); this._zoomOutButton = this._createButton(options.zoomOutText, options.zoomOutTitle, controlName + '-out', container, this._zoomOut.bind(this)); this._updateDisabled(); map.on('zoomend zoomlevelschange', this._updateDisabled, this); return container; }, _zoomHome: function (e) { //jshint unused:false this._map.setView(this.options.homeCoordinates, this.options.homeZoom); } }); L.Control.zoomHome = function (options) { return new L.Control.ZoomHome(options); }; }());