diff --git a/dist/ol-geocoder-debug.js b/dist/ol-geocoder-debug.js index 315035d..7585543 100644 --- a/dist/ol-geocoder-debug.js +++ b/dist/ol-geocoder-debug.js @@ -1,1225 +1,1217 @@ /*! - * ol-geocoder - v3.0.01 + * ol-geocoder - v3.1.0 * A geocoder extension for OpenLayers. * https://github.com/jonataswalker/ol-geocoder - * Built: Mon Nov 27 2017 17:57:30 GMT-0200 (-02) + * Built: Fri Apr 06 2018 09:18:51 GMT-0300 (-03) */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('openlayers')) : - typeof define === 'function' && define.amd ? define(['openlayers'], factory) : - (global.Geocoder = factory(global.ol)); -}(this, (function (ol) { 'use strict'; - -ol = ol && ol.hasOwnProperty('default') ? ol['default'] : ol; - -var containerId = "gcd-container"; -var buttonControlId = "gcd-button-control"; -var inputQueryId = "gcd-input-query"; -var inputResetId = "gcd-input-reset"; -var cssClasses = {"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":"gcd-txt-input","reset":"gcd-txt-reset","icon":"gcd-txt-glass","result":"gcd-txt-result"}}; -var vars = { - containerId: containerId, - buttonControlId: buttonControlId, - inputQueryId: inputQueryId, - inputResetId: inputResetId, - cssClasses: cssClasses -}; - -var _VARS_ = Object.freeze({ - containerId: containerId, - buttonControlId: buttonControlId, - inputQueryId: inputQueryId, - inputResetId: inputResetId, - cssClasses: cssClasses, - default: vars -}); - -const VARS = _VARS_; - -const EVENT_TYPE = { - ADDRESSCHOSEN: 'addresschosen' -}; - -const CONTROL_TYPE = { - NOMINATIM: 'nominatim', - REVERSE: 'reverse' -}; - -const TARGET_TYPE = { - GLASS: 'glass-button', - INPUT: 'text-input' -}; - - -const FEATURE_SRC = - '//cdn.rawgit.com/jonataswalker/map-utils/master/images/marker.png'; - -const PROVIDERS = { - OSM: 'osm', - MAPQUEST: 'mapquest', - GOOGLE: 'google', - PHOTON: 'photon', - BING: 'bing', - OPENCAGE: 'opencage', - PELIAS: 'pelias' -}; - -const DEFAULT_OPTIONS = { - provider: PROVIDERS.OSM, - placeholder: 'Search for an address', - featureStyle: null, - targetType: TARGET_TYPE.GLASS, - lang: 'en-US', - limit: 5, - keepOpen: false, - preventDefault: false, - autoComplete: false, - autoCompleteMinLength: 2, - debug: false -}; - -/** - * Overwrites obj1's values with obj2's and adds - * obj2's if non existent in obj1 - * @returns obj3 a new object based on obj1 and obj2 - */ -function mergeOptions(obj1, obj2) { - let obj3 = {}; - for (let attr1 in obj1) { obj3[attr1] = obj1[attr1]; } - for (let attr2 in obj2) { obj3[attr2] = obj2[attr2]; } - return obj3; -} - -function assert(condition, message) { - if ( message === void 0 ) message = 'Assertion failed'; - - if (!condition) { - if (typeof Error !== 'undefined') { throw new Error(message); } - throw message; // Fallback - } -} - -function now() { - // Polyfill for window.performance.now() - // @license http://opensource.org/licenses/MIT - // copyright Paul Irish 2015 - // https://gist.github.com/paulirish/5438650 - if ('performance' in window === false) { - window.performance = {}; - } + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(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')) : + typeof define === 'function' && 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'], factory) : + (global.Geocoder = factory(global.ol.layer.Vector,global.ol.source.Vector,global.ol.geom.Point,global.ol.Feature,global.ol.proj,global.ol.control.Control,global.ol.style.Style,global.ol.style.Icon)); +}(this, (function (LayerVector,SourceVector,Point,Feature,proj,Control,Style,Icon) { 'use strict'; + + LayerVector = LayerVector && LayerVector.hasOwnProperty('default') ? LayerVector['default'] : LayerVector; + SourceVector = SourceVector && SourceVector.hasOwnProperty('default') ? SourceVector['default'] : SourceVector; + Point = Point && Point.hasOwnProperty('default') ? Point['default'] : Point; + Feature = Feature && Feature.hasOwnProperty('default') ? Feature['default'] : Feature; + proj = proj && proj.hasOwnProperty('default') ? proj['default'] : proj; + Control = Control && Control.hasOwnProperty('default') ? Control['default'] : Control; + Style = Style && Style.hasOwnProperty('default') ? Style['default'] : Style; + Icon = Icon && Icon.hasOwnProperty('default') ? Icon['default'] : Icon; + + var containerId = "gcd-container"; + var buttonControlId = "gcd-button-control"; + var inputQueryId = "gcd-input-query"; + var inputResetId = "gcd-input-reset"; + var cssClasses = {"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":"gcd-txt-input","reset":"gcd-txt-reset","icon":"gcd-txt-glass","result":"gcd-txt-result"}}; + var vars = { + containerId: containerId, + buttonControlId: buttonControlId, + inputQueryId: inputQueryId, + inputResetId: inputResetId, + cssClasses: cssClasses + }; - Date.now = (Date.now || function () { // thanks IE8 - return new Date().getTime(); + var _VARS_ = /*#__PURE__*/Object.freeze({ + containerId: containerId, + buttonControlId: buttonControlId, + inputQueryId: inputQueryId, + inputResetId: inputResetId, + cssClasses: cssClasses, + default: vars }); - if ('now' in window.performance === false) { + const VARS = _VARS_; - let nowOffset = Date.now(); + const EVENT_TYPE = { + ADDRESSCHOSEN: 'addresschosen' + }; - if (performance.timing && performance.timing.navigationStart) { - nowOffset = performance.timing.navigationStart; - } + const CONTROL_TYPE = { + NOMINATIM: 'nominatim', + REVERSE: 'reverse' + }; - window.performance.now = function () { return Date.now() - nowOffset; }; - } + const TARGET_TYPE = { + GLASS: 'glass-button', + INPUT: 'text-input' + }; - return window.performance.now(); -} - -function flyTo(map, coord, duration, resolution) { - resolution = resolution || 2.388657133911758; - duration = duration || 500; - map.getView().animate( - { duration: duration, resolution: resolution }, - { duration: duration, center: coord } - ); -} - -function randomId(prefix) { - const id = now().toString(36); - return prefix ? prefix + id : id; -} - -function isNumeric(str) { - return /^\d+$/.test(str); -} - -/** - * @param {Element|Array} element DOM node or array of nodes. - * @param {String|Array} classname Class or array of classes. - * For example: 'class1 class2' or ['class1', 'class2'] - * @param {Number|undefined} timeout Timeout to remove a class. - */ -function addClass(element, classname, timeout) { - if (Array.isArray(element)) { - element.forEach(function (each) { return addClass(each, classname); }); - return; - } - const array = (Array.isArray(classname)) - ? classname - : classname.split(/\s+/); - let i = array.length; + const FEATURE_SRC = + '//cdn.rawgit.com/jonataswalker/map-utils/master/images/marker.png'; - while (i--) { - if (!hasClass(element, array[i])) { - _addClass(element, array[i], timeout); - } - } -} + const PROVIDERS = { + OSM: 'osm', + MAPQUEST: 'mapquest', + GOOGLE: 'google', + PHOTON: 'photon', + BING: 'bing', + OPENCAGE: 'opencage', + PELIAS: 'pelias' + }; -/** - * @param {Element|Array} element DOM node or array of nodes. - * @param {String|Array} classname Class or array of classes. - * For example: 'class1 class2' or ['class1', 'class2'] - * @param {Number|undefined} timeout Timeout to add a class. - */ -function removeClass(element, classname, timeout) { - if (Array.isArray(element)) { - element.forEach(function (each) { return removeClass(each, classname, timeout); }); - return; + const DEFAULT_OPTIONS = { + provider: PROVIDERS.OSM, + placeholder: 'Search for an address', + featureStyle: null, + targetType: TARGET_TYPE.GLASS, + lang: 'en-US', + limit: 5, + keepOpen: false, + preventDefault: false, + autoComplete: false, + autoCompleteMinLength: 2, + debug: false + }; + + /** + * Overwrites obj1's values with obj2's and adds + * obj2's if non existent in obj1 + * @returns obj3 a new object based on obj1 and obj2 + */ + function mergeOptions(obj1, obj2) { + let obj3 = {}; + for (let attr1 in obj1) { obj3[attr1] = obj1[attr1]; } + for (let attr2 in obj2) { obj3[attr2] = obj2[attr2]; } + return obj3; } - const array = (Array.isArray(classname)) - ? classname - : classname.split(/\s+/); - let i = array.length; + function assert(condition, message) { + if ( message === void 0 ) message = 'Assertion failed'; - while (i--) { - if (hasClass(element, array[i])) { - _removeClass(element, array[i], timeout); + if (!condition) { + if (typeof Error !== 'undefined') { throw new Error(message); } + throw message; // Fallback } } -} + function now() { + // Polyfill for window.performance.now() + // @license http://opensource.org/licenses/MIT + // copyright Paul Irish 2015 + // https://gist.github.com/paulirish/5438650 + if ('performance' in window === false) { + window.performance = {}; + } -/** - * @param {Element} element DOM node. - * @param {String} classname Classname. - * @return {Boolean} - */ -function hasClass(element, c) { - // use native if available - return element.classList - ? element.classList.contains(c) - : classRegex(c).test(element.className); -} - -/** - * @param {Element|Array} element DOM node or array of nodes. - * @param {String} classname Classe. - */ + Date.now = (Date.now || function () { // thanks IE8 + return new Date().getTime(); + }); + if ('now' in window.performance === false) { -/** - * Abstraction to querySelectorAll for increased - * performance and greater usability - * @param {String} selector - * @param {Element} context (optional) - * @param {Boolean} find_all (optional) - * @return (find_all) {Element} : {Array} - */ -function find(selector, context, find_all) { - if ( context === void 0 ) context = window.document; - - let simpleRe = /^(#?[\w-]+|\.[\w-.]+)$/, - periodRe = /\./g, - slice = Array.prototype.slice, - matches = []; - - // Redirect call to the more performant function - // if it's a simple selector and return an array - // for easier usage - if (simpleRe.test(selector)) { - switch (selector[0]) { - case '#': - matches = [$(selector.substr(1))]; - break; - case '.': - matches = slice.call(context.getElementsByClassName( - selector.substr(1).replace(periodRe, ' '))); - break; - default: - matches = slice.call(context.getElementsByTagName(selector)); + let nowOffset = Date.now(); + + if (performance.timing && performance.timing.navigationStart) { + nowOffset = performance.timing.navigationStart; + } + + window.performance.now = function () { return Date.now() - nowOffset; }; } - } else { - // If not a simple selector, query the DOM as usual - // and return an array for easier usage - matches = slice.call(context.querySelectorAll(selector)); + + return window.performance.now(); } - return (find_all) ? matches : matches[0]; -} + function flyTo(map, coord, duration, resolution) { + resolution = resolution || 2.388657133911758; + duration = duration || 500; + map.getView().animate( + { duration: duration, resolution: resolution }, + { duration: duration, center: coord } + ); + } -function $(id) { - id = (id[0] === '#') ? id.substr(1, id.length) : id; - return document.getElementById(id); -} + function randomId(prefix) { + const id = now().toString(36); + return prefix ? prefix + id : id; + } + function isNumeric(str) { + return /^\d+$/.test(str); + } + /** + * @param {Element|Array} element DOM node or array of nodes. + * @param {String|Array} classname Class or array of classes. + * For example: 'class1 class2' or ['class1', 'class2'] + * @param {Number|undefined} timeout Timeout to remove a class. + */ + function addClass(element, classname, timeout) { + if (Array.isArray(element)) { + element.forEach(function (each) { return addClass(each, classname); }); + return; + } + const array = (Array.isArray(classname)) + ? classname + : classname.split(/\s+/); + let i = array.length; + while (i--) { + if (!hasClass(element, array[i])) { + _addClass(element, array[i], timeout); + } + } + } -function removeAllChildren(node) { - while (node.firstChild) { node.removeChild(node.firstChild); } -} + /** + * @param {Element|Array} element DOM node or array of nodes. + * @param {String|Array} classname Class or array of classes. + * For example: 'class1 class2' or ['class1', 'class2'] + * @param {Number|undefined} timeout Timeout to add a class. + */ + function removeClass(element, classname, timeout) { + if (Array.isArray(element)) { + element.forEach(function (each) { return removeClass(each, classname, timeout); }); + return; + } + const array = (Array.isArray(classname)) + ? classname + : classname.split(/\s+/); + let i = array.length; + while (i--) { + if (hasClass(element, array[i])) { + _removeClass(element, array[i], timeout); + } + } + } + /** + * @param {Element} element DOM node. + * @param {String} classname Classname. + * @return {Boolean} + */ + function hasClass(element, c) { + // use native if available + return element.classList + ? element.classList.contains(c) + : classRegex(c).test(element.className); + } -function template(html, row) { - return html.replace(/\{ *([\w_-]+) *\}/g, function (htm, key) { - let value = (row[key] === undefined) ? '' : row[key]; - return htmlEscape(value); - }); -} - -function htmlEscape(str) { - return String(str) - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); -} - -function createElement(node, html) { - let elem; - if (Array.isArray(node)) { - elem = document.createElement(node[0]); - - if (node[1].id) { elem.id = node[1].id; } - if (node[1].classname) { elem.className = node[1].classname; } - - if (node[1].attr) { - let attr = node[1].attr; - if (Array.isArray(attr)) { - let i = -1; - while (++i < attr.length) { - elem.setAttribute(attr[i].name, attr[i].value); - } - } else { - elem.setAttribute(attr.name, attr.value); + /** + * Abstraction to querySelectorAll for increased + * performance and greater usability + * @param {String} selector + * @param {Element} context (optional) + * @param {Boolean} find_all (optional) + * @return (find_all) {Element} : {Array} + */ + function find(selector, context, find_all) { + if ( context === void 0 ) context = window.document; + + let simpleRe = /^(#?[\w-]+|\.[\w-.]+)$/, + periodRe = /\./g, + slice = Array.prototype.slice, + matches = []; + + // Redirect call to the more performant function + // if it's a simple selector and return an array + // for easier usage + if (simpleRe.test(selector)) { + switch (selector[0]) { + case '#': + matches = [$(selector.substr(1))]; + break; + case '.': + matches = slice.call(context.getElementsByClassName( + selector.substr(1).replace(periodRe, ' '))); + break; + default: + matches = slice.call(context.getElementsByTagName(selector)); } + } else { + // If not a simple selector, query the DOM as usual + // and return an array for easier usage + matches = slice.call(context.querySelectorAll(selector)); } - } else { - elem = document.createElement(node); + + return (find_all) ? matches : matches[0]; } - elem.innerHTML = html; - let frag = document.createDocumentFragment(); - - while (elem.childNodes[0]) { frag.appendChild(elem.childNodes[0]); } - elem.appendChild(frag); - return elem; -} - -function classRegex(classname) { - return new RegExp(("(^|\\s+) " + classname + " (\\s+|$)")); -} - -function _addClass(el, klass, timeout) { - // use native if available - if (el.classList) { - el.classList.add(klass); - } else { - el.className = (el.className + ' ' + klass).trim(); + + function $(id) { + id = (id[0] === '#') ? id.substr(1, id.length) : id; + return document.getElementById(id); } - if (timeout && isNumeric(timeout)) { - window.setTimeout(function () { return _removeClass(el, klass); }, timeout); + function removeAllChildren(node) { + while (node.firstChild) { node.removeChild(node.firstChild); } } -} -function _removeClass(el, klass, timeout) { - if (el.classList) { - el.classList.remove(klass); - } else { - el.className = (el.className.replace(classRegex(klass), ' ')).trim(); + function template(html, row) { + return html.replace(/\{ *([\w_-]+) *\}/g, function (htm, key) { + let value = (row[key] === undefined) ? '' : row[key]; + return htmlEscape(value); + }); } - if (timeout && isNumeric(timeout)) { - window.setTimeout(function () { return _addClass(el, klass); }, timeout); + + function htmlEscape(str) { + return String(str) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); } -} -const klasses = VARS.cssClasses; + function createElement(node, html) { + let elem; + if (Array.isArray(node)) { + elem = document.createElement(node[0]); + + if (node[1].id) { elem.id = node[1].id; } + if (node[1].classname) { elem.className = node[1].classname; } + + if (node[1].attr) { + let attr = node[1].attr; + if (Array.isArray(attr)) { + let i = -1; + while (++i < attr.length) { + elem.setAttribute(attr[i].name, attr[i].value); + } + } else { + elem.setAttribute(attr.name, attr.value); + } + } + } else { + elem = document.createElement(node); + } + elem.innerHTML = html; + let frag = document.createDocumentFragment(); -/** - * @class Html - */ -var Html = function Html(base) { - this.options = base.options; - this.els = this.createControl(); -}; - -Html.prototype.createControl = function createControl () { - let container, containerClass, elements; - - if (this.options.targetType === TARGET_TYPE.INPUT) { - containerClass = klasses.namespace + ' ' + klasses.inputText.container; - container = createElement( - ['div', { id: VARS.containerId, classname: containerClass }], - Html.input - ); - elements = { - container: container, - control: find('.' + klasses.inputText.control, container), - input: find('.' + klasses.inputText.input, container), - reset: find('.' + klasses.inputText.reset, container), - result: find('.' + klasses.inputText.result, container) - }; - } else { - containerClass = (klasses.namespace) + " " + (klasses.glass.container); - container = createElement( - ['div', { id: VARS.containerId, classname: containerClass }], - Html.glass - ); - elements = { - container: container, - control: find('.' + klasses.glass.control, container), - button: find('.' + klasses.glass.button, container), - input: find('.' + klasses.glass.input, container), - reset: find('.' + klasses.glass.reset, container), - result: find('.' + klasses.glass.result, container) - }; + while (elem.childNodes[0]) { frag.appendChild(elem.childNodes[0]); } + elem.appendChild(frag); + return elem; } - //set placeholder from options - elements.input.placeholder = this.options.placeholder; - return elements; -}; - -/* eslint-disable indent */ -Html.glass = [ - '
', - '', - '', - '', - '
', - '
    ' -].join(''); - -Html.input = [ - '
    ', - '', - '', - '', - '
    ', - '
      ' -].join(''); -/* eslint-enable indent */ - -/** - * @class Photon - */ -var Photon = function Photon() { - - this.settings = { - url: 'https://photon.komoot.de/api/', - params: { - q: '', - limit: 10, - lang: 'en' - }, - langs: ['de', 'it', 'fr', 'en'] - }; -}; - -Photon.prototype.getParameters = function getParameters (options) { - options.lang = options.lang.toLowerCase(); - - return { - url: this.settings.url, - params: { - q: options.query, - limit: options.limit || this.settings.params.limit, - lang: this.settings.langs.indexOf(options.lang) > -1 ? - options.lang : this.settings.params.lang + + function classRegex(classname) { + return new RegExp(("(^|\\s+) " + classname + " (\\s+|$)")); + } + + function _addClass(el, klass, timeout) { + // use native if available + if (el.classList) { + el.classList.add(klass); + } else { + el.className = (el.className + ' ' + klass).trim(); } - }; -}; - -Photon.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.geometry.coordinates[0], - lat: result.geometry.coordinates[1], - address: { - name: result.properties.name, - postcode: result.properties.postcode, - city: result.properties.city, - state: result.properties.state, - country: result.properties.country - }, - original: { - formatted: result.properties.name, - details: result.properties + + if (timeout && isNumeric(timeout)) { + window.setTimeout(function () { return _removeClass(el, klass); }, timeout); } - }); }); -}; + } -/** - * @class OpenStreet - */ -var OpenStreet = function OpenStreet() { - - this.settings = { - url: 'http://nominatim.openstreetmap.org/search/', - params: { - q: '', - format: 'json', - addressdetails: 1, - limit: 10, - countrycodes: '', - 'accept-language': 'en-US' + function _removeClass(el, klass, timeout) { + if (el.classList) { + el.classList.remove(klass); + } else { + el.className = (el.className.replace(classRegex(klass), ' ')).trim(); } - }; -}; - -OpenStreet.prototype.getParameters = function getParameters (opt) { - return { - url: this.settings.url, - params: { - q: opt.query, - format: this.settings.params.format, - addressdetails: this.settings.params.addressdetails, - limit: opt.limit || this.settings.params.limit, - countrycodes: opt.countrycodes || this.settings.params.countrycodes, - 'accept-language': opt.lang || this.settings.params['accept-language'] + if (timeout && isNumeric(timeout)) { + window.setTimeout(function () { return _addClass(el, klass); }, timeout); } + } + + const klasses = VARS.cssClasses; + + /** + * @class Html + */ + var Html = function Html(base) { + this.options = base.options; + this.els = this.createControl(); }; -}; - -OpenStreet.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.lon, - lat: result.lat, - address: { - name: result.display_name, - road: result.address.road || '', - houseNumber: result.address.house_number || '', - postcode: result.address.postcode, - city: result.address.city || result.address.town, - state: result.address.state, - country: result.address.country - }, - original: { - formatted: result.display_name, - details: result.address - } - }); }); -}; -/** - * @class MapQuest - */ -var MapQuest = function MapQuest() { - - 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' + Html.prototype.createControl = function createControl () { + let container, containerClass, elements; + + if (this.options.targetType === TARGET_TYPE.INPUT) { + containerClass = klasses.namespace + ' ' + klasses.inputText.container; + container = createElement( + ['div', { id: VARS.containerId, classname: containerClass }], + Html.input + ); + elements = { + container: container, + control: find('.' + klasses.inputText.control, container), + input: find('.' + klasses.inputText.input, container), + reset: find('.' + klasses.inputText.reset, container), + result: find('.' + klasses.inputText.result, container) + }; + } else { + containerClass = (klasses.namespace) + " " + (klasses.glass.container); + container = createElement( + ['div', { id: VARS.containerId, classname: containerClass }], + Html.glass + ); + elements = { + container: container, + control: find('.' + klasses.glass.control, container), + button: find('.' + klasses.glass.button, container), + input: find('.' + klasses.glass.input, container), + reset: find('.' + klasses.glass.reset, container), + result: find('.' + klasses.glass.result, container) + }; } + //set placeholder from options + elements.input.placeholder = this.options.placeholder; + return elements; }; -}; - -MapQuest.prototype.getParameters = function getParameters (options) { - return { - url: this.settings.url, - params: { - q: options.query, - key: options.key, - format: 'json', - addressdetails: 1, - limit: options.limit || this.settings.params.limit, - countrycodes: options.countrycodes || this.settings.params.countrycodes, - 'accept-language': - options.lang || this.settings.params['accept-language'] - } + + /* eslint-disable indent */ + Html.glass = [ + '
      ', + '', + '', + '', + '
      ', + '
        ' + ].join(''); + + Html.input = [ + '
        ', + '', + '', + '', + '
        ', + '
          ' + ].join(''); + /* eslint-enable indent */ + + /** + * @class Photon + */ + var Photon = function Photon() { + + this.settings = { + url: 'https://photon.komoot.de/api/', + params: { + q: '', + limit: 10, + lang: 'en' + }, + langs: ['de', 'it', 'fr', 'en'] + }; }; -}; - -MapQuest.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.lon, - lat: result.lat, - address: { - name: result.address.neighbourhood || '', - road: result.address.road || '', - postcode: result.address.postcode, - city: result.address.city || result.address.town, - state: result.address.state, - country: result.address.country - }, - original: { - formatted: result.display_name, - details: result.address - } - }); }); -}; -/** - * @class Pelias - */ -var Pelias = function Pelias() { + Photon.prototype.getParameters = function getParameters (options) { + options.lang = options.lang.toLowerCase(); - this.settings = { - url: 'http://search.mapzen.com/v1/search', - params: { - size: 10 - } + return { + url: this.settings.url, + params: { + q: options.query, + limit: options.limit || this.settings.params.limit, + lang: this.settings.langs.indexOf(options.lang) > -1 ? + options.lang : this.settings.params.lang + } + }; }; -}; - -Pelias.prototype.getParameters = function getParameters (options) { - return { - url: this.settings.url, - params: { - text: options.query, - api_key: options.key, - size: options.limit || this.settings.params.size - } + + Photon.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.geometry.coordinates[0], + lat: result.geometry.coordinates[1], + address: { + name: result.properties.name, + postcode: result.properties.postcode, + city: result.properties.city, + state: result.properties.state, + country: result.properties.country + }, + original: { + formatted: result.properties.name, + details: result.properties + } + }); }); }; -}; - -Pelias.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.geometry.coordinates[0], - lat: result.geometry.coordinates[1], - address: { - name: result.properties.name, - house_number: result.properties.housenumber, - postcode: result.properties.postalcode, - road: result.properties.street, - city: result.properties.city, - state: result.properties.region, - country: result.properties.country - }, - original: { - formatted: result.properties.label, - details: result.properties - } - }); }); -}; -/** - * @class Bing - */ -var Bing = function Bing() { - this.settings = { - url: 'https://dev.virtualearth.net/REST/v1/Locations', - callbackName: 'jsonp', - params: { - query: '', - key: '', - includeNeighborhood: 0, - maxResults: 10 - } + /** + * @class OpenStreet + */ + var OpenStreet = function OpenStreet() { + + this.settings = { + url: 'https://nominatim.openstreetmap.org/search/', + params: { + q: '', + format: 'json', + addressdetails: 1, + limit: 10, + countrycodes: '', + 'accept-language': 'en-US' + } + }; }; -}; - -Bing.prototype.getParameters = function getParameters (options) { - return { - url: this.settings.url, - callbackName: this.settings.callbackName, - params: { - query: options.query, - key: options.key, - includeNeighborhood: options.includeNeighborhood || - this.settings.params.includeNeighborhood, - maxResults: options.maxResults || this.settings.params.maxResults - } + + OpenStreet.prototype.getParameters = function getParameters (opt) { + return { + url: this.settings.url, + params: { + q: opt.query, + format: this.settings.params.format, + addressdetails: this.settings.params.addressdetails, + limit: opt.limit || this.settings.params.limit, + countrycodes: opt.countrycodes || this.settings.params.countrycodes, + 'accept-language': opt.lang || this.settings.params['accept-language'] + } + }; }; -}; - -Bing.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.point.coordinates[1], - lat: result.point.coordinates[0], - address: { - name: result.name - }, - original: { - formatted: result.address.formattedAddress, - details: result.address - } - }); }); -}; -/** - * @class OpenCage - */ -var OpenCage = function OpenCage() { - - this.settings = { - url: 'https://api.opencagedata.com/geocode/v1/json?', - params: { - q: '', - key: '', - limit: 10, - countrycode: '', - pretty: 1, - no_annotations: 1 - } + OpenStreet.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.lon, + lat: result.lat, + address: { + name: result.display_name, + road: result.address.road || '', + houseNumber: result.address.house_number || '', + postcode: result.address.postcode, + city: result.address.city || result.address.town, + state: result.address.state, + country: result.address.country + }, + original: { + formatted: result.display_name, + details: result.address + } + }); }); }; -}; - -OpenCage.prototype.getParameters = function getParameters (options) { - return { - url: this.settings.url, - params: { - q: options.query, - key: options.key, - limit: options.limit || this.settings.params.limit, - countrycode: options.countrycodes || this.settings.params.countrycodes - } + + /** + * @class MapQuest + */ + var MapQuest = function MapQuest() { + + 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' + } + }; }; -}; - -OpenCage.prototype.handleResponse = function handleResponse (results) { - return results.map(function (result) { return ({ - lon: result.geometry.lng, - lat: result.geometry.lat, - address: { - name: result.components.house_number || '', - road: result.components.road || '', - postcode: result.components.postcode, - city: result.components.city || result.components.town, - state: result.components.state, - country: result.components.country - }, - original: { - formatted: result.formatted, - details: result.components - } - }); }); -}; - -function json(obj) { - return new Promise(function (resolve, reject) { - const url = encodeUrlXhr(obj.url, obj.data); - const config = { - method: 'GET', - mode: 'cors', + + MapQuest.prototype.getParameters = function getParameters (options) { + return { + url: this.settings.url, + params: { + q: options.query, + key: options.key, + format: 'json', + addressdetails: 1, + limit: options.limit || this.settings.params.limit, + countrycodes: options.countrycodes || this.settings.params.countrycodes, + 'accept-language': + options.lang || this.settings.params['accept-language'] + } }; + }; - if (obj.jsonp) { - jsonp(url, obj.callbackName, resolve); - } else { - fetch(url, config) - .then(function (r) { return r.json(); }) - .then(resolve) - .catch(reject); - } + MapQuest.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.lon, + lat: result.lat, + address: { + name: result.address.neighbourhood || '', + road: result.address.road || '', + postcode: result.address.postcode, + city: result.address.city || result.address.town, + state: result.address.state, + country: result.address.country + }, + original: { + formatted: result.display_name, + details: result.address + } + }); }); + }; - }); -} + /** + * @class Pelias + */ + var Pelias = function Pelias() { + + this.settings = { + url: 'http://search.mapzen.com/v1/search', + params: { + size: 10 + } + }; + }; + Pelias.prototype.getParameters = function getParameters (options) { + return { + url: this.settings.url, + params: { + text: options.query, + api_key: options.key, + size: options.limit || this.settings.params.size + } + }; + }; -function toQueryString(obj) { - return Object.keys(obj).reduce(function (a, k) { - a.push( - typeof obj[k] === 'object' - ? toQueryString(obj[k]) - : ((encodeURIComponent(k)) + "=" + (encodeURIComponent(obj[k]))) - ); - return a; - }, []).join('&'); -} + Pelias.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.geometry.coordinates[0], + lat: result.geometry.coordinates[1], + address: { + name: result.properties.name, + house_number: result.properties.housenumber, + postcode: result.properties.postalcode, + road: result.properties.street, + city: result.properties.city, + state: result.properties.region, + country: result.properties.country + }, + original: { + formatted: result.properties.label, + details: result.properties + } + }); }); + }; -function encodeUrlXhr(url, data) { - if (data && typeof data === 'object') { - url += (/\?/.test(url) ? '&' : '?') + toQueryString(data); - } - return url; -} - -function jsonp(url, key, callback) { - // https://github.com/Fresheyeball/micro-jsonp/blob/master/src/jsonp.js - let head = document.head, - script = document.createElement('script'), - // generate minimally unique name for callback function - callbackName = 'f' + Math.round(Math.random() * Date.now()); - - // set request url - script.setAttribute('src', - /* add callback parameter to the url - where key is the parameter key supplied - and callbackName is the parameter value */ - (url + (url.indexOf('?') > 0 ? '&' : '?') + key + '=' + callbackName)); - - /* place jsonp callback on window, - the script sent by the server should call this - function as it was passed as a url parameter */ - window[callbackName] = function (data) { - window[callbackName] = undefined; - - // clean up script tag created for request - setTimeout(function () { return head.removeChild(script); }, 0); - - // hand data back to the user - callback(data); + /** + * @class Bing + */ + var Bing = function Bing() { + this.settings = { + url: 'https://dev.virtualearth.net/REST/v1/Locations', + callbackName: 'jsonp', + params: { + query: '', + key: '', + includeNeighborhood: 0, + maxResults: 10 + } + }; }; - // actually make the request - head.appendChild(script); -} + Bing.prototype.getParameters = function getParameters (options) { + return { + url: this.settings.url, + callbackName: this.settings.callbackName, + params: { + query: options.query, + key: options.key, + includeNeighborhood: options.includeNeighborhood || + this.settings.params.includeNeighborhood, + maxResults: options.maxResults || this.settings.params.maxResults + } + }; + }; -const klasses$1 = VARS.cssClasses; + Bing.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.point.coordinates[1], + lat: result.point.coordinates[0], + address: { + name: result.name + }, + original: { + formatted: result.address.formattedAddress, + details: result.address + } + }); }); + }; -/** - * @class Nominatim - */ -var Nominatim = function Nominatim(base, els) { - this.Base = base; + /** + * @class OpenCage + */ + var OpenCage = function OpenCage() { + + this.settings = { + url: 'https://api.opencagedata.com/geocode/v1/json?', + params: { + q: '', + key: '', + limit: 10, + countrycode: '', + pretty: 1, + no_annotations: 1 + } + }; + }; - this.layerName = randomId('geocoder-layer-'); - this.layer = new ol.layer.Vector({ - name: this.layerName, - source: new ol.source.Vector() - }); + OpenCage.prototype.getParameters = function getParameters (options) { + return { + url: this.settings.url, + params: { + q: options.query, + key: options.key, + limit: options.limit || this.settings.params.limit, + countrycode: options.countrycodes || this.settings.params.countrycodes + } + }; + }; - this.options = base.options; - // provider is either the name of a built-in provider as a string or an - // object that implements the provider API - this.options.provider = (typeof this.options.provider === 'string') - ? this.options.provider.toLowerCase() - : this.options.provider; - - this.els = els; - this.lastQuery = ''; - this.container = this.els.container; - this.registeredListeners = { mapClick: false }; - this.setListeners(); - - // providers - this.Photon = new Photon(); - this.OpenStreet = new OpenStreet(); - this.MapQuest = new MapQuest(); - this.Pelias = new Pelias(); - this.Bing = new Bing(); - this.OpenCage = new OpenCage(); -}; - -Nominatim.prototype.setListeners = function setListeners () { - var this$1 = this; - - let timeout, lastQuery; - const openSearch = function () { - hasClass(this$1.els.control, klasses$1.glass.expanded) ? - this$1.collapse() : this$1.expand(); + OpenCage.prototype.handleResponse = function handleResponse (results) { + return results.map(function (result) { return ({ + lon: result.geometry.lng, + lat: result.geometry.lat, + address: { + name: result.components.house_number || '', + road: result.components.road || '', + postcode: result.components.postcode, + city: result.components.city || result.components.town, + state: result.components.state, + country: result.components.country + }, + original: { + formatted: result.formatted, + details: result.components + } + }); }); }; - const query = function (evt) { - const value = evt.target.value.trim(); - const hit = evt.key ? evt.key === 'Enter' : - evt.which ? evt.which === 13 : - evt.keyCode ? evt.keyCode === 13 : false; - - if (hit) { - evt.preventDefault(); - this$1.query(value); + + function json(obj) { + return new Promise(function (resolve, reject) { + const url = encodeUrlXhr(obj.url, obj.data); + const config = { + method: 'GET', + mode: 'cors', + credentials: 'same-origin', + }; + + if (obj.jsonp) { + jsonp(url, obj.callbackName, resolve); + } else { + fetch(url, config) + .then(function (r) { return r.json(); }) + .then(resolve) + .catch(reject); + } + + }); + } + + + function toQueryString(obj) { + return Object.keys(obj).reduce(function (a, k) { + a.push( + typeof obj[k] === 'object' + ? toQueryString(obj[k]) + : ((encodeURIComponent(k)) + "=" + (encodeURIComponent(obj[k]))) + ); + return a; + }, []).join('&'); + } + + function encodeUrlXhr(url, data) { + if (data && typeof data === 'object') { + url += (/\?/.test(url) ? '&' : '?') + toQueryString(data); } + return url; + } + + function jsonp(url, key, callback) { + // https://github.com/Fresheyeball/micro-jsonp/blob/master/src/jsonp.js + let head = document.head, + script = document.createElement('script'), + // generate minimally unique name for callback function + callbackName = 'f' + Math.round(Math.random() * Date.now()); + + // set request url + script.setAttribute('src', + /* add callback parameter to the url + where key is the parameter key supplied + and callbackName is the parameter value */ + (url + (url.indexOf('?') > 0 ? '&' : '?') + key + '=' + callbackName)); + + /* place jsonp callback on window, + the script sent by the server should call this + function as it was passed as a url parameter */ + window[callbackName] = function (data) { + window[callbackName] = undefined; + + // clean up script tag created for request + setTimeout(function () { return head.removeChild(script); }, 0); + + // hand data back to the user + callback(data); + }; + + // actually make the request + head.appendChild(script); + } + + const klasses$1 = VARS.cssClasses; + + /** + * @class Nominatim + */ + var Nominatim = function Nominatim(base, els) { + this.Base = base; + + this.layerName = randomId('geocoder-layer-'); + this.layer = new LayerVector({ + name: this.layerName, + source: new SourceVector() + }); + + this.options = base.options; + // provider is either the name of a built-in provider as a string or an + // object that implements the provider API + this.options.provider = (typeof this.options.provider === 'string') + ? this.options.provider.toLowerCase() + : this.options.provider; + + this.els = els; + this.lastQuery = ''; + this.container = this.els.container; + this.registeredListeners = { mapClick: false }; + this.setListeners(); + + // providers + this.Photon = new Photon(); + this.OpenStreet = new OpenStreet(); + this.MapQuest = new MapQuest(); + this.Pelias = new Pelias(); + this.Bing = new Bing(); + this.OpenCage = new OpenCage(); }; - const reset = function (evt) { - this$1.els.input.focus(); - this$1.els.input.value = ''; - this$1.lastQuery = ''; - addClass(this$1.els.reset, klasses$1.hidden); - this$1.clearResults(); + + Nominatim.prototype.setListeners = function setListeners () { + var this$1 = this; + + let timeout, lastQuery; + const openSearch = function () { + hasClass(this$1.els.control, klasses$1.glass.expanded) ? + this$1.collapse() : this$1.expand(); + }; + const query = function (evt) { + const value = evt.target.value.trim(); + const hit = evt.key ? evt.key === 'Enter' : + evt.which ? evt.which === 13 : + evt.keyCode ? evt.keyCode === 13 : false; + + if (hit) { + evt.preventDefault(); + this$1.query(value); + } + }; + const reset = function (evt) { + this$1.els.input.focus(); + this$1.els.input.value = ''; + this$1.lastQuery = ''; + addClass(this$1.els.reset, klasses$1.hidden); + this$1.clearResults(); + }; + const handleValue = function (evt) { + const value = evt.target.value.trim(); + + value.length + ? removeClass(this$1.els.reset, klasses$1.hidden) + : addClass(this$1.els.reset, klasses$1.hidden); + + if (this$1.options.autoComplete && value !== lastQuery) { + lastQuery = value; + timeout && clearTimeout(timeout); + timeout = setTimeout(function () { + if (value.length >= this$1.options.autoCompleteMinLength) { + this$1.query(value); + } + }, 200); + } + }; + this.els.input.addEventListener('keypress', query, false); + this.els.input.addEventListener('input', handleValue, false); + this.els.reset.addEventListener('click', reset, false); + if (this.options.targetType === TARGET_TYPE.GLASS) { + this.els.button.addEventListener('click', openSearch, false); + } }; - const handleValue = function (evt) { - const value = evt.target.value.trim(); - - value.length - ? removeClass(this$1.els.reset, klasses$1.hidden) - : addClass(this$1.els.reset, klasses$1.hidden); - - if (this$1.options.autoComplete && value !== lastQuery) { - lastQuery = value; - timeout && clearTimeout(timeout); - timeout = setTimeout(function () { - if (value.length >= this$1.options.autoCompleteMinLength) { - this$1.query(value); - } - }, 200); + + Nominatim.prototype.query = function query (q) { + var this$1 = this; + + const provider = this.getProvider({ + query: q, + provider: this.options.provider, + key: this.options.key, + lang: this.options.lang, + countrycodes: this.options.countrycodes, + limit: this.options.limit + }); + + if (this.lastQuery === q && this.els.result.firstChild) { return; } + + this.lastQuery = q; + this.clearResults(); + addClass(this.els.reset, klasses$1.spin); + + let ajax = { + url: provider.url, + data: provider.params, + }; + + if (provider.callbackName) { + ajax.jsonp = true; + ajax.callbackName = provider.callbackName; } + + json(ajax).then(function (res) { + // eslint-disable-next-line no-console + this$1.options.debug && console.info(res); + + removeClass(this$1.els.reset, klasses$1.spin); + + //will be fullfiled according to provider + let res_; + switch (this$1.options.provider) { + case PROVIDERS.OSM: + res_ = res.length ? + this$1.OpenStreet.handleResponse(res) : undefined; + break; + case PROVIDERS.MAPQUEST: + res_ = res.length ? + this$1.MapQuest.handleResponse(res) : undefined; + break; + case PROVIDERS.PELIAS: + res_ = res.features.length ? + this$1.Pelias.handleResponse(res.features) : undefined; + break; + case PROVIDERS.PHOTON: + res_ = res.features.length ? + this$1.Photon.handleResponse(res.features) : undefined; + break; + case PROVIDERS.BING: + res_ = res.resourceSets[0].resources.length + ? this$1.Bing.handleResponse(res.resourceSets[0].resources) + : undefined; + break; + case PROVIDERS.OPENCAGE: + res_ = res.results.length ? + this$1.OpenCage.handleResponse(res.results) : undefined; + break; + default: + res_ = this$1.options.provider.handleResponse(res); + break; + } + if (res_) { + this$1.createList(res_); + this$1.listenMapClick(); + } + }).catch(function (err) { + removeClass(this$1.els.reset, klasses$1.spin); + const li = createElement( + 'li', '
          Error! No internet connection?
          '); + this$1.els.result.appendChild(li); + }); }; - this.els.input.addEventListener('keypress', query, false); - this.els.input.addEventListener('input', handleValue, false); - this.els.reset.addEventListener('click', reset, false); - if (this.options.targetType === TARGET_TYPE.GLASS) { - this.els.button.addEventListener('click', openSearch, false); - } -}; - -Nominatim.prototype.query = function query (q) { - var this$1 = this; - - const provider = this.getProvider({ - query: q, - provider: this.options.provider, - key: this.options.key, - lang: this.options.lang, - countrycodes: this.options.countrycodes, - limit: this.options.limit - }); - if (this.lastQuery === q && this.els.result.firstChild) { return; } + Nominatim.prototype.createList = function createList (response) { + var this$1 = this; + + const ul = this.els.result; + + response.forEach(function (row) { + let addressHtml; + + switch (this$1.options.provider) { + case PROVIDERS.OSM: + addressHtml = + "" + (row.address.name) + ""; + break; + default: + addressHtml = this$1.addressTemplate(row.address); + } - this.lastQuery = q; - this.clearResults(); - addClass(this.els.reset, klasses$1.spin); + const html = "" + addressHtml + ""; + const li = createElement('li', html); - let ajax = { - url: provider.url, - data: provider.params, + li.addEventListener('click', function (evt) { + evt.preventDefault(); + this$1.chosen(row, addressHtml, row.address, row.original); + }, false); + + ul.appendChild(li); + }); }; - if (provider.callbackName) { - ajax.jsonp = true; - ajax.callbackName = provider.callbackName; - } + Nominatim.prototype.chosen = function chosen (place, addressHtml, addressObj, addressOriginal) { + const map = this.Base.getMap(); + const coord_ = [parseFloat(place.lon), parseFloat(place.lat)]; + const projection = map.getView().getProjection(); + const coord = proj.transform(coord_, 'EPSG:4326', projection); + let bbox = place.bbox; - json(ajax).then(function (res) { - // eslint-disable-next-line no-console - this$1.options.debug && console.info(res); + if (bbox) { + bbox = proj.transformExtent(bbox, 'EPSG:4326', projection); + } + const address = { + formatted: addressHtml, + details: addressObj, + original: addressOriginal + }; + + this.options.keepOpen === false && this.clearResults(true); + + if (this.options.preventDefault === true) { + this.Base.dispatchEvent({ + type: EVENT_TYPE.ADDRESSCHOSEN, + address: address, + coordinate: coord, + bbox: bbox + }); + } else { + if (bbox) { + map.getView().fit(bbox, { duration: 500 }); + } else { + flyTo(map, coord); + } + const feature = this.createFeature(coord, address); + + this.Base.dispatchEvent({ + type: EVENT_TYPE.ADDRESSCHOSEN, + address: address, + feature: feature, + coordinate: coord, + bbox: bbox + }); + } + }; - removeClass(this$1.els.reset, klasses$1.spin); + Nominatim.prototype.createFeature = function createFeature (coord) { + const feature = new Feature(new Point(coord)); + this.addLayer(); + feature.setStyle(this.options.featureStyle); + feature.setId(randomId('geocoder-ft-')); + this.getSource().addFeature(feature); + return feature; + }; - //will be fullfiled according to provider - let res_; - switch (this$1.options.provider) { + Nominatim.prototype.addressTemplate = function addressTemplate (address) { + let html = []; + if (address.name) { + html.push(['{name}'].join('')); + } + if (address.road || address.building || address.house_number) { + html.push([ + '{building} {road} {house_number}' + ].join('')); + } + if (address.city || address.town || address.village) { + html.push([ + '{postcode} {city} {town} {village}' + ].join('')); + } + if (address.state || address.country) { + html.push([ + '{state} {country}' + ].join('')); + } + return template(html.join('
          '), address); + }; + + Nominatim.prototype.getProvider = function getProvider (options) { + let provider; + /*eslint default-case: 0*/ + switch (options.provider) { case PROVIDERS.OSM: - res_ = res.length ? - this$1.OpenStreet.handleResponse(res) : undefined; + provider = this.OpenStreet.getParameters(options); break; case PROVIDERS.MAPQUEST: - res_ = res.length ? - this$1.MapQuest.handleResponse(res) : undefined; - break; - case PROVIDERS.PELIAS: - res_ = res.features.length ? - this$1.Pelias.handleResponse(res.features) : undefined; + provider = this.MapQuest.getParameters(options); break; case PROVIDERS.PHOTON: - res_ = res.features.length ? - this$1.Photon.handleResponse(res.features) : undefined; + provider = this.Photon.getParameters(options); + break; + case PROVIDERS.PELIAS: + provider = this.Pelias.getParameters(options); break; case PROVIDERS.BING: - res_ = res.resourceSets[0].resources.length - ? this$1.Bing.handleResponse(res.resourceSets[0].resources) - : undefined; + provider = this.Bing.getParameters(options); break; case PROVIDERS.OPENCAGE: - res_ = res.results.length ? - this$1.OpenCage.handleResponse(res.results) : undefined; + provider = this.OpenCage.getParameters(options); break; default: - res_ = this$1.options.provider.handleResponse(res); + provider = options.provider.getParameters(options); break; } - if (res_) { - this$1.createList(res_); - this$1.listenMapClick(); - } - }).catch(function (err) { - removeClass(this$1.els.reset, klasses$1.spin); - const li = createElement( - 'li', '
          Error! No internet connection?
          '); - this$1.els.result.appendChild(li); - }); -}; + return provider; + }; -Nominatim.prototype.createList = function createList (response) { - var this$1 = this; + Nominatim.prototype.expand = function expand () { + var this$1 = this; - const ul = this.els.result; + removeClass(this.els.input, klasses$1.spin); + addClass(this.els.control, klasses$1.glass.expanded); + window.setTimeout(function () { return this$1.els.input.focus(); }, 100); + this.listenMapClick(); + }; - response.forEach(function (row) { - let addressHtml; + Nominatim.prototype.collapse = function collapse () { + this.els.input.value = ''; + this.els.input.blur(); + addClass(this.els.reset, klasses$1.hidden); + removeClass(this.els.control, klasses$1.glass.expanded); + this.clearResults(); + }; - switch (this$1.options.provider) { - case PROVIDERS.OSM: - addressHtml = - "" + (row.address.name) + ""; - break; - default: - addressHtml = this$1.addressTemplate(row.address); - } + Nominatim.prototype.listenMapClick = function listenMapClick () { + // already registered + if (this.registeredListeners.mapClick) { return; } - const html = "" + addressHtml + ""; - const li = createElement('li', html); + const this_ = this; + const mapElement = this.Base.getMap().getTargetElement(); + this.registeredListeners.mapClick = true; - li.addEventListener('click', function (evt) { - evt.preventDefault(); - this$1.chosen(row, addressHtml, row.address, row.original); + //one-time fire click + mapElement.addEventListener('click', { + handleEvent: function (evt) { + this_.clearResults(true); + mapElement.removeEventListener(evt.type, this, false); + this_.registeredListeners.mapClick = false; + } }, false); + }; - ul.appendChild(li); - }); -}; - -Nominatim.prototype.chosen = function chosen (place, addressHtml, addressObj, addressOriginal) { - const map = this.Base.getMap(); - const coord_ = [parseFloat(place.lon), parseFloat(place.lat)]; - const projection = map.getView().getProjection(); - const coord = ol.proj.transform(coord_, 'EPSG:4326', projection); - let bbox = place.bbox; + Nominatim.prototype.clearResults = function clearResults (collapse) { + collapse && this.options.targetType === TARGET_TYPE.GLASS + ? this.collapse() + : removeAllChildren(this.els.result); + }; - if (bbox) { - bbox = ol.proj.transformExtent(bbox, 'EPSG:4326', projection); - } - const address = { - formatted: addressHtml, - details: addressObj, - original: addressOriginal + Nominatim.prototype.getSource = function getSource () { + return this.layer.getSource(); }; - this.options.keepOpen === false && this.clearResults(true); + Nominatim.prototype.addLayer = function addLayer () { + var this$1 = this; - if (this.options.preventDefault === true) { - this.Base.dispatchEvent({ - type: EVENT_TYPE.ADDRESSCHOSEN, - address: address, - coordinate: coord, - bbox: bbox - }); - } else { - if (bbox) { - map.getView().fit(bbox, { duration: 500 }); - } else { - flyTo(map, coord); - } - const feature = this.createFeature(coord, address); - - this.Base.dispatchEvent({ - type: EVENT_TYPE.ADDRESSCHOSEN, - address: address, - feature: feature, - coordinate: coord, - bbox: bbox + let found = false; + const map = this.Base.getMap(); + + map.getLayers().forEach(function (layer) { + if (layer === this$1.layer) { found = true; } }); - } -}; - -Nominatim.prototype.createFeature = function createFeature (coord) { - const feature = new ol.Feature(new ol.geom.Point(coord)); - this.addLayer(); - feature.setStyle(this.options.featureStyle); - feature.setId(randomId('geocoder-ft-')); - this.getSource().addFeature(feature); - return feature; -}; - -Nominatim.prototype.addressTemplate = function addressTemplate (address) { - let html = []; - if (address.name) { - html.push(['{name}'].join('')); - } - if (address.road || address.building || address.house_number) { - html.push([ - '{building} {road} {house_number}' - ].join('')); - } - if (address.city || address.town || address.village) { - html.push([ - '{postcode} {city} {town} {village}' - ].join('')); - } - if (address.state || address.country) { - html.push([ - '{state} {country}' - ].join('')); - } - return template(html.join('
          '), address); -}; - -Nominatim.prototype.getProvider = function getProvider (options) { - let provider; - /*eslint default-case: 0*/ - switch (options.provider) { - case PROVIDERS.OSM: - provider = this.OpenStreet.getParameters(options); - break; - case PROVIDERS.MAPQUEST: - provider = this.MapQuest.getParameters(options); - break; - case PROVIDERS.PHOTON: - provider = this.Photon.getParameters(options); - break; - case PROVIDERS.PELIAS: - provider = this.Pelias.getParameters(options); - break; - case PROVIDERS.BING: - provider = this.Bing.getParameters(options); - break; - case PROVIDERS.OPENCAGE: - provider = this.OpenCage.getParameters(options); - break; - default: - provider = options.provider.getParameters(options); - break; - } - return provider; -}; - -Nominatim.prototype.expand = function expand () { - var this$1 = this; - - removeClass(this.els.input, klasses$1.spin); - addClass(this.els.control, klasses$1.glass.expanded); - window.setTimeout(function () { return this$1.els.input.focus(); }, 100); - this.listenMapClick(); -}; - -Nominatim.prototype.collapse = function collapse () { - this.els.input.value = ''; - this.els.input.blur(); - addClass(this.els.reset, klasses$1.hidden); - removeClass(this.els.control, klasses$1.glass.expanded); - this.clearResults(); -}; - -Nominatim.prototype.listenMapClick = function listenMapClick () { - // already registered - if (this.registeredListeners.mapClick) { return; } - - const this_ = this; - const mapElement = this.Base.getMap().getTargetElement(); - this.registeredListeners.mapClick = true; - - //one-time fire click - mapElement.addEventListener('click', { - handleEvent: function (evt) { - this_.clearResults(true); - mapElement.removeEventListener(evt.type, this, false); - this_.registeredListeners.mapClick = false; - } - }, false); -}; + if (!found) { map.addLayer(this.layer); } + }; -Nominatim.prototype.clearResults = function clearResults (collapse) { - collapse && this.options.targetType === TARGET_TYPE.GLASS - ? this.collapse() - : removeAllChildren(this.els.result); -}; + /** + * @class Base + * @extends {ol.control.Control} + */ + var Base = (function (Control$$1) { + function Base(type, options) { + if ( type === void 0 ) type = CONTROL_TYPE.NOMINATIM; + if ( options === void 0 ) options = {}; -Nominatim.prototype.getSource = function getSource () { - return this.layer.getSource(); -}; -Nominatim.prototype.addLayer = function addLayer () { - var this$1 = this; + if (!(this instanceof Base)) { return new Base(); } - let found = false; - const map = this.Base.getMap(); + assert(typeof type === 'string', '@param `type` should be string!'); + assert( + type === CONTROL_TYPE.NOMINATIM || type === CONTROL_TYPE.REVERSE, + ("@param 'type' should be '" + (CONTROL_TYPE.NOMINATIM) + "'\n or '" + (CONTROL_TYPE.REVERSE) + "'!") + ); + assert(typeof options === 'object', '@param `options` should be object!'); - map.getLayers().forEach(function (layer) { - if (layer === this$1.layer) { found = true; } - }); - if (!found) { map.addLayer(this.layer); } -}; + DEFAULT_OPTIONS.featureStyle = [ + new Style({ image: new Icon({ scale: .7, src: FEATURE_SRC }) }) + ]; -/** - * @class Base - * @extends {ol.control.Control} - */ -var Base = (function (superclass) { - function Base(type, options) { - if ( type === void 0 ) type = CONTROL_TYPE.NOMINATIM; - if ( options === void 0 ) options = {}; + this.options = mergeOptions(DEFAULT_OPTIONS, options); + this.container = undefined; + let $nominatim; + const $html = new Html(this); - if (!(this instanceof Base)) { return new Base(); } + if (type === CONTROL_TYPE.NOMINATIM) { + this.container = $html.els.container; + $nominatim = new Nominatim(this, $html.els); + this.layer = $nominatim.layer; + } else if (type === CONTROL_TYPE.REVERSE) { + // TODO + } - assert(typeof type === 'string', '@param `type` should be string!'); - assert( - type === CONTROL_TYPE.NOMINATIM || type === CONTROL_TYPE.REVERSE, - ("@param 'type' should be '" + (CONTROL_TYPE.NOMINATIM) + "'\n or '" + (CONTROL_TYPE.REVERSE) + "'!") - ); - assert(typeof options === 'object', '@param `options` should be object!'); - - DEFAULT_OPTIONS.featureStyle = [ - new ol.style.Style({ - image: new ol.style.Icon({ scale: .7, src: FEATURE_SRC }) - }) - ]; - - this.options = mergeOptions(DEFAULT_OPTIONS, options); - this.container = undefined; - - let $nominatim; - const $html = new Html(this); - - if (type === CONTROL_TYPE.NOMINATIM) { - this.container = $html.els.container; - $nominatim = new Nominatim(this, $html.els); - this.layer = $nominatim.layer; - } else if (type === CONTROL_TYPE.REVERSE) { - // TODO + Control$$1.call(this, { element: this.container }); } - superclass.call(this, { element: this.container }); - } + if ( Control$$1 ) Base.__proto__ = Control$$1; + Base.prototype = Object.create( Control$$1 && Control$$1.prototype ); + Base.prototype.constructor = Base; - if ( superclass ) Base.__proto__ = superclass; - Base.prototype = Object.create( superclass && superclass.prototype ); - Base.prototype.constructor = Base; + /** + * @return {ol.layer.Vector} Returns the layer created by this control + */ + Base.prototype.getLayer = function getLayer () { + return this.layer; + }; - /** - * @return {ol.layer.Vector} Returns the layer created by this control - */ - Base.prototype.getLayer = function getLayer () { - return this.layer; - }; + /** + * @return {ol.source.Vector} Returns the source created by this control + */ + Base.prototype.getSource = function getSource () { + return this.getLayer().getSource(); + }; - /** - * @return {ol.source.Vector} Returns the source created by this control - */ - Base.prototype.getSource = function getSource () { - return this.getLayer().getSource(); - }; + /** + * Set a new provider + * @param {String} provider + */ + Base.prototype.setProvider = function setProvider (provider) { + this.options.provider = provider; + }; - /** - * Set a new provider - * @param {String} provider - */ - Base.prototype.setProvider = function setProvider (provider) { - this.options.provider = provider; - }; + /** + * Set provider key + * @param {String} key + */ + Base.prototype.setProviderKey = function setProviderKey (key) { + this.options.key = key; + }; - /** - * Set provider key - * @param {String} key - */ - Base.prototype.setProviderKey = function setProviderKey (key) { - this.options.key = key; - }; + return Base; + }(Control)); return Base; -}(ol.control.Control)); - -return Base; }))); diff --git a/dist/ol-geocoder.css b/dist/ol-geocoder.css index 8b877b7..a5ed0b1 100644 --- a/dist/ol-geocoder.css +++ b/dist/ol-geocoder.css @@ -1,8 +1,8 @@ /*! - * ol-geocoder - v3.0.01 + * ol-geocoder - v3.1.0 * A geocoder extension for OpenLayers. * https://github.com/jonataswalker/ol-geocoder - * Built: Mon Nov 27 2017 17:57:32 GMT-0200 (-02) + * Built: Fri Apr 06 2018 09:18:53 GMT-0300 (-03) */ .ol-geocoder.gcd-gl-container { position: absolute; @@ -215,24 +215,13 @@ visibility: hidden; } .ol-geocoder .gcd-pseudo-rotate::after { - -webkit-animation: spin .7s linear infinite; - animation: spin .7s linear infinite; } - -@-webkit-keyframes spin { - from { - -webkit-transform: rotate(0deg); - transform: rotate(0deg); } - to { - -webkit-transform: rotate(360deg); - transform: rotate(360deg); } } + animation: spin .7s linear infinite; } @keyframes spin { from { - -webkit-transform: rotate(0deg); - transform: rotate(0deg); } + transform: rotate(0deg); } to { - -webkit-transform: rotate(360deg); - transform: rotate(360deg); } } + transform: rotate(360deg); } } .gcd-address { font-size: 0.875em; diff --git a/dist/ol-geocoder.js b/dist/ol-geocoder.js index 254f175..e688939 100644 --- a/dist/ol-geocoder.js +++ b/dist/ol-geocoder.js @@ -1,7 +1,7 @@ /*! - * ol-geocoder - v3.0.01 + * ol-geocoder - v3.1.0 * A geocoder extension for OpenLayers. * https://github.com/jonataswalker/ol-geocoder - * Built: Mon Nov 27 2017 17:57:30 GMT-0200 (-02) + * Built: Fri Apr 06 2018 09:18:51 GMT-0300 (-03) */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("openlayers")):"function"==typeof define&&define.amd?define(["openlayers"],t):e.Geocoder=t(e.ol)}(this,function(e){"use strict";function t(e,t){if(void 0===t&&(t="Assertion failed"),!e){if("undefined"!=typeof Error)throw new Error(t);throw t}}function s(e){const t=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);return e?e+t:t}function n(e){return/^\d+$/.test(e)}function r(e,t,s){if(Array.isArray(e))return void e.forEach(function(e){return r(e,t)});const n=Array.isArray(t)?t:t.split(/\s+/);let o=n.length;for(;o--;)i(e,n[o])||p(e,n[o],s)}function o(e,t,s){if(Array.isArray(e))return void e.forEach(function(e){return o(e,t,s)});const n=Array.isArray(t)?t:t.split(/\s+/);let r=n.length;for(;r--;)i(e,n[r])&&d(e,n[r],s)}function i(e,t){return e.classList?e.classList.contains(t):u(t).test(e.className)}function a(e,t,s){void 0===t&&(t=window.document);let n=/\./g,r=Array.prototype.slice,o=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(e))switch(e[0]){case"#":o=[function(e){return e="#"===e[0]?e.substr(1,e.length):e,document.getElementById(e)}(e.substr(1))];break;case".":o=r.call(t.getElementsByClassName(e.substr(1).replace(n," ")));break;default:o=r.call(t.getElementsByTagName(e))}else o=r.call(t.querySelectorAll(e));return s?o:o[0]}function c(e,t){return e.replace(/\{ *([\w_-]+) *\}/g,function(e,s){return function(e){return String(e).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}(void 0===t[s]?"":t[s])})}function l(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){let t=e[1].attr;if(Array.isArray(t)){let e=-1;for(;++e0?"&":"?")+t+"="+o),window[o]=function(e){window[o]=void 0,setTimeout(function(){return n.removeChild(r)},0),s(e)},n.appendChild(r)}(n,e.callbackName,t):fetch(n,r).then(function(e){return e.json()}).then(t).catch(s)})}function m(e){return Object.keys(e).reduce(function(t,s){return t.push("object"==typeof e[s]?m(e[s]):encodeURIComponent(s)+"="+encodeURIComponent(e[s])),t},[]).join("&")}e=e&&e.hasOwnProperty("default")?e.default:e;var g={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:"gcd-txt-input",reset:"gcd-txt-reset",icon:"gcd-txt-glass",result:"gcd-txt-result"}},f={containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:g};const y=Object.freeze({containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:g,default:f}),v={ADDRESSCHOSEN:"addresschosen"},b={NOMINATIM:"nominatim",REVERSE:"reverse"},w={GLASS:"glass-button",INPUT:"text-input"},E="//cdn.rawgit.com/jonataswalker/map-utils/master/images/marker.png",S={OSM:"osm",MAPQUEST:"mapquest",GOOGLE:"google",PHOTON:"photon",BING:"bing",OPENCAGE:"opencage",PELIAS:"pelias"},k={provider:S.OSM,placeholder:"Search for an address",featureStyle:null,targetType:w.GLASS,lang:"en-US",limit:5,keepOpen:!1,preventDefault:!1,autoComplete:!1,autoCompleteMinLength:2,debug:!1},C=y.cssClasses;var N=function(e){this.options=e.options,this.els=this.createControl()};N.prototype.createControl=function(){let e,t,s;return this.options.targetType===w.INPUT?(t=C.namespace+" "+C.inputText.container,s={container:e=l(["div",{id:y.containerId,classname:t}],N.input),control:a("."+C.inputText.control,e),input:a("."+C.inputText.input,e),reset:a("."+C.inputText.reset,e),result:a("."+C.inputText.result,e)}):(t=C.namespace+" "+C.glass.container,s={container:e=l(["div",{id:y.containerId,classname:t}],N.glass),control:a("."+C.glass.control,e),button:a("."+C.glass.button,e),input:a("."+C.glass.input,e),reset:a("."+C.glass.reset,e),result:a("."+C.glass.result,e)}),s.input.placeholder=this.options.placeholder,s},N.glass=['
          ','','',"","
          ",'
            '].join(""),N.input=['
            ','','','","
            ",'
              '].join("");var P=function(){this.settings={url:"https://photon.komoot.de/api/",params:{q:"",limit:10,lang:"en"},langs:["de","it","fr","en"]}};P.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:this.settings.langs.indexOf(e.lang)>-1?e.lang:this.settings.params.lang}}},P.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}}})};var R=function(){this.settings={url:"http://nominatim.openstreetmap.org/search/",params:{q:"",format:"json",addressdetails:1,limit:10,countrycodes:"","accept-language":"en-US"}}};R.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"]}}},R.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}}})};var T=function(){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"}}};T.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"]}}},T.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}}})};var x=function(){this.settings={url:"http://search.mapzen.com/v1/search",params:{size:10}}};x.prototype.getParameters=function(e){return{url:this.settings.url,params:{text:e.query,api_key:e.key,size:e.limit||this.settings.params.size}}},x.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}}})};var L=function(){this.settings={url:"https://dev.virtualearth.net/REST/v1/Locations",callbackName:"jsonp",params:{query:"",key:"",includeNeighborhood:0,maxResults:10}}};L.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}}},L.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}}})};var A=function(){this.settings={url:"https://api.opencagedata.com/geocode/v1/json?",params:{q:"",key:"",limit:10,countrycode:"",pretty:1,no_annotations:1}}};A.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}}},A.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 I=y.cssClasses;var O=function(t,n){this.Base=t,this.layerName=s("geocoder-layer-"),this.layer=new e.layer.Vector({name:this.layerName,source:new e.source.Vector}),this.options=t.options,this.options.provider="string"==typeof this.options.provider?this.options.provider.toLowerCase():this.options.provider,this.els=n,this.lastQuery="",this.container=this.els.container,this.registeredListeners={mapClick:!1},this.setListeners(),this.Photon=new P,this.OpenStreet=new R,this.MapQuest=new T,this.Pelias=new x,this.Bing=new L,this.OpenCage=new A};O.prototype.setListeners=function(){var e=this;let t,s;const n=function(){i(e.els.control,I.glass.expanded)?e.collapse():e.expand()};this.els.input.addEventListener("keypress",function(t){const s=t.target.value.trim();(t.key?"Enter"===t.key:t.which?13===t.which:!!t.keyCode&&13===t.keyCode)&&(t.preventDefault(),e.query(s))},!1),this.els.input.addEventListener("input",function(n){const i=n.target.value.trim();i.length?o(e.els.reset,I.hidden):r(e.els.reset,I.hidden),e.options.autoComplete&&i!==s&&(s=i,t&&clearTimeout(t),t=setTimeout(function(){i.length>=e.options.autoCompleteMinLength&&e.query(i)},200))},!1),this.els.reset.addEventListener("click",function(t){e.els.input.focus(),e.els.input.value="",e.lastQuery="",r(e.els.reset,I.hidden),e.clearResults()},!1),this.options.targetType===w.GLASS&&this.els.button.addEventListener("click",n,!1)},O.prototype.query=function(e){var t=this;const s=this.getProvider({query:e,provider:this.options.provider,key:this.options.key,lang:this.options.lang,countrycodes:this.options.countrycodes,limit:this.options.limit});if(this.lastQuery===e&&this.els.result.firstChild)return;this.lastQuery=e,this.clearResults(),r(this.els.reset,I.spin);let n={url:s.url,data:s.params};s.callbackName&&(n.jsonp=!0,n.callbackName=s.callbackName),h(n).then(function(e){t.options.debug&&console.info(e),o(t.els.reset,I.spin);let s;switch(t.options.provider){case S.OSM:s=e.length?t.OpenStreet.handleResponse(e):void 0;break;case S.MAPQUEST:s=e.length?t.MapQuest.handleResponse(e):void 0;break;case S.PELIAS:s=e.features.length?t.Pelias.handleResponse(e.features):void 0;break;case S.PHOTON:s=e.features.length?t.Photon.handleResponse(e.features):void 0;break;case S.BING:s=e.resourceSets[0].resources.length?t.Bing.handleResponse(e.resourceSets[0].resources):void 0;break;case S.OPENCAGE:s=e.results.length?t.OpenCage.handleResponse(e.results):void 0;break;default:s=t.options.provider.handleResponse(e)}s&&(t.createList(s),t.listenMapClick())}).catch(function(e){o(t.els.reset,I.spin);const s=l("li","
              Error! No internet connection?
              ");t.els.result.appendChild(s)})},O.prototype.createList=function(e){var t=this;const s=this.els.result;e.forEach(function(e){let n;switch(t.options.provider){case S.OSM:n=''+e.address.name+"";break;default:n=t.addressTemplate(e.address)}const r=l("li",''+n+"");r.addEventListener("click",function(s){s.preventDefault(),t.chosen(e,n,e.address,e.original)},!1),s.appendChild(r)})},O.prototype.chosen=function(t,s,n,r){const o=this.Base.getMap(),i=[parseFloat(t.lon),parseFloat(t.lat)],a=o.getView().getProjection(),c=e.proj.transform(i,"EPSG:4326",a);let l=t.bbox;l&&(l=e.proj.transformExtent(l,"EPSG:4326",a));const u={formatted:s,details:n,original:r};if(!1===this.options.keepOpen&&this.clearResults(!0),!0===this.options.preventDefault)this.Base.dispatchEvent({type:v.ADDRESSCHOSEN,address:u,coordinate:c,bbox:l});else{l?o.getView().fit(l,{duration:500}):function(e,t,s,n){n=n||2.388657133911758,s=s||500,e.getView().animate({duration:s,resolution:n},{duration:s,center:t})}(o,c);const e=this.createFeature(c,u);this.Base.dispatchEvent({type:v.ADDRESSCHOSEN,address:u,feature:e,coordinate:c,bbox:l})}},O.prototype.createFeature=function(t){const n=new e.Feature(new e.geom.Point(t));return this.addLayer(),n.setStyle(this.options.featureStyle),n.setId(s("geocoder-ft-")),this.getSource().addFeature(n),n},O.prototype.addressTemplate=function(e){let t=[];return e.name&&t.push(['{name}'].join("")),(e.road||e.building||e.house_number)&&t.push(['{building} {road} {house_number}'].join("")),(e.city||e.town||e.village)&&t.push(['{postcode} {city} {town} {village}'].join("")),(e.state||e.country)&&t.push(['{state} {country}'].join("")),c(t.join("
              "),e)},O.prototype.getProvider=function(e){let t;switch(e.provider){case S.OSM:t=this.OpenStreet.getParameters(e);break;case S.MAPQUEST:t=this.MapQuest.getParameters(e);break;case S.PHOTON:t=this.Photon.getParameters(e);break;case S.PELIAS:t=this.Pelias.getParameters(e);break;case S.BING:t=this.Bing.getParameters(e);break;case S.OPENCAGE:t=this.OpenCage.getParameters(e);break;default:t=e.provider.getParameters(e)}return t},O.prototype.expand=function(){var e=this;o(this.els.input,I.spin),r(this.els.control,I.glass.expanded),window.setTimeout(function(){return e.els.input.focus()},100),this.listenMapClick()},O.prototype.collapse=function(){this.els.input.value="",this.els.input.blur(),r(this.els.reset,I.hidden),o(this.els.control,I.glass.expanded),this.clearResults()},O.prototype.listenMapClick=function(){if(this.registeredListeners.mapClick)return;const e=this,t=this.Base.getMap().getTargetElement();this.registeredListeners.mapClick=!0,t.addEventListener("click",{handleEvent:function(s){e.clearResults(!0),t.removeEventListener(s.type,this,!1),e.registeredListeners.mapClick=!1}},!1)},O.prototype.clearResults=function(e){e&&this.options.targetType===w.GLASS?this.collapse():function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}(this.els.result)},O.prototype.getSource=function(){return this.layer.getSource()},O.prototype.addLayer=function(){var e=this;let t=!1;const s=this.Base.getMap();s.getLayers().forEach(function(s){s===e.layer&&(t=!0)}),t||s.addLayer(this.layer)};return function(s){function n(r,o){if(void 0===r&&(r=b.NOMINATIM),void 0===o&&(o={}),!(this instanceof n))return new n;t("string"==typeof r,"@param `type` should be string!"),t(r===b.NOMINATIM||r===b.REVERSE,"@param 'type' should be '"+b.NOMINATIM+"'\n or '"+b.REVERSE+"'!"),t("object"==typeof o,"@param `options` should be object!"),k.featureStyle=[new e.style.Style({image:new e.style.Icon({scale:.7,src:E})})],this.options=function(e,t){let s={};for(let t in e)s[t]=e[t];for(let e in t)s[e]=t[e];return s}(k,o),this.container=void 0;let i;const a=new N(this);r===b.NOMINATIM?(this.container=a.els.container,i=new O(this,a.els),this.layer=i.layer):b.REVERSE,s.call(this,{element:this.container})}return s&&(n.__proto__=s),n.prototype=Object.create(s&&s.prototype),n.prototype.constructor=n,n.prototype.getLayer=function(){return this.layer},n.prototype.getSource=function(){return this.getLayer().getSource()},n.prototype.setProvider=function(e){this.options.provider=e},n.prototype.setProviderKey=function(e){this.options.key=e},n}(e.control.Control)}); +!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(e,t,s,n,r,o,a,i){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t,s=s&&s.hasOwnProperty("default")?s.default:s,n=n&&n.hasOwnProperty("default")?n.default:n,r=r&&r.hasOwnProperty("default")?r.default:r,o=o&&o.hasOwnProperty("default")?o.default:o,a=a&&a.hasOwnProperty("default")?a.default:a,i=i&&i.hasOwnProperty("default")?i.default:i;var l={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:"gcd-txt-input",reset:"gcd-txt-reset",icon:"gcd-txt-glass",result:"gcd-txt-result"}},c={containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:l};const u=Object.freeze({containerId:"gcd-container",buttonControlId:"gcd-button-control",inputQueryId:"gcd-input-query",inputResetId:"gcd-input-reset",cssClasses:l,default:c}),p="addresschosen",d={NOMINATIM:"nominatim",REVERSE:"reverse"},h="glass-button",m="text-input",g="//cdn.rawgit.com/jonataswalker/map-utils/master/images/marker.png",f="osm",y="mapquest",v="photon",b="bing",w="opencage",k="pelias",C={provider:f,placeholder:"Search for an address",featureStyle:null,targetType:h,lang:"en-US",limit:5,keepOpen:!1,preventDefault:!1,autoComplete:!1,autoCompleteMinLength:2,debug:!1};function E(e,t){if(void 0===t&&(t="Assertion failed"),!e){if("undefined"!=typeof Error)throw new Error(t);throw t}}function x(e){const t=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);return e?e+t:t}function R(e){return/^\d+$/.test(e)}function P(e,t,s){if(Array.isArray(e))return void e.forEach(function(e){return P(e,t)});const n=Array.isArray(t)?t:t.split(/\s+/);let r=n.length;for(;r--;)q(e,n[r])||j(e,n[r],s)}function N(e,t,s){if(Array.isArray(e))return void e.forEach(function(e){return N(e,t,s)});const n=Array.isArray(t)?t:t.split(/\s+/);let r=n.length;for(;r--;)q(e,n[r])&&O(e,n[r],s)}function q(e,t){return e.classList?e.classList.contains(t):I(t).test(e.className)}function T(e,t,s){void 0===t&&(t=window.document);let n=/\./g,r=Array.prototype.slice,o=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(e))switch(e[0]){case"#":o=[(a=e.substr(1),a="#"===a[0]?a.substr(1,a.length):a,document.getElementById(a))];break;case".":o=r.call(t.getElementsByClassName(e.substr(1).replace(n," ")));break;default:o=r.call(t.getElementsByTagName(e))}else o=r.call(t.querySelectorAll(e));var a;return s?o:o[0]}function L(e,t){return e.replace(/\{ *([\w_-]+) *\}/g,function(e,s){let n=void 0===t[s]?"":t[s];return String(n).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")})}function S(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){let t=e[1].attr;if(Array.isArray(t)){let e=-1;for(;++e','','',"","",'
                '].join(""),M.input=['
                ','','','","
                ",'
                  '].join("");var _=function(){this.settings={url:"https://photon.komoot.de/api/",params:{q:"",limit:10,lang:"en"},langs:["de","it","fr","en"]}};_.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:this.settings.langs.indexOf(e.lang)>-1?e.lang:this.settings.params.lang}}},_.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}}})};var B=function(){this.settings={url:"https://nominatim.openstreetmap.org/search/",params:{q:"",format:"json",addressdetails:1,limit:10,countrycodes:"","accept-language":"en-US"}}};B.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"]}}},B.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}}})};var D=function(){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"}}};D.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"]}}},D.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}}})};var Q=function(){this.settings={url:"http://search.mapzen.com/v1/search",params:{size:10}}};Q.prototype.getParameters=function(e){return{url:this.settings.url,params:{text:e.query,api_key:e.key,size:e.limit||this.settings.params.size}}},Q.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}}})};var V=function(){this.settings={url:"https://dev.virtualearth.net/REST/v1/Locations",callbackName:"jsonp",params:{query:"",key:"",includeNeighborhood:0,maxResults:10}}};V.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}}},V.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}}})};var F=function(){this.settings={url:"https://api.opencagedata.com/geocode/v1/json?",params:{q:"",key:"",limit:10,countrycode:"",pretty:1,no_annotations:1}}};function z(e){return new Promise(function(t,s){const n=function(e,t){t&&"object"==typeof t&&(e+=(/\?/.test(e)?"&":"?")+function e(t){return Object.keys(t).reduce(function(s,n){return s.push("object"==typeof t[n]?e(t[n]):encodeURIComponent(n)+"="+encodeURIComponent(t[n])),s},[]).join("&")}(t));return e}(e.url,e.data),r={method:"GET",mode:"cors",credentials:"same-origin"};e.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+(e.indexOf("?")>0?"&":"?")+t+"="+o),window[o]=function(e){window[o]=void 0,setTimeout(function(){return n.removeChild(r)},0),s(e)},n.appendChild(r)}(n,e.callbackName,t):fetch(n,r).then(function(e){return e.json()}).then(t).catch(s)})}F.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}}},F.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 U=u.cssClasses;var G=function(s,n){this.Base=s,this.layerName=x("geocoder-layer-"),this.layer=new e({name:this.layerName,source:new t}),this.options=s.options,this.options.provider="string"==typeof this.options.provider?this.options.provider.toLowerCase():this.options.provider,this.els=n,this.lastQuery="",this.container=this.els.container,this.registeredListeners={mapClick:!1},this.setListeners(),this.Photon=new _,this.OpenStreet=new B,this.MapQuest=new D,this.Pelias=new Q,this.Bing=new V,this.OpenCage=new F};return G.prototype.setListeners=function(){var e=this;let t,s;const n=function(){q(e.els.control,U.glass.expanded)?e.collapse():e.expand()};this.els.input.addEventListener("keypress",function(t){const s=t.target.value.trim();(t.key?"Enter"===t.key:t.which?13===t.which:t.keyCode&&13===t.keyCode)&&(t.preventDefault(),e.query(s))},!1),this.els.input.addEventListener("input",function(n){const r=n.target.value.trim();r.length?N(e.els.reset,U.hidden):P(e.els.reset,U.hidden),e.options.autoComplete&&r!==s&&(s=r,t&&clearTimeout(t),t=setTimeout(function(){r.length>=e.options.autoCompleteMinLength&&e.query(r)},200))},!1),this.els.reset.addEventListener("click",function(t){e.els.input.focus(),e.els.input.value="",e.lastQuery="",P(e.els.reset,U.hidden),e.clearResults()},!1),this.options.targetType===h&&this.els.button.addEventListener("click",n,!1)},G.prototype.query=function(e){var t=this;const s=this.getProvider({query:e,provider:this.options.provider,key:this.options.key,lang:this.options.lang,countrycodes:this.options.countrycodes,limit:this.options.limit});if(this.lastQuery===e&&this.els.result.firstChild)return;this.lastQuery=e,this.clearResults(),P(this.els.reset,U.spin);let n={url:s.url,data:s.params};s.callbackName&&(n.jsonp=!0,n.callbackName=s.callbackName),z(n).then(function(e){let s;switch(t.options.debug&&console.info(e),N(t.els.reset,U.spin),t.options.provider){case f:s=e.length?t.OpenStreet.handleResponse(e):void 0;break;case y:s=e.length?t.MapQuest.handleResponse(e):void 0;break;case k:s=e.features.length?t.Pelias.handleResponse(e.features):void 0;break;case v:s=e.features.length?t.Photon.handleResponse(e.features):void 0;break;case b:s=e.resourceSets[0].resources.length?t.Bing.handleResponse(e.resourceSets[0].resources):void 0;break;case w:s=e.results.length?t.OpenCage.handleResponse(e.results):void 0;break;default:s=t.options.provider.handleResponse(e)}s&&(t.createList(s),t.listenMapClick())}).catch(function(e){N(t.els.reset,U.spin);const s=S("li","
                  Error! No internet connection?
                  ");t.els.result.appendChild(s)})},G.prototype.createList=function(e){var t=this;const s=this.els.result;e.forEach(function(e){let n;switch(t.options.provider){case f:n=''+e.address.name+"";break;default:n=t.addressTemplate(e.address)}const r=S("li",''+n+"");r.addEventListener("click",function(s){s.preventDefault(),t.chosen(e,n,e.address,e.original)},!1),s.appendChild(r)})},G.prototype.chosen=function(e,t,s,n){const o=this.Base.getMap(),a=[parseFloat(e.lon),parseFloat(e.lat)],i=o.getView().getProjection(),l=r.transform(a,"EPSG:4326",i);let c=e.bbox;c&&(c=r.transformExtent(c,"EPSG:4326",i));const u={formatted:t,details:s,original:n};if(!1===this.options.keepOpen&&this.clearResults(!0),!0===this.options.preventDefault)this.Base.dispatchEvent({type:p,address:u,coordinate:l,bbox:c});else{c?o.getView().fit(c,{duration:500}):function(e,t,s,n){n=n||2.388657133911758,s=s||500,e.getView().animate({duration:s,resolution:n},{duration:s,center:t})}(o,l);const e=this.createFeature(l,u);this.Base.dispatchEvent({type:p,address:u,feature:e,coordinate:l,bbox:c})}},G.prototype.createFeature=function(e){const t=new n(new s(e));return this.addLayer(),t.setStyle(this.options.featureStyle),t.setId(x("geocoder-ft-")),this.getSource().addFeature(t),t},G.prototype.addressTemplate=function(e){let t=[];return e.name&&t.push(['{name}'].join("")),(e.road||e.building||e.house_number)&&t.push(['{building} {road} {house_number}'].join("")),(e.city||e.town||e.village)&&t.push(['{postcode} {city} {town} {village}'].join("")),(e.state||e.country)&&t.push(['{state} {country}'].join("")),L(t.join("
                  "),e)},G.prototype.getProvider=function(e){let t;switch(e.provider){case f:t=this.OpenStreet.getParameters(e);break;case y:t=this.MapQuest.getParameters(e);break;case v:t=this.Photon.getParameters(e);break;case k:t=this.Pelias.getParameters(e);break;case b:t=this.Bing.getParameters(e);break;case w:t=this.OpenCage.getParameters(e);break;default:t=e.provider.getParameters(e)}return t},G.prototype.expand=function(){var e=this;N(this.els.input,U.spin),P(this.els.control,U.glass.expanded),window.setTimeout(function(){return e.els.input.focus()},100),this.listenMapClick()},G.prototype.collapse=function(){this.els.input.value="",this.els.input.blur(),P(this.els.reset,U.hidden),N(this.els.control,U.glass.expanded),this.clearResults()},G.prototype.listenMapClick=function(){if(this.registeredListeners.mapClick)return;const e=this,t=this.Base.getMap().getTargetElement();this.registeredListeners.mapClick=!0,t.addEventListener("click",{handleEvent:function(s){e.clearResults(!0),t.removeEventListener(s.type,this,!1),e.registeredListeners.mapClick=!1}},!1)},G.prototype.clearResults=function(e){e&&this.options.targetType===h?this.collapse():function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}(this.els.result)},G.prototype.getSource=function(){return this.layer.getSource()},G.prototype.addLayer=function(){var e=this;let t=!1;const s=this.Base.getMap();s.getLayers().forEach(function(s){s===e.layer&&(t=!0)}),t||s.addLayer(this.layer)},function(e){function t(s,n){if(void 0===s&&(s=d.NOMINATIM),void 0===n&&(n={}),!(this instanceof t))return new t;let r;E("string"==typeof s,"@param `type` should be string!"),E(s===d.NOMINATIM||s===d.REVERSE,"@param 'type' should be '"+d.NOMINATIM+"'\n or '"+d.REVERSE+"'!"),E("object"==typeof n,"@param `options` should be object!"),C.featureStyle=[new a({image:new i({scale:.7,src:g})})],this.options=function(e,t){let s={};for(let t in e)s[t]=e[t];for(let e in t)s[e]=t[e];return s}(C,n),this.container=void 0;const o=new M(this);s===d.NOMINATIM?(this.container=o.els.container,r=new G(this,o.els),this.layer=r.layer):d.REVERSE,e.call(this,{element:this.container})}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.getLayer=function(){return this.layer},t.prototype.getSource=function(){return this.getLayer().getSource()},t.prototype.setProvider=function(e){this.options.provider=e},t.prototype.setProviderKey=function(e){this.options.key=e},t}(o)}); diff --git a/dist/ol-geocoder.min.css b/dist/ol-geocoder.min.css index 0f7ae8c..0bfd028 100644 --- a/dist/ol-geocoder.min.css +++ b/dist/ol-geocoder.min.css @@ -1,7 +1,7 @@ /*! - * ol-geocoder - v3.0.01 + * ol-geocoder - v3.1.0 * A geocoder extension for OpenLayers. * https://github.com/jonataswalker/ol-geocoder - * Built: Mon Nov 27 2017 17:57:32 GMT-0200 (-02) + * Built: Fri Apr 06 2018 09:18:53 GMT-0300 (-03) */ -.ol-geocoder.gcd-gl-container{position:absolute;top:4.875em;left:.5em;box-sizing:border-box}.ol-geocoder.gcd-gl-container *,.ol-geocoder.gcd-gl-container :after,.ol-geocoder.gcd-gl-container :before{box-sizing:inherit}.ol-geocoder .gcd-gl-control{width:2.1875em;height:2.1875em;overflow:hidden;transition:width .2s,height .2s}.ol-geocoder .gcd-gl-expanded{width:15.625em;height:2.1875em}.ol-geocoder .gcd-gl-input{position:absolute;z-index:1;top:.25em;left:2.5em;width:14.84375em;padding:5px;border:1px solid #ccc;font-family:inherit;font-size:.875em;background-color:#fff;color:#222}.ol-geocoder .gcd-gl-input:focus{border:none;outline:none;box-shadow:inset 0 0 0 1px #4d90fe,inset 0 0 5px #4d90fe}.ol-geocoder .gcd-gl-reset{position:absolute;z-index:2;top:0;right:0;width:1.5625em;height:100%;line-height:1.4;border:none;background-color:transparent;display:inline-block;outline:0;cursor:pointer}.ol-geocoder .gcd-gl-reset:after{content:"\d7";display:inline-block;color:#333;font-size:1.5em;cursor:pointer}.ol-geocoder .gcd-gl-btn{position:absolute;width:1.5625em;height:1.5625em;top:.125em;left:.125em;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAABPUlEQVQoU41SwXHCQAzUHh58eoUOIBWEDkI6oAToIKkg7iAuwakgpAIowXRACcnrzp6BzchjMx4wE/S6kW5XK60gvQghzJIkmVoqSZI9gJ9+/fINS5Cc1HX9QXIlIr/tpwcRyb33b7cIGnAIYQdg4pxbjcfj0nJ1Xc+Px+PGObdN03Q9RIAQwgpAnqbp7FKmjQGgJLlU1d2V7BjjRkQO3vvXIXarkyxVNbsCm2QR2Q0V7XOMMReRmfd+OQQubN6hYgs22ZtbnRcAtiRfLueqqmpJ8ovko6oeBq0KIWQA3gFkzrlmMafTaUEyI/mpqmbhVTRWWbRdbClPbeobQNES5KPRqOxs7DBn8K1DsAOKMZYApiTXqlrcDe4d0XN7jWeCfzt351tVle2iGalTcBd4gGDvvZ/fDe4RmCOFLe8Pr7mvEP2N9PQAAAAASUVORK5CYII=");background-repeat:no-repeat;background-position:50%}.ol-geocoder ul.gcd-gl-result{position:absolute;top:2.1875em;left:2em;width:16.25em;max-height:18.75em;white-space:normal;list-style:none;padding:0;margin:0;background-color:#fff;border-radius:4px;border-top:none;border-top-left-radius:0;border-top-right-radius:0;overflow-x:hidden;overflow-y:auto;box-shadow:0 1px 7px rgba(0,0,0,.8);transition:max-height .3s ease-in}.ol-geocoder ul.gcd-gl-result>li{width:100%;overflow:hidden;border-bottom:1px solid #eee;padding:0;line-height:.875rem}.ol-geocoder ul.gcd-gl-result>li>a{display:block;text-decoration:none;padding:3px 5px}.ol-geocoder ul.gcd-gl-result>li>a:hover{background-color:#d4d4d4}.ol-geocoder ul.gcd-gl-result>li:nth-child(odd){background-color:#e0ffe0}.ol-geocoder.gcd-txt-container{position:absolute;width:25em;height:4.375em;top:.5em;left:calc(50% - 12.5em);box-sizing:border-box}.ol-geocoder.gcd-txt-container *,.ol-geocoder.gcd-txt-container :after,.ol-geocoder.gcd-txt-container :before{box-sizing:inherit}.ol-geocoder .gcd-txt-control{position:relative;width:100%;height:4.375em;border:1px solid #ccc;background-color:#fff;overflow:hidden}.ol-geocoder .gcd-txt-input{position:absolute;z-index:1;top:0;left:0;width:100%;height:100%;padding:5px 30px 5px 40px;border:none;text-indent:6px;background-color:transparent;font-family:inherit;font-size:.875em}.ol-geocoder .gcd-txt-input:focus{outline:none;box-shadow:inset 0 0 0 1px #4d90fe,inset 0 0 6px #4d90fe}.ol-geocoder .gcd-txt-reset{position:absolute;z-index:2;top:0;right:0;width:2.5em;height:100%;line-height:100%;border:none;background-color:transparent;display:inline-block;vertical-align:middle;outline:0;cursor:pointer}.ol-geocoder .gcd-txt-reset:after{content:"\d7";display:inline-block;color:#333;font-size:2em;cursor:pointer}.ol-geocoder .gcd-txt-glass{position:absolute;top:0;left:0;z-index:2;display:inline-block;width:2.5em;height:100%;background-size:1.38889em;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath fill='%23333' d='M29.156 29.961l-.709.709a2.006 2.006 0 0 1-2.838 0l-5.676-5.674c-.656-.658-.729-1.644-.281-2.412l-3.104-3.102a9.975 9.975 0 0 1-5.965 1.979C5.043 21.461.552 16.97.552 11.43S5.043 1.398 10.583 1.398c5.541 0 10.031 4.491 10.031 10.032 0 2.579-.98 4.923-2.58 6.7l3.035 3.035c.768-.447 1.754-.375 2.41.283l5.676 5.674c.784.785.784 2.056.001 2.839zM18.088 11.389a7.524 7.524 0 0 0-7.524-7.523 7.523 7.523 0 1 0-.001 15.046 7.525 7.525 0 0 0 7.525-7.523z'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:50%}.ol-geocoder ul.gcd-txt-result{position:absolute;top:4.575em;left:0;width:25em;max-height:18.75em;white-space:normal;list-style:none;padding:0;margin:0;background-color:#fff;border-radius:4px;border-top:none;border-top-left-radius:0;border-top-right-radius:0;overflow-x:hidden;overflow-y:auto;box-shadow:0 1px 7px rgba(0,0,0,.8);transition:max-height .3s ease-in}.ol-geocoder ul.gcd-txt-result>li{width:100%;overflow:hidden;border-bottom:1px solid #eee;padding:0;line-height:.875rem}.ol-geocoder ul.gcd-txt-result>li>a{display:block;text-decoration:none;padding:3px 5px}.ol-geocoder ul.gcd-txt-result>li>a:hover{background-color:#d4d4d4}.ol-geocoder ul.gcd-txt-result>li:nth-child(odd){background-color:#e0ffe0}.ol-geocoder .gcd-hidden{opacity:0;visibility:hidden}.ol-geocoder .gcd-pseudo-rotate:after{-webkit-animation:a .7s linear infinite;animation:a .7s linear infinite}@-webkit-keyframes a{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes a{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}.gcd-address,.gcd-road{font-size:.875em;font-weight:500;color:#333}.gcd-city{font-weight:400}.gcd-city,.gcd-country{font-size:.75em;color:#333}.gcd-country{font-weight:lighter} \ No newline at end of file +.ol-geocoder.gcd-gl-container{position:absolute;top:4.875em;left:.5em;box-sizing:border-box}.ol-geocoder.gcd-gl-container *,.ol-geocoder.gcd-gl-container :after,.ol-geocoder.gcd-gl-container :before{box-sizing:inherit}.ol-geocoder .gcd-gl-control{width:2.1875em;height:2.1875em;overflow:hidden;transition:width .2s,height .2s}.ol-geocoder .gcd-gl-expanded{width:15.625em;height:2.1875em}.ol-geocoder .gcd-gl-input{position:absolute;z-index:1;top:.25em;left:2.5em;width:14.84375em;padding:5px;border:1px solid #ccc;font-family:inherit;font-size:.875em;background-color:#fff;color:#222}.ol-geocoder .gcd-gl-input:focus{border:none;outline:none;box-shadow:inset 0 0 0 1px #4d90fe,inset 0 0 5px #4d90fe}.ol-geocoder .gcd-gl-reset{position:absolute;z-index:2;top:0;right:0;width:1.5625em;height:100%;line-height:1.4;border:none;background-color:transparent;display:inline-block;outline:0;cursor:pointer}.ol-geocoder .gcd-gl-reset:after{content:"\d7";display:inline-block;color:#333;font-size:1.5em;cursor:pointer}.ol-geocoder .gcd-gl-btn{position:absolute;width:1.5625em;height:1.5625em;top:.125em;left:.125em;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAABPUlEQVQoU41SwXHCQAzUHh58eoUOIBWEDkI6oAToIKkg7iAuwakgpAIowXRACcnrzp6BzchjMx4wE/S6kW5XK60gvQghzJIkmVoqSZI9gJ9+/fINS5Cc1HX9QXIlIr/tpwcRyb33b7cIGnAIYQdg4pxbjcfj0nJ1Xc+Px+PGObdN03Q9RIAQwgpAnqbp7FKmjQGgJLlU1d2V7BjjRkQO3vvXIXarkyxVNbsCm2QR2Q0V7XOMMReRmfd+OQQubN6hYgs22ZtbnRcAtiRfLueqqmpJ8ovko6oeBq0KIWQA3gFkzrlmMafTaUEyI/mpqmbhVTRWWbRdbClPbeobQNES5KPRqOxs7DBn8K1DsAOKMZYApiTXqlrcDe4d0XN7jWeCfzt351tVle2iGalTcBd4gGDvvZ/fDe4RmCOFLe8Pr7mvEP2N9PQAAAAASUVORK5CYII=");background-repeat:no-repeat;background-position:50%}.ol-geocoder ul.gcd-gl-result{position:absolute;top:2.1875em;left:2em;width:16.25em;max-height:18.75em;white-space:normal;list-style:none;padding:0;margin:0;background-color:#fff;border-radius:4px;border-top:none;border-top-left-radius:0;border-top-right-radius:0;overflow-x:hidden;overflow-y:auto;box-shadow:0 1px 7px rgba(0,0,0,.8);transition:max-height .3s ease-in}.ol-geocoder ul.gcd-gl-result>li{width:100%;overflow:hidden;border-bottom:1px solid #eee;padding:0;line-height:.875rem}.ol-geocoder ul.gcd-gl-result>li>a{display:block;text-decoration:none;padding:3px 5px}.ol-geocoder ul.gcd-gl-result>li>a:hover{background-color:#d4d4d4}.ol-geocoder ul.gcd-gl-result>li:nth-child(odd){background-color:#e0ffe0}.ol-geocoder.gcd-txt-container{position:absolute;width:25em;height:4.375em;top:.5em;left:calc(50% - 12.5em);box-sizing:border-box}.ol-geocoder.gcd-txt-container *,.ol-geocoder.gcd-txt-container :after,.ol-geocoder.gcd-txt-container :before{box-sizing:inherit}.ol-geocoder .gcd-txt-control{position:relative;width:100%;height:4.375em;border:1px solid #ccc;background-color:#fff;overflow:hidden}.ol-geocoder .gcd-txt-input{position:absolute;z-index:1;top:0;left:0;width:100%;height:100%;padding:5px 30px 5px 40px;border:none;text-indent:6px;background-color:transparent;font-family:inherit;font-size:.875em}.ol-geocoder .gcd-txt-input:focus{outline:none;box-shadow:inset 0 0 0 1px #4d90fe,inset 0 0 6px #4d90fe}.ol-geocoder .gcd-txt-reset{position:absolute;z-index:2;top:0;right:0;width:2.5em;height:100%;line-height:100%;border:none;background-color:transparent;display:inline-block;vertical-align:middle;outline:0;cursor:pointer}.ol-geocoder .gcd-txt-reset:after{content:"\d7";display:inline-block;color:#333;font-size:2em;cursor:pointer}.ol-geocoder .gcd-txt-glass{position:absolute;top:0;left:0;z-index:2;display:inline-block;width:2.5em;height:100%;background-size:1.38889em;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath fill='%23333' d='M29.156 29.961l-.709.709a2.006 2.006 0 0 1-2.838 0l-5.676-5.674c-.656-.658-.729-1.644-.281-2.412l-3.104-3.102a9.975 9.975 0 0 1-5.965 1.979C5.043 21.461.552 16.97.552 11.43S5.043 1.398 10.583 1.398c5.541 0 10.031 4.491 10.031 10.032 0 2.579-.98 4.923-2.58 6.7l3.035 3.035c.768-.447 1.754-.375 2.41.283l5.676 5.674c.784.785.784 2.056.001 2.839zM18.088 11.389a7.524 7.524 0 0 0-7.524-7.523 7.523 7.523 0 1 0-.001 15.046 7.525 7.525 0 0 0 7.525-7.523z'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:50%}.ol-geocoder ul.gcd-txt-result{position:absolute;top:4.575em;left:0;width:25em;max-height:18.75em;white-space:normal;list-style:none;padding:0;margin:0;background-color:#fff;border-radius:4px;border-top:none;border-top-left-radius:0;border-top-right-radius:0;overflow-x:hidden;overflow-y:auto;box-shadow:0 1px 7px rgba(0,0,0,.8);transition:max-height .3s ease-in}.ol-geocoder ul.gcd-txt-result>li{width:100%;overflow:hidden;border-bottom:1px solid #eee;padding:0;line-height:.875rem}.ol-geocoder ul.gcd-txt-result>li>a{display:block;text-decoration:none;padding:3px 5px}.ol-geocoder ul.gcd-txt-result>li>a:hover{background-color:#d4d4d4}.ol-geocoder ul.gcd-txt-result>li:nth-child(odd){background-color:#e0ffe0}.ol-geocoder .gcd-hidden{opacity:0;visibility:hidden}.ol-geocoder .gcd-pseudo-rotate:after{animation:a .7s linear infinite}@keyframes a{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.gcd-address,.gcd-road{font-size:.875em;font-weight:500;color:#333}.gcd-city{font-weight:400}.gcd-city,.gcd-country{font-size:.75em;color:#333}.gcd-country{font-weight:lighter} \ No newline at end of file diff --git a/package.json b/package.json index 0a6b3f6..90c78ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ol-geocoder", - "version": "3.0.01", + "version": "3.1.0", "description": "A geocoder extension for OpenLayers.", "author": "Jonatas Walker", "homepage": "https://github.com/jonataswalker/ol-geocoder",