L.Control.MiniMap=L.Control.extend({options:{position:"bottomright",toggleDisplay:!1,zoomLevelOffset:-5,zoomLevelFixed:!1,zoomAnimation:!1,autoToggleDisplay:!1,width:150,height:150,aimingRectOptions:{color:"#ff7800",weight:1,clickable:!1},shadowRectOptions:{color:"#000000",weight:1,clickable:!1,opacity:0,fillOpacity:0}},hideText:"Hide MiniMap",showText:"Show MiniMap",initialize:function(a,c){L.Util.setOptions(this,c);this.options.aimingRectOptions.clickable=!1;this.options.shadowRectOptions.clickable=
!1;this._layer=a},onAdd:function(a){this._mainMap=a;this._container=L.DomUtil.create("div","leaflet-control-minimap");this._container.style.width=this.options.width+"px";this._container.style.height=this.options.height+"px";L.DomEvent.disableClickPropagation(this._container);L.DomEvent.on(this._container,"mousewheel",L.DomEvent.stopPropagation);this._miniMap=new L.Map(this._container,{attributionControl:!1,zoomControl:!1,zoomAnimation:this.options.zoomAnimation,autoToggleDisplay:this.options.autoToggleDisplay,
touchZoom:!this.options.zoomLevelFixed,scrollWheelZoom:!this.options.zoomLevelFixed,doubleClickZoom:!this.options.zoomLevelFixed,boxZoom:!this.options.zoomLevelFixed,crs:a.options.crs});this._miniMap.addLayer(this._layer);this._minimized=this._userToggledDisplay=this._miniMapMoving=this._mainMapMoving=!1;this.options.toggleDisplay&&this._addToggleButton();this._miniMap.whenReady(L.Util.bind(function(){this._aimingRect=L.rectangle(this._mainMap.getBounds(),this.options.aimingRectOptions).addTo(this._miniMap);
this._shadowRect=L.rectangle(this._mainMap.getBounds(),this.options.shadowRectOptions).addTo(this._miniMap);this._mainMap.on("moveend",this._onMainMapMoved,this);this._mainMap.on("move",this._onMainMapMoving,this);this._miniMap.on("movestart",this._onMiniMapMoveStarted,this);this._miniMap.on("move",this._onMiniMapMoving,this);this._miniMap.on("moveend",this._onMiniMapMoved,this)},this));return this._container},addTo:function(a){L.Control.prototype.addTo.call(this,a);this._miniMap.setView(this._mainMap.getCenter(),
this._decideZoom(!0));this._setDisplay(this._decideMinimized());return this},onRemove:function(a){this._mainMap.off("moveend",this._onMainMapMoved,this);this._mainMap.off("move",this._onMainMapMoving,this);this._miniMap.off("moveend",this._onMiniMapMoved,this);this._miniMap.removeLayer(this._layer)},_addToggleButton:function(){this._toggleDisplayButton=this.options.toggleDisplay?this._createButton("",this.hideText,"leaflet-control-minimap-toggle-display",this._container,this._toggleDisplayButtonClicked,
this):void 0},_createButton:function(a,c,b,d,e,f){b=L.DomUtil.create("a",b,d);b.innerHTML=a;b.href="#";b.title=c;a=L.DomEvent.stopPropagation;L.DomEvent.on(b,"click",a).on(b,"mousedown",a).on(b,"dblclick",a).on(b,"click",L.DomEvent.preventDefault).on(b,"click",e,f);return b},_toggleDisplayButtonClicked:function(){this._userToggledDisplay=!0;this._minimized?(this._restore(),this._toggleDisplayButton.title=this.hideText):(this._minimize(),this._toggleDisplayButton.title=this.showText)},_setDisplay:function(a){a!=
this._minimized&&(this._minimized?this._restore():this._minimize())},_minimize:function(){this.options.toggleDisplay?(this._container.style.width="19px",this._container.style.height="19px",this._toggleDisplayButton.className+=" minimized"):this._container.style.display="none";this._minimized=!0},_restore:function(){this.options.toggleDisplay?(this._container.style.width=this.options.width+"px",this._container.style.height=this.options.height+"px",this._toggleDisplayButton.className=this._toggleDisplayButton.className.replace(/(?:^|\s)minimized(?!\S)/g,
"")):this._container.style.display="block";this._minimized=!1},_onMainMapMoved:function(a){this._miniMapMoving?this._miniMapMoving=!1:(this._mainMapMoving=!0,this._miniMap.setView(this._mainMap.getCenter(),this._decideZoom(!0)),this._setDisplay(this._decideMinimized()));this._aimingRect.setBounds(this._mainMap.getBounds())},_onMainMapMoving:function(a){this._aimingRect.setBounds(this._mainMap.getBounds())},_onMiniMapMoveStarted:function(a){var c=this._aimingRect.getBounds();a=this._miniMap.latLngToContainerPoint(c.getSouthWest());
c=this._miniMap.latLngToContainerPoint(c.getNorthEast());this._lastAimingRectPosition={sw:a,ne:c}},_onMiniMapMoving:function(a){!this._mainMapMoving&&this._lastAimingRectPosition&&(this._shadowRect.setBounds(new L.LatLngBounds(this._miniMap.containerPointToLatLng(this._lastAimingRectPosition.sw),this._miniMap.containerPointToLatLng(this._lastAimingRectPosition.ne))),this._shadowRect.setStyle({opacity:1,fillOpacity:.3}))},_onMiniMapMoved:function(a){this._mainMapMoving?this._mainMapMoving=!1:(this._miniMapMoving=
!0,this._mainMap.setView(this._miniMap.getCenter(),this._decideZoom(!1)),this._shadowRect.setStyle({opacity:0,fillOpacity:0}))},_decideZoom:function(a){if(this.options.zoomLevelFixed)return a?this.options.zoomLevelFixed:this._mainMap.getZoom();if(a)return this._mainMap.getZoom()+this.options.zoomLevelOffset;a=this._miniMap.getZoom()-this._mainMap.getZoom();var c=this._miniMap.getZoom()-this.options.zoomLevelOffset;a>this.options.zoomLevelOffset&&this._mainMap.getZoom()<this._miniMap.getMinZoom()-
this.options.zoomLevelOffset?this._miniMap.getZoom()>this._lastMiniMapZoom?(a=this._mainMap.getZoom()+1,this._miniMap.setZoom(this._miniMap.getZoom()-1)):a=this._mainMap.getZoom():a=c;this._lastMiniMapZoom=this._miniMap.getZoom();return a},_decideMinimized:function(){return this._userToggledDisplay?this._minimized:this.options.autoToggleDisplay?this._mainMap.getBounds().contains(this._miniMap.getBounds())?!0:!1:this._minimized}});L.Map.mergeOptions({miniMapControl:!1});
L.Map.addInitHook(function(){this.options.miniMapControl&&(this.miniMapControl=(new L.Control.MiniMap).addTo(this))});L.control.minimap=function(a){return new L.Control.MiniMap(a)};