TileQuery for Federal Electorate lookup
// Demo of using Mapbox's TileQuery API to find out which Australian federal electorate a given point is within.
const key = 'pk.eyJ1Ijoic3RldmFnZSIsImEiOiJjamlqbmtjNTMxYWdyM2xueDJkc2R5cGFlIn0.kQepm5b9pg3koSiZErFp1g';
const lngLat = [145,-35];
require("request")
const request = require('request-promise');
const tileset = 'stevage.7ux6xzbz';
void request({
uri: `https://api.mapbox.com/v4/${tileset}/tilequery/${lngLat}.json?`,
qs: { access_token: key },
json: true
}).then(result => {
if (result && result.features && result.features.length) {
const p = result.features[0].properties;
console.log(`The point ${lngLat} is in the federal electorate of ${p.ELECT_DIV} (${p.STATE}).`);
} else {
console.error(`Couldn't find an electorate for ${lngLat}.`);
}
});
no comments