UNPKG

@inelo/leaflet-control-geocoder

Version:

Extendable geocoder with builtin support for OpenStreetMap Nominatim, Bing, Google, Mapbox, MapQuest, What3Words, Photon, Pelias, HERE, Neutrino, Plus codes

3 lines (2 loc) 27.5 kB
var leafletControlGeocoder=function(t,e){function o(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(o){if("default"!==o){var n=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,n.get?n:{enumerable:!0,get:function(){return t[o]}})}}),e.default=t,e}var n=o(e);function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function i(t,e){return n.Util.extend(e,t.geocodingQueryParams)}function r(t,e){return n.Util.extend(e,t.reverseQueryParams)}var a=0,l=/[&<>"'`]/g,c=/[&<>"'`]/,p={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"};function u(t){return p[t]}function d(t,e,o,s,i){var r="_l_geocoder_"+a++;e[i||"callback"]=r,window[r]=n.Util.bind(o,s);var l=document.createElement("script");l.type="text/javascript",l.src=t+g(e),l.id=r,document.getElementsByTagName("head")[0].appendChild(l)}function h(t,e,o){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState){var t;if(200!==n.status&&304!==n.status)t="";else if("string"==typeof n.response)try{t=JSON.parse(n.response)}catch(e){t=n.response}else t=n.response;o(t)}},n.open("GET",t+g(e),!0),n.responseType="json",n.setRequestHeader("Accept","application/json"),n.send(null)}function g(t,e,o){var n=[];for(var s in t){var i=encodeURIComponent(o?s.toUpperCase():s),r=t[s];if(Array.isArray(r))for(var a=0;a<r.length;a++)n.push(i+"="+encodeURIComponent(r[a]));else n.push(i+"="+encodeURIComponent(String(r)))}return(e&&-1!==e.indexOf("?")?"&":"?")+n.join("&")}var f=function(){function t(t){this.options={serviceUrl:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",apiKey:""},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{token:this.options.apiKey,SingleLine:t,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"});h(this.options.serviceUrl+"/findAddressCandidates",s,function(t){var s=[];if(t.candidates&&t.candidates.length)for(var i=0;i<=t.candidates.length-1;i++){var r=t.candidates[i],a=n.latLng(r.location.y,r.location.x),l=n.latLngBounds(n.latLng(r.extent.ymax,r.extent.xmax),n.latLng(r.extent.ymin,r.extent.xmin));s[i]={name:r.address,bbox:l,center:a}}e.call(o,s)})},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){var i=r(this.options,{location:t.lng+","+t.lat,distance:100,f:"json"});h(this.options.serviceUrl+"/reverseGeocode",i,function(t){var e=[];if(t&&!t.error){var i=n.latLng(t.location.y,t.location.x),r=n.latLngBounds(i,i);e.push({name:t.address.Match_addr,center:i,bbox:r})}o.call(s,e)})},t}(),v=function(){function t(t){this.options={serviceUrl:"https://dev.virtualearth.net/REST/v1/Locations"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{query:t,key:this.options.apiKey});d(this.options.apiKey,s,function(t){var s=[];if(t.resourceSets.length>0)for(var i=t.resourceSets[0].resources.length-1;i>=0;i--){var r=t.resourceSets[0].resources[i],a=r.bbox;s[i]={name:r.name,bbox:n.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:n.latLng(r.point.coordinates)}}e.call(o,s)},this,"jsonp")},e.reverse=function(t,e,o,s){var i=r(this.options,{key:this.options.apiKey});d(this.options.serviceUrl+t.lat+","+t.lng,i,function(t){for(var e=[],i=t.resourceSets[0].resources.length-1;i>=0;i--){var r=t.resourceSets[0].resources[i],a=r.bbox;e[i]={name:r.name,bbox:n.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:n.latLng(r.point.coordinates)}}o.call(s,e)},this,"jsonp")},t}(),m=function(){function t(t){this.options={serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{key:this.options.apiKey,address:t});h(this.options.serviceUrl,s,function(t){var s=[];if(t.results&&t.results.length)for(var i=0;i<=t.results.length-1;i++){var r=t.results[i],a=n.latLng(r.geometry.location),l=n.latLngBounds(n.latLng(r.geometry.viewport.northeast),n.latLng(r.geometry.viewport.southwest));s[i]={name:r.formatted_address,bbox:l,center:a,properties:r.address_components}}e.call(o,s)})},e.reverse=function(t,e,o,s){var i=r(this.options,{key:this.options.apiKey,latlng:t.lat+","+t.lng});h(this.options.serviceUrl,i,function(t){var e=[];if(t.results&&t.results.length)for(var i=0;i<=t.results.length-1;i++){var r=t.results[i],a=n.latLng(r.geometry.location),l=n.latLngBounds(n.latLng(r.geometry.viewport.northeast),n.latLng(r.geometry.viewport.southwest));e[i]={name:r.formatted_address,bbox:l,center:a,properties:r.address_components}}o.call(s,e)})},t}(),_=function(){function t(t){if(this.options={serviceUrl:"https://geocoder.api.here.com/6.2/",app_id:"",app_code:"",apiKey:"",maxResults:5,lang:"en"},n.Util.setOptions(this,t),t.apiKey)throw Error("apiKey is not supported, use app_id/app_code instead!")}var e=t.prototype;return e.geocode=function(t,e,o){var n=i(this.options,{searchtext:t,gen:9,app_id:this.options.app_id,app_code:this.options.app_code,jsonattributes:1,maxresults:this.options.maxResults});this.getJSON(this.options.serviceUrl+"geocode.json",n,e,o)},e.reverse=function(t,e,o,n){var s=t.lat+","+t.lng;this.options.reverseGeocodeProxRadius&&(s+=","+this.options.reverseGeocodeProxRadius);var i=r(this.options,{prox:s,mode:"retrieveAddresses",app_id:this.options.app_id,app_code:this.options.app_code,gen:9,jsonattributes:1,maxresults:this.options.maxResults});this.getJSON(this.options.serviceUrl+"reversegeocode.json",i,o,n)},e.getJSON=function(t,e,o,s){h(t,e,function(t){var e=[];if(t.response.view&&t.response.view.length)for(var i=0;i<=t.response.view[0].result.length-1;i++){var r=t.response.view[0].result[i].location,a=n.latLng(r.displayPosition.latitude,r.displayPosition.longitude),l=n.latLngBounds(n.latLng(r.mapView.topLeft.latitude,r.mapView.topLeft.longitude),n.latLng(r.mapView.bottomRight.latitude,r.mapView.bottomRight.longitude));e[i]={name:r.address.label,properties:r.address,bbox:l,center:a}}o.call(s,e)})},t}(),b=function(){function t(t){this.options={serviceUrl:"https://geocode.search.hereapi.com/v1",apiKey:"",app_id:"",app_code:"",maxResults:10,lang:"en"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var n=i(this.options,{q:t,apiKey:this.options.apiKey,limit:this.options.maxResults,lang:this.options.lang});this.getJSON(this.options.serviceUrl+"/geocode",n,e,o)},e.reverse=function(t,e,o,n){var s=t.lat+","+t.lng,i=r(this.options,{limit:this.options.maxResults,apiKey:this.options.apiKey,lang:this.options.lang});this.options.reverseGeocodeProxRadius?i.in="circle:"+s+";r="+this.options.reverseGeocodeProxRadius:i.at=s,this.getJSON(this.options.serviceUrl+"/revgeocode",i,o,n)},e.getJSON=function(t,e,o,s){h(t,e,function(t){var e=[];if(t.items&&t.items.length)for(var i=0;i<=t.items.length-1;i++){var r,a=t.items[i],l=n.latLng(a.position.lat,a.position.lng);r=a.mapView?n.latLngBounds(n.latLng(a.mapView.south,a.mapView.west),n.latLng(a.mapView.north,a.mapView.east)):n.latLngBounds(n.latLng(a.position.lat,a.position.lng),n.latLng(a.position.lat,a.position.lng)),e[i]={name:a.address.label,properties:a.address,bbox:r,center:l}}o.call(s,e)})},t}();function y(t){var e;return(e=t.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/))?n.latLng((/N/i.test(e[1])?1:-1)*+e[2],(/E/i.test(e[3])?1:-1)*+e[4]):(e=t.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/))?n.latLng((/N/i.test(e[2])?1:-1)*+e[1],(/E/i.test(e[4])?1:-1)*+e[3]):(e=t.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/))?n.latLng((/N/i.test(e[1])?1:-1)*(+e[2]+ +e[3]/60),(/E/i.test(e[4])?1:-1)*(+e[5]+ +e[6]/60)):(e=t.match(/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/))?n.latLng((/N/i.test(e[3])?1:-1)*(+e[1]+ +e[2]/60),(/E/i.test(e[6])?1:-1)*(+e[4]+ +e[5]/60)):(e=t.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/))?n.latLng((/N/i.test(e[1])?1:-1)*(+e[2]+ +e[3]/60+ +e[4]/3600),(/E/i.test(e[5])?1:-1)*(+e[6]+ +e[7]/60+ +e[8]/3600)):(e=t.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/))?n.latLng((/N/i.test(e[4])?1:-1)*(+e[1]+ +e[2]/60+ +e[3]/3600),(/E/i.test(e[8])?1:-1)*(+e[5]+ +e[6]/60+ +e[7]/3600)):(e=t.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/))?n.latLng(+e[1],+e[2]):void 0}var L=function(){function t(t){this.options={next:void 0,sizeInMeters:1e4},n.Util.setOptions(this,t)}return t.prototype.geocode=function(t,e,o){var n=y(t);if(n){var s=[{name:t,center:n,bbox:n.toBounds(this.options.sizeInMeters)}];e.call(o,s)}else this.options.next&&this.options.next.geocode(t,e,o)},t}(),x=function(){function t(t){this.options={serviceUrl:"https://api.mapbox.com/geocoding/v5/mapbox.places/"},n.Util.setOptions(this,t)}var e=t.prototype;return e._getProperties=function(t){for(var e={text:t.text,address:t.address},o=0;o<(t.context||[]).length;o++)e[t.context[o].id.split(".")[0]]=t.context[o].text,t.context[o].short_code&&(e.countryShortCode=t.context[o].short_code);return e},e.geocode=function(t,e,o){var s=this,r=i(this.options,{access_token:this.options.apiKey});void 0!==r.proximity&&void 0!==r.proximity.lat&&void 0!==r.proximity.lng&&(r.proximity=r.proximity.lng+","+r.proximity.lat),h(this.options.serviceUrl+encodeURIComponent(t)+".json",r,function(t){var i=[];if(t.features&&t.features.length)for(var r=0;r<=t.features.length-1;r++){var a,l=t.features[r],c=n.latLng(l.center.reverse());a=l.bbox?n.latLngBounds(n.latLng(l.bbox.slice(0,2).reverse()),n.latLng(l.bbox.slice(2,4).reverse())):n.latLngBounds(c,c),i[r]={name:l.place_name,bbox:a,center:c,properties:s._getProperties(l)}}e.call(o,i)})},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){var i=this;h(this.options.serviceUrl+t.lng+","+t.lat+".json",r(this.options,{access_token:this.options.apiKey}),function(t){var e=[];if(t.features&&t.features.length)for(var r=0;r<=t.features.length-1;r++){var a,l=t.features[r],c=n.latLng(l.center.reverse());a=l.bbox?n.latLngBounds(n.latLng(l.bbox.slice(0,2).reverse()),n.latLng(l.bbox.slice(2,4).reverse())):n.latLngBounds(c,c),e[r]={name:l.place_name,bbox:a,center:c,properties:i._getProperties(l)}}o.call(s,e)})},t}(),U=function(){function t(t){this.options={serviceUrl:"https://www.mapquestapi.com/geocoding/v1"},n.Util.setOptions(this,t),this.options.apiKey=decodeURIComponent(this.options.apiKey)}var e=t.prototype;return e._formatName=function(){return[].slice.call(arguments).filter(function(t){return!!t}).join(", ")},e.geocode=function(t,e,o){var s=i(this.options,{key:this.options.apiKey,location:t,limit:5,outFormat:"json"});h(this.options.serviceUrl+"/address",s,n.Util.bind(function(t){var s=[];if(t.results&&t.results[0].locations)for(var i=t.results[0].locations.length-1;i>=0;i--){var r=t.results[0].locations[i],a=n.latLng(r.latLng);s[i]={name:this._formatName(r.street,r.adminArea4,r.adminArea3,r.adminArea1),bbox:n.latLngBounds(a,a),center:a}}e.call(o,s)},this))},e.reverse=function(t,e,o,s){var i=r(this.options,{key:this.options.apiKey,location:t.lat+","+t.lng,outputFormat:"json"});h(this.options.serviceUrl+"/reverse",i,n.Util.bind(function(t){var e=[];if(t.results&&t.results[0].locations)for(var i=t.results[0].locations.length-1;i>=0;i--){var r=t.results[0].locations[i],a=n.latLng(r.latLng);e[i]={name:this._formatName(r.street,r.adminArea4,r.adminArea3,r.adminArea1),bbox:n.latLngBounds(a,a),center:a}}o.call(s,e)},this))},t}(),w=function(){function t(t){this.options={userId:void 0,apiKey:void 0,serviceUrl:"https://neutrinoapi.com/"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{apiKey:this.options.apiKey,userId:this.options.userId,address:t.split(/\s+/).join(".")});h(this.options.serviceUrl+"geocode-address",s,function(t){var s=[];if(t.locations){t.geometry=t.locations[0];var i=n.latLng(t.geometry.latitude,t.geometry.longitude),r=n.latLngBounds(i,i);s[0]={name:t.geometry.address,bbox:r,center:i}}e.call(o,s)})},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){var i=r(this.options,{apiKey:this.options.apiKey,userId:this.options.userId,latitude:t.lat,longitude:t.lng});h(this.options.serviceUrl+"geocode-reverse",i,function(e){var i=[];if(200==e.status.status&&e.found){var r=n.latLng(t.lat,t.lng),a=n.latLngBounds(r,r);i[0]={name:e.address,bbox:a,center:r}}o.call(s,i)})},t}(),C=function(){function t(t){this.options={serviceUrl:"https://nominatim.openstreetmap.org/",htmlTemplate:function(t){var e,o,n=t.address,s=[];return(n.road||n.building)&&s.push("{building} {road} {house_number}"),(n.city||n.town||n.village||n.hamlet)&&s.push('<span class="'+(s.length>0?"leaflet-control-geocoder-address-detail":"")+'">{postcode} {city} {town} {village} {hamlet}</span>'),(n.state||n.country)&&s.push('<span class="'+(s.length>0?"leaflet-control-geocoder-address-context":"")+'">{state} {country}</span>'),e=s.join("<br/>"),o=n,e.replace(/\{ *([\w_]+) *\}/g,function(t,e){var n,s=o[e];return void 0===s?s="":"function"==typeof s&&(s=s(o)),null==(n=s)?"":n?c.test(n=""+n)?n.replace(l,u):n:n+""})}},n.Util.setOptions(this,t||{})}var e=t.prototype;return e.geocode=function(t,e,o){var s=this,r=i(this.options,{q:t,limit:5,format:"json",addressdetails:1});h(this.options.serviceUrl+"search",r,function(t){for(var i=[],r=t.length-1;r>=0;r--){for(var a=t[r].boundingbox,l=0;l<4;l++)a[l]=+a[l];i[r]={icon:t[r].icon,name:t[r].display_name,html:s.options.htmlTemplate?s.options.htmlTemplate(t[r]):void 0,bbox:n.latLngBounds([a[0],a[2]],[a[1],a[3]]),center:n.latLng(t[r].lat,t[r].lon),properties:t[r]}}e.call(o,i)})},e.reverse=function(t,e,o,s){var i=this,a=r(this.options,{lat:t.lat,lon:t.lng,zoom:Math.round(Math.log(e/256)/Math.log(2)),addressdetails:1,format:"json"});h(this.options.serviceUrl+"reverse",a,function(t){var e=[];if(t&&t.lat&&t.lon){var r=n.latLng(t.lat,t.lon),a=n.latLngBounds(r,r);e.push({name:t.display_name,html:i.options.htmlTemplate?i.options.htmlTemplate(t):void 0,center:r,bbox:a,properties:t})}o.call(s,e)})},t}(),E=function(){function t(t){n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){try{var s=this.options.OpenLocationCode.decode(t),i={name:t,center:n.latLng(s.latitudeCenter,s.longitudeCenter),bbox:n.latLngBounds(n.latLng(s.latitudeLo,s.longitudeLo),n.latLng(s.latitudeHi,s.longitudeHi))};e.call(o,[i])}catch(t){console.warn(t),e.call(o,[])}},e.reverse=function(t,e,o,s){try{var i={name:this.options.OpenLocationCode.encode(t.lat,t.lng,this.options.codeLength),center:n.latLng(t.lat,t.lng),bbox:n.latLngBounds(n.latLng(t.lat,t.lng),n.latLng(t.lat,t.lng))};o.call(s,[i])}catch(t){console.warn(t),o.call(s,[])}},t}(),k=function(){function t(t){this.options={serviceUrl:"https://api.opencagedata.com/geocode/v1/json"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{key:this.options.apiKey,q:t});h(this.options.serviceUrl,s,function(t){var s=[];if(t.results&&t.results.length)for(var i=0;i<t.results.length;i++){var r,a=t.results[i],l=n.latLng(a.geometry);r=a.annotations&&a.annotations.bounds?n.latLngBounds(n.latLng(a.annotations.bounds.northeast),n.latLng(a.annotations.bounds.southwest)):n.latLngBounds(l,l),s.push({name:a.formatted,bbox:r,center:l})}e.call(o,s)})},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){var i=r(this.options,{key:this.options.apiKey,q:[t.lat,t.lng].join(",")});h(this.options.serviceUrl,i,function(t){var e=[];if(t.results&&t.results.length)for(var i=0;i<t.results.length;i++){var r,a=t.results[i],l=n.latLng(a.geometry);r=a.annotations&&a.annotations.bounds?n.latLngBounds(n.latLng(a.annotations.bounds.northeast),n.latLng(a.annotations.bounds.southwest)):n.latLngBounds(l,l),e.push({name:a.formatted,bbox:r,center:l})}o.call(s,e)})},t}(),D=function(){function t(t){this.options={serviceUrl:"https://api.geocode.earth/v1"},this._lastSuggest=0,n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var n=this,s=i(this.options,{api_key:this.options.apiKey,text:t});h(this.options.serviceUrl+"/search",s,function(t){e.call(o,n._parseResults(t,"bbox"))})},e.suggest=function(t,e,o){var n=this,s=i(this.options,{api_key:this.options.apiKey,text:t});h(this.options.serviceUrl+"/autocomplete",s,function(t){t.geocoding.timestamp>n._lastSuggest&&(n._lastSuggest=t.geocoding.timestamp,e.call(o,n._parseResults(t,"bbox")))})},e.reverse=function(t,e,o,n){var s=this,i=r(this.options,{api_key:this.options.apiKey,"point.lat":t.lat,"point.lon":t.lng});h(this.options.serviceUrl+"/reverse",i,function(t){o.call(n,s._parseResults(t,"bounds"))})},e._parseResults=function(t,e){var o=[];return n.geoJSON(t,{pointToLayer:function(t,e){return n.circleMarker(e)},onEachFeature:function(t,s){var i,r,a={};s.getBounds?r=(i=s.getBounds()).getCenter():s.feature.bbox?(r=s.getLatLng(),i=n.latLngBounds(n.GeoJSON.coordsToLatLng(s.feature.bbox.slice(0,2)),n.GeoJSON.coordsToLatLng(s.feature.bbox.slice(2,4)))):(r=s.getLatLng(),i=n.latLngBounds(r,r)),a.name=s.feature.properties.label,a.center=r,a[e]=i,a.properties=s.feature.properties,o.push(a)}}),o},t}();function R(t){return new D(t)}var B=D,S=R,O=D,K=R,T=function(t){function e(e){return t.call(this,n.Util.extend({serviceUrl:"https://api.openrouteservice.org/geocode"},e))||this}return s(e,t),e}(D),j=function(){function t(t){this.options={serviceUrl:"https://photon.komoot.io/api/",reverseUrl:"https://photon.komoot.io/reverse/",nameProperties:["name","street","suburb","hamlet","town","city","state","country"]},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){var s=i(this.options,{q:t});h(this.options.serviceUrl,s,n.Util.bind(function(t){e.call(o,this._decodeFeatures(t))},this))},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){var i=r(this.options,{lat:t.lat,lon:t.lng});h(this.options.reverseUrl,i,n.Util.bind(function(t){o.call(s,this._decodeFeatures(t))},this))},e._decodeFeatures=function(t){var e=[];if(t&&t.features)for(var o=0;o<t.features.length;o++){var s=t.features[o],i=s.geometry.coordinates,r=n.latLng(i[1],i[0]),a=s.properties.extent,l=a?n.latLngBounds([a[1],a[0]],[a[3],a[2]]):n.latLngBounds(r,r);e.push({name:this._decodeFeatureName(s),html:this.options.htmlTemplate?this.options.htmlTemplate(s):void 0,center:r,bbox:l,properties:s.properties})}return e},e._decodeFeatureName=function(t){return(this.options.nameProperties||[]).map(function(e){return t.properties[e]}).filter(function(t){return!!t}).join(", ")},t}(),N=function(){function t(t){this.options={serviceUrl:"https://api.what3words.com/v2/"},n.Util.setOptions(this,t)}var e=t.prototype;return e.geocode=function(t,e,o){h(this.options.serviceUrl+"forward",i(this.options,{key:this.options.apiKey,addr:t.split(/\s+/).join(".")}),function(t){var s=[];if(t.geometry){var i=n.latLng(t.geometry.lat,t.geometry.lng),r=n.latLngBounds(i,i);s[0]={name:t.words,bbox:r,center:i}}e.call(o,s)})},e.suggest=function(t,e,o){return this.geocode(t,e,o)},e.reverse=function(t,e,o,s){h(this.options.serviceUrl+"reverse",r(this.options,{key:this.options.apiKey,coords:[t.lat,t.lng].join(",")}),function(t){var e=[];if(200==t.status.status){var i=n.latLng(t.geometry.lat,t.geometry.lng),r=n.latLngBounds(i,i);e[0]={name:t.words,bbox:r,center:i}}o.call(s,e)})},t}(),M={__proto__:null,geocodingParams:i,reverseParams:r,ArcGis:f,arcgis:function(t){return new f(t)},Bing:v,bing:function(t){return new v(t)},Google:m,google:function(t){return new m(t)},HERE:_,HEREv2:b,here:function(t){return t.apiKey?new b(t):new _(t)},parseLatLng:y,LatLng:L,latLng:function(t){return new L(t)},Mapbox:x,mapbox:function(t){return new x(t)},MapQuest:U,mapQuest:function(t){return new U(t)},Neutrino:w,neutrino:function(t){return new w(t)},Nominatim:C,nominatim:function(t){return new C(t)},OpenLocationCode:E,openLocationCode:function(t){return new E(t)},OpenCage:k,opencage:function(t){return new k(t)},Pelias:D,pelias:R,GeocodeEarth:B,geocodeEarth:S,Mapzen:O,mapzen:K,Openrouteservice:T,openrouteservice:function(t){return new T(t)},Photon:j,photon:function(t){return new j(t)},What3Words:N,what3words:function(t){return new N(t)}},P=function(){};n.Util.extend(P.prototype,n.Control.prototype),n.Util.extend(P.prototype,n.Evented.prototype);var G=function(t){function e(e){var o;return(o=t.call(this,e)||this).options={showUniqueResult:!0,showResultIcons:!1,collapsed:!0,expand:"touch",position:"topright",placeholder:"Search...",errorMessage:"Nothing found.",iconLabel:"Initiate a new search",query:"",queryMinLength:1,suggestMinLength:3,suggestTimeout:250,defaultMarkGeocode:!0},o._requestCount=0,n.Util.setOptions(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),e),o.options.geocoder||(o.options.geocoder=new C),o}s(e,t);var o=e.prototype;return o.addThrobberClass=function(){n.DomUtil.addClass(this._container,"leaflet-control-geocoder-throbber")},o.removeThrobberClass=function(){n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-throbber")},o.onAdd=function(t){var e=this,o="leaflet-control-geocoder",s=n.DomUtil.create("div",o+" leaflet-bar"),i=n.DomUtil.create("button",o+"-icon",s),r=this._form=n.DomUtil.create("div",o+"-form",s);this._map=t,this._container=s,i.innerHTML="&nbsp;",i.type="button",i.setAttribute("aria-label",this.options.iconLabel);var a=this._input=n.DomUtil.create("input","",r);return a.type="text",a.value=this.options.query,a.placeholder=this.options.placeholder,n.DomEvent.disableClickPropagation(a),this._errorElement=n.DomUtil.create("div",o+"-form-no-error",s),this._errorElement.innerHTML=this.options.errorMessage,this._alts=n.DomUtil.create("ul",o+"-alternatives leaflet-control-geocoder-alternatives-minimized",s),n.DomEvent.disableClickPropagation(this._alts),n.DomEvent.addListener(a,"keydown",this._keydown,this),this.options.geocoder.suggest&&n.DomEvent.addListener(a,"input",this._change,this),n.DomEvent.addListener(a,"blur",function(){e.options.collapsed&&!e._preventBlurCollapse&&e._collapse(),e._preventBlurCollapse=!1}),this.options.collapsed?"click"===this.options.expand?n.DomEvent.addListener(s,"click",function(t){0===t.button&&2!==t.detail&&e._toggle()}):"touch"===this.options.expand?n.DomEvent.addListener(s,n.Browser.touch?"touchstart mousedown":"mousedown",function(t){e._toggle(),t.preventDefault(),t.stopPropagation()},this):(n.DomEvent.addListener(s,"mouseover",this._expand,this),n.DomEvent.addListener(s,"mouseout",this._collapse,this),this._map.on("movestart",this._collapse,this)):(this._expand(),n.DomEvent.addListener(s,n.Browser.touch?"touchstart":"click",function(){return e._geocode()})),this.options.defaultMarkGeocode&&this.on("markgeocode",this.markGeocode,this),this.on("startgeocode",this.addThrobberClass,this),this.on("finishgeocode",this.removeThrobberClass,this),this.on("startsuggest",this.addThrobberClass,this),this.on("finishsuggest",this.removeThrobberClass,this),n.DomEvent.disableClickPropagation(s),s},o.setQuery=function(t){return this._input.value=t,this},o._geocodeResult=function(t,e){if(!e&&this.options.showUniqueResult&&1===t.length)this._geocodeResultSelected(t[0]);else if(t.length>0){this._alts.innerHTML="",this._results=t,n.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),n.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-open");for(var o=0;o<t.length;o++)this._alts.appendChild(this._createAlt(t[o],o))}else n.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-error"),n.DomUtil.addClass(this._errorElement,"leaflet-control-geocoder-error")},o.markGeocode=function(t){var e=t.geocode;return this._map.fitBounds(e.bbox),this._geocodeMarker&&this._map.removeLayer(this._geocodeMarker),this._geocodeMarker=new n.Marker(e.center).bindPopup(e.html||e.name).addTo(this._map).openPopup(),this},o._geocode=function(t){var e=this,o=this._input.value;if(t||!(o.length<this.options.queryMinLength)){var n=++this._requestCount,s=function(s){n===e._requestCount&&(e.fire(t?"finishsuggest":"finishgeocode",{input:o,results:s}),e._geocodeResult(s,t))};this._lastGeocode=o,t||this._clearResults(),this.fire(t?"startsuggest":"startgeocode",{input:o}),t?this.options.geocoder.suggest(o,s):this.options.geocoder.geocode(o,s)}},o._geocodeResultSelected=function(t){this.fire("markgeocode",{geocode:t})},o._toggle=function(){n.DomUtil.hasClass(this._container,"leaflet-control-geocoder-expanded")?this._collapse():this._expand()},o._expand=function(){n.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select(),this.fire("expand")},o._collapse=function(){n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-expanded"),n.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),n.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error"),this._input.blur(),this.fire("collapse")},o._clearResults=function(){n.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,n.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),n.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error")},o._createAlt=function(t,e){var o=this,s=n.DomUtil.create("li",""),i=n.DomUtil.create("a","",s),r=this.options.showResultIcons&&t.icon?n.DomUtil.create("img","",i):null,a=t.html?void 0:document.createTextNode(t.name);return r&&(r.src=t.icon),s.setAttribute("data-result-index",String(e)),t.html?i.innerHTML=i.innerHTML+t.html:a&&i.appendChild(a),n.DomEvent.addListener(s,"mousedown touchstart",function(e){o._preventBlurCollapse=!0,n.DomEvent.stop(e),o._geocodeResultSelected(t),n.DomEvent.on(s,"click touchend",function(){o.options.collapsed?o._collapse():o._clearResults()})},this),s},o._keydown=function(t){var e=this,o=function(t){e._selection&&(n.DomUtil.removeClass(e._selection,"leaflet-control-geocoder-selected"),e._selection=e._selection[t>0?"nextSibling":"previousSibling"]),e._selection||(e._selection=e._alts[t>0?"firstChild":"lastChild"]),e._selection&&n.DomUtil.addClass(e._selection,"leaflet-control-geocoder-selected")};switch(t.keyCode){case 27:this.options.collapsed?this._collapse():this._clearResults();break;case 38:o(-1);break;case 40:o(1);break;case 13:if(this._selection){var s=parseInt(this._selection.getAttribute("data-result-index"),10);this._geocodeResultSelected(this._results[s]),this._clearResults()}else this._geocode();break;default:return}n.DomEvent.preventDefault(t)},o._change=function(){var t=this,e=this._input.value;e!==this._lastGeocode&&(clearTimeout(this._suggestTimeout),e.length>=this.options.suggestMinLength?this._suggestTimeout=setTimeout(function(){return t._geocode(!0)},this.options.suggestTimeout):this._clearResults())},e}(P);function q(t){return new G(t)}return n.Util.extend(G,M),n.Util.extend(n.Control,{Geocoder:G,geocoder:q}),t.Geocoder=G,t.default=G,t.geocoder=q,t.geocoders=M,t}({},L); //# sourceMappingURL=Control.Geocoder.min.js.map