Deploying your own Slippy Map Gentoo
On gentoo things work a little different than on the other distro's so I decided to dedicate this page to Deploying your own Slippy Map on Gentoo. I hacked some ebuilds (nasty hacks) and compiled some programs so many times that I can't be totally sure if it is correct. However that is the beauty of a wiki that YOU can correct my silly mistakes.
I will use Mapnik, TileCache and Openlayers to create the slippy map.
This page is based on Deploying your own Slippy Map.
Contents |
Setting up your system
You will see version numbers in each emerge. This is because I have not tested it with other versions.
Required packages
The following packages are needed too.
- dev-util/subversion
Overlay
Until Mapnik 7.1 gets into the main portage tree you will need to manually update the ebuild. You can use The one proposed in the Gentoo bugzilla version bump request along with the supplied patch file: http://bugs.gentoo.org/show_bug.cgi?id=311129
If that one doesn't work you can also try this one:
Download the ebuild to your local overlay. (See here for details on using overlays) Then create the digest with this command:
ebuild /usr/local/portage/sci-geosciences/mapnik/mapnik-*.ebuild digest
Use Flags
Set the following useflags:
- geos
- gdal
- proj
- postgres
- python
- icu (for boost, see Mapnik wiki)
Postgres
Run:
emerge ">=dev-db/postgresql-base-9.0" ">=dev-db/postgresql-server-9.0"
As seen in the command, you want version 9.0 or higher. If you are running on something other than x86 or amd64 you will need to add a line to your /etc/portage/package.keywords file to tell it to use the "unstable" version for your platform. For ppc:
dev-db/postgresql-base ~ppc
Postgis
We need version 1.5.2 or higher.
Install with:
emerge ">=dev-db/postgis-1.5.2"
Mapnik
Mark as unstable in /etc/portage/package.keywords as needed:
sci-geosciences/mapnik ~amd64 usci-libs/geos ~amd64 sci-libs/gdal ~amd64
Install:
emerge mapnik
Get files
Get all the files you need.
Get the planet file
Get a planet file or get an extract (saves time to download)
Get the world boundries
Setting up the database
As the database is pretty large you might not want to store it in the default location (own partition maybe).
First su into the postgres user:
su - postgres
Create the directory where you want the database
mkdir /path/to/new/dir
Now initialise the database:
initdb --pgdata /path/to/new/dir
Now create a new user and a new database:
createuser <username> createdb -E UTF8 -T template0 -O <username> <db> createlang plpgsql <db>
The user needs to (temporarily) be a superuser to be able to add postgis in the next step.
Now run:
psql -U <username> -d <db> -f /usr/share/postgresql-9.0/contrib/postgis-1.5/postgis.sql psql -U <username> -d <db> -f /usr/share/postgresql-9.0/contrib/_int.sql psql -U <username> -d <db> -f /usr/share/postgresql-9.0/contrib/postgis-1.5/spatial_ref_sys.sql echo "ALTER TABLE geometry_columns OWNER TO <username>;" | psql -d <db> echo "ALTER TABLE spatial_ref_sys OWNER TO <username>;" | psql -d <db>
Permissions
Make sure you add the users that are going to use the database (user running osm2pgsql, the webserver) to the postgres group
gpasswd -a <username> postgres
Fill the database
Now that the database is all set lets fill it
osm2pgsql
There is no osm2pgsql package for gentoo (yet) so get it from svn and compile it:
svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/ cd osm2pgsql ./autogen.sh ./configure make
Importing the database
./osm2pgsql -U <user> -m -d <db> <planet-file>
If you only want a section of the world do:
./osm2pgsql -U <user> --bbox minlon,minlat,maxlon,maxlat -m -d <db> <planet-file>
Mapnik
Checkout the osm mapnik stuff:
svn checkout http://svn.openstreetmap.org/applications/rendering/mapnik cd mapnik
Create a local copy of set-mapnik-env and edit the variables inside (they are documented there).
Test Mapnik
You can edit generate_tiles if you want to specify a bounding box.
See the main Mapnik article on setting up mapnik for your environment.
TileCache
Download TileCache (tilecache.org) and setup your webserver correctly (see documentation of tilecache for that).
Edit tilecache.cfg for it to suit your needs
You can now browse tilecache on: http://<yourdomain>/tilecache.cgi/1.0.0/osm/z/x/y.png
Make sure this is contained in the index.html file (included in tilecache)
function init(){
map = new OpenLayers.Map('map',
{ maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
numZoomLevels: 19,
maxResolution: 156543,
units: 'm',
controls: [new OpenLayers.Control.MouseDefaults(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition({formatOutput: myFormat}),
new OpenLayers.Control.PanZoomBar()],
displayProjection: new OpenLayers.Projection("EPSG:4326"),
projection: new OpenLayers.Projection("EPSG:900913") });
var layerMapnik = new OpenLayers.Layer.TMS(
"Mapnik",
"tilecache.cgi/1.0.0/osm/",
{type:'png', getURL: get_osm_url,
border: 1} );
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addLayers([layerMapnik]);
// Must add permalink after adding layers, otherwise it causes
// layers to be loaded too early.
var subpagelookup = {
mapnik: [layerMapnik]
};
if( subpagelookup[subpage] != null )
{
map.setBaseLayer(subpagelookup[subpage][0]);
map.setLayerIndex(subpagelookup[subpage][0], 0);
}
map.addControl(new OpenLayers.Control.Permalink() );
map.addControl(new OpenLayers.Control.MousePosition(
{prefix: "RD Coordinates (", separator: ",", suffix: ")",
displayProjection: new OpenLayers.Projection("EPSG:28992"), numdigits:0, displayClass: "olTilePosition" }));
if(!map.getCenter()) {
var pos;
if( subpagelookup[subpage] != null && subpagelookup[subpage].length >= 3 )
pos = new OpenLayers.LonLat(subpagelookup[subpage][1],subpagelookup[subpage][2]);
else
pos = new OpenLayers.LonLat(5,52.25);
map.setCenter(pos.transform(map.displayProjection,map.projection), 10);
}
var info = document.getElementById("info_"+subpage);
if( info != null )
{
info.style.display = "block";
document.getElementById("info").style.display = "none";
}
var info = document.getElementById("forum_"+subpage);
if( info != null )
{
info.style.display = "block";
}
}
function get_osm_url (bounds) {
var res = this.map.getResolution();
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var path = z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}