https://rikiag.github.io/api/boundaries//children.json
JavaScript (Leaflet)
const url = `https://rikiag.github.io/api/boundaries/.json`;
fetch(url)
.then(res => res.json())
.then(json => {
let coordStr = json.data.coordinates;
let coords = typeof coordStr === 'string' ? JSON.parse(coordStr) : coordStr;
const swap = c => typeof c[0] === 'number' ? [c[1], c[0]] : c.map(swap);
const geoJson = {
type: "Feature",
geometry: {
type: Array.isArray(coords[0][0][0]) ? "MultiPolygon" : "Polygon",
coordinates: swap(coords)
}
};
L.geoJSON(geoJson).addTo(map);
});
JSON Format
{
"status": "success",
"data": {
"code": "",
"name": "Region Name",
"centroid": {
"lat": -2.33,
"lng": 115.42
},
"coordinates": "[[[[...]]]]"
}
}