Fix handling of MultiPolygon objects
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
@@ -38,6 +38,24 @@ fetch("wards_withboundaries.json")
|
|||||||
"north": undefined
|
"north": undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToBounds(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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var labelFeatures = [];
|
var labelFeatures = [];
|
||||||
|
|
||||||
filteredWardData.forEach(wardData => {
|
filteredWardData.forEach(wardData => {
|
||||||
@@ -51,23 +69,18 @@ fetch("wards_withboundaries.json")
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
featureCollection.features[0].geometry.coordinates[0].forEach(coordinate => {
|
if (featureCollection.features[0].geometry.type == "Polygon") {
|
||||||
if (bounds.west == undefined || coordinate[0] < bounds.west) {
|
featureCollection.features[0].geometry.coordinates[0].forEach(coordinate => {
|
||||||
bounds.west = coordinate[0];
|
addToBounds(coordinate);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
if (bounds.south == undefined || coordinate[1] < bounds.south) {
|
if (featureCollection.features[0].geometry.type == "MultiPolygon") {
|
||||||
bounds.south = coordinate[1];
|
featureCollection.features[0].geometry.coordinates.forEach(polygon => {
|
||||||
}
|
polygon[0].forEach(coordinate => {
|
||||||
|
addToBounds(coordinate);
|
||||||
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, {
|
||||||
@@ -87,7 +100,19 @@ fetch("wards_withboundaries.json")
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const centrePoint = polylabel(featureCollection.features[0].geometry.coordinates, 0.000001);
|
var centrePoint;
|
||||||
|
if (featureCollection.features[0].geometry.type == "Polygon") {
|
||||||
|
centrePoint = polylabel(featureCollection.features[0].geometry.coordinates, 0.000001);
|
||||||
|
}
|
||||||
|
if (featureCollection.features[0].geometry.type == "MultiPolygon") {
|
||||||
|
// TODO: Find the biggest polygon in the multipolygon and use that to find the centre point
|
||||||
|
// instead of just picking the second polygon.
|
||||||
|
//
|
||||||
|
// The 2024 set of boundaries only uses 2 MultiPolygon objects (Cathedral in Murrindindi Shire Council and Island in Bass Coast Shire Council)
|
||||||
|
// Luckily, the second polygon for both objects results in a good label placement.
|
||||||
|
centrePoint = polylabel(featureCollection.features[0].geometry.coordinates[1], 0.000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (wardData.electorateName.includes(' ')) {
|
if (wardData.electorateName.includes(' ')) {
|
||||||
// Breaking long names into newlines looks better
|
// Breaking long names into newlines looks better
|
||||||
|
|||||||
Reference in New Issue
Block a user