Auto fit map to boundaries
This commit is contained in:
2
map-generator/dist/main.js
vendored
2
map-generator/dist/main.js
vendored
File diff suppressed because one or more lines are too long
@@ -33,6 +33,13 @@ fetch("wards_withboundaries.json")
|
|||||||
.then((wardData) => {
|
.then((wardData) => {
|
||||||
const filteredWardData = wardData.filter((ward) => normaliseCouncilName(ward.parentElectorateName) == councilName);
|
const filteredWardData = wardData.filter((ward) => normaliseCouncilName(ward.parentElectorateName) == councilName);
|
||||||
|
|
||||||
|
var bounds = {
|
||||||
|
"west": undefined,
|
||||||
|
"south": undefined,
|
||||||
|
"east": undefined,
|
||||||
|
"north": undefined
|
||||||
|
}
|
||||||
|
|
||||||
filteredWardData.forEach(wardData => {
|
filteredWardData.forEach(wardData => {
|
||||||
const featureCollection = {
|
const featureCollection = {
|
||||||
'type': 'FeatureCollection',
|
'type': 'FeatureCollection',
|
||||||
@@ -44,6 +51,24 @@ fetch("wards_withboundaries.json")
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
featureCollection.features[0].geometry.coordinates[0].forEach(coordinate => {
|
||||||
|
if (bounds.west == undefined || coordinate[0] < bounds.west) {
|
||||||
|
bounds.west = coordinate[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bounds.south == undefined || coordinate[1] < bounds.south) {
|
||||||
|
bounds.south = coordinate[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bounds.east == undefined || coordinate[0] > bounds.east) {
|
||||||
|
bounds.east = coordinate[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bounds.north == undefined || coordinate[1] > bounds.north) {
|
||||||
|
bounds.north = coordinate[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add data
|
// Add data
|
||||||
map.addSource("data_"+wardData.electorateId, {
|
map.addSource("data_"+wardData.electorateId, {
|
||||||
'type': 'geojson',
|
'type': 'geojson',
|
||||||
@@ -94,7 +119,14 @@ fetch("wards_withboundaries.json")
|
|||||||
'text-allow-overlap': true
|
'text-allow-overlap': true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
map.fitBounds([
|
||||||
|
[bounds.west, bounds.south],
|
||||||
|
[bounds.east, bounds.north]
|
||||||
|
], {
|
||||||
|
padding: 25,
|
||||||
|
animate: false
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|||||||
Reference in New Issue
Block a user