Files
contao-leaflet-libraries/assets/control-geocoder/Control.Geocoder.min.js

1 line
19 KiB
JavaScript
Raw Normal View History

2018-08-23 16:02:27 +02:00
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={"&":"&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.Browse