tupali_fork/librerias/leaflet/leaflet-search.min.js

17 lines
15 KiB
JavaScript
Raw Normal View History

2016-10-29 15:07:15 +00:00
/*
* Leaflet Control Search v1.9.9 - 2016-06-14
*
* Copyright 2016 Stefano Cudini
* stefano.cudini@gmail.com
* http://labs.easyblog.it/
*
* Licensed under the MIT license.
*
* Demo:
* http://labs.easyblog.it/maps/leaflet-search/
*
* Source:
* git@github.com:stefanocudini/leaflet-search.git
*
*/
(function(){L.Control.Search=L.Control.extend({includes:L.Mixin.Events,options:{url:"",layer:null,sourceData:null,jsonpParam:null,propertyLoc:"loc",propertyName:"title",formatData:null,filterData:null,moveToLocation:null,buildTip:null,container:"",zoom:null,minLength:1,initial:!0,casesensitive:!1,autoType:!0,delayType:400,tooltipLimit:-1,tipAutoSubmit:!0,autoResize:!0,collapsed:!0,autoCollapse:!1,autoCollapseTime:1200,textErr:"Location not found",textCancel:"Cancel",textPlaceholder:"Search...",animateLocation:!0,circleLocation:!0,markerLocation:!1,hideMarkerOnCollapse:!1,markerIcon:new L.Icon.Default,position:"topleft"},initialize:function(a){L.Util.setOptions(this,a||{}),this._inputMinSize=this.options.textPlaceholder?this.options.textPlaceholder.length:10,this._layer=this.options.layer||new L.LayerGroup,this._filterData=this.options.filterData||this._defaultFilterData,this._formatData=this.options.formatData||this._defaultFormatData,this._moveToLocation=this.options.moveToLocation||this._defaultMoveToLocation,this._autoTypeTmp=this.options.autoType,this._countertips=0,this._recordsCache={},this._curReq=null},onAdd:function(a){return this._map=a,this._container=L.DomUtil.create("div","leaflet-control-search"),this._input=this._createInput(this.options.textPlaceholder,"search-input"),this._tooltip=this._createTooltip("search-tooltip"),this._cancel=this._createCancel(this.options.textCancel,"search-cancel"),this._button=this._createButton(this.options.textPlaceholder,"search-button"),this._alert=this._createAlert("search-alert"),this.options.collapsed===!1&&this.expand(this.options.collapsed),(this.options.circleLocation||this.options.markerLocation||this.options.markerIcon)&&(this._markerLoc=new L.Control.Search.Marker([0,0],{showCircle:this.options.circleLocation,showMarker:this.options.markerLocation,icon:this.options.markerIcon})),this.setLayer(this._layer),a.on({resize:this._handleAutoresize},this),this._container},addTo:function(a){return this.options.container?(this._container=this.onAdd(a),this._wrapper=L.DomUtil.get(this.options.container),this._wrapper.style.position="relative",this._wrapper.appendChild(this._container)):L.Control.prototype.addTo.call(this,a),this},onRemove:function(a){this._recordsCache={}},_getPath:function(a,b){var c=b.split("."),d=c.pop(),e=c.length,f=c[0],g=1;if(e>0)for(;(a=a[f])&&e>g;)f=c[g++];return a?a[d]:void 0},setLayer:function(a){return this._layer=a,this._layer.addTo(this._map),this._markerLoc&&this._layer.addLayer(this._markerLoc),this},showAlert:function(a){a=a||this.options.textErr,this._alert.style.display="block",this._alert.innerHTML=a,clearTimeout(this.timerAlert);var b=this;return this.timerAlert=setTimeout(function(){b.hideAlert()},this.options.autoCollapseTime),this},hideAlert:function(){return this._alert.style.display="none",this},cancel:function(){return this._input.value="",this._handleKeypress({keyCode:8}),this._input.size=this._inputMinSize,this._input.focus(),this._cancel.style.display="none",this._hideTooltip(),this},expand:function(a){return a="boolean"==typeof a?a:!0,this._input.style.display="block",L.DomUtil.addClass(this._container,"search-exp"),a!==!1&&(this._input.focus(),this._map.on("dragstart click",this.collapse,this)),this.fire("search_expanded"),this},collapse:function(){return this._hideTooltip(),this.cancel(),this._alert.style.display="none",this._input.blur(),this.options.collapsed&&(this._input.style.display="none",this._cancel.style.display="none",L.DomUtil.removeClass(this._container,"search-exp"),this.options.hideMarkerOnCollapse&&this._markerLoc.hide(),this._map.off("dragstart click",this.collapse,this)),this.fire("search_collapsed"),this},collapseDelayed:function(){if(!this.options.autoCollapse)return this;var a=this;return clearTimeout(this.timerCollapse),this.timerCollapse=setTimeout(function(){a.collapse()},this.options.autoCollapseTime),this},collapseDelayedStop:function(){return clearTimeout(this.timerCollapse),this},_createAlert:function(a){var b=L.DomUtil.create("div",a,this._container);return b.style.display="none",L.DomEvent.on(b,"cl