leaflet-collapse-button
Version:
Leaflet Extension for Collapse Panels
1 lines • 2.08 kB
JavaScript
(function(t){if(typeof define==="function"&&define.amd){define(["leaflet"],t)}else if(typeof module!=="undefined"){module.exports=t(require("leaflet"))}else{if(typeof window.L==="undefined"){throw new Error("Leaflet must be loaded first")}t(window.L)}})(function(r){r.Control.CollapseButton=r.Control.extend({options:{currentStatus:1,position:"topleft",title:"",titleCancel:"",elementId:"",targetElementId:"",showClasses:[],hideClasses:[],targetShowClasses:[],targetHideClasses:[]},onAdd:function(t){var e=r.DomUtil.create("div","leaflet-control-collapse leaflet-bar leaflet-control");this.link=r.DomUtil.create("a","leaflet-control-collapse-button leaflet-bar-part "+(this.options.position.endsWith("left")?"lcc-left":"lcc-right")+" "+(this.options.currentStatus?"lcc-collapse":"lcc-collapsed"),e);this.link.href="#";this._map=t;r.DomEvent.on(this.link,"click",this._click,this);return e},_click:function(t){r.DomEvent.stopPropagation(t);r.DomEvent.preventDefault(t);var e=document.getElementById(this.options.elementId);var s=document.getElementById(this.options.targetElementId);var o=this.options.showClasses.split(" ");var l=this.options.hideClasses.split(" ");var i=this.options.targetShowClasses.split(" ");var n=this.options.targetHideClasses.split(" ");if(this.options.currentStatus){this.link.classList.add("lcc-collapsed");this.link.classList.remove("lcc-collapse");for(var a of l){e.classList.add(a)}for(var a of n){s.classList.add(a)}for(var a of o){e.classList.remove(a)}for(var a of i){s.classList.remove(a)}this.options.currentStatus=0;this.link.title=this.options.titleCancel}else{this.link.classList.add("lcc-collapse");this.link.classList.remove("lcc-collapsed");for(var a of i){s.classList.add(a)}for(var a of o){e.classList.add(a)}for(var a of n){s.classList.remove(a)}for(var a of l){e.classList.remove(a)}this.options.currentStatus=1;this.link.title=this.options.title}this._map.invalidateSize()}});r.Map.include({isCollapsed:function(){return this.options.currentStatus}});r.control.collapseButton=function(t){return new r.Control.CollapseButton(t)}});