Mapbox country code
See original GitHub issueHi !
I’m working with this great tool and i have a very small suggestions to do to make it better 😃
I’m working with Mapbox API and i need the country short code which is not parsed in property list.
// Get country code
if (loc.context[j].short_code != 'undefined') {
properties['countryShortCode'] = loc.context[j].short_code
}
I have a PR standing by if you are ok with this. 😉
Here is the full file with changes :
// src/geocoders/mapbox.js
import L from 'leaflet';
import { getJSON } from '../util';
export var Mapbox = L.Class.extend({
options: {
serviceUrl: 'https://api.mapbox.com/geocoding/v5/mapbox.places/',
geocodingQueryParams: {},
reverseQueryParams: {}
},
initialize: function(accessToken, options) {
L.setOptions(this, options);
this.options.geocodingQueryParams.access_token = accessToken;
this.options.reverseQueryParams.access_token = accessToken;
},
geocode: function(query, cb, context) {
var params = this.options.geocodingQueryParams;
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;
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);
}
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
if (loc.context[j].short_code != 'undefined') {
properties['countryShortCode'] = loc.context[j].short_code
}
}
results[i] = {
name: loc.place_name,
bbox: latLngBounds,
center: latLng,
properties: properties
};
}
}
cb.call(context, results);
});
},
suggest: function(query, cb, context) {
return this.geocode(query, cb, context);
},
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);
}
);
}
});
export function mapbox(accessToken, options) {
return new Mapbox(accessToken, options);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Mapbox Countries v1 | Tilesets
The tileset includes vector polygon features for all countries and territories defined in the ISO 3166-1 country code standard, including alternate worldviews ...
Read more >Country - sdk - Mapbox docs
country code in ISO 3166 alpha 2. val code: String. Companion Object Properties. AFGHANISTAN.
Read more >Boundary Maps for State, County, City & Zipcode - Mapbox
Country / Territory by ISO code. Afghanistan (AF), Albania (AL), Algeria (DZ), American Samoa (AS), Andorra (AD), Angola (AO) ...
Read more >countryCode - Mapbox
countryCode. val countryCode: String? Content copied to clipboard. Parameters. countryCode. ISO 3166-1 alpha-3 country code. © 2020 CopyrightSponsored and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Done: https://github.com/perliedman/leaflet-control-geocoder/releases/tag/1.13.0
Is it possible to tag the 1.12.2 so i can use it ?
Thanks.