Compare commits
4 Commits
56f0f73278
...
2028cbbe61
| Author | SHA1 | Date | |
|---|---|---|---|
| 2028cbbe61 | |||
| e1a1ff4af3 | |||
| f60b1802d5 | |||
| 0a7af5c65b |
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
@@ -1,9 +1,13 @@
|
|||||||
# Map Generator
|
# Map Generator
|
||||||
|
|
||||||
This project is displays a map showing the boundaries of wards within a single local government area. Each ward is labelled.
|
This project displays a map showing the boundaries of wards within a single local government area. Each ward is labelled.
|
||||||
|
|
||||||
The data for this comes from the VEC Map API: https://maps.vec.vic.gov.au/api/electorates/4/withboundaries
|
The data for this comes from the VEC Map API: https://maps.vec.vic.gov.au/api/electorates/4/withboundaries
|
||||||
|
|
||||||
To compile the `src.js` file after every edit, run `webpack-cli --mode development --watch` in this folder.
|
To allow the page to download the `wards_withboundaries.json` file, the page needs to be accessed via a `http://` URL (and not a `file:///` URL). One easy way to do this is with the web server built into Python, it can be started by running `python3 -m http.server` in this folder.
|
||||||
|
|
||||||
|
To tell the page which council to load, add a query parameter to the URL eg. `?council=brimbank` or `?council=Melbourne%20City%20Council`
|
||||||
|
|
||||||
|
To automatically compile the `src.js` file after every edit, run `webpack-cli --mode development --watch` in this folder.
|
||||||
|
|
||||||
Changes to `dist/main.js` should be committed so that other users don't need to install node.
|
Changes to `dist/main.js` should be committed so that other users don't need to install node.
|
||||||
@@ -21,6 +21,7 @@ mapboxgl.accessToken = 'pk.eyJ1IjoibWF0dHl3YXkiLCJhIjoiY2x6eG9vMzZyMHY2cDJqb3M1O
|
|||||||
const map = new mapboxgl.Map({
|
const map = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
zoom: 10,
|
zoom: 10,
|
||||||
|
style: 'mapbox://styles/mattyway/clzy2ozzf004k01pn840h9xdb',
|
||||||
center: [145.00724,-37.79011]
|
center: [145.00724,-37.79011]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,6 +33,15 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var labelFeatures = [];
|
||||||
|
|
||||||
filteredWardData.forEach(wardData => {
|
filteredWardData.forEach(wardData => {
|
||||||
const featureCollection = {
|
const featureCollection = {
|
||||||
'type': 'FeatureCollection',
|
'type': 'FeatureCollection',
|
||||||
@@ -43,6 +53,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',
|
||||||
@@ -63,12 +91,28 @@ fetch("wards_withboundaries.json")
|
|||||||
|
|
||||||
const centrePoint = polylabel(featureCollection.features[0].geometry.coordinates, 0.000001);
|
const centrePoint = polylabel(featureCollection.features[0].geometry.coordinates, 0.000001);
|
||||||
|
|
||||||
map.addSource('center_'+wardData.electorateId, {
|
if (wardData.electorateName.includes(' ')) {
|
||||||
'type': 'geojson',
|
// Breaking long names into newlines looks better
|
||||||
'data': {
|
const parts = wardData.electorateName.split(' ');
|
||||||
'type': 'FeatureCollection',
|
// Special case if a ward starts with "St" (like "St Albans East")
|
||||||
'features': [
|
// Join the first two parts
|
||||||
{
|
if (parts[0] == "St") {
|
||||||
|
parts[0] = parts[0] + ' ' + parts[1];
|
||||||
|
parts.splice(1, 1);
|
||||||
|
}
|
||||||
|
const wardNameNewLines = parts.join('\n');
|
||||||
|
labelFeatures.push({
|
||||||
|
'type': 'Feature',
|
||||||
|
'properties': {
|
||||||
|
'description': wardNameNewLines
|
||||||
|
},
|
||||||
|
'geometry': {
|
||||||
|
'type': 'Point',
|
||||||
|
'coordinates': centrePoint
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
labelFeatures.push({
|
||||||
'type': 'Feature',
|
'type': 'Feature',
|
||||||
'properties': {
|
'properties': {
|
||||||
'description': wardData.electorateName
|
'description': wardData.electorateName
|
||||||
@@ -77,36 +121,43 @@ fetch("wards_withboundaries.json")
|
|||||||
'type': 'Point',
|
'type': 'Point',
|
||||||
'coordinates': centrePoint
|
'coordinates': centrePoint
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
]
|
});
|
||||||
|
|
||||||
|
map.addSource('labels', {
|
||||||
|
'type': 'geojson',
|
||||||
|
'data': {
|
||||||
|
'type': 'FeatureCollection',
|
||||||
|
'features': labelFeatures
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
map.addLayer({
|
map.addLayer({
|
||||||
'id': 'label_'+wardData.electorateId,
|
'id': 'labels',
|
||||||
'type': 'symbol',
|
'type': 'symbol',
|
||||||
'source': 'center_'+wardData.electorateId,
|
'source': 'labels',
|
||||||
'layout': {
|
'layout': {
|
||||||
'text-field': ['get', 'description'],
|
'text-field': ['get', 'description'],
|
||||||
'text-variable-anchor': ['center', 'top', 'bottom'],
|
'text-variable-anchor': ['center', 'top', 'bottom'],
|
||||||
|
'text-radial-offset': 0.5,
|
||||||
|
'text-padding': 0,
|
||||||
'text-justify': 'auto',
|
'text-justify': 'auto',
|
||||||
'text-allow-overlap': true
|
'text-allow-overlap': false,
|
||||||
|
'text-ignore-placement': false,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
map.fitBounds([
|
||||||
|
[bounds.west, bounds.south],
|
||||||
|
[bounds.east, bounds.north]
|
||||||
|
], {
|
||||||
|
padding: 25,
|
||||||
|
animate: false
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
map.on('style.load', () => {
|
|
||||||
map.setConfigProperty('basemap', 'showPlaceLabels', false);
|
|
||||||
map.setConfigProperty('basemap', 'showPointOfInterestLabels', false);
|
|
||||||
map.setConfigProperty('basemap', 'showRoadLabels', false);
|
|
||||||
map.setConfigProperty('basemap', 'showTransitLabels', false);
|
|
||||||
map.setConfigProperty('basemap', 'show3dObjects', false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user