/*!
* ol-geocoder - v3.2.0
* A geocoder extension for OpenLayers.
* https://github.com/jonataswalker/ol-geocoder
* Built: Sat Jul 28 2018 15:24:01 GMT-0300 (Brasilia Standard Time)
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("ol/layer/Vector"),require("ol/source/Vector"),require("ol/geom/Point"),require("ol/Feature"),require("ol/proj"),require("ol/control/Control"),require("ol/style/Style"),require("ol/style/Icon")):"function"==typeof define&&define.amd?define(["ol/layer/Vector","ol/source/Vector","ol/geom/Point","ol/Feature","ol/proj","ol/control/Control","ol/style/Style","ol/style/Icon"],t):e.Geocoder=t(e.ol.layer.Vector,e.ol.source.Vector,e.ol.geom.Point,e.ol.Feature,e.ol.proj,e.ol.control.Control,e.ol.style.Style,e.ol.style.Icon)}(this,function(r,o,e,t,c,s,n,a){"use strict";function i(e,t){if(void 0===t&&(t="Assertion failed"),!e){if("undefined"!=typeof Error)throw new Error(t);throw t}}function l(e){return/^\d+$/.test(e)}function u(t,s,n){if(Array.isArray(t))t.forEach(function(e){return u(e,s)});else{var r=Array.isArray(s)?s:s.split(/\s+/);let e=r.length;for(;e--;)d(t,r[e])||y(t,r[e],n)}}function p(t,s,n){if(Array.isArray(t))t.forEach(function(e){return p(e,s,n)});else{var r=Array.isArray(s)?s:s.split(/\s+/);let e=r.length;for(;e--;)d(t,r[e])&&f(t,r[e],n)}}function d(e,t){return e.classList?e.classList.contains(t):g(t).test(e.className)}function h(e,t,s){void 0===t&&(t=window.document);let n=Array.prototype.slice,r=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(e))switch(e[0]){case"#":r=[(o="#"===(o=e.substr(1))[0]?o.substr(1,o.length):o,document.getElementById(o))];break;case".":r=n.call(t.getElementsByClassName(e.substr(1).replace(/\./g," ")));break;default:r=n.call(t.getElementsByTagName(e))}else r=n.call(t.querySelectorAll(e));var o;return s?r:r[0]}function m(e,t){let s;if(Array.isArray(e)){if(s=document.createElement(e[0]),e[1].id&&(s.id=e[1].id),e[1].classname&&(s.className=e[1].classname),e[1].attr){var n=e[1].attr;if(Array.isArray(n)){let e=-1;for(;++e<n.length;)s.setAttribute(n[e].name,n[e].value)}else s.setAttribute(n.name,n.value)}}else s=document.createElement(e);s.innerHTML=t;let r=document.createDocumentFragment();for(;s.childNodes[0];)r.appendChild(s.childNodes[0]);return s.appendChild(r),s}function g(e){return new RegExp("(^|\\s+) "+e+" (\\s+|$)")}function y(e,t,s){e.classList?e.classList.add(t):e.className=(e.className+" "+t).trim(),s&&l(s)&&window.setTimeout(function(){return f(e,t)},s)}function f(e,t,s){e.classList?e.classList.remove(t):e.className=e.className.replace(g(t)," ").trim(),s&&l(s)&&window.setTimeout(function(){return y(e,t)},s)}r=r&&r.hasOwnProperty("default")?r.default:r,o=o&&o.hasOwnProperty("default")?o.default:o,e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t,c=c&&c.hasOwnProperty("default")?c.default:c,s=s&&s.hasOwnProperty("default")?s.default:s,n=n&&n.hasOwnProperty("default")?n.default:n,a=a&&a.hasOwnProperty("default")?a.default:a;e={namespace:"ol-geocoder",spin:"gcd-pseudo-rotate",hidden:"gcd-hidden",address:"gcd-address",country:"gcd-country",city:"gcd-city",road:"gcd-road",olControl:"ol-control",glass:{container:"gcd-gl-container",control:"gcd-gl-control",button:"gcd-gl-btn",input:"gcd-gl-input",expanded:"gcd-gl-expanded",reset:"gcd-gl-reset",result:"gcd-gl-result"},inputText:{container:"gcd-txt-container",control:"gcd-txt-control",input:"form-control",reset:"gcd-txt-reset",icon:"gcd-txt-glass",result:"gcd-txt-result"}},t={containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:e};const v=Object.freeze({containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:e,default:t}),b="addresschosen",w={NOMINATIM:"nominatim",REVERSE:"reverse"},k="glass-button",C="//cdn.rawgit.com/jonataswalker/map-utils/master/images/marker.png",x="osm",E="mapquest",P="photon",R="bing",q="opencage",N="pelias",T={provider:x,placeholder:"Search for an address",featureStyle:null,targetType:k,lang:"en-US",limit:5,keepOpen:!1,preventDefault:!1,autoComplete:!1,autoCompleteMinLength:2,debug:!1},I=v.cssClasses;var L=function(e){this.options=e.options,this.els=this.createControl()};L.prototype.createControl=function(){let e,t,s;return s="text-input"===this.options.targetType?(t=I.namespace+" "+I.inputText.container,{container:e=m(["div",{id:v.containerId,classname:t}],L.input),control:h("."+I.inputText.control,e),input:h("."+I.inputText.input,e),reset:h("."+I.inputText.reset,e),result:h("."+I.inputText.result,e)}):(t=I.namespace+" "+I.glass.container,{container:e=m(["div",{id:v.containerId,classname:t}],L.glass),control:h("."+I.glass.control,e),button:h("."+I.glass.button,e),input:h("."+I.glass.input,e),reset:h("."+I.glass.reset,e),result:h("."+I.glass.result,e)}),s.input.placeholder=this.options.placeholder,s},L.glass=['<div class="',I.glass.control," ",I.olControl,'">','<button type="button"',' id="',v.buttonControlId,'"',' class="',I.glass.button,'"></button>','<input type="text"',' id="',v.inputQueryId,'"',' class="',I.glass.input,'"',' autocomplete="off" placeholder="Search ...">',"<a",' id="',v.inputResetId,'"',' class="',I.glass.reset," ",I.hidden,'"',"></a>","</div>",'<ul class="',I.glass.result,'"></ul>'].join(""),L.input=['<div class="',I.inputText.control,'">','<input type="text"',' id="',v.inputQueryId,'"',' class="',I.inputText.input,' pr-5 pl-5"',' autocomplete="off" placeholder="Search ...">','<span class="',I.inputText.icon,'"></span>','<button type="button"',' id="',v.inputResetId,'"',' class="',I.inputText.reset," ",I.hidden,'"',"></button>","</div>",'<ul class="',I.inputText.result,'"></ul>'].join("");function S(){this.settings={url:"https://photon.komoot.de/api/",params:{q:"",limit:10,lang:"en"},langs:["de","it","fr","en"]}}S.prototype.getParameters=function(e){return e.lang=e.lang.toLowerCase(),{url:this.settings.url,params:{q:e.query,limit:e.limit||this.settings.params.limit,lang:(-1<this.settings.langs.indexOf(e.lang)?e:this.settings.params).lang}}},S.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.geometry.coordinates[0],lat:e.geometry.coordinates[1],address:{name:e.properties.name,postcode:e.properties.postcode,city:e.properties.city,state:e.properties.state,country:e.properties.country},original:{formatted:e.properties.name,details:e.properties}}})};function j(){this.settings={url:"https://nominatim.openstreetmap.org/search",params:{q:"",format:"json",addressdetails:1,limit:10,countrycodes:"","accept-language":"en-US"}}}j.prototype.getParameters=function(e){return{url:this.settings.url,params:{q:e.query,format:this.settings.params.format,addressdetails:this.settings.params.addressdetails,limit:e.limit||this.settings.params.limit,countrycodes:e.countrycodes||this.settings.params.countrycodes,"accept-language":e.lang||this.settings.params["accept-language"]}}},j.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.lon,lat:e.lat,address:{name:e.display_name,road:e.address.road||"",houseNumber:e.address.house_number||"",postcode:e.address.postcode,city:e.address.city||e.address.town,state:e.address.state,country:e.address.country},original:{formatted:e.display_name,details:e.address}}})};function O(){this.settings={url:"http://open.mapquestapi.com/nominatim/v1/search.php",params:{q:"",key:"",format:"json",addressdetails:1,limit:10,countrycodes:"","accept-language":"en-US"}}}O.prototype.getParameters=function(e){return{url:this.settings.url,params:{q:e.query,key:e.key,format:"json",addressdetails:1,limit:e.limit||this.settings.params.limit,countrycodes:e.countrycodes||this.settings.params.countrycodes,"accept-language":e.lang||this.settings.params["accept-language"]}}},O.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.lon,lat:e.lat,address:{name:e.address.neighbourhood||"",road:e.address.road||"",postcode:e.address.postcode,city:e.address.city||e.address.town,state:e.address.state,country:e.address.country},original:{formatted:e.display_name,details:e.address}}})};function A(){this.settings={url:"http://search.mapzen.com/v1/search",params:{size:10}}}A.prototype.getParameters=function(e){return{url:this.settings.url,params:{text:e.query,api_key:e.key,size:e.limit||this.settings.params.size}}},A.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.geometry.coordinates[0],lat:e.geometry.coordinates[1],address:{name:e.properties.name,house_number:e.properties.housenumber,postcode:e.properties.postalcode,road:e.properties.street,city:e.properties.city,state:e.properties.region,country:e.properties.country},original:{formatted:e.properties.label,details:e.properties}}})};function M(){this.settings={url:"https://dev.virtualearth.net/REST/v1/Locations",callbackName:"jsonp",params:{query:"",key:"",includeNeighborhood:0,maxResults:10}}}M.prototype.getParameters=function(e){return{url:this.settings.url,callbackName:this.settings.callbackName,params:{query:e.query,key:e.key,includeNeighborhood:e.includeNeighborhood||this.settings.params.includeNeighborhood,maxResults:e.maxResults||this.settings.params.maxResults}}},M.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.point.coordinates[1],lat:e.point.coordinates[0],address:{name:e.name},original:{formatted:e.address.formattedAddress,details:e.address}}})};function _(){this.settings={url:"https://api.opencagedata.com/geocode/v1/json?",params:{q:"",key:"",limit:10,countrycode:"",pretty:1,no_annotations:1}}}_.prototype.getParameters=function(e){return{url:this.settings.url,params:{q:e.query,key:e.key,limit:e.limit||this.settings.params.limit,countrycode:e.countrycodes||this.settings.params.countrycodes}}},_.prototype.handleResponse=function(e){return e.map(function(e){return{lon:e.geometry.lng,lat:e.geometry.lat,address:{name:e.components.house_number||"",road:e.components.road||"",postcode:e.components.postcode,city:e.components.city||e.components.town,state:e.components.state,country:e.components.country},original:{formatted:e.formatted,details:e.components}}})};const B=v.cssClasses;var V,D=function(e,t){var s,n;this.Base=e,this.layerName=(s="geocoder-layer-",n=function(){if("performance"in window==0&&(window.performance={}),Date.now=Date.now||function(){return(new Date).getTime()},"now"in window.performance==0){let e=Date.now();performance.timing&&performance.timing.navigationStart&&(e=performance.timing.navigationStart),window.performance.now=function(){return Date.now()-e}}return window.performance.now()}().toString(36),s+n),this.layer=new r({name:this.layerName,source:new o}),this.options=e.options,this.options.provider="string"==typeof this.options.provider?this.options.provider.toLowerCase():this.options.provider,this.els=t,this.lastQuery="",this.container=this.els.container,this.registeredListeners={mapClick:!1},this.setListeners(),this.Photon=new S,this.OpenStreet=new j,this.MapQuest=new O,this.Pelias=new A,this.Bing=new M,this.OpenCage=new _};return D.prototype.setListeners=function(){var s=this;let n,r;this.els.input.addEventListener("keypress",function(e){var t=e.target.value.trim();(e.key?"Enter"===e.key:e.which?13===e.which:e.keyCode&&13===e.keyCode)&&(e.preventDefault(),s.query(t))},!1),this.els.input.addEventListener("input",function(e){var t=e.target.value.trim();(t.length?p:u)(s.els.reset,B.hidden),s.options.autoComplete&&t!==r&&(r=t,n&&clearTimeout(n),n=setTimeout(function(){t.length>=s.options.autoCompleteMinLength&&s.query(t)},200))},!1),this.els.reset.addEventListener("click",function(e){s.els.input.focus(),s.els.input.value="",s.lastQuery="",u(s.els.reset,B.hidden),s.clearResults()},!1),this.options.targetType===k&&this.els.button.addEventListener("click",function(){d(s.els.control,B.glass.expanded)?s.collapse():s.expand()},!1)},D.prototype.query=function(t){var r,s=this,n=this.getProvider({query:t,provider:this.options.provider,key:this.options.key,lang:this.options.lang,countrycodes:this.options.countrycodes,limit:this.options.limit});if(this.lastQuery!==t||!this.els.result.firstChild){this.lastQuery=t,this.clearResults(),u(this.els.reset,B.spin);let e={url:n.url,data:n.params};n.callbackName&&(e.jsonp=!0,e.callbackName=n.callbackName),r=e,new Promise(function(e,t){var s,n,s=(s=r.url,(n=r.data)&&"object"==typeof n&&(s+=(/\?/.test(s)?"&":"?")+function s(n){return Object.keys(n).reduce(function(e,t){return e.push("object"==typeof n[t]?s(n[t]):encodeURIComponent(t)+"="+encodeURIComponent(n[t])),e},[]).join("&")}(n)),s);r.jsonp?function(e,t,s){let n=document.head,r=document.createElement("script"),o="f"+Math.round(Math.random()*Date.now());r.setAttribute("src",e+(0<e.indexOf("?")?"&":"?")+t+"="+o),window[o]=function(e){window[o]=void 0,setTimeout(function(){return n.removeChild(r)},0),s(e)},n.appendChild(r)}(s,r.callbackName,e):fetch(s,{method:"GET",mode:"cors",credentials:"same-origin"}).then(function(e){return e.json()}).then(e).catch(t)}).then(function(e){let t;switch(s.options.debug&&console.info(e),p(s.els.reset,B.spin),s.options.provider){case x:t=e.length?s.OpenStreet.handleResponse(e):void 0;break;case E:t=e.length?s.MapQuest.handleResponse(e):void 0;break;case N:t=e.features.length?s.Pelias.handleResponse(e.features):void 0;break;case P:t=e.features.length?s.Photon.handleResponse(e.features):void 0;break;case R:t=e.resourceSets[0].resources.length?s.Bing.handleResponse(e.resourceSets[0].resources):void 0;break;case q:t=e.results.length?s.OpenCage.handleResponse(e.results):void 0;break;default:t=s.options.provider.handleResponse(e)}t&&(s.createList(t),s.listenMapClick())}).catch(function(e){p(s.els.reset,B.spin)/*;var t='';s.els.result.appendChild(t)*/})}},D.prototype.createList=function(e){var n=this;const r=this.els.result;e.forEach(function(t){let s;s=n.options.provider===x?'<span class="'+B.road+'">'+t.address.name+"</span>":n.addressTemplate(t.address);const e=m("li",'<a href="#">'+s+"</a>");e.addEventListener("click",function(e){e.preventDefault(),n.chosen(t,s,t.address,t.original)},!1),r.appendChild(e)})},D.prototype.chosen=function(e,t,s,n){const r=this.Base.getMap(),o=[parseFloat(e.lon),parseFloat(e.lat)],a=r.getView().getProjection(),i=c.transform(o,"EPSG:4326",a);let l=e.bbox;l=l&&c.transformExtent(l,"EPSG:4326",a);s={formatted:t,details:s,original:n};if(!1===this.options.keepOpen&&this.clearResults(!0),!0===this.options.preventDefault)this.Base.dispatchEvent({type:b,address:s,coordinate:i,bbox:l});else{l?r.getView().fit(l,{duration:500}):(n=i,r.getView().animate({duration:500,resolution:2.388657133911758},{duration:500,center:n}));const e=this.createFeature(i,s);this.Base.dispatchEvent({type:b,address:s,feature:e,coordinate:i,bbox:l})}},D.prototype.createFeature=function(e){},D.prototype.addressTemplate=function(e){let t=[];return e.name&&t.push(['<span class="',B.road,'">{name}</span>'].join("")),(e.road||e.building||e.house_number)&&t.push(['<span class="',B.road,'">{building} {road} {house_number}</span>'].join("")),(e.city||e.town||e.village)&&t.push(['<span class="',B.city,'">{postcode} {city} {town} {village}</span>'].join("")),(e.state||e.country)&&t.push(['<span class="',B.country,'">{state} {country}</span>'].join("")),s=t.join("<br>"),n=e,s.replace(/\{ *([\w_-]+) *\}/g,function(e,t){t=void 0===n[t]?"":n[t];return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")});var s,n},D.prototype.getProvider=function(e){let t;switch(e.provider){case x:t=this.OpenStreet.getParameters(e);break;case E:t=this.MapQuest.getParameters(e);break;case P:t=this.Photon.getParameters(e);break;case N:t=this.Pelias.getParameters(e);break;case R:t=this.Bing.getParameters(e);break;case q:t=this.OpenCage.getParameters(e);break;default:t="osm"}return t},D.prototype.expand=function(){var e=this;p(this.els.input,B.spin),u(this.els.control,B.glass.expanded),window.setTimeout(function(){return e.els.input.focus()},100),this.listenMapClick()},D.prototype.collapse=function(){this.els.input.value="",this.els.input.blur(),u(this.els.reset,B.hidden),p(this.els.control,B.glass.expanded),this.clearResults()},D.prototype.listenMapClick=function(){if(!this.registeredListeners.mapClick){const t=this,s=this.Base.getMap().getTargetElement();this.registeredListeners.mapClick=!0,s.addEventListener("click",{handleEvent:function(e){t.clearResults(!0),s.removeEventListener(e.type,this,!1),t.registeredListeners.mapClick=!1}},!1)}},D.prototype.clearResults=function(e){e&&this.options.targetType===k?this.collapse():function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}(this.els.result)},D.prototype.getSource=function(){return this.layer.getSource()},D.prototype.addLayer=function(){var t=this;let s=!1;const e=this.Base.getMap();e.getLayers().forEach(function(e){e===t.layer&&(s=!0)}),s||e.addLayer(this.layer)},(V=s)&&(Q.__proto__=V),((Q.prototype=Object.create(V&&V.prototype)).constructor=Q).prototype.getLayer=function(){return this.layer},Q.prototype.getSource=function(){return this.getLayer().getSource()},Q.prototype.setProvider=function(e){this.options.provider=e},Q.prototype.setProviderKey=function(e){this.options.key=e},Q;function Q(e,t){if(void 0===e&&(e=w.NOMINATIM),void 0===t&&(t={}),!(this instanceof Q))return new Q;let s;i("string"==typeof e,"@param `type` should be string!"),i(e===w.NOMINATIM||e===w.REVERSE,"@param 'type' should be '"+w.NOMINATIM+"'\n or '"+w.REVERSE+"'!"),i("object"==typeof t,"@param `options` should be object!"),T.featureStyle=[new n({image:new a({scale:.7,src:C})})],this.options=function(e,t){let s={};for(var n in e)s[n]=e[n];for(var r in t)s[r]=t[r];return s}(T,t),this.container=void 0;t=new L(this);e===w.NOMINATIM&&(this.container=t.els.container,s=new D(this,t.els),this.layer=s.layer),V.call(this,{element:this.container})}});
|