- Node.js 14+
- PostGIS
- GDAL including python-gdal
- imposm3
git clone https://github.com/FreemapSlovakia/freemap-mapnik.git
- Get OpenStreetMap data (eg. from Geofabrik)
- Create a postgis database (see below for details)
- Import OpenStreetMap data (see below for details)
- Get digital elevation data and import it to database (optional; see below for details)
- Change directory to project directory
- Run
npm i
- Create
config/development.json5
where you can override settings fromconfig/default.json5
for your local environment - Run
npm run watch
- Open preview.html in your browser
To build sources for production run:
npm i
npm run build
In following commands replace <you>
with your username.
sudo su - postgres
(skip this on MacOS)createdb <you>
createuser <you>
psql <you>
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
GRANT CREATE ON DATABASE <you> TO <you>;
ALTER USER <you> WITH PASSWORD '<your_password>';
GRANT ALL ON SCHEMA public TO <you>;
Downgrade password_encryption in PostgreSQL to md5, changing all the passwords and using the md5 authentication method:
- In ``/etc/postgresql/16/main/pg_hba.conf
(your PostgreSQL version may vary), find the line
host all all 127.0.0.1/32 scram-sha-256` and replace the ending directive by md5: `host all all 127.0.0.1/32 md5` - In
/etc/postgresql/16/main/postgresql.conf
(your PostgreSQL version may vary), find the linepassword_encryption = scram-sha-256
and replace the value bymd5
. - Restart the postgresql service:
systemctl restart [email protected]
- Check that the password of the dedicated user was actually converted to using md5:
su - postgres
$ psql -d freemap
psql (16.1 (Debian 16.1-1.pgdg120+1))
freemap=# select rolpassword from pg_authid where rolname = 'freemap';
rolpassword
-------------------------------------
md5e1cd775xjhdsfjkhdjdjfhj
You'll notice the heading md5 caracters of the encoded password. In case this 3 caracters are missing, please reset the dedicated user's password:
ALTER USER freemap WITH PASSWORD 'somepassword';
Import initial.sql to PostgreSQL.
You must have imposm3 installed. For instructions how to build it see https://github.com/omniscale/imposm3.
To import the data use following command (with correct pbf filename):
imposm import -connection postgis://<you>:<your_password>@localhost/<you> -mapping mapping.yaml -read slovakia-latest.osm.pbf -write
Then deploy the import to production:
imposm import -connection postgis://<you>:<your_password>@localhost/<you> -mapping mapping.yaml -deployproduction
Import additional.sql to PostgreSQL.
See instructions to compute and import peak isolations to prioritize peaks with higher isolation. Skip this step if you want to omit this functionality.
From https://osmdata.openstreetmap.de/data/land-polygons.html get simplified-land-polygons-complete-3857
and land-polygons-split-3857
and unpack it to project directory.
In order to run both imposm and freemap-mapnik services, you'll find these two ready made files in the etc/systemd folder.
-
Copy these two files in the relevant directory of your system to allow these services to run independently of any user login, place them into the
/etc/systemd/system
folder. -
Each of these two files must be edited and customized according to the installation folder, the relevant username, the database name and the login/password database account
-
Tell the system some things have changed:
sudo systemctl daemon-reload
-
Enable and start imposm:
systemctl enable imposm3 systemctl start imposm3
-
Enable freemap-mapnik:
systemctl enable freemap-mapnik systemctl start freemap-mapnik
Later on in this documentation will you find mentions of two 'versions' of the freemap-mapnik service:
- freemap-mapnik-prerender which is used to pre-render tiles from zoom 1 to zoom 14 (if a tile is missing or OSM data has been changed)
- freemap-mapnik-ondemand which renders tiles when requested by the user (from zoom 15 to 19) and missing.
brew install golang leveldb geos
and then execute the commands here
If you don't want to use hillshading and contours then set mapFeatures.contours
and mapFeatures.shading
in your config file to false
.
Otherwise follow instructions in SHADING_AND_CONTOURS.md.
Follow these steps also after database reimport, which is required if you've updated mapping.yaml
:
- Download
europe-latest.osm.pbf
from Geofabrik - Stop imposm service
systemctl stop imposm3
- update and compile freemap-mapnik
git pull && npm run build
- Import:
imposm import -connection postgis://freemap:freemap@localhost/freemap -mapping mapping.yaml -read europe-latest.osm.pbf -diff -write -cachedir ./cache -diffdir ./diff -overwritecache -limitto limit-europe.geojson -limittocachebuffer 10000 -optimize
- Delete pbf file
rm europe-latest.osm.pbf extract.pbf
- Stop prerendering
systemctl stop freemap-mapnik-prerender
- Deploy the import to production:
imposm import -connection postgis://freemap:freemap@localhost/freemap -mapping mapping.yaml -deployproduction
- Import
additional.sql
to PostgreSQL - Update
./diff/last.state.txt
to reflect timestamp and sequence number of the imported map. See https://planet.openstreetmap.org/replication/minute/ for finding sequence number. - Start imposm and wait to catch it up
systemctl start imposm3
- Now you can optionally stop imposm service to prevent it from interrupting prerendering. You can start it later after pre-rendering has been finished. You can also start it somewhere during pre-rendering to catch-up and stop again, to apply some recent updates.
- Delete content of
./expires
directory - Edit
./config/prerender.json5
and changererenderOlderThanMs
to current time plus a minute or more - Stop ondemand rendering
systemctl stop freemap-mapnik-ondemand
- Delete cached highzoom tiles and indexes
cd ./tiles rm -rf 15 16 17 18 19 cd .. find ./tiles/14 -name '*.index' -delete
- Start ondemand rendering
systemctl start freemap-mapnik-ondemand
- Start prerendering
systemctl start freemap-mapnik-prerender
server {
...
location /pdf {
proxy_pass http://localhost:4000/pdf;
}
location / {
rewrite ^(.*)$ $1.png break;
root /home/freemap/freemap-mapnik/tiles/;
error_page 404 = @fallback;
}
location @fallback {
proxy_pass http://localhost:4000;
error_page 404 /40x.html;
}
...
}