forked from Snck3rs/contao-leaflet-libraries
Update control geocoder to v1.5.5.
This commit is contained in:
@@ -132,17 +132,19 @@ module.exports = {
|
||||
|
||||
_geocode: function(suggest) {
|
||||
var requestCount = ++this._requestCount,
|
||||
mode = suggest ? 'suggest' : 'geocode';
|
||||
mode = suggest ? 'suggest' : 'geocode',
|
||||
eventData = {input: this._input.value};
|
||||
|
||||
this._lastGeocode = this._input.value;
|
||||
if (!suggest) {
|
||||
this._clearResults();
|
||||
}
|
||||
|
||||
this.fire('start' + mode);
|
||||
this.fire('start' + mode, eventData);
|
||||
this.options.geocoder[mode](this._input.value, function(results) {
|
||||
if (requestCount === this._requestCount) {
|
||||
this.fire('finish' + mode);
|
||||
eventData.results = results;
|
||||
this.fire('finish' + mode, eventData);
|
||||
this._geocodeResult(results, suggest);
|
||||
}
|
||||
}, this);
|
||||
@@ -608,18 +610,26 @@ var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefi
|
||||
module.exports = {
|
||||
"class": L.Class.extend({
|
||||
options: {
|
||||
serviceUrl: 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/'
|
||||
serviceUrl: 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/',
|
||||
geocodingQueryParams: {},
|
||||
reverseQueryParams: {}
|
||||
},
|
||||
|
||||
initialize: function(accessToken, options) {
|
||||
L.setOptions(this, options);
|
||||
this._accessToken = accessToken;
|
||||
this.options.geocodingQueryParams.access_token = accessToken;
|
||||
this.options.reverseQueryParams.access_token = accessToken;
|
||||
},
|
||||
|
||||
geocode: function(query, cb, context) {
|
||||
Util.getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', {
|
||||
access_token: this._accessToken
|
||||
}, function(data) {
|
||||
var params = this.options.geocodingQueryParams;
|
||||
if (typeof params.proximity !== 'undefined'
|
||||
&& params.proximity.hasOwnProperty('lat')
|
||||
&& params.proximity.hasOwnProperty('lng'))
|
||||
{
|
||||
params.proximity = params.proximity.lng + ',' + params.proximity.lat;
|
||||
}
|
||||
Util.getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', params, function(data) {
|
||||
var results = [],
|
||||
loc,
|
||||
latLng,
|
||||
@@ -628,7 +638,7 @@ module.exports = {
|
||||
for (var i = 0; i <= data.features.length - 1; i++) {
|
||||
loc = data.features[i];
|
||||
latLng = L.latLng(loc.center.reverse());
|
||||
if(loc.hasOwnProperty('bbox'))
|
||||
if (loc.hasOwnProperty('bbox'))
|
||||
{
|
||||
latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse()));
|
||||
}
|
||||
@@ -653,9 +663,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
reverse: function(location, scale, cb, context) {
|
||||
Util.getJSON(this.options.serviceUrl + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', {
|
||||
access_token: this._accessToken
|
||||
}, function(data) {
|
||||
Util.getJSON(this.options.serviceUrl + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', this.options.reverseQueryParams, function(data) {
|
||||
var results = [],
|
||||
loc,
|
||||
latLng,
|
||||
@@ -664,7 +672,7 @@ module.exports = {
|
||||
for (var i = 0; i <= data.features.length - 1; i++) {
|
||||
loc = data.features[i];
|
||||
latLng = L.latLng(loc.center.reverse());
|
||||
if(loc.hasOwnProperty('bbox'))
|
||||
if (loc.hasOwnProperty('bbox'))
|
||||
{
|
||||
latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse()));
|
||||
}
|
||||
@@ -1043,6 +1051,9 @@ module.exports = {
|
||||
|
||||
results.push({
|
||||
name: this._deocodeFeatureName(f),
|
||||
html: this.options.htmlTemplate ?
|
||||
this.options.htmlTemplate(f)
|
||||
: undefined,
|
||||
center: latLng,
|
||||
bbox: bbox,
|
||||
properties: f.properties
|
||||
|
||||
Reference in New Issue
Block a user