Skip to content

Commit

Permalink
encodeURIComponent is not needed for lat/lon
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Dec 10, 2020
1 parent 24efc99 commit 11a9e77
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/geocoders/arcgis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ArcGis implements IGeocoder {

reverse(location: L.LatLngLiteral, scale: number, cb: GeocodingCallback, context?: any): void {
const params = reverseParams(this.options, {
location: encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat),
location: location.lng + ',' + location.lat,
distance: 100,
f: 'json'
});
Expand Down
2 changes: 1 addition & 1 deletion src/geocoders/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Google implements IGeocoder {
reverse(location: L.LatLngLiteral, scale: number, cb: GeocodingCallback, context?: any): void {
const params = reverseParams(this.options, {
key: this.options.apiKey,
latlng: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng)
latlng: location.lat + ',' + location.lng
});
getJSON(this.options.serviceUrl, params, data => {
const results: GeocodingResult[] = [];
Expand Down
22 changes: 7 additions & 15 deletions src/geocoders/here.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export class HERE implements IGeocoder {
}

reverse(location: L.LatLngLiteral, scale: number, cb: GeocodingCallback, context?: any): void {
const _proxRadius = this.options.reverseGeocodeProxRadius
? this.options.reverseGeocodeProxRadius
: null;
const proxRadius = _proxRadius ? ',' + encodeURIComponent(_proxRadius) : '';
let prox = location.lat + ',' + location.lng;
if (this.options.reverseGeocodeProxRadius) {
prox += ',' + this.options.reverseGeocodeProxRadius;
}
const params = reverseParams(this.options, {
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) + proxRadius,
prox,
mode: 'retrieveAddresses',
app_id: this.options.app_id,
app_code: this.options.app_code,
Expand Down Expand Up @@ -122,19 +122,11 @@ export class HEREv2 implements IGeocoder {
}

reverse(location: L.LatLngLiteral, scale: number, cb: GeocodingCallback, context?: any): void {
const _proxRadius = this.options.reverseGeocodeProxRadius
? this.options.reverseGeocodeProxRadius
: null;
const proxRadius = _proxRadius ? ',' + encodeURIComponent(_proxRadius) : '';
const params = reverseParams(this.options, {
at: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng),
at: location.lat + ',' + location.lng,
limit: this.options.reverseGeocodeProxRadius,
apiKey: this.options.apiKey
});

if (proxRadius) {
params.limit = proxRadius;
}

this.getJSON(this.options.serviceUrl + '/revgeocode', params, cb, context);
}

Expand Down
55 changes: 24 additions & 31 deletions src/geocoders/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,36 @@ export class Mapbox implements IGeocoder {
}

reverse(location: L.LatLngLiteral, scale: number, cb: GeocodingCallback, context?: any): void {
const url = this.options.serviceUrl + location.lng + ',' + location.lat + '.json';
const param = reverseParams(this.options, {
access_token: this.options.apiKey
});
getJSON(
this.options.serviceUrl +
encodeURIComponent(location.lng) +
',' +
encodeURIComponent(location.lat) +
'.json',
param,
data => {
const results: GeocodingResult[] = [];
if (data.features && data.features.length) {
for (let i = 0; i <= data.features.length - 1; i++) {
const loc = data.features[i];
const center = L.latLng(loc.center.reverse());
let bbox: L.LatLngBounds;
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);
}
results[i] = {
name: loc.place_name,
bbox: bbox,
center: center,
properties: this._getProperties(loc)
};
getJSON(url, param, data => {
const results: GeocodingResult[] = [];
if (data.features && data.features.length) {
for (let i = 0; i <= data.features.length - 1; i++) {
const loc = data.features[i];
const center = L.latLng(loc.center.reverse());
let bbox: L.LatLngBounds;
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);
}
results[i] = {
name: loc.place_name,
bbox: bbox,
center: center,
properties: this._getProperties(loc)
};
}

cb.call(context, results);
}
);

cb.call(context, results);
});
}
}

Expand Down

0 comments on commit 11a9e77

Please sign in to comment.