2020-12-18 11:01:28 +01:00
|
|
|
this.L=this.L||{},this.L.Control=this.L.Control||{},this.L.Control.Geocoder=function(d){"use strict";d=d&&d.hasOwnProperty("default")?d.default:d;var r=0,s=/[&<>"'`]/g,n=/[&<>"'`]/,t={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};function i(e){return t[e]}function o(e,t,o,s,n){var i="_l_geocoder_"+r++;t[n||"callback"]=i,window[i]=d.Util.bind(o,s);s=document.createElement("script");s.type="text/javascript",s.src=e+l(t),s.id=i,document.getElementsByTagName("head")[0].appendChild(s)}function u(e,t,o){var s=new XMLHttpRequest;s.onreadystatechange=function(){if(4===s.readyState){var t;if(200!==s.status&&304!==s.status)t="";else if("string"==typeof s.response)try{t=JSON.parse(s.response)}catch(e){t=s.response}else t=s.response;o(t)}},s.open("GET",e+l(t),!0),s.responseType="json",s.setRequestHeader("Accept","application/json"),s.send(null)}function a(e,o){return e.replace(/\{ *([\w_]+) *\}/g,function(e,t){t=o[t];return void 0===t?t="":"function"==typeof t&&(t=t(o)),null==(t=t)?"":t?(t=""+t,n.test(t)?t.replace(s,i):t):t+""})}function l(e,t,o){var s,n=[];for(s in e){var i=encodeURIComponent(o?s.toUpperCase():s),r=e[s];if(d.Util.isArray(r))for(var a=0;a<r.length;a++)n.push(i+"="+encodeURIComponent(r[a]));else n.push(i+"="+encodeURIComponent(r))}return(t&&-1!==t.indexOf("?")?"&":"?")+n.join("&")}var c=d.Class.extend({options:{service_url:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"},initialize:function(e,t){d.setOptions(this,t),this._accessToken=e},geocode:function(e,r,a){e={SingleLine:e,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"};this._key&&this._key.length&&(e.token=this._key),u(this.options.service_url+"/findAddressCandidates",d.extend(e,this.options.geocodingQueryParams),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=d.latLng(t.location.y,t.location.x),s=d.latLngBounds(d.latLng(t.extent.ymax,t.extent.xmax),d.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){e={location:encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat),distance:100,f:"json"};u(this.options.service_url+"/reverseGeocode",e,function(e){var t,o=[];e&&!e.error&&(t=d.latLng(e.location.y,e.location.x),o.push({name:e.address.Match_addr,center:t,bounds:d.latLngBounds(t,t)})),s.call(n,o)})}});var h=d.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:d.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:d.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:d.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:d.latLng(s.point.coordinates)}}i.call(r,t)},this,"jsonp")}});var p=d.Class.extend({options:{serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){this._key=e,d.setOptions(this,t),this.options.serviceUrl=this.options.service_url||this.options.serviceUrl},geocode:function(e,r,a){e={address:e};this._key&&this._key.length&&(e.key=this._key),e=d.Util.extend(e,this.options.geocodingQueryParams),u(this.options.serviceUrl,e,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=d.latLng(t.geometry.location),s=d.latLngBounds(d.latLng(t.geometry.viewport.northeast),d.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){e={latlng:encodeURIComponent(e.lat)+","+encodeURICo
|