leaflet-control-geocoder
Advanced tools
Comparing version 1.13.0 to 2.0.0
@@ -1,23 +0,52 @@ | ||
/* @preserve | ||
* Leaflet Control Geocoder 1.13.0 | ||
* https://github.com/perliedman/leaflet-control-geocoder | ||
* | ||
* Copyright (c) 2012 sa3m (https://github.com/sa3m) | ||
* Copyright (c) 2018 Per Liedman | ||
* All rights reserved. | ||
*/ | ||
var leafletControlGeocoder = (function (L) { | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
this.L = this.L || {}; | ||
this.L.Control = this.L.Control || {}; | ||
this.L.Control.Geocoder = (function (L) { | ||
'use strict'; | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
L = L && L.hasOwnProperty('default') ? L['default'] : L; | ||
return self; | ||
} | ||
var lastCallbackId = 0; | ||
/** | ||
* @internal | ||
*/ | ||
// Adapted from handlebars.js | ||
function geocodingParams(options, params) { | ||
return L.Util.extend(params, options.geocodingQueryParams); | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function reverseParams(options, params) { | ||
return L.Util.extend(params, options.reverseQueryParams); | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
var lastCallbackId = 0; // Adapted from handlebars.js | ||
// https://github.com/wycats/handlebars.js/ | ||
/** | ||
* @internal | ||
*/ | ||
var badChars = /[&<>"'`]/g; | ||
/** | ||
* @internal | ||
*/ | ||
var possible = /[&<>"'`]/; | ||
/** | ||
* @internal | ||
*/ | ||
var escape = { | ||
@@ -31,2 +60,5 @@ '&': '&', | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
@@ -36,3 +68,7 @@ function escapeChar(chr) { | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function htmlEscape(string) { | ||
@@ -43,7 +79,7 @@ if (string == null) { | ||
return string + ''; | ||
} | ||
// Force a string conversion as this will be done by the append regardless and | ||
} // Force a string conversion as this will be done by the append regardless and | ||
// the regex test will do this transparently behind the scenes, causing issues if | ||
// an object's to string has escaped characters in it. | ||
string = '' + string; | ||
@@ -54,4 +90,8 @@ | ||
} | ||
return string.replace(badChars, escapeChar); | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
@@ -68,10 +108,16 @@ function jsonp(url, params, callback, context, jsonpParam) { | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function getJSON(url, params, callback) { | ||
var xmlHttp = new XMLHttpRequest(); | ||
xmlHttp.onreadystatechange = function() { | ||
xmlHttp.onreadystatechange = function () { | ||
if (xmlHttp.readyState !== 4) { | ||
return; | ||
} | ||
var message; | ||
if (xmlHttp.status !== 200 && xmlHttp.status !== 304) { | ||
@@ -90,4 +136,6 @@ message = ''; | ||
} | ||
callback(message); | ||
}; | ||
xmlHttp.open('GET', url + getParamString(params), true); | ||
@@ -98,6 +146,10 @@ xmlHttp.responseType = 'json'; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function template(str, data) { | ||
return str.replace(/\{ *([\w_]+) *\}/g, function(str, key) { | ||
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { | ||
var value = data[key]; | ||
if (value === undefined) { | ||
@@ -108,13 +160,19 @@ value = ''; | ||
} | ||
return htmlEscape(value); | ||
}); | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function getParamString(obj, existingUrl, uppercase) { | ||
var params = []; | ||
for (var i in obj) { | ||
var key = encodeURIComponent(uppercase ? i.toUpperCase() : i); | ||
var value = obj[i]; | ||
if (!L.Util.isArray(value)) { | ||
params.push(key + '=' + encodeURIComponent(value)); | ||
if (!Array.isArray(value)) { | ||
params.push(key + '=' + encodeURIComponent(String(value))); | ||
} else { | ||
@@ -126,17 +184,24 @@ for (var j = 0; j < value.length; j++) { | ||
} | ||
return (!existingUrl || existingUrl.indexOf('?') === -1 ? '?' : '&') + params.join('&'); | ||
} | ||
var ArcGis = L.Class.extend({ | ||
options: { | ||
service_url: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer' | ||
}, | ||
/** | ||
* Implementation of the [ArcGIS geocoder](https://developers.arcgis.com/features/geocoding/) | ||
*/ | ||
initialize: function(accessToken, options) { | ||
L.setOptions(this, options); | ||
this._accessToken = accessToken; | ||
}, | ||
var ArcGis = /*#__PURE__*/function () { | ||
function ArcGis(options) { | ||
this.options = { | ||
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer', | ||
apiKey: '' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var params = { | ||
var _proto = ArcGis.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
token: this.options.apiKey, | ||
SingleLine: query, | ||
@@ -147,59 +212,43 @@ outFields: 'Addr_Type', | ||
f: 'json' | ||
}; | ||
}); | ||
getJSON(this.options.serviceUrl + '/findAddressCandidates', params, function (data) { | ||
var results = []; | ||
if (this._key && this._key.length) { | ||
params.token = this._key; | ||
} | ||
getJSON( | ||
this.options.service_url + '/findAddressCandidates', | ||
L.extend(params, this.options.geocodingQueryParams), | ||
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 | ||
}; | ||
} | ||
if (data.candidates && data.candidates.length) { | ||
for (var i = 0; i <= data.candidates.length - 1; i++) { | ||
var loc = data.candidates[i]; | ||
var latLng = L.latLng(loc.location.y, loc.location.x); | ||
var 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) { | ||
cb.call(context, results); | ||
}); | ||
}; | ||
_proto.suggest = function suggest(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}, | ||
}; | ||
reverse: function(location, scale, cb, context) { | ||
var params = { | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
location: encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat), | ||
distance: 100, | ||
f: 'json' | ||
}; | ||
}); | ||
getJSON(this.options.serviceUrl + '/reverseGeocode', params, function (data) { | ||
var result = []; | ||
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); | ||
var center = L.latLng(data.location.y, data.location.x); | ||
var bbox = L.latLngBounds(center, center); | ||
result.push({ | ||
name: data.address.Match_addr, | ||
center: loc, | ||
bounds: L.latLngBounds(loc, loc) | ||
center: center, | ||
bbox: bbox | ||
}); | ||
@@ -210,52 +259,41 @@ } | ||
}); | ||
} | ||
}); | ||
}; | ||
function arcgis(accessToken, options) { | ||
return new ArcGis(accessToken, options); | ||
return ArcGis; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link ArcGis} | ||
* @param options the options | ||
*/ | ||
function arcgis(options) { | ||
return new ArcGis(options); | ||
} | ||
var Bing = L.Class.extend({ | ||
initialize: function(key) { | ||
this.key = key; | ||
}, | ||
/** | ||
* Implementation of the [Bing Locations API](https://docs.microsoft.com/en-us/bingmaps/rest-services/locations/) | ||
*/ | ||
geocode: function(query, cb, context) { | ||
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' | ||
); | ||
}, | ||
var Bing = /*#__PURE__*/function () { | ||
function Bing(options) { | ||
this.options = { | ||
serviceUrl: 'https://dev.virtualearth.net/REST/v1/Locations' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
reverse: function(location, scale, cb, context) { | ||
jsonp( | ||
'//dev.virtualearth.net/REST/v1/Locations/' + location.lat + ',' + location.lng, | ||
{ | ||
key: this.key | ||
}, | ||
function(data) { | ||
var results = []; | ||
var _proto = Bing.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
query: query, | ||
key: this.options.apiKey | ||
}); | ||
jsonp(this.options.apiKey, params, 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; | ||
bbox = resource.bbox; | ||
results[i] = { | ||
@@ -267,52 +305,63 @@ name: resource.name, | ||
} | ||
cb.call(context, results); | ||
}, | ||
this, | ||
'jsonp' | ||
); | ||
} | ||
}); | ||
} | ||
function bing(key) { | ||
return new Bing(key); | ||
} | ||
cb.call(context, results); | ||
}, this, 'jsonp'); | ||
}; | ||
var Google = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {} | ||
}, | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
key: this.options.apiKey | ||
}); | ||
jsonp(this.options.serviceUrl + location.lat + ',' + location.lng, params, function (data) { | ||
var results = []; | ||
initialize: function(key, options) { | ||
this._key = key; | ||
L.setOptions(this, options); | ||
// Backwards compatibility | ||
this.options.serviceUrl = this.options.service_url || this.options.serviceUrl; | ||
}, | ||
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) | ||
}; | ||
} | ||
geocode: function(query, cb, context) { | ||
var params = { | ||
address: query | ||
cb.call(context, results); | ||
}, this, 'jsonp'); | ||
}; | ||
return Bing; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Bing} | ||
* @param options the options | ||
*/ | ||
function bing(options) { | ||
return new Bing(options); | ||
} | ||
var Google = /*#__PURE__*/function () { | ||
function Google(options) { | ||
this.options = { | ||
serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
if (this._key && this._key.length) { | ||
params.key = this._key; | ||
} | ||
var _proto = Google.prototype; | ||
params = L.Util.extend(params, this.options.geocodingQueryParams); | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
key: this.options.apiKey, | ||
address: query | ||
}); | ||
getJSON(this.options.serviceUrl, params, function (data) { | ||
var results = []; | ||
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) | ||
); | ||
var loc = data.results[i]; | ||
var latLng = L.latLng(loc.geometry.location); | ||
var latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); | ||
results[i] = { | ||
@@ -329,30 +378,21 @@ name: loc.formatted_address, | ||
}); | ||
}, | ||
}; | ||
reverse: function(location, scale, cb, context) { | ||
var params = { | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
key: this.options.apiKey, | ||
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; | ||
} | ||
}); | ||
getJSON(this.options.serviceUrl, params, function (data) { | ||
var results = []; | ||
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) | ||
); | ||
var loc = data.results[i]; | ||
var center = L.latLng(loc.geometry.location); | ||
var bbox = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); | ||
results[i] = { | ||
name: loc.formatted_address, | ||
bbox: latLngBounds, | ||
center: latLng, | ||
bbox: bbox, | ||
center: center, | ||
properties: loc.address_components | ||
@@ -365,24 +405,35 @@ }; | ||
}); | ||
} | ||
}); | ||
}; | ||
function google(key, options) { | ||
return new Google(key, options); | ||
return Google; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Google} | ||
* @param options the options | ||
*/ | ||
function google(options) { | ||
return new Google(options); | ||
} | ||
var HERE = L.Class.extend({ | ||
options: { | ||
geocodeUrl: 'https://geocoder.api.here.com/6.2/geocode.json', | ||
reverseGeocodeUrl: 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json', | ||
app_id: '<insert your app_id here>', | ||
app_code: '<insert your app_code here>', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {}, | ||
reverseGeocodeProxRadius: null | ||
}, | ||
initialize: function(options) { | ||
L.setOptions(this, options); | ||
}, | ||
geocode: function(query, cb, context) { | ||
var params = { | ||
/** | ||
* Implementation of the [HERE Geocoder API](https://developer.here.com/documentation/geocoder/topics/introduction.html) | ||
*/ | ||
var HERE = /*#__PURE__*/function () { | ||
function HERE(options) { | ||
this.options = { | ||
serviceUrl: 'https://geocoder.api.here.com/6.2/', | ||
app_id: '', | ||
app_code: '', | ||
reverseGeocodeProxRadius: null | ||
}; | ||
L.Util.setOptions(this, options); | ||
if (options.apiKey) throw Error('apiKey is not supported, use app_id/app_code instead!'); | ||
} | ||
var _proto = HERE.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
searchtext: query, | ||
@@ -393,12 +444,11 @@ gen: 9, | ||
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 _proxRadius = this.options.reverseGeocodeProxRadius | ||
? this.options.reverseGeocodeProxRadius | ||
: null; | ||
}); | ||
this.getJSON(this.options.serviceUrl + 'geocode.json', params, cb, context); | ||
}; | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var _proxRadius = this.options.reverseGeocodeProxRadius ? this.options.reverseGeocodeProxRadius : null; | ||
var proxRadius = _proxRadius ? ',' + encodeURIComponent(_proxRadius) : ''; | ||
var params = { | ||
var params = reverseParams(this.options, { | ||
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) + proxRadius, | ||
@@ -410,32 +460,35 @@ mode: 'retrieveAddresses', | ||
jsonattributes: 1 | ||
}; | ||
params = L.Util.extend(params, this.options.reverseQueryParams); | ||
this.getJSON(this.options.reverseGeocodeUrl, params, cb, context); | ||
}, | ||
getJSON: function(url, params, cb, context) { | ||
getJSON(url, params, function(data) { | ||
var results = [], | ||
loc, | ||
latLng, | ||
latLngBounds; | ||
}); | ||
this.getJSON(this.options.serviceUrl + 'reversegeocode.json', params, cb, context); | ||
}; | ||
_proto.getJSON = function getJSON$1(url, params, cb, context) { | ||
getJSON(url, params, function (data) { | ||
var results = []; | ||
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) | ||
); | ||
var loc = data.response.view[0].result[i].location; | ||
var center = L.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude); | ||
var bbox = 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, | ||
properties: loc.address, | ||
bbox: latLngBounds, | ||
center: latLng | ||
bbox: bbox, | ||
center: center | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}); | ||
} | ||
}); | ||
}; | ||
return HERE; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link HERE} | ||
* @param options the options | ||
*/ | ||
function here(options) { | ||
@@ -445,88 +498,57 @@ return new HERE(options); | ||
var LatLng = L.Class.extend({ | ||
options: { | ||
// the next geocoder to use | ||
next: undefined, | ||
sizeInMeters: 10000 | ||
}, | ||
/** | ||
* Parses basic latitude/longitude strings such as `'50.06773 14.37742'`, `'N50.06773 W14.37742'`, `'S 50° 04.064 E 014° 22.645'`, or `'S 50° 4′ 03.828″, W 14° 22′ 38.712″'` | ||
* @param query the latitude/longitude string to parse | ||
* @returns the parsed latitude/longitude | ||
*/ | ||
initialize: function(options) { | ||
function parseLatLng(query) { | ||
var match; // regex from https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/geocoder_controller.rb | ||
if (match = query.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/)) { | ||
// [NSEW] decimal degrees | ||
return L.latLng((/N/i.test(match[1]) ? 1 : -1) * parseFloat(match[2]), (/E/i.test(match[3]) ? 1 : -1) * parseFloat(match[4])); | ||
} else if (match = query.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/)) { | ||
// decimal degrees [NSEW] | ||
return L.latLng((/N/i.test(match[2]) ? 1 : -1) * parseFloat(match[1]), (/E/i.test(match[4]) ? 1 : -1) * parseFloat(match[3])); | ||
} else if (match = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/)) { | ||
// [NSEW] degrees, decimal minutes | ||
return L.latLng((/N/i.test(match[1]) ? 1 : -1) * (parseFloat(match[2]) + parseFloat(match[3]) / 60), (/E/i.test(match[4]) ? 1 : -1) * (parseFloat(match[5]) + parseFloat(match[6]) / 60)); | ||
} else if (match = query.match(/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/)) { | ||
// degrees, decimal minutes [NSEW] | ||
return L.latLng((/N/i.test(match[3]) ? 1 : -1) * (parseFloat(match[1]) + parseFloat(match[2]) / 60), (/E/i.test(match[6]) ? 1 : -1) * (parseFloat(match[4]) + parseFloat(match[5]) / 60)); | ||
} else if (match = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/)) { | ||
// [NSEW] degrees, minutes, decimal seconds | ||
return L.latLng((/N/i.test(match[1]) ? 1 : -1) * (parseFloat(match[2]) + parseFloat(match[3]) / 60 + parseFloat(match[4]) / 3600), (/E/i.test(match[5]) ? 1 : -1) * (parseFloat(match[6]) + parseFloat(match[7]) / 60 + parseFloat(match[8]) / 3600)); | ||
} else if (match = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/)) { | ||
// degrees, minutes, decimal seconds [NSEW] | ||
return L.latLng((/N/i.test(match[4]) ? 1 : -1) * (parseFloat(match[1]) + parseFloat(match[2]) / 60 + parseFloat(match[3]) / 3600), (/E/i.test(match[8]) ? 1 : -1) * (parseFloat(match[5]) + parseFloat(match[6]) / 60 + parseFloat(match[7]) / 3600)); | ||
} else if (match = query.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/)) { | ||
return L.latLng(parseFloat(match[1]), parseFloat(match[2])); | ||
} | ||
} | ||
/** | ||
* Parses basic latitude/longitude strings such as `'50.06773 14.37742'`, `'N50.06773 W14.37742'`, `'S 50° 04.064 E 014° 22.645'`, or `'S 50° 4′ 03.828″, W 14° 22′ 38.712″'` | ||
*/ | ||
var LatLng = /*#__PURE__*/function () { | ||
function LatLng(options) { | ||
this.options = { | ||
next: undefined, | ||
sizeInMeters: 10000 | ||
}; | ||
L.Util.setOptions(this, options); | ||
}, | ||
} | ||
geocode: function(query, cb, context) { | ||
var match; | ||
var center; | ||
// regex from https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/geocoder_controller.rb | ||
if ((match = query.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/))) { | ||
// [NSEW] decimal degrees | ||
center = L.latLng( | ||
(/N/i.test(match[1]) ? 1 : -1) * parseFloat(match[2]), | ||
(/E/i.test(match[3]) ? 1 : -1) * parseFloat(match[4]) | ||
); | ||
} else if ( | ||
(match = query.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/)) | ||
) { | ||
// decimal degrees [NSEW] | ||
center = L.latLng( | ||
(/N/i.test(match[2]) ? 1 : -1) * parseFloat(match[1]), | ||
(/E/i.test(match[4]) ? 1 : -1) * parseFloat(match[3]) | ||
); | ||
} else if ( | ||
(match = query.match( | ||
/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/ | ||
)) | ||
) { | ||
// [NSEW] degrees, decimal minutes | ||
center = L.latLng( | ||
(/N/i.test(match[1]) ? 1 : -1) * (parseFloat(match[2]) + parseFloat(match[3] / 60)), | ||
(/E/i.test(match[4]) ? 1 : -1) * (parseFloat(match[5]) + parseFloat(match[6] / 60)) | ||
); | ||
} else if ( | ||
(match = query.match( | ||
/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/ | ||
)) | ||
) { | ||
// degrees, decimal minutes [NSEW] | ||
center = L.latLng( | ||
(/N/i.test(match[3]) ? 1 : -1) * (parseFloat(match[1]) + parseFloat(match[2] / 60)), | ||
(/E/i.test(match[6]) ? 1 : -1) * (parseFloat(match[4]) + parseFloat(match[5] / 60)) | ||
); | ||
} else if ( | ||
(match = query.match( | ||
/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/ | ||
)) | ||
) { | ||
// [NSEW] degrees, minutes, decimal seconds | ||
center = L.latLng( | ||
(/N/i.test(match[1]) ? 1 : -1) * | ||
(parseFloat(match[2]) + parseFloat(match[3] / 60 + parseFloat(match[4] / 3600))), | ||
(/E/i.test(match[5]) ? 1 : -1) * | ||
(parseFloat(match[6]) + parseFloat(match[7] / 60) + parseFloat(match[8] / 3600)) | ||
); | ||
} else if ( | ||
(match = query.match( | ||
/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/ | ||
)) | ||
) { | ||
// degrees, minutes, decimal seconds [NSEW] | ||
center = L.latLng( | ||
(/N/i.test(match[4]) ? 1 : -1) * | ||
(parseFloat(match[1]) + parseFloat(match[2] / 60 + parseFloat(match[3] / 3600))), | ||
(/E/i.test(match[8]) ? 1 : -1) * | ||
(parseFloat(match[5]) + parseFloat(match[6] / 60) + parseFloat(match[7] / 3600)) | ||
); | ||
} else if ( | ||
(match = query.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/)) | ||
) { | ||
center = L.latLng(parseFloat(match[1]), parseFloat(match[2])); | ||
} | ||
var _proto = LatLng.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var center = parseLatLng(query); | ||
if (center) { | ||
var results = [ | ||
{ | ||
name: query, | ||
center: center, | ||
bbox: center.toBounds(this.options.sizeInMeters) | ||
} | ||
]; | ||
var results = [{ | ||
name: query, | ||
center: center, | ||
bbox: center.toBounds(this.options.sizeInMeters) | ||
}]; | ||
cb.call(context, results); | ||
@@ -536,5 +558,11 @@ } else if (this.options.next) { | ||
} | ||
} | ||
}); | ||
}; | ||
return LatLng; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link LatLng} | ||
* @param options the options | ||
*/ | ||
function latLng(options) { | ||
@@ -544,55 +572,96 @@ return new LatLng(options); | ||
var Mapbox = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://api.mapbox.com/geocoding/v5/mapbox.places/', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {} | ||
}, | ||
/** | ||
* Implementation of the [Mapbox Geocoding](https://www.mapbox.com/api-documentation/#geocoding) | ||
*/ | ||
initialize: function(accessToken, options) { | ||
L.setOptions(this, options); | ||
this.options.geocodingQueryParams.access_token = accessToken; | ||
this.options.reverseQueryParams.access_token = accessToken; | ||
}, | ||
var Mapbox = /*#__PURE__*/function () { | ||
function Mapbox(options) { | ||
this.options = { | ||
serviceUrl: 'https://api.mapbox.com/geocoding/v5/mapbox.places/' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var params = this.options.geocodingQueryParams; | ||
if ( | ||
params.proximity !== undefined && | ||
params.proximity.lat !== undefined && | ||
params.proximity.lng !== undefined | ||
) { | ||
var _proto = Mapbox.prototype; | ||
_proto._getProperties = function _getProperties(loc) { | ||
var properties = { | ||
text: loc.text, | ||
address: loc.address | ||
}; | ||
for (var j = 0; j < (loc.context || []).length; j++) { | ||
var id = loc.context[j].id.split('.')[0]; | ||
properties[id] = loc.context[j].text; // Get country code when available | ||
if (loc.context[j].short_code) { | ||
properties['countryShortCode'] = loc.context[j].short_code; | ||
} | ||
} | ||
return properties; | ||
}; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var _this = this; | ||
var params = geocodingParams(this.options, { | ||
access_token: this.options.apiKey | ||
}); | ||
if (params.proximity !== undefined && params.proximity.lat !== undefined && params.proximity.lng !== undefined) { | ||
params.proximity = params.proximity.lng + ',' + params.proximity.lat; | ||
} | ||
getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', params, function(data) { | ||
var results = [], | ||
loc, | ||
latLng, | ||
latLngBounds; | ||
getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', params, function (data) { | ||
var results = []; | ||
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()); | ||
var loc = data.features[i]; | ||
var center = L.latLng(loc.center.reverse()); | ||
var bbox = void 0; | ||
if (loc.bbox) { | ||
latLngBounds = L.latLngBounds( | ||
L.latLng(loc.bbox.slice(0, 2).reverse()), | ||
L.latLng(loc.bbox.slice(2, 4).reverse()) | ||
); | ||
bbox = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); | ||
} else { | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
bbox = L.latLngBounds(center, center); | ||
} | ||
var properties = { | ||
text: loc.text, | ||
address: loc.address | ||
results[i] = { | ||
name: loc.place_name, | ||
bbox: bbox, | ||
center: center, | ||
properties: _this._getProperties(loc) | ||
}; | ||
} | ||
} | ||
for (var j = 0; j < (loc.context || []).length; j++) { | ||
var id = loc.context[j].id.split('.')[0]; | ||
properties[id] = loc.context[j].text; | ||
cb.call(context, results); | ||
}); | ||
}; | ||
// Get country code when available | ||
if (loc.context[j].short_code) { | ||
properties['countryShortCode'] = loc.context[j].short_code; | ||
} | ||
_proto.suggest = function suggest(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}; | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var _this2 = this; | ||
var param = reverseParams(this.options, { | ||
access_token: this.options.apiKey | ||
}); | ||
getJSON(this.options.serviceUrl + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', param, function (data) { | ||
var results = []; | ||
if (data.features && data.features.length) { | ||
for (var i = 0; i <= data.features.length - 1; i++) { | ||
var loc = data.features[i]; | ||
var center = L.latLng(loc.center.reverse()); | ||
var bbox = void 0; | ||
if (loc.bbox) { | ||
bbox = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); | ||
} else { | ||
bbox = L.latLngBounds(center, center); | ||
} | ||
@@ -602,5 +671,5 @@ | ||
name: loc.place_name, | ||
bbox: latLngBounds, | ||
center: latLng, | ||
properties: properties | ||
bbox: bbox, | ||
center: center, | ||
properties: _this2._getProperties(loc) | ||
}; | ||
@@ -612,316 +681,290 @@ } | ||
}); | ||
}, | ||
}; | ||
suggest: function(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}, | ||
return Mapbox; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Mapbox} | ||
* @param options the options | ||
*/ | ||
reverse: function(location, scale, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + | ||
encodeURIComponent(location.lng) + | ||
',' + | ||
encodeURIComponent(location.lat) + | ||
'.json', | ||
this.options.reverseQueryParams, | ||
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.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); | ||
} | ||
); | ||
} | ||
}); | ||
function mapbox(accessToken, options) { | ||
return new Mapbox(accessToken, options); | ||
function mapbox(options) { | ||
return new Mapbox(options); | ||
} | ||
var MapQuest = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://www.mapquestapi.com/geocoding/v1' | ||
}, | ||
/** | ||
* Implementation of the [MapQuest Geocoding API](http://developer.mapquest.com/web/products/dev-services/geocoding-ws) | ||
*/ | ||
initialize: function(key, options) { | ||
// MapQuest seems to provide URI encoded API keys, | ||
var MapQuest = /*#__PURE__*/function () { | ||
function MapQuest(options) { | ||
this.options = { | ||
serviceUrl: 'https://www.mapquestapi.com/geocoding/v1' | ||
}; | ||
L.Util.setOptions(this, 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); | ||
}, | ||
this.options.apiKey = decodeURIComponent(this.options.apiKey); | ||
} | ||
_formatName: function() { | ||
var r = [], | ||
i; | ||
for (i = 0; i < arguments.length; i++) { | ||
if (arguments[i]) { | ||
r.push(arguments[i]); | ||
} | ||
} | ||
var _proto = MapQuest.prototype; | ||
return r.join(', '); | ||
}, | ||
_proto._formatName = function _formatName() { | ||
return [].slice.call(arguments).filter(function (s) { | ||
return !!s; | ||
}).join(', '); | ||
}; | ||
geocode: function(query, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + '/address', | ||
{ | ||
key: this._key, | ||
location: query, | ||
limit: 5, | ||
outFormat: 'json' | ||
}, | ||
L.bind(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 | ||
}; | ||
} | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
key: this.options.apiKey, | ||
location: query, | ||
limit: 5, | ||
outFormat: 'json' | ||
}); | ||
getJSON(this.options.serviceUrl + '/address', params, L.Util.bind(function (data) { | ||
var results = []; | ||
if (data.results && data.results[0].locations) { | ||
for (var i = data.results[0].locations.length - 1; i >= 0; i--) { | ||
var loc = data.results[0].locations[i]; | ||
var center = L.latLng(loc.latLng); | ||
results[i] = { | ||
name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), | ||
bbox: L.latLngBounds(center, center), | ||
center: center | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}, this) | ||
); | ||
}, | ||
cb.call(context, results); | ||
}, this)); | ||
}; | ||
reverse: function(location, scale, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + '/reverse', | ||
{ | ||
key: this._key, | ||
location: location.lat + ',' + location.lng, | ||
outputFormat: 'json' | ||
}, | ||
L.bind(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 | ||
}; | ||
} | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
key: this.options.apiKey, | ||
location: location.lat + ',' + location.lng, | ||
outputFormat: 'json' | ||
}); | ||
getJSON(this.options.serviceUrl + '/reverse', params, L.Util.bind(function (data) { | ||
var results = []; | ||
if (data.results && data.results[0].locations) { | ||
for (var i = data.results[0].locations.length - 1; i >= 0; i--) { | ||
var loc = data.results[0].locations[i]; | ||
var center = L.latLng(loc.latLng); | ||
results[i] = { | ||
name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), | ||
bbox: L.latLngBounds(center, center), | ||
center: center | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}, this) | ||
); | ||
} | ||
}); | ||
cb.call(context, results); | ||
}, this)); | ||
}; | ||
function mapQuest(key, options) { | ||
return new MapQuest(key, options); | ||
return MapQuest; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link MapQuest} | ||
* @param options the options | ||
*/ | ||
function mapQuest(options) { | ||
return new MapQuest(options); | ||
} | ||
var Neutrino = L.Class.extend({ | ||
options: { | ||
userId: '<insert your userId here>', | ||
apiKey: '<insert your apiKey here>', | ||
serviceUrl: 'https://neutrinoapi.com/' | ||
}, | ||
/** | ||
* Implementation of the [Neutrino API](https://www.neutrinoapi.com/api/geocode-address/) | ||
*/ | ||
initialize: function(options) { | ||
var Neutrino = /*#__PURE__*/function () { | ||
function Neutrino(options) { | ||
this.options = { | ||
userId: undefined, | ||
apiKey: undefined, | ||
serviceUrl: 'https://neutrinoapi.com/' | ||
}; | ||
L.Util.setOptions(this, options); | ||
}, | ||
} // https://www.neutrinoapi.com/api/geocode-address/ | ||
// https://www.neutrinoapi.com/api/geocode-address/ | ||
geocode: function(query, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + 'geocode-address', | ||
{ | ||
apiKey: this.options.apiKey, | ||
userId: this.options.userId, | ||
//get three words and make a dot based string | ||
address: query.split(/\s+/).join('.') | ||
}, | ||
function(data) { | ||
var results = [], | ||
latLng, | ||
latLngBounds; | ||
if (data.locations) { | ||
data.geometry = data.locations[0]; | ||
latLng = L.latLng(data.geometry['latitude'], data.geometry['longitude']); | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
results[0] = { | ||
name: data.geometry.address, | ||
bbox: latLngBounds, | ||
center: latLng | ||
}; | ||
} | ||
cb.call(context, results); | ||
var _proto = Neutrino.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
apiKey: this.options.apiKey, | ||
userId: this.options.userId, | ||
//get three words and make a dot based string | ||
address: query.split(/\s+/).join('.') | ||
}); | ||
getJSON(this.options.serviceUrl + 'geocode-address', params, function (data) { | ||
var results = []; | ||
if (data.locations) { | ||
data.geometry = data.locations[0]; | ||
var center = L.latLng(data.geometry['latitude'], data.geometry['longitude']); | ||
var bbox = L.latLngBounds(center, center); | ||
results[0] = { | ||
name: data.geometry.address, | ||
bbox: bbox, | ||
center: center | ||
}; | ||
} | ||
); | ||
}, | ||
suggest: function(query, cb, context) { | ||
cb.call(context, results); | ||
}); | ||
}; | ||
_proto.suggest = function suggest(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}, | ||
} // https://www.neutrinoapi.com/api/geocode-reverse/ | ||
; | ||
// https://www.neutrinoapi.com/api/geocode-reverse/ | ||
reverse: function(location, scale, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + 'geocode-reverse', | ||
{ | ||
apiKey: this.options.apiKey, | ||
userId: this.options.userId, | ||
latitude: location.lat, | ||
longitude: location.lng | ||
}, | ||
function(data) { | ||
var results = [], | ||
latLng, | ||
latLngBounds; | ||
if (data.status.status == 200 && data.found) { | ||
latLng = L.latLng(location.lat, location.lng); | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
results[0] = { | ||
name: data.address, | ||
bbox: latLngBounds, | ||
center: latLng | ||
}; | ||
} | ||
cb.call(context, results); | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
apiKey: this.options.apiKey, | ||
userId: this.options.userId, | ||
latitude: location.lat, | ||
longitude: location.lng | ||
}); | ||
getJSON(this.options.serviceUrl + 'geocode-reverse', params, function (data) { | ||
var results = []; | ||
if (data.status.status == 200 && data.found) { | ||
var center = L.latLng(location.lat, location.lng); | ||
var bbox = L.latLngBounds(center, center); | ||
results[0] = { | ||
name: data.address, | ||
bbox: bbox, | ||
center: center | ||
}; | ||
} | ||
); | ||
} | ||
}); | ||
function neutrino(accessToken) { | ||
return new Neutrino(accessToken); | ||
cb.call(context, results); | ||
}); | ||
}; | ||
return Neutrino; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Neutrino} | ||
* @param options the options | ||
*/ | ||
function neutrino(options) { | ||
return new Neutrino(options); | ||
} | ||
var Nominatim = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://nominatim.openstreetmap.org/', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {}, | ||
htmlTemplate: function(r) { | ||
var a = r.address, | ||
className, | ||
parts = []; | ||
if (a.road || a.building) { | ||
parts.push('{building} {road} {house_number}'); | ||
} | ||
/** | ||
* Implementation of the [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) geocoder. | ||
* | ||
* This is the default geocoding service used by the control, unless otherwise specified in the options. | ||
* | ||
* Unless using your own Nominatim installation, please refer to the [Nominatim usage policy](https://operations.osmfoundation.org/policies/nominatim/). | ||
*/ | ||
if (a.city || a.town || a.village || a.hamlet) { | ||
className = parts.length > 0 ? 'leaflet-control-geocoder-address-detail' : ''; | ||
parts.push( | ||
'<span class="' + className + '">{postcode} {city} {town} {village} {hamlet}</span>' | ||
); | ||
} | ||
var Nominatim = /*#__PURE__*/function () { | ||
function Nominatim(options) { | ||
this.options = { | ||
serviceUrl: 'https://nominatim.openstreetmap.org/', | ||
htmlTemplate: function htmlTemplate(r) { | ||
var address = r.address; | ||
var className; | ||
var parts = []; | ||
if (a.state || a.country) { | ||
className = parts.length > 0 ? 'leaflet-control-geocoder-address-context' : ''; | ||
parts.push('<span class="' + className + '">{state} {country}</span>'); | ||
if (address.road || address.building) { | ||
parts.push('{building} {road} {house_number}'); | ||
} | ||
if (address.city || address.town || address.village || address.hamlet) { | ||
className = parts.length > 0 ? 'leaflet-control-geocoder-address-detail' : ''; | ||
parts.push('<span class="' + className + '">{postcode} {city} {town} {village} {hamlet}</span>'); | ||
} | ||
if (address.state || address.country) { | ||
className = parts.length > 0 ? 'leaflet-control-geocoder-address-context' : ''; | ||
parts.push('<span class="' + className + '">{state} {country}</span>'); | ||
} | ||
return template(parts.join('<br/>'), address); | ||
} | ||
}; | ||
L.Util.setOptions(this, options || {}); | ||
} | ||
return template(parts.join('<br/>'), a, true); | ||
} | ||
}, | ||
var _proto = Nominatim.prototype; | ||
initialize: function(options) { | ||
L.Util.setOptions(this, options); | ||
}, | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var _this = this; | ||
geocode: function(query, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + 'search', | ||
L.extend( | ||
{ | ||
q: query, | ||
limit: 5, | ||
format: 'json', | ||
addressdetails: 1 | ||
}, | ||
this.options.geocodingQueryParams | ||
), | ||
L.bind(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) | ||
); | ||
}, | ||
var params = geocodingParams(this.options, { | ||
q: query, | ||
limit: 5, | ||
format: 'json', | ||
addressdetails: 1 | ||
}); | ||
getJSON(this.options.serviceUrl + 'search', params, function (data) { | ||
var results = []; | ||
reverse: function(location, scale, cb, context) { | ||
getJSON( | ||
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 | ||
), | ||
L.bind(function(data) { | ||
var result = [], | ||
loc; | ||
for (var i = data.length - 1; i >= 0; i--) { | ||
var bbox = data[i].boundingbox; | ||
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 | ||
}); | ||
for (var j = 0; j < 4; j++) { | ||
bbox[j] = parseFloat(bbox[j]); | ||
} | ||
cb.call(context, result); | ||
}, this) | ||
); | ||
} | ||
}); | ||
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); | ||
}); | ||
}; | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var _this2 = this; | ||
var params = reverseParams(this.options, { | ||
lat: location.lat, | ||
lon: location.lng, | ||
zoom: Math.round(Math.log(scale / 256) / Math.log(2)), | ||
addressdetails: 1, | ||
format: 'json' | ||
}); | ||
getJSON(this.options.serviceUrl + 'reverse', params, function (data) { | ||
var result = []; | ||
if (data && data.lat && data.lon) { | ||
var center = L.latLng(data.lat, data.lon); | ||
var bbox = L.latLngBounds(center, center); | ||
result.push({ | ||
name: data.display_name, | ||
html: _this2.options.htmlTemplate ? _this2.options.htmlTemplate(data) : undefined, | ||
center: center, | ||
bbox: bbox, | ||
properties: data | ||
}); | ||
} | ||
cb.call(context, result); | ||
}); | ||
}; | ||
return Nominatim; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Nominatim} | ||
* @param options the options | ||
*/ | ||
function nominatim(options) { | ||
@@ -931,13 +974,14 @@ return new Nominatim(options); | ||
var OpenLocationCode = L.Class.extend({ | ||
options: { | ||
OpenLocationCode: undefined, | ||
codeLength: undefined | ||
}, | ||
/** | ||
* Implementation of the [Plus codes](https://plus.codes/) (formerly OpenLocationCode) (requires [open-location-code](https://www.npmjs.com/package/open-location-code)) | ||
*/ | ||
initialize: function(options) { | ||
L.setOptions(this, options); | ||
}, | ||
var OpenLocationCode = /*#__PURE__*/function () { | ||
function OpenLocationCode(options) { | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var _proto = OpenLocationCode.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
try { | ||
@@ -948,6 +992,3 @@ var decoded = this.options.OpenLocationCode.decode(query); | ||
center: L.latLng(decoded.latitudeCenter, decoded.longitudeCenter), | ||
bbox: L.latLngBounds( | ||
L.latLng(decoded.latitudeLo, decoded.longitudeLo), | ||
L.latLng(decoded.latitudeHi, decoded.longitudeHi) | ||
) | ||
bbox: L.latLngBounds(L.latLng(decoded.latitudeLo, decoded.longitudeLo), L.latLng(decoded.latitudeHi, decoded.longitudeHi)) | ||
}; | ||
@@ -957,19 +998,14 @@ cb.call(context, [result]); | ||
console.warn(e); // eslint-disable-line no-console | ||
cb.call(context, []); | ||
} | ||
}, | ||
reverse: function(location, scale, cb, context) { | ||
}; | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
try { | ||
var code = this.options.OpenLocationCode.encode( | ||
location.lat, | ||
location.lng, | ||
this.options.codeLength | ||
); | ||
var code = this.options.OpenLocationCode.encode(location.lat, location.lng, this.options.codeLength); | ||
var result = { | ||
name: code, | ||
center: L.latLng(location.lat, location.lng), | ||
bbox: L.latLngBounds( | ||
L.latLng(location.lat, location.lng), | ||
L.latLng(location.lat, location.lng) | ||
) | ||
bbox: L.latLngBounds(L.latLng(location.lat, location.lng), L.latLng(location.lat, location.lng)) | ||
}; | ||
@@ -979,7 +1015,14 @@ cb.call(context, [result]); | ||
console.warn(e); // eslint-disable-line no-console | ||
cb.call(context, []); | ||
} | ||
} | ||
}); | ||
}; | ||
return OpenLocationCode; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link OpenLocationCode} | ||
* @param options the options | ||
*/ | ||
function openLocationCode(options) { | ||
@@ -989,169 +1032,155 @@ return new OpenLocationCode(options); | ||
var OpenCage = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://api.opencagedata.com/geocode/v1/json', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {} | ||
}, | ||
/** | ||
* Implementation of the [OpenCage Data API](https://opencagedata.com/) | ||
*/ | ||
initialize: function(apiKey, options) { | ||
L.setOptions(this, options); | ||
this._accessToken = apiKey; | ||
}, | ||
var OpenCage = /*#__PURE__*/function () { | ||
function OpenCage(options) { | ||
this.options = { | ||
serviceUrl: 'https://api.opencagedata.com/geocode/v1/json' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var params = { | ||
key: this._accessToken, | ||
var _proto = OpenCage.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
key: this.options.apiKey, | ||
q: query | ||
}; | ||
params = L.extend(params, this.options.geocodingQueryParams); | ||
getJSON(this.options.serviceUrl, params, function(data) { | ||
var results = [], | ||
latLng, | ||
latLngBounds, | ||
loc; | ||
}); | ||
getJSON(this.options.serviceUrl, params, function (data) { | ||
var results = []; | ||
if (data.results && data.results.length) { | ||
for (var i = 0; i < data.results.length; i++) { | ||
loc = data.results[i]; | ||
latLng = L.latLng(loc.geometry); | ||
var loc = data.results[i]; | ||
var center = L.latLng(loc.geometry); | ||
var bbox = void 0; | ||
if (loc.annotations && loc.annotations.bounds) { | ||
latLngBounds = L.latLngBounds( | ||
L.latLng(loc.annotations.bounds.northeast), | ||
L.latLng(loc.annotations.bounds.southwest) | ||
); | ||
bbox = L.latLngBounds(L.latLng(loc.annotations.bounds.northeast), L.latLng(loc.annotations.bounds.southwest)); | ||
} else { | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
bbox = L.latLngBounds(center, center); | ||
} | ||
results.push({ | ||
name: loc.formatted, | ||
bbox: latLngBounds, | ||
center: latLng | ||
bbox: bbox, | ||
center: center | ||
}); | ||
} | ||
} | ||
cb.call(context, results); | ||
}); | ||
}, | ||
}; | ||
suggest: function(query, cb, context) { | ||
_proto.suggest = function suggest(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}, | ||
}; | ||
reverse: function(location, scale, cb, context) { | ||
var params = { | ||
key: this._accessToken, | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
key: this.options.apiKey, | ||
q: [location.lat, location.lng].join(',') | ||
}; | ||
params = L.extend(params, this.options.reverseQueryParams); | ||
getJSON(this.options.serviceUrl, params, function(data) { | ||
var results = [], | ||
latLng, | ||
latLngBounds, | ||
loc; | ||
}); | ||
getJSON(this.options.serviceUrl, params, function (data) { | ||
var results = []; | ||
if (data.results && data.results.length) { | ||
for (var i = 0; i < data.results.length; i++) { | ||
loc = data.results[i]; | ||
latLng = L.latLng(loc.geometry); | ||
var loc = data.results[i]; | ||
var center = L.latLng(loc.geometry); | ||
var bbox = void 0; | ||
if (loc.annotations && loc.annotations.bounds) { | ||
latLngBounds = L.latLngBounds( | ||
L.latLng(loc.annotations.bounds.northeast), | ||
L.latLng(loc.annotations.bounds.southwest) | ||
); | ||
bbox = L.latLngBounds(L.latLng(loc.annotations.bounds.northeast), L.latLng(loc.annotations.bounds.southwest)); | ||
} else { | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
bbox = L.latLngBounds(center, center); | ||
} | ||
results.push({ | ||
name: loc.formatted, | ||
bbox: latLngBounds, | ||
center: latLng | ||
bbox: bbox, | ||
center: center | ||
}); | ||
} | ||
} | ||
cb.call(context, results); | ||
}); | ||
} | ||
}); | ||
}; | ||
function opencage(apiKey, options) { | ||
return new OpenCage(apiKey, options); | ||
return OpenCage; | ||
}(); | ||
function opencage(options) { | ||
return new OpenCage(options); | ||
} | ||
var Pelias = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://api.geocode.earth/v1', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {} | ||
}, | ||
/** | ||
* Implementation of the [Pelias](https://pelias.io/), [geocode.earth](https://geocode.earth/) geocoder (formerly Mapzen Search) | ||
*/ | ||
initialize: function(apiKey, options) { | ||
var Pelias = /*#__PURE__*/function () { | ||
function Pelias(options) { | ||
this.options = { | ||
serviceUrl: 'https://api.geocode.earth/v1' | ||
}; | ||
this._lastSuggest = 0; | ||
L.Util.setOptions(this, options); | ||
this._apiKey = apiKey; | ||
this._lastSuggest = 0; | ||
}, | ||
} | ||
geocode: function(query, cb, context) { | ||
var _this = this; | ||
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')); | ||
} | ||
); | ||
}, | ||
var _proto = Pelias.prototype; | ||
suggest: function(query, cb, context) { | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var _this = this; | ||
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; | ||
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')); | ||
var params = geocodingParams(this.options, { | ||
api_key: this.options.apiKey, | ||
text: query | ||
}); | ||
getJSON(this.options.serviceUrl + '/search', params, function (data) { | ||
cb.call(context, _this._parseResults(data, 'bbox')); | ||
}); | ||
}; | ||
_proto.suggest = function suggest(query, cb, context) { | ||
var _this2 = this; | ||
var params = geocodingParams(this.options, { | ||
api_key: this.options.apiKey, | ||
text: query | ||
}); | ||
getJSON(this.options.serviceUrl + '/autocomplete', params, function (data) { | ||
if (data.geocoding.timestamp > _this2._lastSuggest) { | ||
_this2._lastSuggest = data.geocoding.timestamp; | ||
cb.call(context, _this2._parseResults(data, 'bbox')); | ||
} | ||
); | ||
}, | ||
}); | ||
}; | ||
_parseResults: function(data, bboxname) { | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
var _this3 = this; | ||
var params = reverseParams(this.options, { | ||
api_key: this.options.apiKey, | ||
'point.lat': location.lat, | ||
'point.lon': location.lng | ||
}); | ||
getJSON(this.options.serviceUrl + '/reverse', params, function (data) { | ||
cb.call(context, _this3._parseResults(data, 'bounds')); | ||
}); | ||
}; | ||
_proto._parseResults = function _parseResults(data, bboxname) { | ||
var results = []; | ||
L.geoJson(data, { | ||
pointToLayer: function(feature, latlng) { | ||
L.geoJSON(data, { | ||
pointToLayer: function pointToLayer(feature, latlng) { | ||
return L.circleMarker(latlng); | ||
}, | ||
onEachFeature: function(feature, layer) { | ||
var result = {}, | ||
bbox, | ||
center; | ||
onEachFeature: function onEachFeature(feature, layer) { | ||
var result = {}; | ||
var bbox; | ||
var center; | ||
@@ -1163,6 +1192,3 @@ if (layer.getBounds) { | ||
center = layer.getLatLng(); | ||
bbox = L.latLngBounds( | ||
L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(0, 2)), | ||
L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(2, 4)) | ||
); | ||
bbox = L.latLngBounds(L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(0, 2)), L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(2, 4))); | ||
} else { | ||
@@ -1181,99 +1207,105 @@ center = layer.getLatLng(); | ||
return results; | ||
} | ||
}); | ||
}; | ||
function pelias(apiKey, options) { | ||
return new Pelias(apiKey, options); | ||
return Pelias; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Pelias} | ||
* @param options the options | ||
*/ | ||
function pelias(options) { | ||
return new Pelias(options); | ||
} | ||
var GeocodeEarth = Pelias; | ||
var geocodeEarth = pelias; | ||
/** | ||
* r.i.p. | ||
* @deprecated | ||
*/ | ||
var Mapzen = Pelias; // r.i.p. | ||
var Mapzen = Pelias; | ||
/** | ||
* r.i.p. | ||
* @deprecated | ||
*/ | ||
var mapzen = pelias; | ||
/** | ||
* Implementation of the [Openrouteservice](https://openrouteservice.org/dev/#/api-docs/geocode) geocoder | ||
*/ | ||
var Openrouteservice = Mapzen.extend({ | ||
options: { | ||
serviceUrl: 'https://api.openrouteservice.org/geocode' | ||
var Openrouteservice = /*#__PURE__*/function (_Pelias) { | ||
_inheritsLoose(Openrouteservice, _Pelias); | ||
function Openrouteservice(options) { | ||
return _Pelias.call(this, L.Util.extend({ | ||
serviceUrl: 'https://api.openrouteservice.org/geocode' | ||
}, options)) || this; | ||
} | ||
}); | ||
function openrouteservice(apiKey, options) { | ||
return new Openrouteservice(apiKey, options); | ||
return Openrouteservice; | ||
}(Pelias); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Openrouteservice} | ||
* @param options the options | ||
*/ | ||
function openrouteservice(options) { | ||
return new Openrouteservice(options); | ||
} | ||
var Photon = 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'] | ||
}, | ||
/** | ||
* Implementation of the [Photon](http://photon.komoot.de/) geocoder | ||
*/ | ||
initialize: function(options) { | ||
L.setOptions(this, options); | ||
}, | ||
var Photon = /*#__PURE__*/function () { | ||
function Photon(options) { | ||
this.options = { | ||
serviceUrl: 'https://photon.komoot.io/api/', | ||
reverseUrl: 'https://photon.komoot.io/reverse/', | ||
nameProperties: ['name', 'street', 'suburb', 'hamlet', 'town', 'city', 'state', 'country'] | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var params = L.extend( | ||
{ | ||
q: query | ||
}, | ||
this.options.geocodingQueryParams | ||
); | ||
var _proto = Photon.prototype; | ||
getJSON( | ||
this.options.serviceUrl, | ||
params, | ||
L.bind(function(data) { | ||
cb.call(context, this._decodeFeatures(data)); | ||
}, this) | ||
); | ||
}, | ||
_proto.geocode = function geocode(query, cb, context) { | ||
var params = geocodingParams(this.options, { | ||
q: query | ||
}); | ||
getJSON(this.options.serviceUrl, params, L.Util.bind(function (data) { | ||
cb.call(context, this._decodeFeatures(data)); | ||
}, this)); | ||
}; | ||
suggest: function(query, cb, context) { | ||
_proto.suggest = function suggest(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.reverseQueryParams | ||
); | ||
_proto.reverse = function reverse(latLng, scale, cb, context) { | ||
var params = reverseParams(this.options, { | ||
lat: latLng.lat, | ||
lon: latLng.lng | ||
}); | ||
getJSON(this.options.reverseUrl, params, L.Util.bind(function (data) { | ||
cb.call(context, this._decodeFeatures(data)); | ||
}, this)); | ||
}; | ||
getJSON( | ||
this.options.reverseUrl, | ||
params, | ||
L.bind(function(data) { | ||
cb.call(context, this._decodeFeatures(data)); | ||
}, this) | ||
); | ||
}, | ||
_proto._decodeFeatures = function _decodeFeatures(data) { | ||
var results = []; | ||
_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); | ||
} | ||
for (var i = 0; i < data.features.length; i++) { | ||
var f = data.features[i]; | ||
var c = f.geometry.coordinates; | ||
var center = L.latLng(c[1], c[0]); | ||
var extent = f.properties.extent; | ||
var bbox = extent ? L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]) : L.latLngBounds(center, center); | ||
results.push({ | ||
name: this._decodeFeatureName(f), | ||
html: this.options.htmlTemplate ? this.options.htmlTemplate(f) : undefined, | ||
center: latLng, | ||
center: center, | ||
bbox: bbox, | ||
@@ -1286,16 +1318,19 @@ properties: f.properties | ||
return results; | ||
}, | ||
}; | ||
_decodeFeatureName: function(f) { | ||
return (this.options.nameProperties || []) | ||
.map(function(p) { | ||
return f.properties[p]; | ||
}) | ||
.filter(function(v) { | ||
return !!v; | ||
}) | ||
.join(', '); | ||
} | ||
}); | ||
_proto._decodeFeatureName = function _decodeFeatureName(f) { | ||
return (this.options.nameProperties || []).map(function (p) { | ||
return f.properties[p]; | ||
}).filter(function (v) { | ||
return !!v; | ||
}).join(', '); | ||
}; | ||
return Photon; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Photon} | ||
* @param options the options | ||
*/ | ||
function photon(options) { | ||
@@ -1305,70 +1340,72 @@ return new Photon(options); | ||
var What3Words = L.Class.extend({ | ||
options: { | ||
serviceUrl: 'https://api.what3words.com/v2/' | ||
}, | ||
/** | ||
* Implementation of the What3Words service | ||
*/ | ||
initialize: function(accessToken) { | ||
this._accessToken = accessToken; | ||
}, | ||
var What3Words = /*#__PURE__*/function () { | ||
function What3Words(options) { | ||
this.options = { | ||
serviceUrl: 'https://api.what3words.com/v2/' | ||
}; | ||
L.Util.setOptions(this, options); | ||
} | ||
geocode: function(query, cb, context) { | ||
var _proto = What3Words.prototype; | ||
_proto.geocode = function geocode(query, cb, context) { | ||
//get three words and make a dot based string | ||
getJSON( | ||
this.options.serviceUrl + 'forward', | ||
{ | ||
key: this._accessToken, | ||
addr: query.split(/\s+/).join('.') | ||
}, | ||
function(data) { | ||
var results = [], | ||
latLng, | ||
latLngBounds; | ||
if (data.geometry) { | ||
latLng = L.latLng(data.geometry['lat'], data.geometry['lng']); | ||
latLngBounds = L.latLngBounds(latLng, latLng); | ||
results[0] = { | ||
name: data.words, | ||
bbox: latLngBounds, | ||
center: latLng | ||
}; | ||
} | ||
getJSON(this.options.serviceUrl + 'forward', geocodingParams(this.options, { | ||
key: this.options.apiKey, | ||
addr: query.split(/\s+/).join('.') | ||
}), function (data) { | ||
var results = []; | ||
cb.call(context, results); | ||
if (data.geometry) { | ||
var latLng = L.latLng(data.geometry['lat'], data.geometry['lng']); | ||
var latLngBounds = L.latLngBounds(latLng, latLng); | ||
results[0] = { | ||
name: data.words, | ||
bbox: latLngBounds, | ||
center: latLng | ||
}; | ||
} | ||
); | ||
}, | ||
suggest: function(query, cb, context) { | ||
cb.call(context, results); | ||
}); | ||
}; | ||
_proto.suggest = function suggest(query, cb, context) { | ||
return this.geocode(query, cb, context); | ||
}, | ||
}; | ||
reverse: function(location, scale, cb, context) { | ||
getJSON( | ||
this.options.serviceUrl + 'reverse', | ||
{ | ||
key: this._accessToken, | ||
coords: [location.lat, location.lng].join(',') | ||
}, | ||
function(data) { | ||
var results = [], | ||
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); | ||
_proto.reverse = function reverse(location, scale, cb, context) { | ||
getJSON(this.options.serviceUrl + 'reverse', reverseParams(this.options, { | ||
key: this.options.apiKey, | ||
coords: [location.lat, location.lng].join(',') | ||
}), function (data) { | ||
var results = []; | ||
if (data.status.status == 200) { | ||
var center = L.latLng(data.geometry['lat'], data.geometry['lng']); | ||
var bbox = L.latLngBounds(center, center); | ||
results[0] = { | ||
name: data.words, | ||
bbox: bbox, | ||
center: center | ||
}; | ||
} | ||
); | ||
} | ||
}); | ||
function what3words(accessToken) { | ||
return new What3Words(accessToken); | ||
cb.call(context, results); | ||
}); | ||
}; | ||
return What3Words; | ||
}(); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link What3Words} | ||
* @param options the options | ||
*/ | ||
function what3words(options) { | ||
return new What3Words(options); | ||
} | ||
@@ -1378,3 +1415,6 @@ | ||
var geocoders = /*#__PURE__*/Object.freeze({ | ||
var geocoders = { | ||
__proto__: null, | ||
geocodingParams: geocodingParams, | ||
reverseParams: reverseParams, | ||
ArcGis: ArcGis, | ||
@@ -1388,2 +1428,3 @@ arcgis: arcgis, | ||
here: here, | ||
parseLatLng: parseLatLng, | ||
LatLng: LatLng, | ||
@@ -1415,111 +1456,153 @@ latLng: latLng, | ||
what3words: what3words | ||
}); | ||
}; | ||
var Geocoder = L.Control.extend({ | ||
options: { | ||
showUniqueResult: true, | ||
showResultIcons: false, | ||
collapsed: true, | ||
expand: 'touch', // options: touch, click, anythingelse | ||
position: 'topright', | ||
placeholder: 'Search...', | ||
errorMessage: 'Nothing found.', | ||
iconLabel: 'Initiate a new search', | ||
queryMinLength: 1, | ||
suggestMinLength: 3, | ||
suggestTimeout: 250, | ||
defaultMarkGeocode: true | ||
}, | ||
/** | ||
* This is the geocoder control. It works like any other [Leaflet control](https://leafletjs.com/reference.html#control), and is added to the map. | ||
*/ | ||
includes: L.Evented.prototype || L.Mixin.Events, | ||
var GeocoderControl = /*#__PURE__*/function (_L$Control) { | ||
_inheritsLoose(GeocoderControl, _L$Control); | ||
initialize: function(options) { | ||
L.Util.setOptions(this, options); | ||
if (!this.options.geocoder) { | ||
this.options.geocoder = new Nominatim(); | ||
/** | ||
* Instantiates a geocoder control (to be invoked using `new`) | ||
* @param options the options | ||
*/ | ||
function GeocoderControl(options) { | ||
var _this; | ||
_this = _L$Control.call(this, options) || this; | ||
_this.options = { | ||
showUniqueResult: true, | ||
showResultIcons: false, | ||
collapsed: true, | ||
expand: 'touch', | ||
position: 'topright', | ||
placeholder: 'Search...', | ||
errorMessage: 'Nothing found.', | ||
iconLabel: 'Initiate a new search', | ||
query: '', | ||
queryMinLength: 1, | ||
suggestMinLength: 3, | ||
suggestTimeout: 250, | ||
defaultMarkGeocode: true | ||
}; | ||
_this._requestCount = 0; | ||
L.Util.setOptions(_assertThisInitialized(_this), options); | ||
if (!_this.options.geocoder) { | ||
_this.options.geocoder = new Nominatim(); | ||
} | ||
this._requestCount = 0; | ||
}, | ||
return _this; | ||
} | ||
/** | ||
* Adds a listener function to a particular event type of the object. | ||
* @param type the event type | ||
* @param fn the listener function | ||
* @param context the this listener function context | ||
* @see https://leafletjs.com/reference.html#evented-on | ||
*/ | ||
addThrobberClass: function() { | ||
var _proto = GeocoderControl.prototype; | ||
_proto.on = function on(type, fn, context) { | ||
L.Evented.prototype.on(type, fn, context); | ||
return this; | ||
} | ||
/** | ||
* Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. | ||
* @param type the event type | ||
* @param fn the listener function | ||
* @param context the this listener function context | ||
* @see https://leafletjs.com/reference.html#evented-off | ||
*/ | ||
; | ||
_proto.off = function off(type, fn, context) { | ||
L.Evented.prototype.off(type, fn, context); | ||
return this; | ||
} | ||
/** | ||
* Fires an event of the specified type. You can optionally provide an data object. | ||
* @param type the event type | ||
* @param data the event data object | ||
* @param propagate whether to propagate to event parents | ||
* @see https://leafletjs.com/reference.html#evented-fire | ||
*/ | ||
; | ||
_proto.fire = function fire(type, data, propagate) { | ||
L.Evented.prototype.fire(type, data, propagate); | ||
return this; | ||
}; | ||
_proto.addThrobberClass = function addThrobberClass() { | ||
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber'); | ||
}, | ||
}; | ||
removeThrobberClass: function() { | ||
_proto.removeThrobberClass = function removeThrobberClass() { | ||
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-throbber'); | ||
}, | ||
} | ||
/** | ||
* Returns the container DOM element for the control and add listeners on relevant map events. | ||
* @param map the map instance | ||
* @see https://leafletjs.com/reference.html#control-onadd | ||
*/ | ||
; | ||
onAdd: function(map) { | ||
var className = 'leaflet-control-geocoder', | ||
container = L.DomUtil.create('div', className + ' leaflet-bar'), | ||
icon = L.DomUtil.create('button', className + '-icon', container), | ||
form = (this._form = L.DomUtil.create('div', className + '-form', container)), | ||
input; | ||
_proto.onAdd = function onAdd(map) { | ||
var _this2 = this; | ||
var className = 'leaflet-control-geocoder'; | ||
var container = L.DomUtil.create('div', className + ' leaflet-bar'); | ||
var icon = L.DomUtil.create('button', className + '-icon', container); | ||
var form = this._form = L.DomUtil.create('div', className + '-form', container); | ||
this._map = map; | ||
this._container = container; | ||
icon.innerHTML = ' '; | ||
icon.type = 'button'; | ||
icon.setAttribute('aria-label', this.options.iconLabel); | ||
input = this._input = L.DomUtil.create('input', '', form); | ||
var input = this._input = L.DomUtil.create('input', '', form); | ||
input.type = 'text'; | ||
input.value = this.options.query || ''; | ||
input.value = this.options.query; | ||
input.placeholder = this.options.placeholder; | ||
L.DomEvent.disableClickPropagation(input); | ||
this._errorElement = L.DomUtil.create('div', className + '-form-no-error', container); | ||
this._errorElement.innerHTML = this.options.errorMessage; | ||
this._alts = L.DomUtil.create( | ||
'ul', | ||
className + '-alternatives leaflet-control-geocoder-alternatives-minimized', | ||
container | ||
); | ||
this._alts = L.DomUtil.create('ul', className + '-alternatives leaflet-control-geocoder-alternatives-minimized', container); | ||
L.DomEvent.disableClickPropagation(this._alts); | ||
L.DomEvent.addListener(input, 'keydown', this._keydown, this); | ||
L.DomEvent.addListener(input, 'keydown', this._keydown, this); | ||
if (this.options.geocoder.suggest) { | ||
L.DomEvent.addListener(input, 'input', this._change, this); | ||
} | ||
L.DomEvent.addListener( | ||
input, | ||
'blur', | ||
function() { | ||
if (this.options.collapsed && !this._preventBlurCollapse) { | ||
this._collapse(); | ||
} | ||
this._preventBlurCollapse = false; | ||
}, | ||
this | ||
); | ||
L.DomEvent.addListener(input, 'blur', function () { | ||
if (_this2.options.collapsed && !_this2._preventBlurCollapse) { | ||
_this2._collapse(); | ||
} | ||
_this2._preventBlurCollapse = false; | ||
}); | ||
if (this.options.collapsed) { | ||
if (this.options.expand === 'click') { | ||
L.DomEvent.addListener( | ||
container, | ||
'click', | ||
function(e) { | ||
if (e.button === 0 && e.detail !== 2) { | ||
this._toggle(); | ||
} | ||
}, | ||
this | ||
); | ||
L.DomEvent.addListener(container, 'click', function (e) { | ||
if (e.button === 0 && e.detail !== 2) { | ||
_this2._toggle(); | ||
} | ||
}); | ||
} else if (this.options.expand === 'touch') { | ||
L.DomEvent.addListener( | ||
container, | ||
L.Browser.touch ? 'touchstart mousedown' : 'mousedown', | ||
function(e) { | ||
this._toggle(); | ||
e.preventDefault(); // mobile: clicking focuses the icon, so UI expands and immediately collapses | ||
e.stopPropagation(); | ||
}, | ||
this | ||
); | ||
L.DomEvent.addListener(container, L.Browser.touch ? 'touchstart mousedown' : 'mousedown', function (e) { | ||
_this2._toggle(); | ||
e.preventDefault(); // mobile: clicking focuses the icon, so UI expands and immediately collapses | ||
e.stopPropagation(); | ||
}, this); | ||
} else { | ||
L.DomEvent.addListener(container, 'mouseover', this._expand, this); | ||
L.DomEvent.addListener(container, 'mouseout', this._collapse, this); | ||
this._map.on('movestart', this._collapse, this); | ||
@@ -1529,20 +1612,11 @@ } | ||
this._expand(); | ||
if (L.Browser.touch) { | ||
L.DomEvent.addListener( | ||
container, | ||
'touchstart', | ||
function() { | ||
this._geocode(); | ||
}, | ||
this | ||
); | ||
L.DomEvent.addListener(container, 'touchstart', function () { | ||
return _this2._geocode(); | ||
}); | ||
} else { | ||
L.DomEvent.addListener( | ||
container, | ||
'click', | ||
function() { | ||
this._geocode(); | ||
}, | ||
this | ||
); | ||
L.DomEvent.addListener(container, 'click', function () { | ||
return _this2._geocode(); | ||
}); | ||
} | ||
@@ -1559,14 +1633,17 @@ } | ||
this.on('finishsuggest', this.removeThrobberClass, this); | ||
L.DomEvent.disableClickPropagation(container); | ||
return container; | ||
}, | ||
} | ||
/** | ||
* Sets the query string on the text input | ||
* @param string the query string | ||
*/ | ||
; | ||
setQuery: function(string) { | ||
_proto.setQuery = function setQuery(string) { | ||
this._input.value = string; | ||
return this; | ||
}, | ||
}; | ||
_geocodeResult: function(results, suggest) { | ||
_proto._geocodeResult = function _geocodeResult(results, suggest) { | ||
if (!suggest && this.options.showUniqueResult && results.length === 1) { | ||
@@ -1579,2 +1656,3 @@ this._geocodeResultSelected(results[0]); | ||
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-options-open'); | ||
for (var i = 0; i < results.length; i++) { | ||
@@ -1587,5 +1665,10 @@ this._alts.appendChild(this._createAlt(results[i], i)); | ||
} | ||
}, | ||
} | ||
/** | ||
* Marks a geocoding result on the map | ||
* @param result the geocoding result | ||
*/ | ||
; | ||
markGeocode: function(result) { | ||
_proto.markGeocode = function markGeocode(result) { | ||
result = result.geocode || result; | ||
@@ -1599,12 +1682,11 @@ | ||
this._geocodeMarker = new L.Marker(result.center) | ||
.bindPopup(result.html || result.name) | ||
.addTo(this._map) | ||
.openPopup(); | ||
this._geocodeMarker = new L.Marker(result.center).bindPopup(result.html || result.name).addTo(this._map).openPopup(); | ||
return this; | ||
}, | ||
}; | ||
_geocode: function(suggest) { | ||
_proto._geocode = function _geocode(suggest) { | ||
var _this3 = this; | ||
var value = this._input.value; | ||
if (!suggest && value.length < this.options.queryMinLength) { | ||
@@ -1614,7 +1696,17 @@ return; | ||
var requestCount = ++this._requestCount, | ||
mode = suggest ? 'suggest' : 'geocode', | ||
eventData = { input: value }; | ||
var requestCount = ++this._requestCount; | ||
var cb = function cb(results) { | ||
if (requestCount === _this3._requestCount) { | ||
_this3.fire(suggest ? 'finishsuggest' : 'finishgeocode', { | ||
input: value, | ||
results: results | ||
}); | ||
_this3._geocodeResult(results, suggest); | ||
} | ||
}; | ||
this._lastGeocode = value; | ||
if (!suggest) { | ||
@@ -1624,21 +1716,20 @@ this._clearResults(); | ||
this.fire('start' + mode, eventData); | ||
this.options.geocoder[mode]( | ||
value, | ||
function(results) { | ||
if (requestCount === this._requestCount) { | ||
eventData.results = results; | ||
this.fire('finish' + mode, eventData); | ||
this._geocodeResult(results, suggest); | ||
} | ||
}, | ||
this | ||
); | ||
}, | ||
this.fire(suggest ? 'startsuggest' : 'startgeocode', { | ||
input: value | ||
}); | ||
_geocodeResultSelected: function(result) { | ||
this.fire('markgeocode', { geocode: result }); | ||
}, | ||
if (suggest) { | ||
this.options.geocoder.suggest(value, cb); | ||
} else { | ||
this.options.geocoder.geocode(value, cb); | ||
} | ||
}; | ||
_toggle: function() { | ||
_proto._geocodeResultSelected = function _geocodeResultSelected(result) { | ||
this.fire('markgeocode', { | ||
geocode: result | ||
}); | ||
}; | ||
_proto._toggle = function _toggle() { | ||
if (L.DomUtil.hasClass(this._container, 'leaflet-control-geocoder-expanded')) { | ||
@@ -1649,11 +1740,13 @@ this._collapse(); | ||
} | ||
}, | ||
}; | ||
_expand: function() { | ||
_proto._expand = function _expand() { | ||
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded'); | ||
this._input.select(); | ||
this.fire('expand'); | ||
}, | ||
}; | ||
_collapse: function() { | ||
_proto._collapse = function _collapse() { | ||
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-expanded'); | ||
@@ -1664,7 +1757,10 @@ L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); | ||
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error'); | ||
this._input.blur(); // mobile: keyboard shouldn't stay expanded | ||
this.fire('collapse'); | ||
}, | ||
}; | ||
_clearResults: function() { | ||
_proto._clearResults = function _clearResults() { | ||
L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); | ||
@@ -1675,32 +1771,31 @@ this._selection = null; | ||
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error'); | ||
}, | ||
}; | ||
_createAlt: function(result, index) { | ||
_proto._createAlt = function _createAlt(result, index) { | ||
var _this4 = this; | ||
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), | ||
mouseDownHandler = function mouseDownHandler(e) { | ||
// In some browsers, a click will fire on the map if the control is | ||
// collapsed directly after mousedown. To work around this, we | ||
// wait until the click is completed, and _then_ collapse the | ||
// control. Messy, but this is the workaround I could come up with | ||
// for #142. | ||
this._preventBlurCollapse = true; | ||
L.DomEvent.stop(e); | ||
this._geocodeResultSelected(result); | ||
L.DomEvent.on( | ||
li, | ||
'click touchend', | ||
function() { | ||
if (this.options.collapsed) { | ||
this._collapse(); | ||
} else { | ||
this._clearResults(); | ||
} | ||
}, | ||
this | ||
); | ||
}; | ||
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), | ||
mouseDownHandler = function mouseDownHandler(e) { | ||
// In some browsers, a click will fire on the map if the control is | ||
// collapsed directly after mousedown. To work around this, we | ||
// wait until the click is completed, and _then_ collapse the | ||
// control. Messy, but this is the workaround I could come up with | ||
// for #142. | ||
_this4._preventBlurCollapse = true; | ||
L.DomEvent.stop(e); | ||
_this4._geocodeResultSelected(result); | ||
L.DomEvent.on(li, 'click touchend', function () { | ||
if (_this4.options.collapsed) { | ||
_this4._collapse(); | ||
} else { | ||
_this4._clearResults(); | ||
} | ||
}); | ||
}; | ||
if (icon) { | ||
@@ -1710,34 +1805,35 @@ icon.src = result.icon; | ||
li.setAttribute('data-result-index', index); | ||
li.setAttribute('data-result-index', String(index)); | ||
if (result.html) { | ||
a.innerHTML = a.innerHTML + result.html; | ||
} else { | ||
} else if (text) { | ||
a.appendChild(text); | ||
} | ||
// Use mousedown and not click, since click will fire _after_ blur, | ||
} // Use mousedown and not click, since click will fire _after_ blur, | ||
// causing the control to have collapsed and removed the items | ||
// before the click can fire. | ||
L.DomEvent.addListener(li, 'mousedown touchstart', mouseDownHandler, this); | ||
return li; | ||
}, | ||
}; | ||
_keydown: function(e) { | ||
var _this = this, | ||
select = function select(dir) { | ||
if (_this._selection) { | ||
L.DomUtil.removeClass(_this._selection, 'leaflet-control-geocoder-selected'); | ||
_this._selection = _this._selection[dir > 0 ? 'nextSibling' : 'previousSibling']; | ||
} | ||
if (!_this._selection) { | ||
_this._selection = _this._alts[dir > 0 ? 'firstChild' : 'lastChild']; | ||
} | ||
_proto._keydown = function _keydown(e) { | ||
var _this5 = this; | ||
if (_this._selection) { | ||
L.DomUtil.addClass(_this._selection, 'leaflet-control-geocoder-selected'); | ||
} | ||
}; | ||
var select = function select(dir) { | ||
if (_this5._selection) { | ||
L.DomUtil.removeClass(_this5._selection, 'leaflet-control-geocoder-selected'); | ||
_this5._selection = _this5._selection[dir > 0 ? 'nextSibling' : 'previousSibling']; | ||
} | ||
if (!_this5._selection) { | ||
_this5._selection = _this5._alts[dir > 0 ? 'firstChild' : 'lastChild']; | ||
} | ||
if (_this5._selection) { | ||
L.DomUtil.addClass(_this5._selection, 'leaflet-control-geocoder-selected'); | ||
} | ||
}; | ||
switch (e.keyCode) { | ||
@@ -1751,4 +1847,6 @@ // Escape | ||
} | ||
break; | ||
// Up | ||
case 38: | ||
@@ -1758,2 +1856,3 @@ select(-1); | ||
// Up | ||
case 40: | ||
@@ -1763,6 +1862,9 @@ select(1); | ||
// Enter | ||
case 13: | ||
if (this._selection) { | ||
var index = parseInt(this._selection.getAttribute('data-result-index'), 10); | ||
this._geocodeResultSelected(this._results[index]); | ||
this._clearResults(); | ||
@@ -1772,3 +1874,5 @@ } else { | ||
} | ||
break; | ||
default: | ||
@@ -1779,14 +1883,16 @@ return; | ||
L.DomEvent.preventDefault(e); | ||
}, | ||
_change: function() { | ||
}; | ||
_proto._change = function _change() { | ||
var _this6 = this; | ||
var v = this._input.value; | ||
if (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 | ||
); | ||
this._suggestTimeout = setTimeout(function () { | ||
return _this6._geocode(true); | ||
}, this.options.suggestTimeout); | ||
} else { | ||
@@ -1796,19 +1902,32 @@ this._clearResults(); | ||
} | ||
} | ||
}); | ||
}; | ||
return GeocoderControl; | ||
}(L.Control); | ||
/** | ||
* [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link GeocoderControl} | ||
* @param options the options | ||
*/ | ||
function geocoder(options) { | ||
return new Geocoder(options); | ||
return new GeocoderControl(options); | ||
} | ||
L.Util.extend(Geocoder, geocoders); | ||
/* @preserve | ||
* Leaflet Control Geocoder | ||
* https://github.com/perliedman/leaflet-control-geocoder | ||
* | ||
* Copyright (c) 2012 sa3m (https://github.com/sa3m) | ||
* Copyright (c) 2018 Per Liedman | ||
* All rights reserved. | ||
*/ | ||
L.Util.extend(GeocoderControl, geocoders); | ||
L.Util.extend(L.Control, { | ||
Geocoder: Geocoder, | ||
Geocoder: GeocoderControl, | ||
geocoder: geocoder | ||
}); | ||
return Geocoder; | ||
return GeocoderControl; | ||
}(L)); | ||
//# sourceMappingURL=Control.Geocoder.js.map |
@@ -1,10 +0,2 @@ | ||
/* @preserve | ||
* Leaflet Control Geocoder 1.13.0 | ||
* https://github.com/perliedman/leaflet-control-geocoder | ||
* | ||
* Copyright (c) 2012 sa3m (https://github.com/sa3m) | ||
* Copyright (c) 2018 Per Liedman | ||
* All rights reserved. | ||
*/ | ||
this.L=this.L||{},this.L.Control=this.L.Control||{},this.L.Control.Geocoder=function(d){"use strict";d=d&&d.hasOwnProperty("default")?d.default:d;var a=0,i=/[&<>"'`]/g,r=/[&<>"'`]/,t={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};function l(e){return t[e]}function o(e,t,o,s,n){var i="_l_geocoder_"+a++;t[n||"callback"]=i,window[i]=d.Util.bind(o,s);var r=document.createElement("script");r.type="text/javascript",r.src=e+c(t),r.id=i,document.getElementsByTagName("head")[0].appendChild(r)}function u(e,t,o){var s=new XMLHttpRequest;s.onreadystatechange=function(){if(4===s.readyState){var t;if(200!==s.status&&304!==s.status)t="";else if("string"==typeof s.response)try{t=JSON.parse(s.response)}catch(e){t=s.response}else t=s.response;o(t)}},s.open("GET",e+c(t),!0),s.responseType="json",s.setRequestHeader("Accept","application/json"),s.send(null)}function n(e,n){return e.replace(/\{ *([\w_]+) *\}/g,function(e,t){var o,s=n[t];return void 0===s?s="":"function"==typeof s&&(s=s(n)),null==(o=s)?"":o?(o=""+o,r.test(o)?o.replace(i,l):o):o+""})}function c(e,t,o){var s=[];for(var n in e){var i=encodeURIComponent(o?n.toUpperCase():n),r=e[n];if(d.Util.isArray(r))for(var a=0;a<r.length;a++)s.push(i+"="+encodeURIComponent(r[a]));else s.push(i+"="+encodeURIComponent(r))}return(t&&-1!==t.indexOf("?")?"&":"?")+s.join("&")}var s=d.Class.extend({options:{service_url:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"},initialize:function(e,t){d.setOptions(this,t),this._accessToken=e},geocode:function(e,r,a){var t={SingleLine:e,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"};this._key&&this._key.length&&(t.token=this._key),u(this.options.service_url+"/findAddressCandidates",d.extend(t,this.options.geocodingQueryParams),function(e){var t,o,s,n=[];if(e.candidates&&e.candidates.length)for(var i=0;i<=e.candidates.length-1;i++)t=e.candidates[i],o=d.latLng(t.location.y,t.location.x),s=d.latLngBounds(d.latLng(t.extent.ymax,t.extent.xmax),d.latLng(t.extent.ymin,t.extent.xmin)),n[i]={name:t.address,bbox:s,center:o};r.call(a,n)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,s,n){var o={location:encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat),distance:100,f:"json"};u(this.options.service_url+"/reverseGeocode",o,function(e){var t,o=[];e&&!e.error&&(t=d.latLng(e.location.y,e.location.x),o.push({name:e.address.Match_addr,center:t,bounds:d.latLngBounds(t,t)})),s.call(n,o)})}});var h=d.Class.extend({initialize:function(e){this.key=e},geocode:function(e,i,r){o("https://dev.virtualearth.net/REST/v1/Locations",{query:e,key:this.key},function(e){var t=[];if(0<e.resourceSets.length)for(var o=e.resourceSets[0].resources.length-1;0<=o;o--){var s=e.resourceSets[0].resources[o],n=s.bbox;t[o]={name:s.name,bbox:d.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:d.latLng(s.point.coordinates)}}i.call(r,t)},this,"jsonp")},reverse:function(e,t,i,r){o("//dev.virtualearth.net/REST/v1/Locations/"+e.lat+","+e.lng,{key:this.key},function(e){for(var t=[],o=e.resourceSets[0].resources.length-1;0<=o;o--){var s=e.resourceSets[0].resources[o],n=s.bbox;t[o]={name:s.name,bbox:d.latLngBounds([n[0],n[1]],[n[2],n[3]]),center:d.latLng(s.point.coordinates)}}i.call(r,t)},this,"jsonp")}});var p=d.Class.extend({options:{serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){this._key=e,d.setOptions(this,t),this.options.serviceUrl=this.options.service_url||this.options.serviceUrl},geocode:function(e,r,a){var t={address:e};this._key&&this._key.length&&(t.key=this._key),t=d.Util.extend(t,this.options.geocodingQueryParams),u(this.options.serviceUrl,t,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<=e.results.length-1;i++)t=e.results[i],o=d.latLng(t.geometry.location),s=d.latLngBounds(d.latLng(t.geometry.viewport.northeast),d.latLng(t.geometry.viewport.southwest)),n[i]={name:t.formatted_address,bbox:s,center:o,properties:t.address_components};r.call(a,n)})},reverse:function(e,t,r,a){var o={latlng:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng)};o=d.Util.extend(o,this.options.reverseQueryParams),this._key&&this._key.length&&(o.key=this._key),u(this.options.serviceUrl,o,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<=e.results.length-1;i++)t=e.results[i],o=d.latLng(t.geometry.location),s=d.latLngBounds(d.latLng(t.geometry.viewport.northeast),d.latLng(t.geometry.viewport.southwest)),n[i]={name:t.formatted_address,bbox:s,center:o,properties:t.address_components};r.call(a,n)})}});var g=d.Class.extend({options:{geocodeUrl:"https://geocoder.api.here.com/6.2/geocode.json",reverseGeocodeUrl:"https://reverse.geocoder.api.here.com/6.2/reversegeocode.json",app_id:"<insert your app_id here>",app_code:"<insert your app_code here>",geocodingQueryParams:{},reverseQueryParams:{},reverseGeocodeProxRadius:null},initialize:function(e){d.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=d.Util.extend(s,this.options.geocodingQueryParams),this.getJSON(this.options.geocodeUrl,s,t,o)},reverse:function(e,t,o,s){var n=this.options.reverseGeocodeProxRadius?this.options.reverseGeocodeProxRadius:null,i=n?","+encodeURIComponent(n):"",r={prox:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng)+i,mode:"retrieveAddresses",app_id:this.options.app_id,app_code:this.options.app_code,gen:9,jsonattributes:1};r=d.Util.extend(r,this.options.reverseQueryParams),this.getJSON(this.options.reverseGeocodeUrl,r,o,s)},getJSON:function(e,t,r,a){u(e,t,function(e){var t,o,s,n=[];if(e.response.view&&e.response.view.length)for(var i=0;i<=e.response.view[0].result.length-1;i++)t=e.response.view[0].result[i].location,o=d.latLng(t.displayPosition.latitude,t.displayPosition.longitude),s=d.latLngBounds(d.latLng(t.mapView.topLeft.latitude,t.mapView.topLeft.longitude),d.latLng(t.mapView.bottomRight.latitude,t.mapView.bottomRight.longitude)),n[i]={name:t.address.label,properties:t.address,bbox:s,center:o};r.call(a,n)})}});var m=d.Class.extend({options:{next:void 0,sizeInMeters:1e4},initialize:function(e){d.Util.setOptions(this,e)},geocode:function(e,t,o){var s,n;if((s=e.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/))?n=d.latLng((/N/i.test(s[1])?1:-1)*parseFloat(s[2]),(/E/i.test(s[3])?1:-1)*parseFloat(s[4])):(s=e.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/))?n=d.latLng((/N/i.test(s[2])?1:-1)*parseFloat(s[1]),(/E/i.test(s[4])?1:-1)*parseFloat(s[3])):(s=e.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/))?n=d.latLng((/N/i.test(s[1])?1:-1)*(parseFloat(s[2])+parseFloat(s[3]/60)),(/E/i.test(s[4])?1:-1)*(parseFloat(s[5])+parseFloat(s[6]/60))):(s=e.match(/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/))?n=d.latLng((/N/i.test(s[3])?1:-1)*(parseFloat(s[1])+parseFloat(s[2]/60)),(/E/i.test(s[6])?1:-1)*(parseFloat(s[4])+parseFloat(s[5]/60))):(s=e.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/))?n=d.latLng((/N/i.test(s[1])?1:-1)*(parseFloat(s[2])+parseFloat(s[3]/60+parseFloat(s[4]/3600))),(/E/i.test(s[5])?1:-1)*(parseFloat(s[6])+parseFloat(s[7]/60)+parseFloat(s[8]/3600))):(s=e.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/))?n=d.latLng((/N/i.test(s[4])?1:-1)*(parseFloat(s[1])+parseFloat(s[2]/60+parseFloat(s[3]/3600))),(/E/i.test(s[8])?1:-1)*(parseFloat(s[5])+parseFloat(s[6]/60)+parseFloat(s[7]/3600))):(s=e.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/))&&(n=d.latLng(parseFloat(s[1]),parseFloat(s[2]))),n){var i=[{name:e,center:n,bbox:n.toBounds(this.options.sizeInMeters)}];t.call(o,i)}else this.options.next&&this.options.next.geocode(e,t,o)}});var v=d.Class.extend({options:{serviceUrl:"https://api.mapbox.com/geocoding/v5/mapbox.places/",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){d.setOptions(this,t),this.options.geocodingQueryParams.access_token=e,this.options.reverseQueryParams.access_token=e},geocode:function(e,l,c){var t=this.options.geocodingQueryParams;void 0!==t.proximity&&void 0!==t.proximity.lat&&void 0!==t.proximity.lng&&(t.proximity=t.proximity.lng+","+t.proximity.lat),u(this.options.serviceUrl+encodeURIComponent(e)+".json",t,function(e){var t,o,s,n=[];if(e.features&&e.features.length)for(var i=0;i<=e.features.length-1;i++){t=e.features[i],o=d.latLng(t.center.reverse()),s=t.bbox?d.latLngBounds(d.latLng(t.bbox.slice(0,2).reverse()),d.latLng(t.bbox.slice(2,4).reverse())):d.latLngBounds(o,o);for(var r={text:t.text,address:t.address},a=0;a<(t.context||[]).length;a++){r[t.context[a].id.split(".")[0]]=t.context[a].text,t.context[a].short_code&&(r.countryShortCode=t.context[a].short_code)}n[i]={name:t.place_name,bbox:s,center:o,properties:r}}l.call(c,n)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,r,a){u(this.options.serviceUrl+encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat)+".json",this.options.reverseQueryParams,function(e){var t,o,s,n=[];if(e.features&&e.features.length)for(var i=0;i<=e.features.length-1;i++)t=e.features[i],o=d.latLng(t.center.reverse()),s=t.bbox?d.latLngBounds(d.latLng(t.bbox.slice(0,2).reverse()),d.latLng(t.bbox.slice(2,4).reverse())):d.latLngBounds(o,o),n[i]={name:t.place_name,bbox:s,center:o};r.call(a,n)})}});var f=d.Class.extend({options:{serviceUrl:"https://www.mapquestapi.com/geocoding/v1"},initialize:function(e,t){this._key=decodeURIComponent(e),d.Util.setOptions(this,t)},_formatName:function(){var e,t=[];for(e=0;e<arguments.length;e++)arguments[e]&&t.push(arguments[e]);return t.join(", ")},geocode:function(e,i,r){u(this.options.serviceUrl+"/address",{key:this._key,location:e,limit:5,outFormat:"json"},d.bind(function(e){var t,o,s=[];if(e.results&&e.results[0].locations)for(var n=e.results[0].locations.length-1;0<=n;n--)t=e.results[0].locations[n],o=d.latLng(t.latLng),s[n]={name:this._formatName(t.street,t.adminArea4,t.adminArea3,t.adminArea1),bbox:d.latLngBounds(o,o),center:o};i.call(r,s)},this))},reverse:function(e,t,i,r){u(this.options.serviceUrl+"/reverse",{key:this._key,location:e.lat+","+e.lng,outputFormat:"json"},d.bind(function(e){var t,o,s=[];if(e.results&&e.results[0].locations)for(var n=e.results[0].locations.length-1;0<=n;n--)t=e.results[0].locations[n],o=d.latLng(t.latLng),s[n]={name:this._formatName(t.street,t.adminArea4,t.adminArea3,t.adminArea1),bbox:d.latLngBounds(o,o),center:o};i.call(r,s)},this))}});var _=d.Class.extend({options:{userId:"<insert your userId here>",apiKey:"<insert your apiKey here>",serviceUrl:"https://neutrinoapi.com/"},initialize:function(e){d.Util.setOptions(this,e)},geocode:function(e,n,i){u(this.options.serviceUrl+"geocode-address",{apiKey:this.options.apiKey,userId:this.options.userId,address:e.split(/\s+/).join(".")},function(e){var t,o,s=[];e.locations&&(e.geometry=e.locations[0],t=d.latLng(e.geometry.latitude,e.geometry.longitude),o=d.latLngBounds(t,t),s[0]={name:e.geometry.address,bbox:o,center:t}),n.call(i,s)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(n,e,i,r){u(this.options.serviceUrl+"geocode-reverse",{apiKey:this.options.apiKey,userId:this.options.userId,latitude:n.lat,longitude:n.lng},function(e){var t,o,s=[];200==e.status.status&&e.found&&(t=d.latLng(n.lat,n.lng),o=d.latLngBounds(t,t),s[0]={name:e.address,bbox:o,center:t}),i.call(r,s)})}});var b=d.Class.extend({options:{serviceUrl:"https://nominatim.openstreetmap.org/",geocodingQueryParams:{},reverseQueryParams:{},htmlTemplate:function(e){var t,o=e.address,s=[];return(o.road||o.building)&&s.push("{building} {road} {house_number}"),(o.city||o.town||o.village||o.hamlet)&&(t=0<s.length?"leaflet-control-geocoder-address-detail":"",s.push('<span class="'+t+'">{postcode} {city} {town} {village} {hamlet}</span>')),(o.state||o.country)&&(t=0<s.length?"leaflet-control-geocoder-address-context":"",s.push('<span class="'+t+'">{state} {country}</span>')),n(s.join("<br/>"),o)}},initialize:function(e){d.Util.setOptions(this,e)},geocode:function(e,i,r){u(this.options.serviceUrl+"search",d.extend({q:e,limit:5,format:"json",addressdetails:1},this.options.geocodingQueryParams),d.bind(function(e){for(var t=[],o=e.length-1;0<=o;o--){for(var s=e[o].boundingbox,n=0;n<4;n++)s[n]=parseFloat(s[n]);t[o]={icon:e[o].icon,name:e[o].display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e[o]):void 0,bbox:d.latLngBounds([s[0],s[2]],[s[1],s[3]]),center:d.latLng(e[o].lat,e[o].lon),properties:e[o]}}i.call(r,t)},this))},reverse:function(e,t,s,n){u(this.options.serviceUrl+"reverse",d.extend({lat:e.lat,lon:e.lng,zoom:Math.round(Math.log(t/256)/Math.log(2)),addressdetails:1,format:"json"},this.options.reverseQueryParams),d.bind(function(e){var t,o=[];e&&e.lat&&e.lon&&(t=d.latLng(e.lat,e.lon),o.push({name:e.display_name,html:this.options.htmlTemplate?this.options.htmlTemplate(e):void 0,center:t,bounds:d.latLngBounds(t,t),properties:e})),s.call(n,o)},this))}});var y=d.Class.extend({options:{OpenLocationCode:void 0,codeLength:void 0},initialize:function(e){d.setOptions(this,e)},geocode:function(e,t,o){try{var s=this.options.OpenLocationCode.decode(e),n={name:e,center:d.latLng(s.latitudeCenter,s.longitudeCenter),bbox:d.latLngBounds(d.latLng(s.latitudeLo,s.longitudeLo),d.latLng(s.latitudeHi,s.longitudeHi))};t.call(o,[n])}catch(e){console.warn(e),t.call(o,[])}},reverse:function(e,t,o,s){try{var n={name:this.options.OpenLocationCode.encode(e.lat,e.lng,this.options.codeLength),center:d.latLng(e.lat,e.lng),bbox:d.latLngBounds(d.latLng(e.lat,e.lng),d.latLng(e.lat,e.lng))};o.call(s,[n])}catch(e){console.warn(e),o.call(s,[])}}});var L=d.Class.extend({options:{serviceUrl:"https://api.opencagedata.com/geocode/v1/json",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){d.setOptions(this,t),this._accessToken=e},geocode:function(e,r,a){var t={key:this._accessToken,q:e};t=d.extend(t,this.options.geocodingQueryParams),u(this.options.serviceUrl,t,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<e.results.length;i++)s=e.results[i],t=d.latLng(s.geometry),o=s.annotations&&s.annotations.bounds?d.latLngBounds(d.latLng(s.annotations.bounds.northeast),d.latLng(s.annotations.bounds.southwest)):d.latLngBounds(t,t),n.push({name:s.formatted,bbox:o,center:t});r.call(a,n)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,r,a){var o={key:this._accessToken,q:[e.lat,e.lng].join(",")};o=d.extend(o,this.options.reverseQueryParams),u(this.options.serviceUrl,o,function(e){var t,o,s,n=[];if(e.results&&e.results.length)for(var i=0;i<e.results.length;i++)s=e.results[i],t=d.latLng(s.geometry),o=s.annotations&&s.annotations.bounds?d.latLngBounds(d.latLng(s.annotations.bounds.northeast),d.latLng(s.annotations.bounds.southwest)):d.latLngBounds(t,t),n.push({name:s.formatted,bbox:o,center:t});r.call(a,n)})}});var x=d.Class.extend({options:{serviceUrl:"https://api.geocode.earth/v1",geocodingQueryParams:{},reverseQueryParams:{}},initialize:function(e,t){d.Util.setOptions(this,t),this._apiKey=e,this._lastSuggest=0},geocode:function(e,t,o){var s=this;u(this.options.serviceUrl+"/search",d.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),function(e){t.call(o,s._parseResults(e,"bbox"))})},suggest:function(e,t,o){var s=this;u(this.options.serviceUrl+"/autocomplete",d.extend({api_key:this._apiKey,text:e},this.options.geocodingQueryParams),d.bind(function(e){e.geocoding.timestamp>this._lastSuggest&&(this._lastSuggest=e.geocoding.timestamp,t.call(o,s._parseResults(e,"bbox")))},this))},reverse:function(e,t,o,s){var n=this;u(this.options.serviceUrl+"/reverse",d.extend({api_key:this._apiKey,"point.lat":e.lat,"point.lon":e.lng},this.options.reverseQueryParams),function(e){o.call(s,n._parseResults(e,"bounds"))})},_parseResults:function(e,i){var r=[];return d.geoJson(e,{pointToLayer:function(e,t){return d.circleMarker(t)},onEachFeature:function(e,t){var o,s,n={};t.getBounds?s=(o=t.getBounds()).getCenter():o=t.feature.bbox?(s=t.getLatLng(),d.latLngBounds(d.GeoJSON.coordsToLatLng(t.feature.bbox.slice(0,2)),d.GeoJSON.coordsToLatLng(t.feature.bbox.slice(2,4)))):(s=t.getLatLng(),d.latLngBounds(s,s)),n.name=t.feature.properties.label,n.center=s,n[i]=o,n.properties=t.feature.properties,r.push(n)}}),r}});function e(e,t){return new x(e,t)}var U=x,C=e,k=x,w=e,D=k.extend({options:{serviceUrl:"https://api.openrouteservice.org/geocode"}});var P=d.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){d.setOptions(this,e)},geocode:function(e,t,o){var s=d.extend({q:e},this.options.geocodingQueryParams);u(this.options.serviceUrl,s,d.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,s){var n=d.extend({lat:e.lat,lon:e.lng},this.options.reverseQueryParams);u(this.options.reverseUrl,n,d.bind(function(e){o.call(s,this._decodeFeatures(e))},this))},_decodeFeatures:function(e){var t,o,s,n,i,r,a=[];if(e&&e.features)for(t=0;t<e.features.length;t++)s=(o=e.features[t]).geometry.coordinates,n=d.latLng(s[1],s[0]),r=(i=o.properties.extent)?d.latLngBounds([i[1],i[0]],[i[3],i[2]]):d.latLngBounds(n,n),a.push({name:this._decodeFeatureName(o),html:this.options.htmlTemplate?this.options.htmlTemplate(o):void 0,center:n,bbox:r,properties:o.properties});return a},_decodeFeatureName:function(t){return(this.options.nameProperties||[]).map(function(e){return t.properties[e]}).filter(function(e){return!!e}).join(", ")}});var E=d.Class.extend({options:{serviceUrl:"https://api.what3words.com/v2/"},initialize:function(e){this._accessToken=e},geocode:function(e,n,i){u(this.options.serviceUrl+"forward",{key:this._accessToken,addr:e.split(/\s+/).join(".")},function(e){var t,o,s=[];e.geometry&&(t=d.latLng(e.geometry.lat,e.geometry.lng),o=d.latLngBounds(t,t),s[0]={name:e.words,bbox:o,center:t}),n.call(i,s)})},suggest:function(e,t,o){return this.geocode(e,t,o)},reverse:function(e,t,n,i){u(this.options.serviceUrl+"reverse",{key:this._accessToken,coords:[e.lat,e.lng].join(",")},function(e){var t,o,s=[];200==e.status.status&&(t=d.latLng(e.geometry.lat,e.geometry.lng),o=d.latLngBounds(t,t),s[0]={name:e.words,bbox:o,center:t}),n.call(i,s)})}});var R=Object.freeze({ArcGis:s,arcgis:function(e,t){return new s(e,t)},Bing:h,bing:function(e){return new h(e)},Google:p,google:function(e,t){return new p(e,t)},HERE:g,here:function(e){return new g(e)},LatLng:m,latLng:function(e){return new m(e)},Mapbox:v,mapbox:function(e,t){return new v(e,t)},MapQuest:f,mapQuest:function(e,t){return new f(e,t)},Neutrino:_,neutrino:function(e){return new _(e)},Nominatim:b,nominatim:function(e){return new b(e)},OpenLocationCode:y,openLocationCode:function(e){return new y(e)},OpenCage:L,opencage:function(e,t){return new L(e,t)},Pelias:x,pelias:e,GeocodeEarth:U,geocodeEarth:C,Mapzen:k,mapzen:w,Openrouteservice:D,openrouteservice:function(e,t){return new D(e,t)},Photon:P,photon:function(e){return new P(e)},What3Words:E,what3words:function(e){return new E(e)}}),T=d.Control.extend({options:{showUniqueResult:!0,showResultIcons:!1,collapsed:!0,expand:"touch",position:"topright",placeholder:"Search...",errorMessage:"Nothing found.",iconLabel:"Initiate a new search",queryMinLength:1,suggestMinLength:3,suggestTimeout:250,defaultMarkGeocode:!0},includes:d.Evented.prototype||d.Mixin.Events,initialize:function(e){d.Util.setOptions(this,e),this.options.geocoder||(this.options.geocoder=new b),this._requestCount=0},addThrobberClass:function(){d.DomUtil.addClass(this._container,"leaflet-control-geocoder-throbber")},removeThrobberClass:function(){d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-throbber")},onAdd:function(e){var t,o="leaflet-control-geocoder",s=d.DomUtil.create("div",o+" leaflet-bar"),n=d.DomUtil.create("button",o+"-icon",s),i=this._form=d.DomUtil.create("div",o+"-form",s);return this._map=e,this._container=s,n.innerHTML=" ",n.type="button",n.setAttribute("aria-label",this.options.iconLabel),(t=this._input=d.DomUtil.create("input","",i)).type="text",t.value=this.options.query||"",t.placeholder=this.options.placeholder,d.DomEvent.disableClickPropagation(t),this._errorElement=d.DomUtil.create("div",o+"-form-no-error",s),this._errorElement.innerHTML=this.options.errorMessage,this._alts=d.DomUtil.create("ul",o+"-alternatives leaflet-control-geocoder-alternatives-minimized",s),d.DomEvent.disableClickPropagation(this._alts),d.DomEvent.addListener(t,"keydown",this._keydown,this),this.options.geocoder.suggest&&d.DomEvent.addListener(t,"input",this._change,this),d.DomEvent.addListener(t,"blur",function(){this.options.collapsed&&!this._preventBlurCollapse&&this._collapse(),this._preventBlurCollapse=!1},this),this.options.collapsed?"click"===this.options.expand?d.DomEvent.addListener(s,"click",function(e){0===e.button&&2!==e.detail&&this._toggle()},this):"touch"===this.options.expand?d.DomEvent.addListener(s,d.Browser.touch?"touchstart mousedown":"mousedown",function(e){this._toggle(),e.preventDefault(),e.stopPropagation()},this):(d.DomEvent.addListener(s,"mouseover",this._expand,this),d.DomEvent.addListener(s,"mouseout",this._collapse,this),this._map.on("movestart",this._collapse,this)):(this._expand(),d.Browser.touch?d.DomEvent.addListener(s,"touchstart",function(){this._geocode()},this):d.DomEvent.addListener(s,"click",function(){this._geocode()},this)),this.options.defaultMarkGeocode&&this.on("markgeocode",this.markGeocode,this),this.on("startgeocode",this.addThrobberClass,this),this.on("finishgeocode",this.removeThrobberClass,this),this.on("startsuggest",this.addThrobberClass,this),this.on("finishsuggest",this.removeThrobberClass,this),d.DomEvent.disableClickPropagation(s),s},setQuery:function(e){return this._input.value=e,this},_geocodeResult:function(e,t){if(!t&&this.options.showUniqueResult&&1===e.length)this._geocodeResultSelected(e[0]);else if(0<e.length){this._alts.innerHTML="",this._results=e,d.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),d.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-open");for(var o=0;o<e.length;o++)this._alts.appendChild(this._createAlt(e[o],o))}else d.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-error"),d.DomUtil.addClass(this._errorElement,"leaflet-control-geocoder-error")},markGeocode:function(e){return e=e.geocode||e,this._map.fitBounds(e.bbox),this._geocodeMarker&&this._map.removeLayer(this._geocodeMarker),this._geocodeMarker=new d.Marker(e.center).bindPopup(e.html||e.name).addTo(this._map).openPopup(),this},_geocode:function(t){var e=this._input.value;if(t||!(e.length<this.options.queryMinLength)){var o=++this._requestCount,s=t?"suggest":"geocode",n={input:e};this._lastGeocode=e,t||this._clearResults(),this.fire("start"+s,n),this.options.geocoder[s](e,function(e){o===this._requestCount&&(n.results=e,this.fire("finish"+s,n),this._geocodeResult(e,t))},this)}},_geocodeResultSelected:function(e){this.fire("markgeocode",{geocode:e})},_toggle:function(){d.DomUtil.hasClass(this._container,"leaflet-control-geocoder-expanded")?this._collapse():this._expand()},_expand:function(){d.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select(),this.fire("expand")},_collapse:function(){d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-expanded"),d.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),d.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error"),this._input.blur(),this.fire("collapse")},_clearResults:function(){d.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,d.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),d.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error")},_createAlt:function(t,e){var o=d.DomUtil.create("li",""),s=d.DomUtil.create("a","",o),n=this.options.showResultIcons&&t.icon?d.DomUtil.create("img","",s):null,i=t.html?void 0:document.createTextNode(t.name);return n&&(n.src=t.icon),o.setAttribute("data-result-index",e),t.html?s.innerHTML=s.innerHTML+t.html:s.appendChild(i),d.DomEvent.addListener(o,"mousedown touchstart",function(e){this._preventBlurCollapse=!0,d.DomEvent.stop(e),this._geocodeResultSelected(t),d.DomEvent.on(o,"click touchend",function(){this.options.collapsed?this._collapse():this._clearResults()},this)},this),o},_keydown:function(e){function t(e){o._selection&&(d.DomUtil.removeClass(o._selection,"leaflet-control-geocoder-selected"),o._selection=o._selection[0<e?"nextSibling":"previousSibling"]),o._selection||(o._selection=o._alts[0<e?"firstChild":"lastChild"]),o._selection&&d.DomUtil.addClass(o._selection,"leaflet-control-geocoder-selected")}var o=this;switch(e.keyCode){case 27:this.options.collapsed?this._collapse():this._clearResults();break;case 38:t(-1);break;case 40:t(1);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();break;default:return}d.DomEvent.preventDefault(e)},_change:function(){var e=this._input.value;e!==this._lastGeocode&&(clearTimeout(this._suggestTimeout),e.length>=this.options.suggestMinLength?this._suggestTimeout=setTimeout(d.bind(function(){this._geocode(!0)},this),this.options.suggestTimeout):this._clearResults())}});return d.Util.extend(T,R),d.Util.extend(d.Control,{Geocoder:T,geocoder:function(e){return new T(e)}}),T}(L); | ||
var leafletControlGeocoder=function(t){function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(e,o){return t.Util.extend(o,e.geocodingQueryParams)}function n(e,o){return t.Util.extend(o,e.reverseQueryParams)}var s=0,i=/[&<>"'`]/g,r=/[&<>"'`]/,a={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};function l(t){return a[t]}function c(e,o,n,i,r){var a="_l_geocoder_"+s++;o[r||"callback"]=a,window[a]=t.Util.bind(n,i);var l=document.createElement("script");l.type="text/javascript",l.src=e+u(o),l.id=a,document.getElementsByTagName("head")[0].appendChild(l)}function p(t,e,o){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState){var t;if(200!==n.status&&304!==n.status)t="";else if("string"==typeof n.response)try{t=JSON.parse(n.response)}catch(e){t=n.response}else t=n.response;o(t)}},n.open("GET",t+u(e),!0),n.responseType="json",n.setRequestHeader("Accept","application/json"),n.send(null)}function u(t,e,o){var n=[];for(var s in t){var i=encodeURIComponent(o?s.toUpperCase():s),r=t[s];if(Array.isArray(r))for(var a=0;a<r.length;a++)n.push(i+"="+encodeURIComponent(r[a]));else n.push(i+"="+encodeURIComponent(String(r)))}return(e&&-1!==e.indexOf("?")?"&":"?")+n.join("&")}var d=function(){function e(e){this.options={serviceUrl:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",apiKey:""},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{token:this.options.apiKey,SingleLine:e,outFields:"Addr_Type",forStorage:!1,maxLocations:10,f:"json"});p(this.options.serviceUrl+"/findAddressCandidates",i,function(e){var o=[];if(e.candidates&&e.candidates.length)for(var i=0;i<=e.candidates.length-1;i++){var r=e.candidates[i],a=t.latLng(r.location.y,r.location.x),l=t.latLngBounds(t.latLng(r.extent.ymax,r.extent.xmax),t.latLng(r.extent.ymin,r.extent.xmin));o[i]={name:r.address,bbox:l,center:a}}n.call(s,o)})},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){var r=n(this.options,{location:encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat),distance:100,f:"json"});p(this.options.serviceUrl+"/reverseGeocode",r,function(e){var o=[];if(e&&!e.error){var n=t.latLng(e.location.y,e.location.x),r=t.latLngBounds(n,n);o.push({name:e.address.Match_addr,center:n,bbox:r})}s.call(i,o)})},e}(),h=function(){function e(e){this.options={serviceUrl:"https://dev.virtualearth.net/REST/v1/Locations"},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{query:e,key:this.options.apiKey});c(this.options.apiKey,i,function(e){var o=[];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;o[i]={name:r.name,bbox:t.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:t.latLng(r.point.coordinates)}}n.call(s,o)},this,"jsonp")},s.reverse=function(e,o,s,i){var r=n(this.options,{key:this.options.apiKey});c(this.options.serviceUrl+e.lat+","+e.lng,r,function(e){for(var o=[],n=e.resourceSets[0].resources.length-1;n>=0;n--){var r=e.resourceSets[0].resources[n],a=r.bbox;o[n]={name:r.name,bbox:t.latLngBounds([a[0],a[1]],[a[2],a[3]]),center:t.latLng(r.point.coordinates)}}s.call(i,o)},this,"jsonp")},e}(),g=function(){function e(e){this.options={serviceUrl:"https://maps.googleapis.com/maps/api/geocode/json"},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{key:this.options.apiKey,address:e});p(this.options.serviceUrl,i,function(e){var o=[];if(e.results&&e.results.length)for(var i=0;i<=e.results.length-1;i++){var r=e.results[i],a=t.latLng(r.geometry.location),l=t.latLngBounds(t.latLng(r.geometry.viewport.northeast),t.latLng(r.geometry.viewport.southwest));o[i]={name:r.formatted_address,bbox:l,center:a,properties:r.address_components}}n.call(s,o)})},s.reverse=function(e,o,s,i){var r=n(this.options,{key:this.options.apiKey,latlng:encodeURIComponent(e.lat)+","+encodeURIComponent(e.lng)});p(this.options.serviceUrl,r,function(e){var o=[];if(e.results&&e.results.length)for(var n=0;n<=e.results.length-1;n++){var r=e.results[n],a=t.latLng(r.geometry.location),l=t.latLngBounds(t.latLng(r.geometry.viewport.northeast),t.latLng(r.geometry.viewport.southwest));o[n]={name:r.formatted_address,bbox:l,center:a,properties:r.address_components}}s.call(i,o)})},e}(),f=function(){function e(e){if(this.options={serviceUrl:"https://geocoder.api.here.com/6.2/",app_id:"",app_code:"",reverseGeocodeProxRadius:null},t.Util.setOptions(this,e),e.apiKey)throw Error("apiKey is not supported, use app_id/app_code instead!")}var s=e.prototype;return s.geocode=function(t,e,n){var s=o(this.options,{searchtext:t,gen:9,app_id:this.options.app_id,app_code:this.options.app_code,jsonattributes:1});this.getJSON(this.options.serviceUrl+"geocode.json",s,e,n)},s.reverse=function(t,e,o,s){var i=this.options.reverseGeocodeProxRadius?this.options.reverseGeocodeProxRadius:null,r=i?","+encodeURIComponent(i):"",a=n(this.options,{prox:encodeURIComponent(t.lat)+","+encodeURIComponent(t.lng)+r,mode:"retrieveAddresses",app_id:this.options.app_id,app_code:this.options.app_code,gen:9,jsonattributes:1});this.getJSON(this.options.serviceUrl+"reversegeocode.json",a,o,s)},s.getJSON=function(e,o,n,s){p(e,o,function(e){var o=[];if(e.response.view&&e.response.view.length)for(var i=0;i<=e.response.view[0].result.length-1;i++){var r=e.response.view[0].result[i].location,a=t.latLng(r.displayPosition.latitude,r.displayPosition.longitude),l=t.latLngBounds(t.latLng(r.mapView.topLeft.latitude,r.mapView.topLeft.longitude),t.latLng(r.mapView.bottomRight.latitude,r.mapView.bottomRight.longitude));o[i]={name:r.address.label,properties:r.address,bbox:l,center:a}}n.call(s,o)})},e}();function v(e){var o;return(o=e.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/))?t.latLng((/N/i.test(o[1])?1:-1)*parseFloat(o[2]),(/E/i.test(o[3])?1:-1)*parseFloat(o[4])):(o=e.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/))?t.latLng((/N/i.test(o[2])?1:-1)*parseFloat(o[1]),(/E/i.test(o[4])?1:-1)*parseFloat(o[3])):(o=e.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/))?t.latLng((/N/i.test(o[1])?1:-1)*(parseFloat(o[2])+parseFloat(o[3])/60),(/E/i.test(o[4])?1:-1)*(parseFloat(o[5])+parseFloat(o[6])/60)):(o=e.match(/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/))?t.latLng((/N/i.test(o[3])?1:-1)*(parseFloat(o[1])+parseFloat(o[2])/60),(/E/i.test(o[6])?1:-1)*(parseFloat(o[4])+parseFloat(o[5])/60)):(o=e.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/))?t.latLng((/N/i.test(o[1])?1:-1)*(parseFloat(o[2])+parseFloat(o[3])/60+parseFloat(o[4])/3600),(/E/i.test(o[5])?1:-1)*(parseFloat(o[6])+parseFloat(o[7])/60+parseFloat(o[8])/3600)):(o=e.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/))?t.latLng((/N/i.test(o[4])?1:-1)*(parseFloat(o[1])+parseFloat(o[2])/60+parseFloat(o[3])/3600),(/E/i.test(o[8])?1:-1)*(parseFloat(o[5])+parseFloat(o[6])/60+parseFloat(o[7])/3600)):(o=e.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/))?t.latLng(parseFloat(o[1]),parseFloat(o[2])):void 0}var m=function(){function e(e){this.options={next:void 0,sizeInMeters:1e4},t.Util.setOptions(this,e)}return e.prototype.geocode=function(t,e,o){var n=v(t);if(n){var s=[{name:t,center:n,bbox:n.toBounds(this.options.sizeInMeters)}];e.call(o,s)}else this.options.next&&this.options.next.geocode(t,e,o)},e}(),_=function(){function e(e){this.options={serviceUrl:"https://api.mapbox.com/geocoding/v5/mapbox.places/"},t.Util.setOptions(this,e)}var s=e.prototype;return s._getProperties=function(t){for(var e={text:t.text,address:t.address},o=0;o<(t.context||[]).length;o++)e[t.context[o].id.split(".")[0]]=t.context[o].text,t.context[o].short_code&&(e.countryShortCode=t.context[o].short_code);return e},s.geocode=function(e,n,s){var i=this,r=o(this.options,{access_token:this.options.apiKey});void 0!==r.proximity&&void 0!==r.proximity.lat&&void 0!==r.proximity.lng&&(r.proximity=r.proximity.lng+","+r.proximity.lat),p(this.options.serviceUrl+encodeURIComponent(e)+".json",r,function(e){var o=[];if(e.features&&e.features.length)for(var r=0;r<=e.features.length-1;r++){var a,l=e.features[r],c=t.latLng(l.center.reverse());a=l.bbox?t.latLngBounds(t.latLng(l.bbox.slice(0,2).reverse()),t.latLng(l.bbox.slice(2,4).reverse())):t.latLngBounds(c,c),o[r]={name:l.place_name,bbox:a,center:c,properties:i._getProperties(l)}}n.call(s,o)})},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){var r=this,a=n(this.options,{access_token:this.options.apiKey});p(this.options.serviceUrl+encodeURIComponent(e.lng)+","+encodeURIComponent(e.lat)+".json",a,function(e){var o=[];if(e.features&&e.features.length)for(var n=0;n<=e.features.length-1;n++){var a,l=e.features[n],c=t.latLng(l.center.reverse());a=l.bbox?t.latLngBounds(t.latLng(l.bbox.slice(0,2).reverse()),t.latLng(l.bbox.slice(2,4).reverse())):t.latLngBounds(c,c),o[n]={name:l.place_name,bbox:a,center:c,properties:r._getProperties(l)}}s.call(i,o)})},e}(),b=function(){function e(e){this.options={serviceUrl:"https://www.mapquestapi.com/geocoding/v1"},t.Util.setOptions(this,e),this.options.apiKey=decodeURIComponent(this.options.apiKey)}var s=e.prototype;return s._formatName=function(){return[].slice.call(arguments).filter(function(t){return!!t}).join(", ")},s.geocode=function(e,n,s){var i=o(this.options,{key:this.options.apiKey,location:e,limit:5,outFormat:"json"});p(this.options.serviceUrl+"/address",i,t.Util.bind(function(e){var o=[];if(e.results&&e.results[0].locations)for(var i=e.results[0].locations.length-1;i>=0;i--){var r=e.results[0].locations[i],a=t.latLng(r.latLng);o[i]={name:this._formatName(r.street,r.adminArea4,r.adminArea3,r.adminArea1),bbox:t.latLngBounds(a,a),center:a}}n.call(s,o)},this))},s.reverse=function(e,o,s,i){var r=n(this.options,{key:this.options.apiKey,location:e.lat+","+e.lng,outputFormat:"json"});p(this.options.serviceUrl+"/reverse",r,t.Util.bind(function(e){var o=[];if(e.results&&e.results[0].locations)for(var n=e.results[0].locations.length-1;n>=0;n--){var r=e.results[0].locations[n],a=t.latLng(r.latLng);o[n]={name:this._formatName(r.street,r.adminArea4,r.adminArea3,r.adminArea1),bbox:t.latLngBounds(a,a),center:a}}s.call(i,o)},this))},e}(),y=function(){function e(e){this.options={userId:void 0,apiKey:void 0,serviceUrl:"https://neutrinoapi.com/"},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{apiKey:this.options.apiKey,userId:this.options.userId,address:e.split(/\s+/).join(".")});p(this.options.serviceUrl+"geocode-address",i,function(e){var o=[];if(e.locations){e.geometry=e.locations[0];var i=t.latLng(e.geometry.latitude,e.geometry.longitude),r=t.latLngBounds(i,i);o[0]={name:e.geometry.address,bbox:r,center:i}}n.call(s,o)})},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){var r=n(this.options,{apiKey:this.options.apiKey,userId:this.options.userId,latitude:e.lat,longitude:e.lng});p(this.options.serviceUrl+"geocode-reverse",r,function(o){var n=[];if(200==o.status.status&&o.found){var r=t.latLng(e.lat,e.lng),a=t.latLngBounds(r,r);n[0]={name:o.address,bbox:a,center:r}}s.call(i,n)})},e}(),L=function(){function e(e){this.options={serviceUrl:"https://nominatim.openstreetmap.org/",htmlTemplate:function(t){var e,o,n=t.address,s=[];return(n.road||n.building)&&s.push("{building} {road} {house_number}"),(n.city||n.town||n.village||n.hamlet)&&s.push('<span class="'+(s.length>0?"leaflet-control-geocoder-address-detail":"")+'">{postcode} {city} {town} {village} {hamlet}</span>'),(n.state||n.country)&&s.push('<span class="'+(s.length>0?"leaflet-control-geocoder-address-context":"")+'">{state} {country}</span>'),e=s.join("<br/>"),o=n,e.replace(/\{ *([\w_]+) *\}/g,function(t,e){var n,s=o[e];return void 0===s?s="":"function"==typeof s&&(s=s(o)),null==(n=s)?"":n?r.test(n=""+n)?n.replace(i,l):n:n+""})}},t.Util.setOptions(this,e||{})}var s=e.prototype;return s.geocode=function(e,n,s){var i=this,r=o(this.options,{q:e,limit:5,format:"json",addressdetails:1});p(this.options.serviceUrl+"search",r,function(e){for(var o=[],r=e.length-1;r>=0;r--){for(var a=e[r].boundingbox,l=0;l<4;l++)a[l]=parseFloat(a[l]);o[r]={icon:e[r].icon,name:e[r].display_name,html:i.options.htmlTemplate?i.options.htmlTemplate(e[r]):void 0,bbox:t.latLngBounds([a[0],a[2]],[a[1],a[3]]),center:t.latLng(e[r].lat,e[r].lon),properties:e[r]}}n.call(s,o)})},s.reverse=function(e,o,s,i){var r=this,a=n(this.options,{lat:e.lat,lon:e.lng,zoom:Math.round(Math.log(o/256)/Math.log(2)),addressdetails:1,format:"json"});p(this.options.serviceUrl+"reverse",a,function(e){var o=[];if(e&&e.lat&&e.lon){var n=t.latLng(e.lat,e.lon),a=t.latLngBounds(n,n);o.push({name:e.display_name,html:r.options.htmlTemplate?r.options.htmlTemplate(e):void 0,center:n,bbox:a,properties:e})}s.call(i,o)})},e}(),U=function(){function e(e){t.Util.setOptions(this,e)}var o=e.prototype;return o.geocode=function(e,o,n){try{var s=this.options.OpenLocationCode.decode(e),i={name:e,center:t.latLng(s.latitudeCenter,s.longitudeCenter),bbox:t.latLngBounds(t.latLng(s.latitudeLo,s.longitudeLo),t.latLng(s.latitudeHi,s.longitudeHi))};o.call(n,[i])}catch(t){console.warn(t),o.call(n,[])}},o.reverse=function(e,o,n,s){try{var i={name:this.options.OpenLocationCode.encode(e.lat,e.lng,this.options.codeLength),center:t.latLng(e.lat,e.lng),bbox:t.latLngBounds(t.latLng(e.lat,e.lng),t.latLng(e.lat,e.lng))};n.call(s,[i])}catch(t){console.warn(t),n.call(s,[])}},e}(),x=function(){function e(e){this.options={serviceUrl:"https://api.opencagedata.com/geocode/v1/json"},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{key:this.options.apiKey,q:e});p(this.options.serviceUrl,i,function(e){var o=[];if(e.results&&e.results.length)for(var i=0;i<e.results.length;i++){var r,a=e.results[i],l=t.latLng(a.geometry);r=a.annotations&&a.annotations.bounds?t.latLngBounds(t.latLng(a.annotations.bounds.northeast),t.latLng(a.annotations.bounds.southwest)):t.latLngBounds(l,l),o.push({name:a.formatted,bbox:r,center:l})}n.call(s,o)})},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){var r=n(this.options,{key:this.options.apiKey,q:[e.lat,e.lng].join(",")});p(this.options.serviceUrl,r,function(e){var o=[];if(e.results&&e.results.length)for(var n=0;n<e.results.length;n++){var r,a=e.results[n],l=t.latLng(a.geometry);r=a.annotations&&a.annotations.bounds?t.latLngBounds(t.latLng(a.annotations.bounds.northeast),t.latLng(a.annotations.bounds.southwest)):t.latLngBounds(l,l),o.push({name:a.formatted,bbox:r,center:l})}s.call(i,o)})},e}(),w=function(){function e(e){this.options={serviceUrl:"https://api.geocode.earth/v1"},this._lastSuggest=0,t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(t,e,n){var s=this,i=o(this.options,{api_key:this.options.apiKey,text:t});p(this.options.serviceUrl+"/search",i,function(t){e.call(n,s._parseResults(t,"bbox"))})},s.suggest=function(t,e,n){var s=this,i=o(this.options,{api_key:this.options.apiKey,text:t});p(this.options.serviceUrl+"/autocomplete",i,function(t){t.geocoding.timestamp>s._lastSuggest&&(s._lastSuggest=t.geocoding.timestamp,e.call(n,s._parseResults(t,"bbox")))})},s.reverse=function(t,e,o,s){var i=this,r=n(this.options,{api_key:this.options.apiKey,"point.lat":t.lat,"point.lon":t.lng});p(this.options.serviceUrl+"/reverse",r,function(t){o.call(s,i._parseResults(t,"bounds"))})},s._parseResults=function(e,o){var n=[];return t.geoJSON(e,{pointToLayer:function(e,o){return t.circleMarker(o)},onEachFeature:function(e,s){var i,r,a={};s.getBounds?r=(i=s.getBounds()).getCenter():s.feature.bbox?(r=s.getLatLng(),i=t.latLngBounds(t.GeoJSON.coordsToLatLng(s.feature.bbox.slice(0,2)),t.GeoJSON.coordsToLatLng(s.feature.bbox.slice(2,4)))):(r=s.getLatLng(),i=t.latLngBounds(r,r)),a.name=s.feature.properties.label,a.center=r,a[o]=i,a.properties=s.feature.properties,n.push(a)}}),n},e}();function C(t){return new w(t)}var E=w,k=C,D=w,R=C,B=function(o){function n(e){return o.call(this,t.Util.extend({serviceUrl:"https://api.openrouteservice.org/geocode"},e))||this}return e(n,o),n}(w),F=function(){function e(e){this.options={serviceUrl:"https://photon.komoot.io/api/",reverseUrl:"https://photon.komoot.io/reverse/",nameProperties:["name","street","suburb","hamlet","town","city","state","country"]},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){var i=o(this.options,{q:e});p(this.options.serviceUrl,i,t.Util.bind(function(t){n.call(s,this._decodeFeatures(t))},this))},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){var r=n(this.options,{lat:e.lat,lon:e.lng});p(this.options.reverseUrl,r,t.Util.bind(function(t){s.call(i,this._decodeFeatures(t))},this))},s._decodeFeatures=function(e){var o=[];if(e&&e.features)for(var n=0;n<e.features.length;n++){var s=e.features[n],i=s.geometry.coordinates,r=t.latLng(i[1],i[0]),a=s.properties.extent,l=a?t.latLngBounds([a[1],a[0]],[a[3],a[2]]):t.latLngBounds(r,r);o.push({name:this._decodeFeatureName(s),html:this.options.htmlTemplate?this.options.htmlTemplate(s):void 0,center:r,bbox:l,properties:s.properties})}return o},s._decodeFeatureName=function(t){return(this.options.nameProperties||[]).map(function(e){return t.properties[e]}).filter(function(t){return!!t}).join(", ")},e}(),S=function(){function e(e){this.options={serviceUrl:"https://api.what3words.com/v2/"},t.Util.setOptions(this,e)}var s=e.prototype;return s.geocode=function(e,n,s){p(this.options.serviceUrl+"forward",o(this.options,{key:this.options.apiKey,addr:e.split(/\s+/).join(".")}),function(e){var o=[];if(e.geometry){var i=t.latLng(e.geometry.lat,e.geometry.lng),r=t.latLngBounds(i,i);o[0]={name:e.words,bbox:r,center:i}}n.call(s,o)})},s.suggest=function(t,e,o){return this.geocode(t,e,o)},s.reverse=function(e,o,s,i){p(this.options.serviceUrl+"reverse",n(this.options,{key:this.options.apiKey,coords:[e.lat,e.lng].join(",")}),function(e){var o=[];if(200==e.status.status){var n=t.latLng(e.geometry.lat,e.geometry.lng),r=t.latLngBounds(n,n);o[0]={name:e.words,bbox:r,center:n}}s.call(i,o)})},e}(),T={__proto__:null,geocodingParams:o,reverseParams:n,ArcGis:d,arcgis:function(t){return new d(t)},Bing:h,bing:function(t){return new h(t)},Google:g,google:function(t){return new g(t)},HERE:f,here:function(t){return new f(t)},parseLatLng:v,LatLng:m,latLng:function(t){return new m(t)},Mapbox:_,mapbox:function(t){return new _(t)},MapQuest:b,mapQuest:function(t){return new b(t)},Neutrino:y,neutrino:function(t){return new y(t)},Nominatim:L,nominatim:function(t){return new L(t)},OpenLocationCode:U,openLocationCode:function(t){return new U(t)},OpenCage:x,opencage:function(t){return new x(t)},Pelias:w,pelias:C,GeocodeEarth:E,geocodeEarth:k,Mapzen:D,mapzen:R,Openrouteservice:B,openrouteservice:function(t){return new B(t)},Photon:F,photon:function(t){return new F(t)},What3Words:S,what3words:function(t){return new S(t)}},N=function(o){function n(e){var n;return(n=o.call(this,e)||this).options={showUniqueResult:!0,showResultIcons:!1,collapsed:!0,expand:"touch",position:"topright",placeholder:"Search...",errorMessage:"Nothing found.",iconLabel:"Initiate a new search",query:"",queryMinLength:1,suggestMinLength:3,suggestTimeout:250,defaultMarkGeocode:!0},n._requestCount=0,t.Util.setOptions(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n),e),n.options.geocoder||(n.options.geocoder=new L),n}e(n,o);var s=n.prototype;return s.on=function(e,o,n){return t.Evented.prototype.on(e,o,n),this},s.off=function(e,o,n){return t.Evented.prototype.off(e,o,n),this},s.fire=function(e,o,n){return t.Evented.prototype.fire(e,o,n),this},s.addThrobberClass=function(){t.DomUtil.addClass(this._container,"leaflet-control-geocoder-throbber")},s.removeThrobberClass=function(){t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-throbber")},s.onAdd=function(e){var o=this,n="leaflet-control-geocoder",s=t.DomUtil.create("div",n+" leaflet-bar"),i=t.DomUtil.create("button",n+"-icon",s),r=this._form=t.DomUtil.create("div",n+"-form",s);this._map=e,this._container=s,i.innerHTML=" ",i.type="button",i.setAttribute("aria-label",this.options.iconLabel);var a=this._input=t.DomUtil.create("input","",r);return a.type="text",a.value=this.options.query,a.placeholder=this.options.placeholder,t.DomEvent.disableClickPropagation(a),this._errorElement=t.DomUtil.create("div",n+"-form-no-error",s),this._errorElement.innerHTML=this.options.errorMessage,this._alts=t.DomUtil.create("ul",n+"-alternatives leaflet-control-geocoder-alternatives-minimized",s),t.DomEvent.disableClickPropagation(this._alts),t.DomEvent.addListener(a,"keydown",this._keydown,this),this.options.geocoder.suggest&&t.DomEvent.addListener(a,"input",this._change,this),t.DomEvent.addListener(a,"blur",function(){o.options.collapsed&&!o._preventBlurCollapse&&o._collapse(),o._preventBlurCollapse=!1}),this.options.collapsed?"click"===this.options.expand?t.DomEvent.addListener(s,"click",function(t){0===t.button&&2!==t.detail&&o._toggle()}):"touch"===this.options.expand?t.DomEvent.addListener(s,t.Browser.touch?"touchstart mousedown":"mousedown",function(t){o._toggle(),t.preventDefault(),t.stopPropagation()},this):(t.DomEvent.addListener(s,"mouseover",this._expand,this),t.DomEvent.addListener(s,"mouseout",this._collapse,this),this._map.on("movestart",this._collapse,this)):(this._expand(),t.DomEvent.addListener(s,t.Browser.touch?"touchstart":"click",function(){return o._geocode()})),this.options.defaultMarkGeocode&&this.on("markgeocode",this.markGeocode,this),this.on("startgeocode",this.addThrobberClass,this),this.on("finishgeocode",this.removeThrobberClass,this),this.on("startsuggest",this.addThrobberClass,this),this.on("finishsuggest",this.removeThrobberClass,this),t.DomEvent.disableClickPropagation(s),s},s.setQuery=function(t){return this._input.value=t,this},s._geocodeResult=function(e,o){if(!o&&this.options.showUniqueResult&&1===e.length)this._geocodeResultSelected(e[0]);else if(e.length>0){this._alts.innerHTML="",this._results=e,t.DomUtil.removeClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),t.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-open");for(var n=0;n<e.length;n++)this._alts.appendChild(this._createAlt(e[n],n))}else t.DomUtil.addClass(this._container,"leaflet-control-geocoder-options-error"),t.DomUtil.addClass(this._errorElement,"leaflet-control-geocoder-error")},s.markGeocode=function(e){return this._map.fitBounds((e=e.geocode||e).bbox),this._geocodeMarker&&this._map.removeLayer(this._geocodeMarker),this._geocodeMarker=new t.Marker(e.center).bindPopup(e.html||e.name).addTo(this._map).openPopup(),this},s._geocode=function(t){var e=this,o=this._input.value;if(t||!(o.length<this.options.queryMinLength)){var n=++this._requestCount,s=function(s){n===e._requestCount&&(e.fire(t?"finishsuggest":"finishgeocode",{input:o,results:s}),e._geocodeResult(s,t))};this._lastGeocode=o,t||this._clearResults(),this.fire(t?"startsuggest":"startgeocode",{input:o}),t?this.options.geocoder.suggest(o,s):this.options.geocoder.geocode(o,s)}},s._geocodeResultSelected=function(t){this.fire("markgeocode",{geocode:t})},s._toggle=function(){t.DomUtil.hasClass(this._container,"leaflet-control-geocoder-expanded")?this._collapse():this._expand()},s._expand=function(){t.DomUtil.addClass(this._container,"leaflet-control-geocoder-expanded"),this._input.select(),this.fire("expand")},s._collapse=function(){t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-expanded"),t.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),t.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error"),this._input.blur(),this.fire("collapse")},s._clearResults=function(){t.DomUtil.addClass(this._alts,"leaflet-control-geocoder-alternatives-minimized"),this._selection=null,t.DomUtil.removeClass(this._errorElement,"leaflet-control-geocoder-error"),t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-open"),t.DomUtil.removeClass(this._container,"leaflet-control-geocoder-options-error")},s._createAlt=function(e,o){var n=this,s=t.DomUtil.create("li",""),i=t.DomUtil.create("a","",s),r=this.options.showResultIcons&&e.icon?t.DomUtil.create("img","",i):null,a=e.html?void 0:document.createTextNode(e.name);return r&&(r.src=e.icon),s.setAttribute("data-result-index",String(o)),e.html?i.innerHTML=i.innerHTML+e.html:a&&i.appendChild(a),t.DomEvent.addListener(s,"mousedown touchstart",function(o){n._preventBlurCollapse=!0,t.DomEvent.stop(o),n._geocodeResultSelected(e),t.DomEvent.on(s,"click touchend",function(){n.options.collapsed?n._collapse():n._clearResults()})},this),s},s._keydown=function(e){var o=this,n=function(e){o._selection&&(t.DomUtil.removeClass(o._selection,"leaflet-control-geocoder-selected"),o._selection=o._selection[e>0?"nextSibling":"previousSibling"]),o._selection||(o._selection=o._alts[e>0?"firstChild":"lastChild"]),o._selection&&t.DomUtil.addClass(o._selection,"leaflet-control-geocoder-selected")};switch(e.keyCode){case 27:this.options.collapsed?this._collapse():this._clearResults();break;case 38:n(-1);break;case 40:n(1);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();break;default:return}t.DomEvent.preventDefault(e)},s._change=function(){var t=this,e=this._input.value;e!==this._lastGeocode&&(clearTimeout(this._suggestTimeout),e.length>=this.options.suggestMinLength?this._suggestTimeout=setTimeout(function(){return t._geocode(!0)},this.options.suggestTimeout):this._clearResults())},n}(t.Control);return t.Util.extend(N,T),t.Util.extend(t.Control,{Geocoder:N,geocoder:function(t){return new N(t)}}),N}(L); | ||
//# sourceMappingURL=Control.Geocoder.min.js.map |
{ | ||
"name": "leaflet-control-geocoder", | ||
"version": "1.13.0", | ||
"version": "2.0.0", | ||
"description": "Extendable geocoder with builtin support for OpenStreetMap Nominatim, Bing, Google, Mapbox, MapQuest, What3Words, Photon, Pelias, HERE, Neutrino, Plus codes", | ||
"source": "src/index.ts", | ||
"main": "dist/Control.Geocoder.js", | ||
"module": "src/index.js", | ||
"module": "dist/Control.Geocoder.modern.js", | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "npm run build:js && npm run build:css && npm run build:img && npm run build:demo-rollup && npm run build:demo-webpack", | ||
"build:js": "rollup -c", | ||
"build:css": "cpr Control.Geocoder.css dist/Control.Geocoder.css --overwrite", | ||
"build:img": "cpr images/ dist/images/ --overwrite", | ||
"build": "npm run build:1 && npm run build:2 && npm run build:3", | ||
"build:1": "microbundle --no-pkg-main --entry src/index.ts --format iife --globals leaflet=L --output dist/Control.Geocoder.js --no-compress", | ||
"build:2": "microbundle --no-pkg-main --entry src/index.ts --format iife --globals leaflet=L --output dist/Control.Geocoder.min.js", | ||
"build:3": "microbundle --no-pkg-main --entry src/index.ts --format modern --output dist/Control.Geocoder.modern.js --no-compress", | ||
"build:demo": "npm run build:demo-esbuild && npm run build:demo-rollup && npm run build:demo-webpack", | ||
"build:demo-esbuild": "cd demo-esbuild && npm install && npm run build", | ||
"build:demo-rollup": "cd demo-rollup && npm install && npm run build", | ||
"build:demo-webpack": "cd demo-rollup && npm install && npm run build", | ||
"test": "npm run test:karma -- --single-run && npm run lint", | ||
"test:karma": "karma start spec/karma.conf.js", | ||
"lint": "npm run lint:js && npm run lint:style", | ||
"lint:js": "eslint .", | ||
"lint:style": "prettier --check $(npm run ls-files)", | ||
"fix:style": "prettier --write $(npm run ls-files)", | ||
"ls-files": "git ls-files '*.js' '*.json' '*.css' '*.html' '*.yaml' '*.yml' '*.md'" | ||
"changelog": "conventional-changelog --infile CHANGELOG.md --same-file --output-unreleased", | ||
"doc": "typedoc --mode file --excludePrivate --stripInternal --moduleResolution node --out docs/ src/", | ||
"test": "jest", | ||
"lint": "eslint --ext .js,.ts ." | ||
}, | ||
@@ -31,5 +31,3 @@ "repository": { | ||
"demo/**", | ||
"images/**", | ||
"src/**", | ||
"*.css" | ||
"src/**" | ||
], | ||
@@ -66,21 +64,21 @@ "keywords": [ | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"cpr": "^3.0.1", | ||
"@types/leaflet": "^1.5.12", | ||
"@typescript-eslint/eslint-plugin": "^4.8.1", | ||
"@typescript-eslint/parser": "^4.8.1", | ||
"conventional-changelog-cli": "^2.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"karma": "^4.4.1", | ||
"karma-expect": "^1.1.3", | ||
"karma-mocha": "^1.3.0", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-sinon": "^1.0.5", | ||
"jest": "^26.6.3", | ||
"leaflet": "^1.6.0", | ||
"mocha": "^6.2.2", | ||
"phantomjs-prebuilt": "^2.1.16", | ||
"microbundle": "^0.12.4", | ||
"prettier": "^1.19.1", | ||
"rollup": "^0.65.2", | ||
"rollup-plugin-uglify": "^5.0.2", | ||
"sinon": "^7.5.0", | ||
"uglify-js": "^3.7.5" | ||
"ts-jest": "^26.4.4", | ||
"tslib": "^1.11.1", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^3.8.3" | ||
}, | ||
"peerDependencies": { | ||
"leaflet": "^1.6.0" | ||
}, | ||
"optionalDependencies": { | ||
@@ -87,0 +85,0 @@ "open-location-code": "^1.0.0" |
146
README.md
@@ -27,2 +27,3 @@ ## A few words on diversity in tech | ||
- [Plus codes](https://plus.codes/) (formerly OpenLocationCode) (requires [open-location-code](https://www.npmjs.com/package/open-location-code)) | ||
- [ArcGIS](https://developers.arcgis.com/features/geocoding/) | ||
@@ -89,144 +90,3 @@ The plugin can easily be extended to support other providers. Current extensions: | ||
## L.Control.Geocoder | ||
This is the geocoder control. It works like any other Leaflet control, and is added to the map. | ||
### Constructor | ||
This plugin supports the standard JavaScript constructor (to be invoked using `new`) as well as the [class factory methods](https://leafletjs.com/reference.html#class-class-factories) known from Leaflet: | ||
```js | ||
new L.Control.Geocoder(options); | ||
// or | ||
L.Control.geocoder(options); | ||
``` | ||
### Options | ||
| Option | Type | Default | Description | | ||
| ------------------ | --------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | ||
| `collapsed` | Boolean | `true` | Collapse control unless hovered/clicked | | ||
| `expand` | String | `"touch"` | How to expand a collapsed control: `touch` or `click` or `hover` | | ||
| `position` | String | `"topright"` | Control [position](https://leafletjs.com/reference.html#control-positions) | | ||
| `placeholder` | String | `"Search..."` | Placeholder text for text input | | ||
| `errorMessage` | String | `"Nothing found."` | Message when no result found / geocoding error occurs | | ||
| `iconLabel` | String | `"Initiate a new search"` | Accessibility label for the search icon used by screen readers | | ||
| `geocoder` | IGeocoder | `new L.Control.Geocoder.Nominatim()` | Object to perform the actual geocoding queries | | ||
| `showUniqueResult` | Boolean | `true` | Immediately show the unique result without prompting for alternatives | | ||
| `showResultIcons` | Boolean | `false` | Show icons for geocoding results (if available); supported by Nominatim | | ||
| `suggestMinLength` | Number | `3` | Minimum number characters before suggest functionality is used (if available from geocoder) | | ||
| `suggestTimeout` | Number | `250` | Number of milliseconds after typing stopped before suggest functionality is used (if available from geocoder) | | ||
| `query` | String | `""` | Initial query string for text input | | ||
| `queryMinLength` | Number | `1` | Minimum number of characters in search text before performing a query | | ||
### Methods | ||
| Method | Returns | Description | | ||
| --------------------------------------- | ------- | --------------------------------------- | | ||
| `markGeocode(<GeocodingResult> result)` | `this` | Marks a geocoding result on the map | | ||
| `setQuery(<String> query)` | `this` | Sets the query string on the text input | | ||
## L.Control.Geocoder.Nominatim | ||
Uses [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) to respond to geocoding queries. This is the default | ||
geocoding service used by the control, unless otherwise specified in the options. Implements `IGeocoder`. | ||
Unless using your own Nominatim installation, please refer to the [Nominatim usage policy](https://operations.osmfoundation.org/policies/nominatim/). | ||
### Constructor | ||
```js | ||
new L.Control.Geocoder.Nominatim(options); | ||
// or | ||
L.Control.Geocoder.nominatim(options); | ||
``` | ||
### Options | ||
| Option | Type | Default | Description | | ||
| ---------------------- | -------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `serviceUrl` | String | `"https://nominatim.openstreetmap.org/"` | URL of the service | | ||
| `geocodingQueryParams` | Object | `{}` | Additional URL parameters (strings) that will be added to geocoding requests; can be used to restrict results to a specific country for example, by providing the [`countrycodes`](https://wiki.openstreetmap.org/wiki/Nominatim#Parameters) parameter to Nominatim | | ||
| `reverseQueryParams` | Object | `{}` | Additional URL parameters (strings) that will be added to reverse geocoding requests | | ||
| `htmlTemplate` | function | special | A function that takes an GeocodingResult as argument and returns an HTML formatted string that represents the result. Default function breaks up address in parts from most to least specific, in attempt to increase readability compared to Nominatim's naming | | ||
## L.Control.Geocoder.Bing | ||
Uses [Bing Locations API](http://msdn.microsoft.com/en-us/library/ff701715.aspx) to respond to geocoding queries. Implements `IGeocoder`. | ||
Note that you need an API key to use this service. | ||
### Constructor | ||
```ts | ||
new L.Control.Geocoder.Bing(<String>key); | ||
// or | ||
L.Control.Geocoder.bing(<String>key); | ||
``` | ||
## L.Control.Geocoder.OpenCage | ||
Uses [OpenCage Data API](https://opencagedata.com/) to respond to geocoding queries. Implements `IGeocoder`. | ||
Note that you need an API key to use this service. | ||
### Constructor | ||
```ts | ||
new L.Control.Geocoder.OpenCage(<String>key, options); | ||
// or | ||
L.Control.Geocoder.opencage(<String>key, options); | ||
``` | ||
### Options | ||
| Option | Type | Default | Description | | ||
| ---------------------- | ------ | ------------------------------------------------ | ------------------------------------------------------------------------------------ | | ||
| `serviceUrl` | String | `"https://api.opencagedata.com/geocode/v1/json"` | URL of the service | | ||
| `geocodingQueryParams` | Object | `{}` | Additional URL parameters (strings) that will be added to geocoding requests | | ||
| `reverseQueryParams` | Object | `{}` | Additional URL parameters (strings) that will be added to reverse geocoding requests | | ||
## L.Control.Geocoder.LatLng | ||
Parses basic latitude/longitude strings such as `'50.06773 14.37742'`, `'N50.06773 W14.37742'`, `'S 50° 04.064 E 014° 22.645'`, or `'S 50° 4′ 03.828″, W 14° 22′ 38.712″'`. | ||
### Constructor | ||
```ts | ||
new L.Control.Geocoder.LatLng(options); | ||
// or | ||
L.Control.Geocoder.latLng(options); | ||
``` | ||
### Options | ||
| Option | Type | Default | Description | | ||
| -------------- | --------- | ------- | --------------------------------------------------------- | | ||
| `next` | IGeocoder | | The next geocoder to use for non-supported queries. | | ||
| `sizeInMeters` | Number | 10000 | The size in meters used for passing to `LatLng.toBounds`. | | ||
## IGeocoder | ||
An interface implemented to respond to geocoding queries. | ||
### Methods | ||
| Method | Returns | Description | | ||
| ----------------------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | ||
| `geocode(<String> query, callback, context)` | `GeocodingResult[]` | Performs a geocoding query and returns the results to the callback in the provided context | | ||
| `suggest(<String> query, callback, context)` | `GeocodingResult[]` | Performs a geocoding query suggestion (this happens while typing) and returns the results to the callback in the provided context | | ||
| `reverse(<L.LatLng> location, <Number> scale, callback, context)` | `GeocodingResult[]` | Performs a reverse geocoding query and returns the results to the callback in the provided context | | ||
## GeocodingResult | ||
An object that represents a result from a geocoding query. | ||
### Properties | ||
| Property | Type | Description | | ||
| -------- | -------------- | ---------------------------------------------------- | | ||
| `name` | String | Name of found location | | ||
| `bbox` | L.LatLngBounds | The bounds of the location | | ||
| `center` | L.LatLng | The center coordinate of the location | | ||
| `icon` | String | URL for icon representing result; optional | | ||
| `html` | String | (optional) HTML formatted representation of the name | | ||
- latest → https://www.liedman.net/leaflet-control-geocoder/docs/ | ||
- version 1.13.0 → https://github.com/perliedman/leaflet-control-geocoder/tree/1.13.0#api |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
641065
14
50
5944
2
91
1