
Welcome to OpenPlacesMap!
Now you may stay in Gotham Metropolis, Hogwarts, or Center Earth – simply by altering your city’s identify on OpenPlacesMap! In fact, be ready: another person simply may change your city’s identify to Mordor, Cranium Island, or Past the Wall.
Background
OpenPlacesMap is my newest weekend mission. I’ve had the thought for making a map with editable place-name labels for a very long time. Nonetheless, I’ve at all times been a little bit cautious of how the map is perhaps abused. I additionally have not had entry to a backend server to retailer the consumer knowledge.
Right here’s a short “how-to” information explaining how the map was created:
Initialize the Map
OpenLabelMap is powered by MapLibre GL JS with OpenFreeMap tiles. These tiles are primarily based on OpenStreetMap (OSM) knowledge and permit us to show a ravishing, open-source map.
Expressions
MapLibre Expressions enable builders to model the information in vector map tiles primarily based on circumstances. In OpenLabelMap, we use expressions to filter the place identify labels within the OpenFreeMap map tiles. Listed here are the OpenFreeMap label layers that we use expressions to model:
const placeNameLayers = [
'label_other',
'label_city_capital',
'label_city',
'label_town',
'label_village',
'label_state',
'label_country_1',
'label_country_2',
'label_country_3',
];
This array defines all of the completely different OpenFreeMap layers that comprise place names. Utilizing expressions, we will enable map customers to work together with these layers and alter the names displayed.
Persisting Consumer Information with Node.js
As soon as a map consumer clicks on a spot identify label, they will enter an alternate identify. To retailer and retrieve user-defined names, OpenLabelMap makes use of a Node.js server with Specific. The server handles API requests from the shopper to avoid wasting and fetch the user-edited place names. When the web page masses, the shopper fetches the beforehand saved names from the server and updates the map labels accordingly. This ensures that the user-defined place names are displayed each time the map is loaded.
Conclusion
By combining MapLibre GL JS, OpenFreeMap tiles, and a Node.js backend, it’s doable to create a dynamic map that permits customers to work together with place names, customise them, and save these modifications for future use.