this.L=this.L||{},this.L.Control=this.L.Control||{},this.L.Control.Geocoder=function(l){"use strict";l=l&&l.hasOwnProperty("default")?l.default:l;var a=0,i=/[&<>"'`]/g,r=/[&<>"'`]/,t={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};function c(e){return t[e]}function o(e,t,o,s,n){var i="_l_geocoder_"+a++;t[n||"callback"]=i,window[i]=l.Util.bind(o,s);var r=document.createElement("script");r.type="text/javascript",r.src=e+l.Util.getParamString(t),r.id=i,document.getElementsByTagName("head")[0].appendChild(r)}function d(e,t,o){var s=new XMLHttpRequest;s.onreadystatechange=function(){4===s.readyState&&(200===s.status||304===s.status?o(JSON.parse(s.response)):o(""))},s.open("GET",e+l.Util.getParamString(t),!0),s.setRequestHeader("Accept","application/json"),s.send(null)}function s(e,n){return e.replace(/\{ *([\w_]+) *\}/g,function(e,t){var o,s=n[t];return void 0===s?s="":"function"==typeof s&&(s=s(n)),null==(o=s)?"":o?(o=""+o,r.test(o)?o.replace(i,c):o):o+""})}var n={class:l.Class.extend({options:{serviceUrl:"https://nominatim.openstreetmap.org/",geocodingQueryParams:{},reverseQueryParams:{},htmlTemplate:function(e){var t=e.address,o=[];return(t.road||t.building)&&o.push("{building} {road} {house_number}"),(t.city||t.town||t.village||t.hamlet)&&o.push('{postcode} {city} {town} {village} {hamlet}'),(t.state||t.country)&&o.push('{state} {country}'),s(o.join("
"),t)}},initialize:function(e){l.Util.setOptions(this,e)},geocode:function(e,i,r){d(this.options.serviceUrl+"search",l.extend({q:e,limit:5,format:"json",addressdetails:1},this.options.geocodingQueryParams),l.bind(function(e){for(var t=[],o=e.length-1;0<=o;o--){for(var s=e[o].boundingbox,n=0;n<4;n++)s[n]=parseFloat(s[n]);t[o]={icon:e[o].icon,name:e[o].display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e[o]):void 0,bbox:l.latLngBounds([s[0],s[2]],[s[1],s[3]]),center:l.latLng(e[o].lat,e[o].lon),properties:e[o]}}i.call(r,t)},this))},reverse:function(e,t,s,n){d(this.options.serviceUrl+"reverse",l.extend({lat:e.lat,lon:e.lng,zoom:Math.round(Math.log(t/256)/Math.log(2)),addressdetails:1,format:"json"},this.options.reverseQueryParams),l.bind(function(e){var t,o=[];e&&e.lat&&e.lon&&(t=l.latLng(e.lat,e.lon),o.push({name:e.display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e):void 0,center:t,bounds:l.latLngBounds(t,t),properties:e})),s.call(n,o)},this))}}),factory:function(e){return new l.Control.Geocoder.Nominatim(e)}},e={class:l.Control.extend({options:{showResultIcons:!1,collapsed:!0,expand:"touch",position:"topright",placeholder:"Search...",errorMessage:"Nothing found.",suggestMinLength:3,suggestTimeout:250,defaultMarkGeocode:!0},includes:l.Evented.prototype||l.Mixin.Events,initialize:function(e){l.Util.setOptions(this,e),this.options.geocoder||(this.options.geocoder=new n.class),this._requestCount=0},onAdd:function(e){var t,o="leaflet-control-geocoder",s=l.DomUtil.create("div",o+" leaflet-bar"),n=l.DomUtil.create("button",o+"-icon",s),i=this._form=l.DomUtil.create("div",o+"-form",s);return this._map=e,this._container=s,n.innerHTML=" ",n.type="button",(t=this._input=l.DomUtil.create("input","",i)).type="text",t.placeholder=this.options.placeholder,this._errorElement=l.DomUtil.create("div",o+"-form-no-error",s),this._errorElement.innerHTML=this.options.errorMessage,this._alts=l.DomUtil.create("ul",o+"-alternatives leaflet-control-geocoder-alternatives-minimized",s),l.DomEvent.disableClickPropagation(this._alts),l.DomEvent.addListener(t,"keydown",this._keydown,this),this.options.geocoder.suggest&&l.DomEvent.addListener(t,"input",this._change,this),l.DomEvent.addListener(t,"blur",function(){this.options.collapsed&&!this._preventBlurCollapse&&this._collapse(),this._preventBlurCollapse=!1},this),this.options.collapsed?"click"===this.options.expand?l.DomEvent.addListener(s,"click",function(e){0===e.button&&2!==e.detail&&this._toggle()},this):l.Browser.touch&&"touch"===this.options.expand?l.DomEvent.addListener(s,"touchstart mousedown",function(e){this._toggle(),e.preventDefault(),e.stopPropagation()},this):(l.DomEvent.addListener(s,"mouseover",this._expand,this),l.DomEvent.addListener(s,"mouseout",this._collapse,this),this._map.on("movestart",this._collapse,this)):(this._expand(),l.Browser.touch?l.DomEvent.addListener(s,"touchstart",function(){this._geocode()},this):l.DomEvent.addListener(s,"click",function(){this._geocode()},this)),this.options.defaultMarkGeocode&&this.on("markgeocode",this.markGeocode,this),this.on("startgeocode",function(){l.DomUtil.addClass(this._container,"leaflet-control-geocoder-throbber")},this),this.on("finishgeocode",function(){l.DomUtil.removeClass(this._container,"leaflet-control-geocoder-throbber")},this),l.DomEvent.disableClickPropagation(s),s},_geocodeResult:function(e,t){if(t||1!==e.length)if(0=this.options.suggestMinLength?this._suggestTimeout=setTimeout(l.bind(function(){this._geocode(!0)},this),this.options.suggestTimeout):this._clearResults())}}),factory:function(e){return new l.Control.Geocoder(e)}},u={class:l.Class.extend({initialize:function(e){this.key=e},geocode:function(e,i,r){o("https://dev.virtualearth.net/REST/v1/Locations",{query:e,key:this.key},function(e){var t=[];if(0this._lastSuggest&&(this._lastSuggest=e.geocoding.timestamp,t.call(o,s._parseResults(e,"bbox")))},this))},reverse:function(e,t,o,s){var n=this;d(this.options.serviceUrl+"/reverse",l.extend({api_key:this._apiKey,"point.lat":e.lat,"point.lon":e.lng},this.options.reverseQueryParams),function(e){o.call(s,n._parseResults(e,"bounds"))})},_parseResults:function(e,i){var r=[];return l.geoJson(e,{pointToLayer:function(e,t){return l.circleMarker(t)},onEachFeature:function(e,t){var o,s,n={};t.getBounds?s=(o=t.getBounds()).getCenter():(s=t.getLatLng(),o=l.latLngBounds(s,s)),n.name=t.feature.properties.label,n.center=s,n[i]=o,n.properties=t.feature.properties,r.push(n)}}),r}}),factory:function(e,t){return new l.Control.Geocoder.Mapzen(e,t)}},_={class:l.Class.extend({options:{service_url:"http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"},initialize:function(e,t){l.setOptions(this,t),this._accessToken=e},geocode:function(e,r,a){var t={SingleLine:e,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"};this._key&&this._key.length&&(t.token=this._key),d(this.options.service_url+"/findAddressCandidates",t,function(e){var t,o,s,n=[];if(e.candidates&&e.candidates.length)for(var i=0;i<=e.candidates.length-1;i++)t=e.candidates[i],o=l.latLng(t.location.y,t.location.x),s=l.latLngBounds(l.latLng(t.extent.ymax,t.extent.xmax),l.latLng(t.extent.ymin,t.extent.xmin)),n[i]={name:t.address,bbox:s,center:o};r.call(a,n)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,s,n){var o={location:encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat),distance:100,f:"json"};d(this.options.service_url+"/reverseGeocode",o,function(e){var t,o=[];e&&!e.error&&(t=l.latLng(e.location.y,e.location.x),o.push({name:e.address.Match_addr,center:t,bounds:l.latLngBounds(t,t)})),s.call(n,o)})}}),factory:function(e,t){return new l.Control.Geocoder.ArcGis(e,t)}},y={class:l.Class.extend({options:{geocodeUrl:"http://geocoder.api.here.com/6.2/geocode.json",reverseGeocodeUrl:"http://reverse.geocoder.api.here.com/6.2/reversegeocode.json",app_id:"",app_code:"",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e){l.setOptions(this,e)},geocode:function(e,t,o){var s={searchtext:e,gen:9,app_id:this.options.app_id,app_code:this.options.app_code,jsonattributes:1};s=l.Util.extend(s,this.options.geocodingQueryParams),this.getJSON(this.options.geocodeUrl,s,t,o)},reverse:function(e,t,o,s){var n={prox:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng),mode:"retrieveAddresses",app_id:this.options.app_id,app_code:this.options.app_code,gen:9,jsonattributes:1};n=l.Util.extend(n,this.options.reverseQueryParams),this.getJSON(this.options.reverseGeocodeUrl,n,o,s)},getJSON:function(e,t,r,a){d(e,t,function(e){var t,o,s,n=[];if(e.response.view&&e.response.view.length)for(var i=0;i<=e.response.view[0].result.length-1;i++)t=e.response.view[0].result[i].location,o=l.latLng(t.displayPosition.latitude,t.displayPosition.longitude),s=l.latLngBounds(l.latLng(t.mapView.topLeft.latitude,t.mapView.topLeft.longitude),l.latLng(t.mapView.bottomRight.latitude,t.mapView.bottomRight.longitude)),n[i]={name:t.address.label,bbox:s,center:o};r.call(a,n)})}}),factory:function(e){return new l.Control.Geocoder.HERE(e)}},b=l.Util.extend(e.class,{Nominatim:n.class,nominatim:n.factory,Bing:u.class,bing:u.factory,MapQuest:h.class,mapQuest:h.factory,Mapbox:p.class,mapbox:p.factory,What3Words:g.class,what3words:g.factory,Google:m.class,google:m.factory,Photon:f.class,photon:f.factory,Mapzen:v.class,mapzen:v.factory,ArcGis:_.class,arcgis:_.factory,HERE:y.class,here:y.factory});return l.Util.extend(l.Control,{Geocoder:b,geocoder:e.factory}),b}(L);