Skip to content

mapnik

There are better solutions, use openlayers or see graphhopper for alternatives

This is when I started the web site and new code.

openstreetmap website

The main trigger to do this was that google maps only allowed me 1 request per day before I registered a billing account. It was still free but I really wanted to have a backup. Also it might be better to have a different 'face' than google for some applications.

The build status of openstreetmaps is here : https://travis-ci.org/openstreetmap There are a number of packages there, but the website itself is of course openstreetmap-website and you can get it with :

changetitle
git clone git://git.openstreetmap.org/rails.git

However, the last time I tried it timed out, so maybe you can download the tar from : https://github.com/openstreetmap/openstreetmap-website If you follow the INSTALL Guide there you end up with a fully functional clone of the openstreetmap website that also get's it's tiles from an openstreetmap server.

source

Best starting point : https://github.com/mapnik/mapnik/wiki

Since the installation of the website mentions mapnik and faster ways of importing the data. openstreetmap is a rigid site made for editing networks. It uses mapnik and that's the level I need. Mapnik mentions sqlite3 at installation, but as far as I can see it is only an option. One I do not want to use because of the horrible speeds. However, mapnik needs a lot more manual work, since it just generates tiles into png files. This links is the best starting point : https://switch2osm.org/serving-tiles/manually-building-a-tile-server-12-04/ Skip that, newer versions are available, so take :

https://switch2osm.org/manually-building-a-tile-server-18-04-lts/

Some versions on that site are older, so here is mu install history:

changetitle
apt-get install python-software-properties
add-apt-repository ppa:mapnik/boost
apt-get update
apt-get install libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-system-dev libboost-thread-dev
apt-get install subversion git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libpq-dev libbz2-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev libpng12-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont

sudo -u postgres createuser gisuser
sudo -u postgres createdb --encoding=UTF8 --owner=gisuser gis

psql -f /usr/share/postgresql/9.4/contrib/postgis-2.1/postgis.sql -d gis
psql -d gis -c "ALTER TABLE geometry_columns OWNER TO gisuser; ALTER TABLE spatial_ref_sys OWNER TO gisuser;"

Sadly the way we compiled mapnik above leads to errors such as :

Error

failed to initialize projection with: '&srs900913;'

But since I already did all of that, I left the description. Which seems to be caused by the xml library, so this command fixed it :

changetitle
cd mapnik-v3.0.21
python scons/scons.py install XMLPARSER=libxml2

Filling the database

Install osm2pgsql from source, since the package one is likely outdated.

changetitle
1
2
3
4
5
6
7
git clone git://github.com/openstreetmap/osm2pgsql.git
# forget about the website, there is no autogen.sh, we use cmake
cd osm2pgsql
mkdir build
cd build
cmake ..
make

Install mod_tile

changetitle
1
2
3
4
5
6
7
8
git clone git://github.com/openstreetmap/mod_tile.git
cd mod_tile
./autogen.sh
./configure
make
sudo make install
sudo make install-mod_tile
sudo ldconfig

Changes settings in renderd.conf

changetitle
1
2
3
4
5
mapnik-config --input-plugins
# copy the output of this command. for instance :
# /usr/local/lib/mapnik/input
sudo vim /usr/local/etc/renderd.conf
# now change the plugins_dir in [mapnik] to the copied value

Test the server with :

changetitle
1
2
3
4
# start renderd in the foreground
renderd -f -c /usr/local/etc/renderd.conf
# restart apache
/etc/init.d/apache2 restart

Browse to http://192.168.2.49/osm_tiles/0/0/0.png

To test this with live tiles first tail the output of

changetitle
tail -f /var/log/syslog | grep " TILE " 

So you can watch the TILEs being generated. Then open up this file on you local machine and make the url point to the server and url just installed :

changetitle
<!DOCTYPE html>
<html style="height:100%;margin:0;padding:0;">
<title>Leaflet page with OSM render server selection</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<style type="text/css">
.leaflet-tile-container { pointer-events: auto; }
</style>
</head>
<body style="height:100%;margin:0;padding:0;">
<div id="map" style="height:100%"></div>
<script>
//<![CDATA[
var map = L.map('map').setView([52.2, 5.54], 8);

L.tileLayer('http://127.0.0.1/osm_tiles/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var hash = L.hash(map)
//]]>
</script>
</body>
</html>

The setView is set to zoom out around Netherlands. Open it with chrome and you can start browsing. Note that new tiles will take some time to render.