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

1 line
19 KiB
JavaScript
Raw Normal View History

2018-08-23 15:45:06 +02:00
this.L=this.L||{},this.L.Control=this.L.Control||{},this.L.Control.Geocoder=function(e){"use strict";function t(e){return c[e]}function o(e){return null==e?"":e?(e=""+e,l.test(e)?e.replace(a,t):e):e+""}function s(t,o,s,n,i){var a="_l_geocoder_"+r++;o[i||"callback"]=a,window[a]=e.Util.bind(s,n);var l=document.createElement("script");l.type="text/javascript",l.src=t+e.Util.getParamString(o),l.id=a,document.getElementsByTagName("head")[0].appendChild(l)}function n(t,o,s){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState)return 200!==n.status&&304!==n.status?void s(""):void s(JSON.parse(n.response))},n.open("GET",t+e.Util.getParamString(o),!0),n.setRequestHeader("Accept","application/json"),n.send(null)}function i(e,t){return e.replace(/\{ *([\w_]+) *\}/g,function(e,s){var n=t[s];return void 0===n?n="":"function"==typeof n&&(n=n(t)),o(n)})}e=e&&e.hasOwnProperty("default")?e.default:e;var r=0,a=/[&<>"'`]/g,l=/[&<>"'`]/,c={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},d={class:e.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="'+(o.length>0?"leaflet-control-geocoder-address-detail":"")+'">{postcode} {city} {town} {village} {hamlet}</span>'),(t.state||t.country)&&o.push('<span class="'+(o.length>0?"leaflet-control-geocoder-address-context":"")+'">{state} {country}</span>'),i(o.join("<br/>"),t)}},initialize:function(t){e.Util.setOptions(this,t)},geocode:function(t,o,s){n(this.options.serviceUrl+"search",e.extend({q:t,limit:5,format:"json",addressdetails:1},this.options.geocodingQueryParams),e.bind(function(t){for(var n=[],i=t.length-1;i>=0;i--){for(var r=t[i].boundingbox,a=0;a<4;a++)r[a]=parseFloat(r[a]);n[i]={icon:t[i].icon,name:t[i].display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(t[i]):void 0,bbox:e.latLngBounds([r[0],r[2]],[r[1],r[3]]),center:e.latLng(t[i].lat,t[i].lon),properties:t[i]}}o.call(s,n)},this))},reverse:function(t,o,s,i){n(this.options.serviceUrl+"reverse",e.extend({lat:t.lat,lon:t.lng,zoom:Math.round(Math.log(o/256)/Math.log(2)),addressdetails:1,format:"json"},this.options.reverseQueryParams),e.bind(function(t){var o,n=[];t&&t.lat&&t.lon&&(o=e.latLng(t.lat,t.lon),n.push({name:t.display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(t):void 0,center:o,bounds:e.latLngBounds(o,o),properties:t})),s.call(i,n)},this))}}),factory:function(t){return new e.Control.Geocoder.Nominatim(t)}},u={class:e.Control.extend({options:{showResultIcons:!1,collapsed:!0,expand:"touch",position:"topright",placeholder:"Search...",errorMessage:"Nothing found.",suggestMinLength:3,suggestTimeout:250,defaultMarkGeocode:!0},includes:e.Evented.prototype||e.Mixin.Events,initialize:function(t){e.Util.setOptions(this,t),this.options.geocoder||(this.options.geocoder=new d.class),this._requestCount=0},onAdd:function(t){var o,s="leaflet-control-geocoder",n=e.DomUtil.create("div",s+" leaflet-bar"),i=e.DomUtil.create("button",s+"-icon",n),r=this._form=e.DomUtil.create("div",s+"-form",n);return this._map=t,this._container=n,i.innerHTML="&nbsp;",i.type="button",o=this._input=e.DomUtil.create("input","",r),o.type="text",o.placeholder=this.options.placeholder,this._errorElement=e.DomUtil.create("div",s+"-form-no-error",n),this._errorElement.innerHTML=this.options.errorMessage,this._alts=e.DomUtil.create("ul",s+"-alternatives leaflet-control-geocoder-alternatives-minimized",n),e.DomEvent.disableClickPropagation(this._alts),e.DomEvent.addListener(o,"keydown",this._keydown,this),this.options.geocoder.suggest&&e.DomEvent.addListener(o,"input",this._change,this),e.DomEvent.addListener(o,"blur",function(){this.options.collapsed&&!this._preventBlurCollapse&&this._collapse(),this._preventBlurCollapse=!1},this),this.options.collapsed?"click"===this.options.expand?e.DomEvent.addListener(n,"click",function(e){0===e.button&&2!==e.detai