]> git.ipfire.org Git - ipfire.org.git/blame - src/static/js/Control.Geocoder.min.js
location: Bring back map
[ipfire.org.git] / src / static / js / Control.Geocoder.min.js
CommitLineData
cf503f2b 1this.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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"};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('<span class="'+(0<o.length?"leaflet-control-geocoder-address-detail":"")+'">{postcode} {city} {town} {village} {hamlet}</span>'),(t.state||t.country)&&o.push('<span class="'+(0<o.length?"leaflet-control-geocoder-address-context":"")+'">{state} {country}</span>'),s(o.join("<br/>"),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="&nbsp;",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<e.length){this._alts.innerHTML="",this._results=e,l.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized");for(var o=0;o<e.length;o++)this._alts.appendChild(this._createAlt(e[o],o))}else l.DomUtil.addClass(this._errorElement,"leaflet-control-geocoder-error");else this._geocodeResultSelected(e[0])},markGeocode:function(e){return e=e.geocode||e,this._map.fitBounds(e.bbox),this._geocodeMarker&&this._map.removeLayer(this._geocodeMarker),this._geocodeMarker=new l.Marker(e.center).bindPopup(e.html||e.name).addTo(this._map).openPopup(),this},_geocode:function(t){var o=++this._requestCount,s=t?"suggest":"geocode",n={input:this._input.value};this._lastGeocode=this._input.value,t||this._clearResults(),this.fire("start"+s,n),this.options.geocoder[s](this._input.value,function(e){o===this._requestCount&&(n.results=e,this.fire("finish"+s,n),this._geocodeResult(e,t))},this)},_geocodeResultSelected:function(e){this.fire("markgeocode",{geocode:e})},_toggle:function(){l.DomUtil.hasClass(this._container,"leaflet-control-geocoder-expanded")?this._collapse():this._expand()},_expand:function(){l.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select(),this.fire("expand")},_collapse:function(){l.DomUtil.removeClass(this._container,"leaflet-control-geocoder-expanded"),l.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),l.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),this._input.blur(),this.fire("collapse")},_clearResults:function(){l.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,l.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error")},_createAlt:function(t,e){var o=l.DomUtil.create("li",""),s=l.DomUtil.create("a","",o),n=this.options.showResultIcons&&t.icon?l.DomUtil.create("img","",s):null,i=t.html?void 0:document.createTextNode(t.name);return n&&(n.src=t.icon),o.setAttribute("data-result-index",e),t.html?s.innerHTML=s.innerHTML+t.html:s.appendChild(i),l.DomEvent.addListener(o,"mousedown touchstart",function(e){this._preventBlurCollapse=!0,l.DomEvent.stop(e),this._geocodeResultSelected(t),l.DomEvent.on(o,"click",function(){this.options.collapsed?this._collapse():this._clearResults()},this)},this),o},_keydown:function(e){var t=this,o=function(e){t._selection&&(l.DomUtil.removeClass(t._selection,"leaflet-control-geocoder-selected"),t._selection=t._selection[0<e?"nextSibling":"previousSibling"]),t._selection||(t._selection=t._alts[0<e?"firstChild":"lastChild"]),t._selection&&l.DomUtil.addClass(t._selection,"leaflet-control-geocoder-selected")};switch(e.keyCode){case 27:this.options.collapsed&&this._collapse();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()}},_change:function(){var e=this._input.value;e!==this._lastGeocode&&(clearTimeout(this._suggestTimeout),e.length>=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(0<e.resourceSets.length)for(var o=e.resourceSets[0].resources.length-1;0<=o;o--){var s=e.resourceSets[0].resources[o],n=s.bbox;t[o]={name:s.name,bbox:l.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:l.latLng(s.point.coordinates)}}i.call(r,t)},this,"jsonp")},reverse:function(e,t,i,r){o("//dev.virtualearth.net/REST/v1/Locations/"+e.lat+","+e.lng,{key:this.key},function(e){for(var t=[],o=e.resourceSets[0].resources.length-1;0<=o;o--){var s=e.resourceSets[0].resources[o],n=s.bbox;t[o]={name:s.name,bbox:l.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:l.latLng(s.point.coordinates)}}i.call(r,t)},this,"jsonp")}}),factory:function(e){return new l.Control.Geocoder.Bing(e)}},h={class:l.Class.extend({options:{serviceUrl:"https://www.mapquestapi.com/geocoding/v1"},initialize:function(e,t){this._key=decodeURIComponent(e),l.Util.setOptions(this,t)},_formatName:function(){var e,t=[];for(e=0;e<arguments.length;e++)arguments[e]&&t.push(arguments[e]);return t.join(", ")},geocode:function(e,i,r){d(this.options.serviceUrl+"/address",{key:this._key,location:e,limit:5,outFormat:"json"},l.bind(function(e){var t,o,s=[];if(e.results&&e.results[0].locations)for(var n=e.results[0].locations.length-1;0<=n;n--)t=e.results[0].locations[n],o=l.latLng(t.latLng),s[n]={name:this._formatName(t.street,t.adminArea4,t.adminArea3,t.adminArea1),bbox:l.latLngBounds(o,o),center:o};i.call(r,s)},this))},reverse:function(e,t,i,r){d(this.options.serviceUrl+"/reverse",{key:this._key,location:e.lat+","+e.lng,outputFormat:"json"},l.bind(function(e){var t,o,s=[];if(e.results&&e.results[0].locations)for(var n=e.results[0].locations.length-1;0<=n;n--)t=e.results[0].locations[n],o=l.latLng(t.latLng),s[n]={name:this._formatName(t.street,t.adminArea4,t.adminArea3,t.adminArea1),bbox:l.latLngBounds(o,o),center:o};i.call(r,s)},this))}}),factory:function(e,t){return new l.Control.Geocoder.MapQuest(e,t)}},p={class:l.Class.extend({options:{serviceUrl:"https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){l.setOptions(this,t),this.options.geocodingQueryParams.access_token=e,this.options.reverseQueryParams.access_token=e},geocode:function(e,r,a){var t=this.options.geocodingQueryParams;void 0!==t.proximity&&t.proximity.hasOwnProperty("lat")&&t.proximity.hasOwnProperty("lng")&&(t.proximity=t.proximity.lng+","+t.proximity.lat),d(this.options.serviceUrl+encodeURIComponent(e)+".json",t,function(e){var t,o,s,n=[];if(e.features&&e.features.length)for(var i=0;i<=e.features.length-1;i++)t=e.features[i],o=l.latLng(t.center.reverse()),s=t.hasOwnProperty("bbox")?l.latLngBounds(l.latLng(t.bbox.slice(0,2).reverse()),l.latLng(t.bbox.slice(2,4).reverse())):l.latLngBounds(o,o),n[i]={name:t.place_name,bbox:s,center:o};r.call(a,n)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,r,a){d(this.options.serviceUrl+encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat)+".json",this.options.reverseQueryParams,function(e){var t,o,s,n=[];if(e.features&&e.features.length)for(var i=0;i<=e.features.length-1;i++)t=e.features[i],o=l.latLng(t.center.reverse()),s=t.hasOwnProperty("bbox")?l.latLngBounds(l.latLng(t.bbox.slice(0,2).reverse()),l.latLng(t.bbox.slice(2,4).reverse())):l.latLngBounds(o,o),n[i]={name:t.place_name,bbox:s,center:o};r.call(a,n)})}}),factory:function(e,t){return new l.Control.Geocoder.Mapbox(e,t)}},g={class:l.Class.extend({options:{serviceUrl:"https://api.what3words.com/v2/"},initialize:function(e){this._accessToken=e},geocode:function(e,n,i){d(this.options.serviceUrl+"forward",{key:this._accessToken,addr:e.split(/\s+/).join(".")},function(e){var t,o,s=[];e.hasOwnProperty("geometry")&&(t=l.latLng(e.geometry.lat,e.geometry.lng),o=l.latLngBounds(t,t),s[0]={name:e.words,bbox:o,center:t}),n.call(i,s)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,n,i){d(this.options.serviceUrl+"reverse",{key:this._accessToken,coords:[e.lat,e.lng].join(",")},function(e){var t,o,s=[];200==e.status.status&&(t=l.latLng(e.geometry.lat,e.geometry.lng),o=l.latLngBounds(t,t),s[0]={name:e.words,bbox:o,center:t}),n.call(i,s)})}}),factory:function(e){return new l.Control.Geocoder.What3Words(e)}},m={class:l.Class.extend({options:{serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){this._key=e,l.setOptions(this,t),this.options.serviceUrl=this.options.service_url||this.options.serviceUrl},geocode:function(e,r,a){var t={address:e};this._key&&this._key.length&&(t.key=this._key),t=l.Util.extend(t,this.options.geocodingQueryParams),d(this.options.serviceUrl,t,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<=e.results.length-1;i++)t=e.results[i],o=l.latLng(t.geometry.location),s=l.latLngBounds(l.latLng(t.geometry.viewport.northeast),l.latLng(t.geometry.viewport.southwest)),n[i]={name:t.formatted_address,bbox:s,center:o,properties:t.address_components};r.call(a,n)})},reverse:function(e,t,r,a){var o={latlng:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng)};o=l.Util.extend(o,this.options.reverseQueryParams),this._key&&this._key.length&&(o.key=this._key),d(this.options.serviceUrl,o,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<=e.results.length-1;i++)t=e.results[i],o=l.latLng(t.geometry.location),s=l.latLngBounds(l.latLng(t.geometry.viewport.northeast),l.latLng(t.geometry.viewport.southwest)),n[i]={name:t.formatted_address,bbox:s,center:o,properties:t.address_components};r.call(a,n)})}}),factory:function(e,t){return new l.Control.Geocoder.Google(e,t)}},f={class:l.Class.extend({options:{serviceUrl:"https://photon.komoot.de/api/",reverseUrl:"https://photon.komoot.de/reverse/",nameProperties:["name","street","suburb","hamlet","town","city","state","country"]},initialize:function(e){l.setOptions(this,e)},geocode:function(e,t,o){var s=l.extend({q:e},this.options.geocodingQueryParams);d(this.options.serviceUrl,s,l.bind(function(e){t.call(o,this._decodeFeatures(e))},this))},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,o,s){var n=l.extend({lat:e.lat,lon:e.lng},this.options.reverseQueryParams);d(this.options.reverseUrl,n,l.bind(function(e){o.call(s,this._decodeFeatures(e))},this))},_decodeFeatures:function(e){var t,o,s,n,i,r,a=[];if(e&&e.features)for(t=0;t<e.features.length;t++)s=(o=e.features[t]).geometry.coordinates,n=l.latLng(s[1],s[0]),r=(i=o.properties.extent)?l.latLngBounds([i[1],i[0]],[i[3],i[2]]):l.latLngBounds(n,n),a.push({name:this._deocodeFeatureName(o),html:this.options.htmlTemplate?this.options.htmlTemplate(o):void 0,center:n,bbox:r,properties:o.properties});return a},_deocodeFeatureName:function(e){var t,o;for(t=0;!o&&t<this.options.nameProperties.length;t++)o=e.properties[this.options.nameProperties[t]];return o}}),factory:function(e){return new l.Control.Geocoder.Photon(e)}},v={class:l.Class.extend({options:{serviceUrl:"https://search.mapzen.com/v1",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){l.Util.setOptions(this,t),this._apiKey=e,this._lastSuggest=0},geocode:function(e,t,o){var s=this;d(this.options.serviceUrl+"/search",l.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),function(e){t.call(o,s._parseResults(e,"bbox"))})},suggest:function(e,t,o){var s=this;d(this.options.serviceUrl+"/autocomplete",l.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),l.bind(function(e){e.geocoding.timestamp>this._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:"<insert your app_id here>",app_code:"<insert your app_code here>",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);