diff --git a/assets/control-geocoder/Control.Geocoder.css b/assets/control-geocoder/Control.Geocoder.css index 47bb0bd..3418d89 100644 --- a/assets/control-geocoder/Control.Geocoder.css +++ b/assets/control-geocoder/Control.Geocoder.css @@ -1,64 +1,67 @@ .leaflet-control-geocoder { + border-radius: 4px; background: white; - box-shadow: 0 1px 7px rgba(0,0,0,0.65); - -webkit-border-radius: 4px; - border-radius: 4px; - line-height: 26px; - overflow: hidden; + min-width: 26px; + min-height: 26px; } .leaflet-touch .leaflet-control-geocoder { - box-shadow: none; - border: 2px solid rgba(0,0,0,0.2); - background-clip: padding-box; - line-height: 30px; + min-width: 30px; + min-height: 30px; +} + +.leaflet-control-geocoder a, .leaflet-control-geocoder .leaflet-control-geocoder-icon { + border-bottom: none; + display: inline-block; +} + +.leaflet-control-geocoder .leaflet-control-geocoder-alternatives a { + width: inherit; + height: inherit; + line-height: inherit; +} + +.leaflet-control-geocoder a:hover, .leaflet-control-geocoder .leaflet-control-geocoder-icon:hover { + border-bottom: none; + display: inline-block; } .leaflet-control-geocoder-form { - display: inline; + display: none; + vertical-align: middle; } - -.leaflet-control-geocoder-form input, .leaflet-control-geocoder-form ul, .leaflet-control-geocoder-error { - border: 0; - color: transparent; - background: white; +.leaflet-control-geocoder-expanded .leaflet-control-geocoder-form { + display: inline-block; } - .leaflet-control-geocoder-form input { - font-size: 16px; - width: 0; - transition: width 0.125s ease-in; -} - -.leaflet-touch .leaflet-control-geocoder-form input { - font-size: 22px; + font-size: 120%; + border: 0; + background-color: transparent; + width: 246px; } .leaflet-control-geocoder-icon { + border-radius: 4px; width: 26px; height: 26px; + border: none; + background-color: white; background-image: url(images/geocoder.png); background-repeat: no-repeat; background-position: center; - float: right; - cursor: pointer; } .leaflet-touch .leaflet-control-geocoder-icon { - margin-top: 2px; width: 30px; + height: 30px; } .leaflet-control-geocoder-throbber .leaflet-control-geocoder-icon { background-image: url(images/throbber.gif); } -.leaflet-control-geocoder-expanded input, .leaflet-control-geocoder-error { - width: 226px; - margin: 0 0 0 4px; - padding: 0 0 0 4px; - vertical-align: middle; - color: #000; +.leaflet-control-geocoder-form-no-error { + display: none; } .leaflet-control-geocoder-form input:focus { @@ -68,73 +71,52 @@ .leaflet-control-geocoder-form button { display: none; } - -.leaflet-control-geocoder-form-no-error { - display: none; -} - .leaflet-control-geocoder-error { margin-top: 8px; + margin-left: 8px; display: block; color: #444; } - -ul.leaflet-control-geocoder-alternatives { - width: 260px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - list-style: none; - padding: 0; - transition: height 0.125s ease-in; +.leaflet-control-geocoder-alternatives { + display: block; + width: 272px; + list-style: none; + padding: 0; + margin: 0; } .leaflet-control-geocoder-alternatives-minimized { - width: 0 !important; + display: none; height: 0; - overflow: hidden; - margin: 0; - padding: 0; } - .leaflet-control-geocoder-alternatives li { - width: 100%; + white-space: nowrap; + display: block; overflow: hidden; + padding: 5px 8px; text-overflow: ellipsis; - border-bottom: 1px solid #eee; - padding: 0; + border-bottom: 1px solid #ccc; + cursor: pointer; } +.leaflet-control-geocoder-alternatives li a, .leaflet-control-geocoder-alternatives li a:hover { + width: inherit; + height: inherit; + line-height: inherit; + background: inherit; + border-radius: inherit; + text-align: left; +} .leaflet-control-geocoder-alternatives li:last-child { border-bottom: none; } - -.leaflet-control-geocoder-alternatives a { - display: block; - text-decoration: none; - color: black; - padding: 6px 8px 16px 6px; - font-size: 14px; - line-height: 1; - font-weight: bold; +.leaflet-control-geocoder-alternatives li:hover, .leaflet-control-geocoder-selected { + background-color: #f5f5f5; } - -.leaflet-touch .leaflet-control-geocoder-alternatives a { - font-size: 18px; -} - -.leaflet-control-geocoder-alternatives a:hover, .leaflet-control-geocoder-selected { - background-color: #ddd; -} - .leaflet-control-geocoder-address-detail { - font-size: 12px; - font-weight: normal; + } - .leaflet-control-geocoder-address-context { color: #666; - font-size: 12px; - font-weight: lighter; } \ No newline at end of file diff --git a/assets/control-geocoder/Control.Geocoder.js b/assets/control-geocoder/Control.Geocoder.js index e419ce2..e7d5b28 100644 --- a/assets/control-geocoder/Control.Geocoder.js +++ b/assets/control-geocoder/Control.Geocoder.js @@ -1,68 +1,64 @@ -(function (factory) { - // Packaging/modules magic dance - var L; - if (typeof define === 'function' && define.amd) { - // AMD - define(['leaflet'], factory); - } else if (typeof module !== 'undefined') { - // Node/CommonJS - L = require('leaflet'); - module.exports = factory(L); - } else { - // Browser globals - if (typeof window.L === 'undefined') - throw 'Leaflet must be loaded first'; - factory(window.L); - } -}(function (L) { - 'use strict'; - L.Control.Geocoder = L.Control.extend({ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { this._alts.innerHTML = ''; @@ -103,6 +112,8 @@ }, markGeocode: function(result) { + result = result.geocode || result; + this._map.fitBounds(result.bbox); if (this._geocodeMarker) { @@ -117,14 +128,22 @@ return this; }, - _geocode: function(event) { - L.DomEvent.preventDefault(event); + _geocode: function(suggest) { + var requestCount = ++this._requestCount, + mode = suggest ? 'suggest' : 'geocode'; - L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber'); - this._clearResults(); - this.options.geocoder.geocode(this._input.value, this._geocodeResult, this); + this._lastGeocode = this._input.value; + if (!suggest) { + this._clearResults(); + } - return false; + this.fire('start' + mode); + this.options.geocoder[mode](this._input.value, function(results) { + if (requestCount === this._requestCount) { + this.fire('finish' + mode); + this._geocodeResult(results, suggest); + } + }, this); }, _geocodeResultSelected: function(result) { @@ -133,7 +152,8 @@ } else { this._clearResults(); } - this.markGeocode(result); + + this.fire('markgeocode', {geocode: result}); }, _toggle: function() { @@ -147,12 +167,14 @@ _expand: function () { L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded'); this._input.select(); + this.fire('expand'); }, _collapse: function () { this._container.className = this._container.className.replace(' leaflet-control-geocoder-expanded', ''); L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); + this.fire('collapse'); }, _clearResults: function () { @@ -162,37 +184,37 @@ }, _createAlt: function(result, index) { - var li = document.createElement('li'), - a = L.DomUtil.create('a', '', li), + var li = L.DomUtil.create('li', ''), + a = L.DomUtil.create('a', '', li), icon = this.options.showResultIcons && result.icon ? L.DomUtil.create('img', '', a) : null, - text = result.html ? undefined : document.createTextNode(result.name); + text = result.html ? undefined : document.createTextNode(result.name), + clickHandler = function clickHandler(e) { + L.DomEvent.preventDefault(e); + this._geocodeResultSelected(result); + }; if (icon) { icon.src = result.icon; } - a.href = '#'; - a.setAttribute('data-result-index', index); + li.setAttribute('data-result-index', index); if (result.html) { - a.innerHTML = result.html; + a.innerHTML = a.innerHTML + result.html; } else { a.appendChild(text); } - L.DomEvent.addListener(li, 'click', function clickHandler(e) { - L.DomEvent.preventDefault(e); - this._geocodeResultSelected(result); - }, this); + L.DomEvent.addListener(li, 'mousedown', clickHandler, this); return li; }, _keydown: function(e) { var _this = this, - select = function select(dir) { + select = function select(dir) { if (_this._selection) { - L.DomUtil.removeClass(_this._selection.firstChild, 'leaflet-control-geocoder-selected'); + L.DomUtil.removeClass(_this._selection, 'leaflet-control-geocoder-selected'); _this._selection = _this._selection[dir > 0 ? 'nextSibling' : 'previousSibling']; } if (!_this._selection) { @@ -200,7 +222,7 @@ } if (_this._selection) { - L.DomUtil.addClass(_this._selection.firstChild, 'leaflet-control-geocoder-selected'); + L.DomUtil.addClass(_this._selection, 'leaflet-control-geocoder-selected'); } }; @@ -224,57 +246,934 @@ // Enter case 13: if (this._selection) { - var index = parseInt(this._selection.firstChild.getAttribute('data-result-index'), 10); + var index = parseInt(this._selection.getAttribute('data-result-index'), 10); this._geocodeResultSelected(this._results[index]); this._clearResults(); - L.DomEvent.preventDefault(e); + } else { + this._geocode(); + } + L.DomEvent.preventDefault(e); + break; + default: + var v = this._input.value; + if (this.options.geocoder.suggest && v !== this._lastGeocode) { + clearTimeout(this._suggestTimeout); + if (v.length >= this.options.suggestMinLength) { + this._suggestTimeout = setTimeout(L.bind(function() { + this._geocode(true); + }, this), this.options.suggestTimeout); + } else { + this._clearResults(); + } } } - return true; } - }); + }), + factory: function(options) { + return new L.Control.Geocoder(options); + } +}; - L.Control.geocoder = function(id, options) { - return new L.Control.Geocoder(id, options); - }; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./geocoders/nominatim":9}],2:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); - L.Control.Geocoder.callbackId = 0; - L.Control.Geocoder.jsonp = function(url, params, callback, context, jsonpParam) { - var callbackId = '_l_geocoder_' + (L.Control.Geocoder.callbackId++); - params[jsonpParam || 'callback'] = callbackId; - window[callbackId] = L.Util.bind(callback, context); - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = url + L.Util.getParamString(params); - script.id = callbackId; - document.getElementsByTagName('head')[0].appendChild(script); - }; - L.Control.Geocoder.getJSON = function(url, params, callback) { - var xmlHttp = new XMLHttpRequest(); - xmlHttp.open( "GET", url + L.Util.getParamString(params), true); - xmlHttp.send(null); - xmlHttp.onreadystatechange = function () { - if (xmlHttp.readyState != 4) return; - if (xmlHttp.status != 200 && req.status != 304) return; - callback(JSON.parse(xmlHttp.response)); - }; - }; +module.exports = { + "class": L.Class.extend({ + options: { + service_url: 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer' + }, - L.Control.Geocoder.template = function (str, data, htmlEscape) { - return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { - var value = data[key]; - if (value === undefined) { - value = ''; - } else if (typeof value === 'function') { - value = value(data); + initialize: function(accessToken, options) { + L.setOptions(this, options); + this._accessToken = accessToken; + }, + + geocode: function(query, cb, context) { + var params = { + SingleLine: query, + outFields: 'Addr_Type', + forStorage: false, + maxLocations: 10, + f: 'json' + }; + + if (this._key && this._key.length) { + params.token = this._key; } - return L.Control.Geocoder.htmlEscape(value); - }); - }; - // Adapted from handlebars.js - // https://github.com/wycats/handlebars.js/ - L.Control.Geocoder.htmlEscape = (function() { + Util.getJSON(this.options.service_url + '/findAddressCandidates', params, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + + if (data.candidates && data.candidates.length) { + for (var i = 0; i <= data.candidates.length - 1; i++) { + loc = data.candidates[i]; + latLng = L.latLng(loc.location.y, loc.location.x); + latLngBounds = L.latLngBounds(L.latLng(loc.extent.ymax, loc.extent.xmax), L.latLng(loc.extent.ymin, loc.extent.xmin)); + results[i] = { + name: loc.address, + bbox: latLngBounds, + center: latLng + }; + } + } + + cb.call(context, results); + }); + }, + + suggest: function(query, cb, context) { + return this.geocode(query, cb, context); + }, + + reverse: function(location, scale, cb, context) { + var params = { + location: encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat), + distance: 100, + f: 'json' + }; + + Util.getJSON(this.options.service_url + '/reverseGeocode', params, function(data) { + var result = [], + loc; + + if (data && !data.error) { + loc = L.latLng(data.location.y, data.location.x); + result.push({ + name: data.address.Match_addr, + center: loc, + bounds: L.latLngBounds(loc, loc) + }); + } + + cb.call(context, result); + }); + } + }), + + factory: function(accessToken, options) { + return new L.Control.Geocoder.ArcGis(accessToken, options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],3:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + initialize: function(key) { + this.key = key; + }, + + geocode : function (query, cb, context) { + Util.jsonp('https://dev.virtualearth.net/REST/v1/Locations', { + query: query, + key : this.key + }, function(data) { + var results = []; + if( data.resourceSets.length > 0 ){ + for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { + var resource = data.resourceSets[0].resources[i], + bbox = resource.bbox; + results[i] = { + name: resource.name, + bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), + center: L.latLng(resource.point.coordinates) + }; + } + } + cb.call(context, results); + }, this, 'jsonp'); + }, + + reverse: function(location, scale, cb, context) { + Util.jsonp('//dev.virtualearth.net/REST/v1/Locations/' + location.lat + ',' + location.lng, { + key : this.key + }, function(data) { + var results = []; + for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { + var resource = data.resourceSets[0].resources[i], + bbox = resource.bbox; + results[i] = { + name: resource.name, + bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), + center: L.latLng(resource.point.coordinates) + }; + } + cb.call(context, results); + }, this, 'jsonp'); + } + }), + + factory: function(key) { + return new L.Control.Geocoder.Bing(key); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],4:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json', + geocodingQueryParams: {}, + reverseQueryParams: {} + }, + + initialize: function(key, options) { + this._key = key; + L.setOptions(this, options); + // Backwards compatibility + this.options.serviceUrl = this.options.service_url || this.options.serviceUrl; + }, + + geocode: function(query, cb, context) { + var params = { + address: query + }; + + if (this._key && this._key.length) { + params.key = this._key; + } + + params = L.Util.extend(params, this.options.geocodingQueryParams); + + Util.getJSON(this.options.serviceUrl, params, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + if (data.results && data.results.length) { + for (var i = 0; i <= data.results.length - 1; i++) { + loc = data.results[i]; + latLng = L.latLng(loc.geometry.location); + latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); + results[i] = { + name: loc.formatted_address, + bbox: latLngBounds, + center: latLng, + properties: loc.address_components + }; + } + } + + cb.call(context, results); + }); + }, + + reverse: function(location, scale, cb, context) { + var params = { + latlng: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) + }; + params = L.Util.extend(params, this.options.reverseQueryParams); + if (this._key && this._key.length) { + params.key = this._key; + } + + Util.getJSON(this.options.serviceUrl, params, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + if (data.results && data.results.length) { + for (var i = 0; i <= data.results.length - 1; i++) { + loc = data.results[i]; + latLng = L.latLng(loc.geometry.location); + latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); + results[i] = { + name: loc.formatted_address, + bbox: latLngBounds, + center: latLng, + properties: loc.address_components + }; + } + } + + cb.call(context, results); + }); + } + }), + + factory: function(key, options) { + return new L.Control.Geocoder.Google(key, options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],5:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + geocodeUrl: 'http://geocoder.api.here.com/6.2/geocode.json', + reverseGeocodeUrl: 'http://reverse.geocoder.api.here.com/6.2/reversegeocode.json', + app_id: '', + app_code: '', + geocodingQueryParams: {}, + reverseQueryParams: {} + }, + + initialize: function(options) { + L.setOptions(this, options); + }, + + geocode: function(query, cb, context) { + var params = { + searchtext: query, + gen: 9, + app_id: this.options.app_id, + app_code: this.options.app_code, + jsonattributes: 1 + }; + params = L.Util.extend(params, this.options.geocodingQueryParams); + this.getJSON(this.options.geocodeUrl, params, cb, context); + }, + + reverse: function(location, scale, cb, context) { + var params = { + prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng), + mode: 'retrieveAddresses', + app_id: this.options.app_id, + app_code: this.options.app_code, + gen: 9, + jsonattributes: 1 + }; + params = L.Util.extend(params, this.options.reverseQueryParams); + this.getJSON(this.options.reverseGeocodeUrl, params, cb, context); + }, + + getJSON: function(url, params, cb, context) { + Util.getJSON(url, params, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + if (data.response.view && data.response.view.length) { + for (var i = 0; i <= data.response.view[0].result.length - 1; i++) { + loc = data.response.view[0].result[i].location; + latLng = L.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude); + latLngBounds = L.latLngBounds(L.latLng(loc.mapView.topLeft.latitude, loc.mapView.topLeft.longitude), L.latLng(loc.mapView.bottomRight.latitude, loc.mapView.bottomRight.longitude)); + results[i] = { + name: loc.address.label, + bbox: latLngBounds, + center: latLng + }; + } + } + cb.call(context, results); + }) + } + }), + + factory: function(options) { + return new L.Control.Geocoder.HERE(options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],6:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/' + }, + + initialize: function(accessToken, options) { + L.setOptions(this, options); + this._accessToken = accessToken; + }, + + geocode: function(query, cb, context) { + Util.getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', { + access_token: this._accessToken + }, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + if (data.features && data.features.length) { + for (var i = 0; i <= data.features.length - 1; i++) { + loc = data.features[i]; + latLng = L.latLng(loc.center.reverse()); + if(loc.hasOwnProperty('bbox')) + { + latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); + } + else + { + latLngBounds = L.latLngBounds(latLng, latLng); + } + results[i] = { + name: loc.place_name, + bbox: latLngBounds, + center: latLng + }; + } + } + + cb.call(context, results); + }); + }, + + suggest: function(query, cb, context) { + return this.geocode(query, cb, context); + }, + + reverse: function(location, scale, cb, context) { + Util.getJSON(this.options.serviceUrl + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', { + access_token: this._accessToken + }, function(data) { + var results = [], + loc, + latLng, + latLngBounds; + if (data.features && data.features.length) { + for (var i = 0; i <= data.features.length - 1; i++) { + loc = data.features[i]; + latLng = L.latLng(loc.center.reverse()); + if(loc.hasOwnProperty('bbox')) + { + latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); + } + else + { + latLngBounds = L.latLngBounds(latLng, latLng); + } + results[i] = { + name: loc.place_name, + bbox: latLngBounds, + center: latLng + }; + } + } + + cb.call(context, results); + }); + } + }), + + factory: function(accessToken, options) { + return new L.Control.Geocoder.Mapbox(accessToken, options); + } +}; + + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],7:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://www.mapquestapi.com/geocoding/v1' + }, + + initialize: function(key, options) { + // MapQuest seems to provide URI encoded API keys, + // so to avoid encoding them twice, we decode them here + this._key = decodeURIComponent(key); + + L.Util.setOptions(this, options); + }, + + _formatName: function() { + var r = [], + i; + for (i = 0; i < arguments.length; i++) { + if (arguments[i]) { + r.push(arguments[i]); + } + } + + return r.join(', '); + }, + + geocode: function(query, cb, context) { + Util.jsonp(this.options.serviceUrl + '/address', { + key: this._key, + location: query, + limit: 5, + outFormat: 'json' + }, function(data) { + var results = [], + loc, + latLng; + if (data.results && data.results[0].locations) { + for (var i = data.results[0].locations.length - 1; i >= 0; i--) { + loc = data.results[0].locations[i]; + latLng = L.latLng(loc.latLng); + results[i] = { + name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), + bbox: L.latLngBounds(latLng, latLng), + center: latLng + }; + } + } + + cb.call(context, results); + }, this); + }, + + reverse: function(location, scale, cb, context) { + Util.jsonp(this.options.serviceUrl + '/reverse', { + key: this._key, + location: location.lat + ',' + location.lng, + outputFormat: 'json' + }, function(data) { + var results = [], + loc, + latLng; + if (data.results && data.results[0].locations) { + for (var i = data.results[0].locations.length - 1; i >= 0; i--) { + loc = data.results[0].locations[i]; + latLng = L.latLng(loc.latLng); + results[i] = { + name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), + bbox: L.latLngBounds(latLng, latLng), + center: latLng + }; + } + } + + cb.call(context, results); + }, this); + } + }), + + factory: function(key, options) { + return new L.Control.Geocoder.MapQuest(key, options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],8:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://search.mapzen.com/v1', + geocodingQueryParams: {}, + reverseQueryParams: {} + }, + + initialize: function(apiKey, options) { + L.Util.setOptions(this, options); + this._apiKey = apiKey; + this._lastSuggest = 0; + }, + + geocode: function(query, cb, context) { + var _this = this; + Util.getJSON(this.options.serviceUrl + "/search", L.extend({ + 'api_key': this._apiKey, + 'text': query + }, this.options.geocodingQueryParams), function(data) { + cb.call(context, _this._parseResults(data, "bbox")); + }); + }, + + suggest: function(query, cb, context) { + var _this = this; + Util.getJSON(this.options.serviceUrl + "/autocomplete", L.extend({ + 'api_key': this._apiKey, + 'text': query + }, this.options.geocodingQueryParams), L.bind(function(data) { + if (data.geocoding.timestamp > this._lastSuggest) { + this._lastSuggest = data.geocoding.timestamp; + cb.call(context, _this._parseResults(data, "bbox")); + } + }, this)); + }, + + reverse: function(location, scale, cb, context) { + var _this = this; + Util.getJSON(this.options.serviceUrl + "/reverse", L.extend({ + 'api_key': this._apiKey, + 'point.lat': location.lat, + 'point.lon': location.lng + }, this.options.reverseQueryParams), function(data) { + cb.call(context, _this._parseResults(data, "bounds")); + }); + }, + + _parseResults: function(data, bboxname) { + var results = []; + L.geoJson(data, { + pointToLayer: function (feature, latlng) { + return L.circleMarker(latlng); + }, + onEachFeature: function(feature, layer) { + var result = {}, + bbox, + center; + + if (layer.getBounds) { + bbox = layer.getBounds(); + center = bbox.getCenter(); + } else { + center = layer.getLatLng(); + bbox = L.latLngBounds(center, center); + } + + result.name = layer.feature.properties.label; + result.center = center; + result[bboxname] = bbox; + result.properties = layer.feature.properties; + results.push(result); + } + }); + return results; + } + }), + + factory: function(apiKey, options) { + return new L.Control.Geocoder.Mapzen(apiKey, options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],9:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://nominatim.openstreetmap.org/', + geocodingQueryParams: {}, + reverseQueryParams: {}, + htmlTemplate: function(r) { + var a = r.address, + parts = []; + if (a.road || a.building) { + parts.push('{building} {road} {house_number}'); + } + + if (a.city || a.town || a.village || a.hamlet) { + parts.push('{postcode} {city} {town} {village} {hamlet}'); + } + + if (a.state || a.country) { + parts.push('{state} {country}'); + } + + return Util.template(parts.join('
'), a, true); + } + }, + + initialize: function(options) { + L.Util.setOptions(this, options); + }, + + geocode: function(query, cb, context) { + Util.jsonp(this.options.serviceUrl + 'search', L.extend({ + q: query, + limit: 5, + format: 'json', + addressdetails: 1 + }, this.options.geocodingQueryParams), + function(data) { + var results = []; + for (var i = data.length - 1; i >= 0; i--) { + var bbox = data[i].boundingbox; + for (var j = 0; j < 4; j++) bbox[j] = parseFloat(bbox[j]); + results[i] = { + icon: data[i].icon, + name: data[i].display_name, + html: this.options.htmlTemplate ? + this.options.htmlTemplate(data[i]) + : undefined, + bbox: L.latLngBounds([bbox[0], bbox[2]], [bbox[1], bbox[3]]), + center: L.latLng(data[i].lat, data[i].lon), + properties: data[i] + }; + } + cb.call(context, results); + }, this, 'json_callback'); + }, + + reverse: function(location, scale, cb, context) { + Util.jsonp(this.options.serviceUrl + 'reverse', L.extend({ + lat: location.lat, + lon: location.lng, + zoom: Math.round(Math.log(scale / 256) / Math.log(2)), + addressdetails: 1, + format: 'json' + }, this.options.reverseQueryParams), function(data) { + var result = [], + loc; + + if (data && data.lat && data.lon) { + loc = L.latLng(data.lat, data.lon); + result.push({ + name: data.display_name, + html: this.options.htmlTemplate ? + this.options.htmlTemplate(data) + : undefined, + center: loc, + bounds: L.latLngBounds(loc, loc), + properties: data + }); + } + + cb.call(context, result); + }, this, 'json_callback'); + } + }), + + factory: function(options) { + return new L.Control.Geocoder.Nominatim(options); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],10:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://photon.komoot.de/api/', + reverseUrl: 'https://photon.komoot.de/reverse/', + nameProperties: [ + 'name', + 'street', + 'suburb', + 'hamlet', + 'town', + 'city', + 'state', + 'country' + ] + }, + + initialize: function(options) { + L.setOptions(this, options); + }, + + geocode: function(query, cb, context) { + var params = L.extend({ + q: query + }, this.options.geocodingQueryParams); + + Util.getJSON(this.options.serviceUrl, params, L.bind(function(data) { + cb.call(context, this._decodeFeatures(data)); + }, this)); + }, + + suggest: function(query, cb, context) { + return this.geocode(query, cb, context); + }, + + reverse: function(latLng, scale, cb, context) { + var params = L.extend({ + lat: latLng.lat, + lon: latLng.lng + }, this.options.geocodingQueryParams); + + Util.getJSON(this.options.reverseUrl, params, L.bind(function(data) { + cb.call(context, this._decodeFeatures(data)); + }, this)); + }, + + _decodeFeatures: function(data) { + var results = [], + i, + f, + c, + latLng, + extent, + bbox; + + if (data && data.features) { + for (i = 0; i < data.features.length; i++) { + f = data.features[i]; + c = f.geometry.coordinates; + latLng = L.latLng(c[1], c[0]); + extent = f.properties.extent; + + if (extent) { + bbox = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]); + } else { + bbox = L.latLngBounds(latLng, latLng); + } + + results.push({ + name: this._deocodeFeatureName(f), + center: latLng, + bbox: bbox, + properties: f.properties + }); + } + } + + return results; + }, + + _deocodeFeatureName: function(f) { + var j, + name; + for (j = 0; !name && j < this.options.nameProperties.length; j++) { + name = f.properties[this.options.nameProperties[j]]; + } + + return name; + } + }), + + factory: function(options) { + return new L.Control.Geocoder.Photon(options); + } +}; + + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],11:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Util = require('../util'); + +module.exports = { + "class": L.Class.extend({ + options: { + serviceUrl: 'https://api.what3words.com/v2/' + }, + + initialize: function(accessToken) { + this._accessToken = accessToken; + }, + + geocode: function(query, cb, context) { + //get three words and make a dot based string + Util.getJSON(this.options.serviceUrl +'forward', { + key: this._accessToken, + addr: query.split(/\s+/).join('.') + }, function(data) { + var results = [], loc, latLng, latLngBounds; + if (data.hasOwnProperty('geometry')) { + latLng = L.latLng(data.geometry['lat'],data.geometry['lng']); + latLngBounds = L.latLngBounds(latLng, latLng); + results[0] = { + name: data.words, + bbox: latLngBounds, + center: latLng + }; + } + + cb.call(context, results); + }); + }, + + suggest: function(query, cb, context) { + return this.geocode(query, cb, context); + }, + + reverse: function(location, scale, cb, context) { + Util.getJSON(this.options.serviceUrl +'reverse', { + key: this._accessToken, + coords: [location.lat,location.lng].join(',') + }, function(data) { + var results = [],loc,latLng,latLngBounds; + if (data.status.status == 200) { + latLng = L.latLng(data.geometry['lat'],data.geometry['lng']); + latLngBounds = L.latLngBounds(latLng, latLng); + results[0] = { + name: data.words, + bbox: latLngBounds, + center: latLng + }; + } + cb.call(context, results); + }); + } + }), + + factory: function(accessToken) { + return new L.Control.Geocoder.What3Words(accessToken); + } +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":13}],12:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + Control = require('./control'), + Nominatim = require('./geocoders/nominatim'), + Bing = require('./geocoders/bing'), + MapQuest = require('./geocoders/mapquest'), + Mapbox = require('./geocoders/mapbox'), + What3Words = require('./geocoders/what3words'), + Google = require('./geocoders/google'), + Photon = require('./geocoders/photon'), + Mapzen = require('./geocoders/mapzen'), + ArcGis = require('./geocoders/arcgis'), + HERE = require('./geocoders/here'); + +module.exports = L.Util.extend(Control["class"], { + Nominatim: Nominatim["class"], + nominatim: Nominatim.factory, + Bing: Bing["class"], + bing: Bing.factory, + MapQuest: MapQuest["class"], + mapQuest: MapQuest.factory, + Mapbox: Mapbox["class"], + mapbox: Mapbox.factory, + What3Words: What3Words["class"], + what3words: What3Words.factory, + Google: Google["class"], + google: Google.factory, + Photon: Photon["class"], + photon: Photon.factory, + Mapzen: Mapzen["class"], + mapzen: Mapzen.factory, + ArcGis: ArcGis["class"], + arcgis: ArcGis.factory, + HERE: HERE["class"], + here: HERE.factory +}); + +L.Util.extend(L.Control, { + Geocoder: module.exports, + geocoder: Control.factory +}); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./control":1,"./geocoders/arcgis":2,"./geocoders/bing":3,"./geocoders/google":4,"./geocoders/here":5,"./geocoders/mapbox":6,"./geocoders/mapquest":7,"./geocoders/mapzen":8,"./geocoders/nominatim":9,"./geocoders/photon":10,"./geocoders/what3words":11}],13:[function(require,module,exports){ +(function (global){ +var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), + lastCallbackId = 0, + htmlEscape = (function() { + // Adapted from handlebars.js + // https://github.com/wycats/handlebars.js/ var badChars = /[&<>"'`]/g; var possible = /[&<>"'`]/; var escape = { @@ -309,431 +1208,49 @@ }; })(); - L.Control.Geocoder.Nominatim = L.Class.extend({ - options: { - serviceUrl: '//nominatim.openstreetmap.org/', - geocodingQueryParams: {}, - reverseQueryParams: {}, - htmlTemplate: function(r) { - var a = r.address, - parts = []; - if (a.road || a.building) { - parts.push('{building} {road} {house_number}'); - } +module.exports = { + jsonp: function(url, params, callback, context, jsonpParam) { + var callbackId = '_l_geocoder_' + (lastCallbackId++); + params[jsonpParam || 'callback'] = callbackId; + window[callbackId] = L.Util.bind(callback, context); + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url + L.Util.getParamString(params); + script.id = callbackId; + document.getElementsByTagName('head')[0].appendChild(script); + }, - if (a.city || a.town || a.village) { - parts.push('{postcode} {city} {town} {village}'); - } - - if (a.state || a.country) { - parts.push('{state} {country}'); - } - - return L.Control.Geocoder.template(parts.join('
'), a, true); + getJSON: function(url, params, callback) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState !== 4){ + return; } - }, - - initialize: function(options) { - L.Util.setOptions(this, options); - }, - - geocode: function(query, cb, context) { - L.Control.Geocoder.jsonp(this.options.serviceUrl + 'search/', L.extend({ - q: query, - limit: 5, - format: 'json', - addressdetails: 1 - }, this.options.geocodingQueryParams), - function(data) { - var results = []; - for (var i = data.length - 1; i >= 0; i--) { - var bbox = data[i].boundingbox; - for (var j = 0; j < 4; j++) bbox[j] = parseFloat(bbox[j]); - results[i] = { - icon: data[i].icon, - name: data[i].display_name, - html: this.options.htmlTemplate ? - this.options.htmlTemplate(data[i]) - : undefined, - bbox: L.latLngBounds([bbox[0], bbox[2]], [bbox[1], bbox[3]]), - center: L.latLng(data[i].lat, data[i].lon), - properties: data[i] - }; - } - cb.call(context, results); - }, this, 'json_callback'); - }, - - reverse: function(location, scale, cb, context) { - L.Control.Geocoder.jsonp(this.options.serviceUrl + 'reverse/', L.extend({ - lat: location.lat, - lon: location.lng, - zoom: Math.round(Math.log(scale / 256) / Math.log(2)), - addressdetails: 1, - format: 'json' - }, this.options.reverseQueryParams), function(data) { - var result = [], - loc; - - if (data && data.lat && data.lon) { - loc = L.latLng(data.lat, data.lon); - result.push({ - name: data.display_name, - html: this.options.htmlTemplate ? - this.options.htmlTemplate(data) - : undefined, - center: loc, - bounds: L.latLngBounds(loc, loc), - properties: data - }); - } - - cb.call(context, result); - }, this, 'json_callback'); - } - }); - - L.Control.Geocoder.nominatim = function(options) { - return new L.Control.Geocoder.Nominatim(options); - }; - - L.Control.Geocoder.Bing = L.Class.extend({ - initialize: function(key) { - this.key = key; - }, - - geocode : function (query, cb, context) { - L.Control.Geocoder.jsonp('//dev.virtualearth.net/REST/v1/Locations', { - query: query, - key : this.key - }, function(data) { - var results = []; - for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { - var resource = data.resourceSets[0].resources[i], - bbox = resource.bbox; - results[i] = { - name: resource.name, - bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), - center: L.latLng(resource.point.coordinates) - }; - } - cb.call(context, results); - }, this, 'jsonp'); - }, - - reverse: function(location, scale, cb, context) { - L.Control.Geocoder.jsonp('//dev.virtualearth.net/REST/v1/Locations/' + location.lat + ',' + location.lng, { - key : this.key - }, function(data) { - var results = []; - for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { - var resource = data.resourceSets[0].resources[i], - bbox = resource.bbox; - results[i] = { - name: resource.name, - bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), - center: L.latLng(resource.point.coordinates) - }; - } - cb.call(context, results); - }, this, 'jsonp'); - } - }); - - L.Control.Geocoder.bing = function(key) { - return new L.Control.Geocoder.Bing(key); - }; - - L.Control.Geocoder.RaveGeo = L.Class.extend({ - options: { - querySuffix: '', - deepSearch: true, - wordBased: false - }, - - jsonp: function(params, callback, context) { - var callbackId = '_l_geocoder_' + (L.Control.Geocoder.callbackId++), - paramParts = []; - params.prepend = callbackId + '('; - params.append = ')'; - for (var p in params) { - paramParts.push(p + '=' + escape(params[p])); + if (xmlHttp.status !== 200 && xmlHttp.status !== 304){ + callback(''); + return; } + callback(JSON.parse(xmlHttp.response)); + }; + xmlHttp.open('GET', url + L.Util.getParamString(params), true); + xmlHttp.setRequestHeader('Accept', 'application/json'); + xmlHttp.send(null); + }, - window[callbackId] = L.Util.bind(callback, context); - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = this._serviceUrl + '?' + paramParts.join('&'); - script.id = callbackId; - document.getElementsByTagName('head')[0].appendChild(script); - }, - - initialize: function(serviceUrl, scheme, options) { - L.Util.setOptions(this, options); - - this._serviceUrl = serviceUrl; - this._scheme = scheme; - }, - - geocode: function(query, cb, context) { - L.Control.Geocoder.jsonp(this._serviceUrl, { - address: query + this.options.querySuffix, - scheme: this._scheme, - outputFormat: 'jsonp', - deepSearch: this.options.deepSearch, - wordBased: this.options.wordBased - }, function(data) { - var results = []; - for (var i = data.length - 1; i >= 0; i--) { - var r = data[i], - c = L.latLng(r.y, r.x); - results[i] = { - name: r.address, - bbox: L.latLngBounds([c]), - center: c - }; - } - cb.call(context, results); - }, this); - } - }); - - L.Control.Geocoder.raveGeo = function(serviceUrl, scheme, options) { - return new L.Control.Geocoder.RaveGeo(serviceUrl, scheme, options); - }; - - L.Control.Geocoder.MapQuest = L.Class.extend({ - initialize: function(key) { - // MapQuest seems to provide URI encoded API keys, - // so to avoid encoding them twice, we decode them here - this._key = decodeURIComponent(key); - }, - - _formatName: function() { - var r = [], - i; - for (i = 0; i < arguments.length; i++) { - if (arguments[i]) { - r.push(arguments[i]); - } + template: function (str, data) { + return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { + var value = data[key]; + if (value === undefined) { + value = ''; + } else if (typeof value === 'function') { + value = value(data); } + return htmlEscape(value); + }); + }, - return r.join(', '); - }, + htmlEscape: htmlEscape +}; - geocode: function(query, cb, context) { - L.Control.Geocoder.jsonp('//www.mapquestapi.com/geocoding/v1/address', { - key: this._key, - location: query, - limit: 5, - outFormat: 'json' - }, function(data) { - var results = [], - loc, - latLng; - if (data.results && data.results[0].locations) { - for (var i = data.results[0].locations.length - 1; i >= 0; i--) { - loc = data.results[0].locations[i]; - latLng = L.latLng(loc.latLng); - results[i] = { - name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), - bbox: L.latLngBounds(latLng, latLng), - center: latLng - }; - } - } - - cb.call(context, results); - }, this); - }, - - reverse: function(location, scale, cb, context) { - L.Control.Geocoder.jsonp('//www.mapquestapi.com/geocoding/v1/reverse', { - key: this._key, - location: location.lat + ',' + location.lng, - outputFormat: 'json' - }, function(data) { - var results = [], - loc, - latLng; - if (data.results && data.results[0].locations) { - for (var i = data.results[0].locations.length - 1; i >= 0; i--) { - loc = data.results[0].locations[i]; - latLng = L.latLng(loc.latLng); - results[i] = { - name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), - bbox: L.latLngBounds(latLng, latLng), - center: latLng - }; - } - } - - cb.call(context, results); - }, this); - } - }); - - L.Control.Geocoder.mapQuest = function(key) { - return new L.Control.Geocoder.MapQuest(key); - }; - - L.Control.Geocoder.Mapbox = L.Class.extend({ - options: { - service_url: 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/' - }, - - initialize: function(access_token) { - this._access_token = access_token; - }, - - geocode: function(query, cb, context) { - L.Control.Geocoder.getJSON(this.options.service_url + encodeURIComponent(query) + '.json', { - access_token: this._access_token, - }, function(data) { - var results = [], - loc, - latLng, - latLngBounds; - if (data.features && data.features.length) { - for (var i = 0; i <= data.features.length - 1; i++) { - loc = data.features[i]; - latLng = L.latLng(loc.center.reverse()); - if(loc.hasOwnProperty('bbox')) - { - latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); - } - else - { - latLngBounds = L.latLngBounds(latLng, latLng); - } - results[i] = { - name: loc.place_name, - bbox: latLngBounds, - center: latLng - }; - } - } - - cb.call(context, results); - }); - }, - - suggest: function(query, cb, context) { - return this.geocode(query, cb, context); - }, - - reverse: function(location, scale, cb, context) { - L.Control.Geocoder.getJSON(this.options.service_url + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', { - access_token: this._access_token, - }, function(data) { - var results = [], - loc, - latLng, - latLngBounds; - if (data.features && data.features.length) { - for (var i = 0; i <= data.features.length - 1; i++) { - loc = data.features[i]; - latLng = L.latLng(loc.center.reverse()); - if(loc.hasOwnProperty('bbox')) - { - latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); - } - else - { - latLngBounds = L.latLngBounds(latLng, latLng); - } - results[i] = { - name: loc.place_name, - bbox: latLngBounds, - center: latLng - }; - } - } - - cb.call(context, results); - }); - } - }); - - L.Control.Geocoder.mapbox = function(access_token) { - return new L.Control.Geocoder.Mapbox(access_token); - }; - - L.Control.Geocoder.Google = L.Class.extend({ - options: { - service_url: 'https://maps.googleapis.com/maps/api/geocode/json' - }, - - initialize: function(key) { - this._key = key; - }, - - geocode: function(query, cb, context) { - var params = { - address: query, - }; - if(this._key && this._key.length) - { - params['key'] = this._key - } - - L.Control.Geocoder.getJSON(this.options.service_url, params, function(data) { - var results = [], - loc, - latLng, - latLngBounds; - if (data.results && data.results.length) { - for (var i = 0; i <= data.results.length - 1; i++) { - loc = data.results[i]; - latLng = L.latLng(loc.geometry.location); - latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); - results[i] = { - name: loc.formatted_address, - bbox: latLngBounds, - center: latLng - }; - } - } - - cb.call(context, results); - }); - }, - - reverse: function(location, scale, cb, context) { - var params = { - latlng: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) - }; - if(this._key && this._key.length) - { - params['key'] = this._key - } - L.Control.Geocoder.getJSON(this.options.service_url, params, function(data) { - var results = [], - loc, - latLng, - latLngBounds; - if (data.results && data.results.length) { - for (var i = 0; i <= data.results.length - 1; i++) { - loc = data.results[i]; - latLng = L.latLng(loc.geometry.location); - latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); - results[i] = { - name: loc.formatted_address, - bbox: latLngBounds, - center: latLng - }; - } - } - - cb.call(context, results); - }); - } - }); - - L.Control.Geocoder.google = function(key) { - return new L.Control.Geocoder.Google(key); - }; - return L.Control.Geocoder; -})); +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}]},{},[12]); diff --git a/assets/control-geocoder/Control.Geocoder.min.css b/assets/control-geocoder/Control.Geocoder.min.css index 50b0cef..44e3a84 100644 --- a/assets/control-geocoder/Control.Geocoder.min.css +++ b/assets/control-geocoder/Control.Geocoder.min.css @@ -1 +1 @@ -.leaflet-control-geocoder{background:#fff;box-shadow:0 1px 7px rgba(0,0,0,.65);-webkit-border-radius:4px;border-radius:4px;line-height:26px;overflow:hidden}.leaflet-touch .leaflet-control-geocoder{box-shadow:none;border:2px solid rgba(0,0,0,.2);background-clip:padding-box;line-height:30px}.leaflet-control-geocoder-form{display:inline}.leaflet-control-geocoder-error,.leaflet-control-geocoder-form input,.leaflet-control-geocoder-form ul{border:0;color:transparent;background:#fff}.leaflet-control-geocoder-form input{font-size:16px;width:0;transition:width .125s ease-in}.leaflet-touch .leaflet-control-geocoder-form input{font-size:22px}.leaflet-control-geocoder-icon{width:26px;height:26px;background-image:url('images/geocoder.png');background-repeat:no-repeat;background-position:center;float:right;cursor:pointer}.leaflet-touch .leaflet-control-geocoder-icon{margin-top:2px;width:30px}.leaflet-control-geocoder-throbber .leaflet-control-geocoder-icon{background-image:url('images/throbber.gif')}.leaflet-control-geocoder-error,.leaflet-control-geocoder-expanded input{width:226px;margin:0 0 0 4px;padding:0 0 0 4px;vertical-align:middle;color:#000}.leaflet-control-geocoder-form input:focus{outline:0}.leaflet-control-geocoder-form button,.leaflet-control-geocoder-form-no-error{display:none}.leaflet-control-geocoder-error{margin-top:8px;display:block;color:#444}ul.leaflet-control-geocoder-alternatives{width:260px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;list-style:none;padding:0;transition:height .125s ease-in}.leaflet-control-geocoder-alternatives-minimized{width:0!important;height:0;overflow:hidden;margin:0;padding:0}.leaflet-control-geocoder-alternatives li{width:100%;overflow:hidden;text-overflow:ellipsis;border-bottom:1px solid #eee;padding:0}.leaflet-control-geocoder-alternatives li:last-child{border-bottom:none}.leaflet-control-geocoder-alternatives a{display:block;text-decoration:none;color:#000;padding:6px 8px 16px 6px;font-size:14px;line-height:1;font-weight:700}.leaflet-touch .leaflet-control-geocoder-alternatives a{font-size:18px}.leaflet-control-geocoder-alternatives a:hover,.leaflet-control-geocoder-selected{background-color:#ddd}.leaflet-control-geocoder-address-detail{font-size:12px;font-weight:400}.leaflet-control-geocoder-address-context{color:#666;font-size:12px;font-weight:lighter} \ No newline at end of file +.leaflet-control-geocoder .leaflet-control-geocoder-icon,.leaflet-control-geocoder .leaflet-control-geocoder-icon:hover,.leaflet-control-geocoder a,.leaflet-control-geocoder a:hover{border-bottom:none;display:inline-block}.leaflet-control-geocoder{border-radius:4px;background:#fff;min-width:26px;min-height:26px}.leaflet-touch .leaflet-control-geocoder{min-width:30px;min-height:30px}.leaflet-control-geocoder .leaflet-control-geocoder-alternatives a{width:inherit;height:inherit;line-height:inherit}.leaflet-control-geocoder-form{display:none;vertical-align:middle}.leaflet-control-geocoder-expanded .leaflet-control-geocoder-form{display:inline-block}.leaflet-control-geocoder-form button,.leaflet-control-geocoder-form-no-error{display:none}.leaflet-control-geocoder-form input{font-size:120%;border:0;background-color:transparent;width:246px}.leaflet-control-geocoder-icon{border-radius:4px;width:26px;height:26px;border:none;background-color:#fff;background-image:url('images/geocoder.png');background-repeat:no-repeat;background-position:center}.leaflet-touch .leaflet-control-geocoder-icon{width:30px;height:30px}.leaflet-control-geocoder-throbber .leaflet-control-geocoder-icon{background-image:url('images/throbber.gif')}.leaflet-control-geocoder-form input:focus{outline:0}.leaflet-control-geocoder-error{margin-top:8px;margin-left:8px;display:block;color:#444}.leaflet-control-geocoder-alternatives{display:block;width:272px;list-style:none;padding:0;margin:0}.leaflet-control-geocoder-alternatives-minimized{display:none;height:0}.leaflet-control-geocoder-alternatives li{white-space:nowrap;display:block;overflow:hidden;padding:5px 8px;text-overflow:ellipsis;border-bottom:1px solid #ccc;cursor:pointer}.leaflet-control-geocoder-alternatives li a,.leaflet-control-geocoder-alternatives li a:hover{width:inherit;height:inherit;line-height:inherit;background:inherit;border-radius:inherit;text-align:left}.leaflet-control-geocoder-alternatives li:last-child{border-bottom:none}.leaflet-control-geocoder-alternatives li:hover,.leaflet-control-geocoder-selected{background-color:#f5f5f5}.leaflet-control-geocoder-address-context{color:#666} \ No newline at end of file diff --git a/assets/control-geocoder/Control.Geocoder.min.js b/assets/control-geocoder/Control.Geocoder.min.js index 47a7e0e..93c9261 100644 --- a/assets/control-geocoder/Control.Geocoder.min.js +++ b/assets/control-geocoder/Control.Geocoder.min.js @@ -1 +1 @@ -!function(e){var t;if("function"==typeof define&&define.amd)define(["leaflet"],e);else if("undefined"!=typeof module)t=require("leaflet"),module.exports=e(t);else{if("undefined"==typeof window.L)throw"Leaflet must be loaded first";e(window.L)}}(function(e){"use strict";return e.Control.Geocoder=e.Control.extend({options:{showResultIcons:!1,collapsed:!0,expand:"click",position:"topright",placeholder:"Search...",errorMessage:"Nothing found."},_callbackId:0,initialize:function(t){e.Util.setOptions(this,t),this.options.geocoder||(this.options.geocoder=new e.Control.Geocoder.Nominatim)},onAdd:function(t){var o,n="leaflet-control-geocoder",r=e.DomUtil.create("div",n),s=e.DomUtil.create("div","leaflet-control-geocoder-icon",r),i=this._form=e.DomUtil.create("form",n+"-form",r);return this._map=t,this._container=r,o=this._input=e.DomUtil.create("input"),o.type="text",o.placeholder=this.options.placeholder,e.DomEvent.addListener(o,"keydown",this._keydown,this),this._errorElement=document.createElement("div"),this._errorElement.className=n+"-form-no-error",this._errorElement.innerHTML=this.options.errorMessage,this._alts=e.DomUtil.create("ul",n+"-alternatives leaflet-control-geocoder-alternatives-minimized"),i.appendChild(o),i.appendChild(this._errorElement),r.appendChild(this._alts),e.DomEvent.addListener(i,"submit",this._geocode,this),this.options.collapsed?"click"===this.options.expand?e.DomEvent.addListener(s,"click",function(e){0===e.button&&2!==e.detail&&this._toggle()},this):(e.DomEvent.addListener(s,"mouseover",this._expand,this),e.DomEvent.addListener(s,"mouseout",this._collapse,this),this._map.on("movestart",this._collapse,this)):this._expand(),e.DomEvent.disableClickPropagation(r),r},_geocodeResult:function(t){if(e.DomUtil.removeClass(this._container,"leaflet-control-geocoder-throbber"),1===t.length)this._geocodeResultSelected(t[0]);else if(t.length>0){this._alts.innerHTML="",this._results=t,e.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized");for(var o=0;o=0?this._collapse():this._expand()},_expand:function(){e.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select()},_collapse:function(){this._container.className=this._container.className.replace(" leaflet-control-geocoder-expanded",""),e.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),e.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error")},_clearResults:function(){e.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,e.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error")},_createAlt:function(t,o){var n=document.createElement("li"),r=e.DomUtil.create("a","",n),s=this.options.showResultIcons&&t.icon?e.DomUtil.create("img","",r):null,i=t.html?void 0:document.createTextNode(t.name);return s&&(s.src=t.icon),r.href="#",r.setAttribute("data-result-index",o),t.html?r.innerHTML=t.html:r.appendChild(i),e.DomEvent.addListener(n,"click",function(o){e.DomEvent.preventDefault(o),this._geocodeResultSelected(t)},this),n},_keydown:function(t){var o=this,n=function(t){o._selection&&(e.DomUtil.removeClass(o._selection.firstChild,"leaflet-control-geocoder-selected"),o._selection=o._selection[t>0?"nextSibling":"previousSibling"]),o._selection||(o._selection=o._alts[t>0?"firstChild":"lastChild"]),o._selection&&e.DomUtil.addClass(o._selection.firstChild,"leaflet-control-geocoder-selected")};switch(t.keyCode){case 27:this.options.collapsed&&this._collapse();break;case 38:n(-1),e.DomEvent.preventDefault(t);break;case 40:n(1),e.DomEvent.preventDefault(t);break;case 13:if(this._selection){var r=parseInt(this._selection.firstChild.getAttribute("data-result-index"),10);this._geocodeResultSelected(this._results[r]),this._clearResults(),e.DomEvent.preventDefault(t)}}return!0}}),e.Control.geocoder=function(t,o){return new e.Control.Geocoder(t,o)},e.Control.Geocoder.callbackId=0,e.Control.Geocoder.jsonp=function(t,o,n,r,s){var i="_l_geocoder_"+e.Control.Geocoder.callbackId++;o[s||"callback"]=i,window[i]=e.Util.bind(n,r);var l=document.createElement("script");l.type="text/javascript",l.src=t+e.Util.getParamString(o),l.id=i,document.getElementsByTagName("head")[0].appendChild(l)},e.Control.Geocoder.getJSON=function(t,o,n){var r=new XMLHttpRequest;r.open("GET",t+e.Util.getParamString(o),!0),r.send(null),r.onreadystatechange=function(){4==r.readyState&&(200==r.status||304==req.status)&&n(JSON.parse(r.response))}},e.Control.Geocoder.template=function(t,o){return t.replace(/\{ *([\w_]+) *\}/g,function(t,n){var r=o[n];return void 0===r?r="":"function"==typeof r&&(r=r(o)),e.Control.Geocoder.htmlEscape(r)})},e.Control.Geocoder.htmlEscape=function(){function e(e){return n[e]}var t=/[&<>"'`]/g,o=/[&<>"'`]/,n={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};return function(n){return null==n?"":n?(n=""+n,o.test(n)?n.replace(t,e):n):n+""}}(),e.Control.Geocoder.Nominatim=e.Class.extend({options:{serviceUrl:"//nominatim.openstreetmap.org/",geocodingQueryParams:{},reverseQueryParams:{},htmlTemplate:function(t){var o=t.address,n=[];return(o.road||o.building)&&n.push("{building} {road} {house_number}"),(o.city||o.town||o.village)&&n.push('{postcode} {city} {town} {village}'),(o.state||o.country)&&n.push('{state} {country}'),e.Control.Geocoder.template(n.join("
"),o,!0)}},initialize:function(t){e.Util.setOptions(this,t)},geocode:function(t,o,n){e.Control.Geocoder.jsonp(this.options.serviceUrl+"search/",e.extend({q:t,limit:5,format:"json",addressdetails:1},this.options.geocodingQueryParams),function(t){for(var r=[],s=t.length-1;s>=0;s--){for(var i=t[s].boundingbox,l=0;4>l;l++)i[l]=parseFloat(i[l]);r[s]={icon:t[s].icon,name:t[s].display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(t[s]):void 0,bbox:e.latLngBounds([i[0],i[2]],[i[1],i[3]]),center:e.latLng(t[s].lat,t[s].lon),properties:t[s]}}o.call(n,r)},this,"json_callback")},reverse:function(t,o,n,r){e.Control.Geocoder.jsonp(this.options.serviceUrl+"reverse/",e.extend({lat:t.lat,lon:t.lng,zoom:Math.round(Math.log(o/256)/Math.log(2)),addressdetails:1,format:"json"},this.options.reverseQueryParams),function(t){var o,s=[];t&&t.lat&&t.lon&&(o=e.latLng(t.lat,t.lon),s.push({name:t.display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(t):void 0,center:o,bounds:e.latLngBounds(o,o),properties:t})),n.call(r,s)},this,"json_callback")}}),e.Control.Geocoder.nominatim=function(t){return new e.Control.Geocoder.Nominatim(t)},e.Control.Geocoder.Bing=e.Class.extend({initialize:function(e){this.key=e},geocode:function(t,o,n){e.Control.Geocoder.jsonp("//dev.virtualearth.net/REST/v1/Locations",{query:t,key:this.key},function(t){for(var r=[],s=t.resourceSets[0].resources.length-1;s>=0;s--){var i=t.resourceSets[0].resources[s],l=i.bbox;r[s]={name:i.name,bbox:e.latLngBounds([l[0],l[1]],[l[2],l[3]]),center:e.latLng(i.point.coordinates)}}o.call(n,r)},this,"jsonp")},reverse:function(t,o,n,r){e.Control.Geocoder.jsonp("//dev.virtualearth.net/REST/v1/Locations/"+t.lat+","+t.lng,{key:this.key},function(t){for(var o=[],s=t.resourceSets[0].resources.length-1;s>=0;s--){var i=t.resourceSets[0].resources[s],l=i.bbox;o[s]={name:i.name,bbox:e.latLngBounds([l[0],l[1]],[l[2],l[3]]),center:e.latLng(i.point.coordinates)}}n.call(r,o)},this,"jsonp")}}),e.Control.Geocoder.bing=function(t){return new e.Control.Geocoder.Bing(t)},e.Control.Geocoder.RaveGeo=e.Class.extend({options:{querySuffix:"",deepSearch:!0,wordBased:!1},jsonp:function(t,o,n){var r="_l_geocoder_"+e.Control.Geocoder.callbackId++,s=[];t.prepend=r+"(",t.append=")";for(var i in t)s.push(i+"="+escape(t[i]));window[r]=e.Util.bind(o,n);var l=document.createElement("script");l.type="text/javascript",l.src=this._serviceUrl+"?"+s.join("&"),l.id=r,document.getElementsByTagName("head")[0].appendChild(l)},initialize:function(t,o,n){e.Util.setOptions(this,n),this._serviceUrl=t,this._scheme=o},geocode:function(t,o,n){e.Control.Geocoder.jsonp(this._serviceUrl,{address:t+this.options.querySuffix,scheme:this._scheme,outputFormat:"jsonp",deepSearch:this.options.deepSearch,wordBased:this.options.wordBased},function(t){for(var r=[],s=t.length-1;s>=0;s--){var i=t[s],l=e.latLng(i.y,i.x);r[s]={name:i.address,bbox:e.latLngBounds([l]),center:l}}o.call(n,r)},this)}}),e.Control.Geocoder.raveGeo=function(t,o,n){return new e.Control.Geocoder.RaveGeo(t,o,n)},e.Control.Geocoder.MapQuest=e.Class.extend({initialize:function(e){this._key=decodeURIComponent(e)},_formatName:function(){var e,t=[];for(e=0;e=0;l--)r=t.results[0].locations[l],s=e.latLng(r.latLng),i[l]={name:this._formatName(r.street,r.adminArea4,r.adminArea3,r.adminArea1),bbox:e.latLngBounds(s,s),center:s};o.call(n,i)},this)},reverse:function(t,o,n,r){e.Control.Geocoder.jsonp("//www.mapquestapi.com/geocoding/v1/reverse",{key:this._key,location:t.lat+","+t.lng,outputFormat:"json"},function(t){var o,s,i=[];if(t.results&&t.results[0].locations)for(var l=t.results[0].locations.length-1;l>=0;l--)o=t.results[0].locations[l],s=e.latLng(o.latLng),i[l]={name:this._formatName(o.street,o.adminArea4,o.adminArea3,o.adminArea1),bbox:e.latLngBounds(s,s),center:s};n.call(r,i)},this)}}),e.Control.Geocoder.mapQuest=function(t){return new e.Control.Geocoder.MapQuest(t)},e.Control.Geocoder.Mapbox=e.Class.extend({options:{service_url:"https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/"},initialize:function(e){this._access_token=e},geocode:function(t,o,n){e.Control.Geocoder.getJSON(this.options.service_url+encodeURIComponent(t)+".json",{access_token:this._access_token},function(t){var r,s,i,l=[];if(t.features&&t.features.length)for(var a=0;a<=t.features.length-1;a++)r=t.features[a],s=e.latLng(r.center.reverse()),i=r.hasOwnProperty("bbox")?e.latLngBounds(e.latLng(r.bbox.slice(0,2).reverse()),e.latLng(r.bbox.slice(2,4).reverse())):e.latLngBounds(s,s),l[a]={name:r.place_name,bbox:i,center:s};o.call(n,l)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(t,o,n,r){e.Control.Geocoder.getJSON(this.options.service_url+encodeURIComponent(t.lng)+","+encodeURIComponent(t.lat)+".json",{access_token:this._access_token},function(t){var o,s,i,l=[];if(t.features&&t.features.length)for(var a=0;a<=t.features.length-1;a++)o=t.features[a],s=e.latLng(o.center.reverse()),i=o.hasOwnProperty("bbox")?e.latLngBounds(e.latLng(o.bbox.slice(0,2).reverse()),e.latLng(o.bbox.slice(2,4).reverse())):e.latLngBounds(s,s),l[a]={name:o.place_name,bbox:i,center:s};n.call(r,l)})}}),e.Control.Geocoder.mapbox=function(t){return new e.Control.Geocoder.Mapbox(t)},e.Control.Geocoder.Google=e.Class.extend({options:{service_url:"https://maps.googleapis.com/maps/api/geocode/json"},initialize:function(e){this._key=e},geocode:function(t,o,n){var r={address:t};this._key&&this._key.length&&(r.key=this._key),e.Control.Geocoder.getJSON(this.options.service_url,r,function(t){var r,s,i,l=[];if(t.results&&t.results.length)for(var a=0;a<=t.results.length-1;a++)r=t.results[a],s=e.latLng(r.geometry.location),i=e.latLngBounds(e.latLng(r.geometry.viewport.northeast),e.latLng(r.geometry.viewport.southwest)),l[a]={name:r.formatted_address,bbox:i,center:s};o.call(n,l)})},reverse:function(t,o,n,r){var s={latlng:encodeURIComponent(t.lat)+","+encodeURIComponent(t.lng)};this._key&&this._key.length&&(s.key=this._key),e.Control.Geocoder.getJSON(this.options.service_url,s,function(t){var o,s,i,l=[];if(t.results&&t.results.length)for(var a=0;a<=t.results.length-1;a++)o=t.results[a],s=e.latLng(o.geometry.location),i=e.latLngBounds(e.latLng(o.geometry.viewport.northeast),e.latLng(o.geometry.viewport.southwest)),l[a]={name:o.formatted_address,bbox:i,center:s};n.call(r,l)})}}),e.Control.Geocoder.google=function(t){return new e.Control.Geocoder.Google(t)},e.Control.Geocoder}); \ No newline at end of file +!function e(t,o,n){function s(r,a){if(!o[r]){if(!t[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(i)return i(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var d=o[r]={exports:{}};t[r][0].call(d.exports,function(e){var o=t[r][1][e];return s(o?o:e)},d,d.exports,e,t,o,n)}return o[r].exports}for(var i="function"==typeof require&&require,r=0;r0){this._alts.innerHTML="",this._results=e,n.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized");for(var o=0;o=0?this._collapse():this._expand()},_expand:function(){n.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select(),this.fire("expand")},_collapse:function(){this._container.className=this._container.className.replace(" leaflet-control-geocoder-expanded",""),n.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),n.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),this.fire("collapse")},_clearResults:function(){n.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,n.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error")},_createAlt:function(e,t){var o=n.DomUtil.create("li",""),s=n.DomUtil.create("a","",o),i=this.options.showResultIcons&&e.icon?n.DomUtil.create("img","",s):null,r=e.html?void 0:document.createTextNode(e.name),a=function(t){n.DomEvent.preventDefault(t),this._geocodeResultSelected(e)};return i&&(i.src=e.icon),o.setAttribute("data-result-index",t),e.html?s.innerHTML=s.innerHTML+e.html:s.appendChild(r),n.DomEvent.addListener(o,"mousedown",a,this),o},_keydown:function(e){var t=this,o=function(e){t._selection&&(n.DomUtil.removeClass(t._selection,"leaflet-control-geocoder-selected"),t._selection=t._selection[e>0?"nextSibling":"previousSibling"]),t._selection||(t._selection=t._alts[e>0?"firstChild":"lastChild"]),t._selection&&n.DomUtil.addClass(t._selection,"leaflet-control-geocoder-selected")};switch(e.keyCode){case 27:this.options.collapsed&&this._collapse();break;case 38:o(-1),n.DomEvent.preventDefault(e);break;case 40:o(1),n.DomEvent.preventDefault(e);break;case 13:if(this._selection){var s=parseInt(this._selection.getAttribute("data-result-index"),10);this._geocodeResultSelected(this._results[s]),this._clearResults()}else this._geocode();n.DomEvent.preventDefault(e);break;default:var i=this._input.value;this.options.geocoder.suggest&&i!==this._lastGeocode&&(clearTimeout(this._suggestTimeout),i.length>=this.options.suggestMinLength?this._suggestTimeout=setTimeout(n.bind(function(){this._geocode(!0)},this),this.options.suggestTimeout):this._clearResults())}}}),factory:function(e){return new n.Control.Geocoder(e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./geocoders/nominatim":9}],2:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{service_url:"http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"},initialize:function(e,t){n.setOptions(this,t),this._accessToken=e},geocode:function(e,t,o){var i={SingleLine:e,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"};this._key&&this._key.length&&(i.token=this._key),s.getJSON(this.options.service_url+"/findAddressCandidates",i,function(e){var s,i,r,a=[];if(e.candidates&&e.candidates.length)for(var l=0;l<=e.candidates.length-1;l++)s=e.candidates[l],i=n.latLng(s.location.y,s.location.x),r=n.latLngBounds(n.latLng(s.extent.ymax,s.extent.xmax),n.latLng(s.extent.ymin,s.extent.xmin)),a[l]={name:s.address,bbox:r,center:i};t.call(o,a)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,o,i){var r={location:encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat),distance:100,f:"json"};s.getJSON(this.options.service_url+"/reverseGeocode",r,function(e){var t,s=[];e&&!e.error&&(t=n.latLng(e.location.y,e.location.x),s.push({name:e.address.Match_addr,center:t,bounds:n.latLngBounds(t,t)})),o.call(i,s)})}}),factory:function(e,t){return new n.Control.Geocoder.ArcGis(e,t)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],3:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({initialize:function(e){this.key=e},geocode:function(e,t,o){s.jsonp("https://dev.virtualearth.net/REST/v1/Locations",{query:e,key:this.key},function(e){var s=[];if(e.resourceSets.length>0)for(var i=e.resourceSets[0].resources.length-1;i>=0;i--){var r=e.resourceSets[0].resources[i],a=r.bbox;s[i]={name:r.name,bbox:n.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:n.latLng(r.point.coordinates)}}t.call(o,s)},this,"jsonp")},reverse:function(e,t,o,i){s.jsonp("//dev.virtualearth.net/REST/v1/Locations/"+e.lat+","+e.lng,{key:this.key},function(e){for(var t=[],s=e.resourceSets[0].resources.length-1;s>=0;s--){var r=e.resourceSets[0].resources[s],a=r.bbox;t[s]={name:r.name,bbox:n.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:n.latLng(r.point.coordinates)}}o.call(i,t)},this,"jsonp")}}),factory:function(e){return new n.Control.Geocoder.Bing(e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],4:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){this._key=e,n.setOptions(this,t),this.options.serviceUrl=this.options.service_url||this.options.serviceUrl},geocode:function(e,t,o){var i={address:e};this._key&&this._key.length&&(i.key=this._key),i=n.Util.extend(i,this.options.geocodingQueryParams),s.getJSON(this.options.serviceUrl,i,function(e){var s,i,r,a=[];if(e.results&&e.results.length)for(var l=0;l<=e.results.length-1;l++)s=e.results[l],i=n.latLng(s.geometry.location),r=n.latLngBounds(n.latLng(s.geometry.viewport.northeast),n.latLng(s.geometry.viewport.southwest)),a[l]={name:s.formatted_address,bbox:r,center:i,properties:s.address_components};t.call(o,a)})},reverse:function(e,t,o,i){var r={latlng:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng)};r=n.Util.extend(r,this.options.reverseQueryParams),this._key&&this._key.length&&(r.key=this._key),s.getJSON(this.options.serviceUrl,r,function(e){var t,s,r,a=[];if(e.results&&e.results.length)for(var l=0;l<=e.results.length-1;l++)t=e.results[l],s=n.latLng(t.geometry.location),r=n.latLngBounds(n.latLng(t.geometry.viewport.northeast),n.latLng(t.geometry.viewport.southwest)),a[l]={name:t.formatted_address,bbox:r,center:s,properties:t.address_components};o.call(i,a)})}}),factory:function(e,t){return new n.Control.Geocoder.Google(e,t)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],5:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{geocodeUrl:"http://geocoder.api.here.com/6.2/geocode.json",reverseGeocodeUrl:"http://reverse.geocoder.api.here.com/6.2/reversegeocode.json",app_id:"",app_code:"",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e){n.setOptions(this,e)},geocode:function(e,t,o){var s={searchtext:e,gen:9,app_id:this.options.app_id,app_code:this.options.app_code,jsonattributes:1};s=n.Util.extend(s,this.options.geocodingQueryParams),this.getJSON(this.options.geocodeUrl,s,t,o)},reverse:function(e,t,o,s){var i={prox:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng),mode:"retrieveAddresses",app_id:this.options.app_id,app_code:this.options.app_code,gen:9,jsonattributes:1};i=n.Util.extend(i,this.options.reverseQueryParams),this.getJSON(this.options.reverseGeocodeUrl,i,o,s)},getJSON:function(e,t,o,i){s.getJSON(e,t,function(e){var t,s,r,a=[];if(e.response.view&&e.response.view.length)for(var l=0;l<=e.response.view[0].result.length-1;l++)t=e.response.view[0].result[l].location,s=n.latLng(t.displayPosition.latitude,t.displayPosition.longitude),r=n.latLngBounds(n.latLng(t.mapView.topLeft.latitude,t.mapView.topLeft.longitude),n.latLng(t.mapView.bottomRight.latitude,t.mapView.bottomRight.longitude)),a[l]={name:t.address.label,bbox:r,center:s};o.call(i,a)})}}),factory:function(e){return new n.Control.Geocoder.HERE(e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],6:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/"},initialize:function(e,t){n.setOptions(this,t),this._accessToken=e},geocode:function(e,t,o){s.getJSON(this.options.serviceUrl+encodeURIComponent(e)+".json",{access_token:this._accessToken},function(e){var s,i,r,a=[];if(e.features&&e.features.length)for(var l=0;l<=e.features.length-1;l++)s=e.features[l],i=n.latLng(s.center.reverse()),r=s.hasOwnProperty("bbox")?n.latLngBounds(n.latLng(s.bbox.slice(0,2).reverse()),n.latLng(s.bbox.slice(2,4).reverse())):n.latLngBounds(i,i),a[l]={name:s.place_name,bbox:r,center:i};t.call(o,a)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,o,i){s.getJSON(this.options.serviceUrl+encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat)+".json",{access_token:this._accessToken},function(e){var t,s,r,a=[];if(e.features&&e.features.length)for(var l=0;l<=e.features.length-1;l++)t=e.features[l],s=n.latLng(t.center.reverse()),r=t.hasOwnProperty("bbox")?n.latLngBounds(n.latLng(t.bbox.slice(0,2).reverse()),n.latLng(t.bbox.slice(2,4).reverse())):n.latLngBounds(s,s),a[l]={name:t.place_name,bbox:r,center:s};o.call(i,a)})}}),factory:function(e,t){return new n.Control.Geocoder.Mapbox(e,t)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],7:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://www.mapquestapi.com/geocoding/v1"},initialize:function(e,t){this._key=decodeURIComponent(e),n.Util.setOptions(this,t)},_formatName:function(){var e,t=[];for(e=0;e=0;a--)s=e.results[0].locations[a],i=n.latLng(s.latLng),r[a]={name:this._formatName(s.street,s.adminArea4,s.adminArea3,s.adminArea1),bbox:n.latLngBounds(i,i),center:i};t.call(o,r)},this)},reverse:function(e,t,o,i){s.jsonp(this.options.serviceUrl+"/reverse",{key:this._key,location:e.lat+","+e.lng,outputFormat:"json"},function(e){var t,s,r=[];if(e.results&&e.results[0].locations)for(var a=e.results[0].locations.length-1;a>=0;a--)t=e.results[0].locations[a],s=n.latLng(t.latLng),r[a]={name:this._formatName(t.street,t.adminArea4,t.adminArea3,t.adminArea1),bbox:n.latLngBounds(s,s),center:s};o.call(i,r)},this)}}),factory:function(e,t){return new n.Control.Geocoder.MapQuest(e,t)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],8:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://search.mapzen.com/v1",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){n.Util.setOptions(this,t),this._apiKey=e,this._lastSuggest=0},geocode:function(e,t,o){var i=this;s.getJSON(this.options.serviceUrl+"/search",n.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),function(e){t.call(o,i._parseResults(e,"bbox"))})},suggest:function(e,t,o){var i=this;s.getJSON(this.options.serviceUrl+"/autocomplete",n.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),n.bind(function(e){e.geocoding.timestamp>this._lastSuggest&&(this._lastSuggest=e.geocoding.timestamp,t.call(o,i._parseResults(e,"bbox")))},this))},reverse:function(e,t,o,i){var r=this;s.getJSON(this.options.serviceUrl+"/reverse",n.extend({api_key:this._apiKey,"point.lat":e.lat,"point.lon":e.lng},this.options.reverseQueryParams),function(e){o.call(i,r._parseResults(e,"bounds"))})},_parseResults:function(e,t){var o=[];return n.geoJson(e,{pointToLayer:function(e,t){return n.circleMarker(t)},onEachFeature:function(e,s){var i,r,a={};s.getBounds?(i=s.getBounds(),r=i.getCenter()):(r=s.getLatLng(),i=n.latLngBounds(r,r)),a.name=s.feature.properties.label,a.center=r,a[t]=i,a.properties=s.feature.properties,o.push(a)}}),o}}),factory:function(e,t){return new n.Control.Geocoder.Mapzen(e,t)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],9:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://nominatim.openstreetmap.org/",geocodingQueryParams:{},reverseQueryParams:{},htmlTemplate:function(e){var t=e.address,o=[];return(t.road||t.building)&&o.push("{building} {road} {house_number}"),(t.city||t.town||t.village||t.hamlet)&&o.push('{postcode} {city} {town} {village} {hamlet}'),(t.state||t.country)&&o.push('{state} {country}'),s.template(o.join("
"),t,!0)}},initialize:function(e){n.Util.setOptions(this,e)},geocode:function(e,t,o){s.jsonp(this.options.serviceUrl+"search",n.extend({q:e,limit:5,format:"json",addressdetails:1},this.options.geocodingQueryParams),function(e){for(var s=[],i=e.length-1;i>=0;i--){for(var r=e[i].boundingbox,a=0;a<4;a++)r[a]=parseFloat(r[a]);s[i]={icon:e[i].icon,name:e[i].display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e[i]):void 0,bbox:n.latLngBounds([r[0],r[2]],[r[1],r[3]]),center:n.latLng(e[i].lat,e[i].lon),properties:e[i]}}t.call(o,s)},this,"json_callback")},reverse:function(e,t,o,i){s.jsonp(this.options.serviceUrl+"reverse",n.extend({lat:e.lat,lon:e.lng,zoom:Math.round(Math.log(t/256)/Math.log(2)),addressdetails:1,format:"json"},this.options.reverseQueryParams),function(e){var t,s=[];e&&e.lat&&e.lon&&(t=n.latLng(e.lat,e.lon),s.push({name:e.display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e):void 0,center:t,bounds:n.latLngBounds(t,t),properties:e})),o.call(i,s)},this,"json_callback")}}),factory:function(e){return new n.Control.Geocoder.Nominatim(e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../util":13}],10:[function(e,t,o){(function(o){var n="undefined"!=typeof window?window.L:"undefined"!=typeof o?o.L:null,s=e("../util");t.exports={class:n.Class.extend({options:{serviceUrl:"https://photon.komoot.de/api/",reverseUrl:"https://photon.komoot.de/reverse/",nameProperties:["name","street","suburb","hamlet","town","city","state","country"]},initialize:function(e){n.setOptions(this,e)},geocode:function(e,t,o){var i=n.extend({q:e},this.options.geocodingQueryParams);s.getJSON(this.options.serviceUrl,i,n.bind(function(e){t.call(o,this._decodeFeatures(e))},this))},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,o,i){var r=n.extend({lat:e.lat,lon:e.lng},this.options.geocodingQueryParams);s.getJSON(this.options.reverseUrl,r,n.bind(function(e){o.call(i,this._decodeFeatures(e))},this))},_decodeFeatures:function(e){var t,o,s,i,r,a,l=[];if(e&&e.features)for(t=0;t"'`]/g,o=/[&<>"'`]/,n={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};return function(n){return null==n?"":n?(n=""+n,o.test(n)?n.replace(t,e):n):n+""}}();t.exports={jsonp:function(e,t,s,i,r){var a="_l_geocoder_"+n++;t[r||"callback"]=a,window[a]=o.Util.bind(s,i);var l=document.createElement("script");l.type="text/javascript",l.src=e+o.Util.getParamString(t),l.id=a,document.getElementsByTagName("head")[0].appendChild(l)},getJSON:function(e,t,n){var s=new XMLHttpRequest;s.onreadystatechange=function(){if(4===s.readyState)return 200!==s.status&&304!==s.status?void n(""):void n(JSON.parse(s.response))},s.open("GET",e+o.Util.getParamString(t),!0),s.setRequestHeader("Accept","application/json"),s.send(null)},template:function(e,t){return e.replace(/\{ *([\w_]+) *\}/g,function(e,o){var n=t[o];return void 0===n?n="":"function"==typeof n&&(n=n(t)),s(n)})},htmlEscape:s}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[12]); \ No newline at end of file diff --git a/assets/control-geocoder/images/geocoder.png b/assets/control-geocoder/images/geocoder.png index 246bbe7..d82a017 100644 Binary files a/assets/control-geocoder/images/geocoder.png and b/assets/control-geocoder/images/geocoder.png differ diff --git a/module/config/config.php b/module/config/config.php index 2de3289..047255c 100644 --- a/module/config/config.php +++ b/module/config/config.php @@ -75,7 +75,7 @@ $GLOBALS['LEAFLET_LIBRARIES']['leaflet-fullscreen'] = array $GLOBALS['LEAFLET_LIBRARIES']['leaflet-control-geocoder'] = array ( 'name' => 'Leaflet Control Geocoder', - 'version' => '1.1.0', + 'version' => '1.5.1', 'license' => 'BSD-2-Clause', 'homepage' => 'https://github.com/perliedman/leaflet-control-geocoder', 'css' => 'assets/leaflet/libs/control-geocoder/Control.Geocoder.min.css',