phdbrianlee / docker-kosmtik

Light docker for ksomtik https://github.com/kosmtik/kosmtik

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker-kosmtik

Light docker for ksomtik https://github.com/kosmtik/kosmtik This docker is an alternative to the other kosmtik docker which is 2 times bigger.

Image name Image Size Image layers
joxit/kosmtik Image Size Image Layers
kosmtik/kosmtik Image Size Image Layers

Kosmtik

Very lite but extendable mapping framework to create Mapnik ready maps with OpenStreetMap data (and more).

For now, only Carto based projects are supported (with .mml or .yml config), but in the future we hope to plug in MapCSS too.

Alpha version, installable only from source

Lite

Only the core needs:

  • project loading
  • local configuration management
  • tiles server for live feedback when coding
  • exports to common formats (Mapnik XML, PNG…)
  • hooks everywhere to make easy to extend it with plugins

Usage

Get the docker image

You can get the image in three ways

From sources with this command :

git clone https://github.com/Joxit/docker-kosmtik.git
docker build -t joxit/kosmtik docker-kosmtik

Or build with the url :

docker build -t joxit/kosmtik github.com/Joxit/docker-kosmtik

Or pull the image from docker hub :

docker pull joxit/kosmtik

Run

Database

First of all, you need a database with OSM datas. You can use a postgres database in a docker or on a computer. If you want your database to be in a docker, I suggest you to use openfirmware/postgres-osm docker.

In order to fill this database, you can use openfirmware/osm2pgsql. You can download a continent or country on geofabrik.de or the whole planet on planet.osm.org.

Project

To run a Carto project (or .yml, .yaml):

docker run -d \
    -p 6789:6789 \
    -v /path/to/your/project:/opt/project \
    --link postgres-osm:postgres-osm \
    -e USER_ID=1000 \
    joxit/kosmtik \
    kosmtik serve </opt/project/project.(mml|yml)> --host 0.0.0.0

The env USER_ID is your user ID on your host. The shell kosmtik will perform a chown -R $USER_ID:$USER_ID /opt/project at the end of the import. Then open your browser at http://127.0.0.1:6789/.

Try it

You can try kosmtik with HDM CartoCSS project.

You can add an alias in your .bashrc or .bash_aliases for kosmtik serve. You can use KOSMTIK_OPTS env to add your own docker options for kosmtik (such as --link postgres-osm:postgres-osm or --net postgres-osm for networks).

alias kosmtik="docker run -ti --rm -p 6789:6789 -v $(pwd):/opt/project -e USER_ID=1000 $KOSMTIK_OPTS joxit/kosmtik kosmtik serve --host 0.0.0.0"

Or use the shell in tools (add the folder in your PATH var). If you are using serve command, the shell will add --host 0.0.0.0 as arg.

Plugins

Tiles export

To export tiles from your project (see kosmtik-tiles-export plugin):

docker run -d \
    -v /path/to/your/project:/opt/project \
    --link postgres-osm:postgres-osm \
    -e USER_ID=1000 \
    joxit/kosmtik \
    kosmtik export /opt/project/project.(mml|yml) \
    --format tiles --output /opt/project/tiles --minZoom 1 --maxZoom 13

The env USER_ID is your user ID on your host. The shell kosmtik will perform a chown -R $USER_ID:$USER_ID /opt/project at the end of the import.

Fetch remote

Download the remote files referenced in your layers and update their name to use them automatically. Kosmtik is launched as root in the docker, so fetched datas and tmp tiles will be owned by root. This is why you should use kosmtik cmd which will chown the curent directory (/opt/project) with your user id.

Overlay

You can add an overlay key to your project.mml or your kosmtik config.yml files to override the behaviour. For example:

overlay:
    url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
    active: true
    opacity: 1
    position: -1
"overlay": {
    "url": "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    "active": true,
    "opacity": 1,
    "position": -1
}

Local config

Because you often need to change the project config to match your local env, for example to adapt the database connection credentials, kosmtik comes with an internal plugin to manage that. You have two options: with a json file named localconfig.json, or with a js module name localconfig.js.

Place your localconfig.js or localconfig.json file in the same directory as your carto project (or .yml, .yaml).

In both cases, the behaviour is the same, you create some rules to target the configuration and changes the values. Those rules are started by the keyword where, and you define which changes to apply using then keyword. You can also filter the targeted objects by using the if clause. See the examples below to get it working right now.

Example of a json file

[
    {
        "where": "center",
        "then": [29.9377, -3.4216, 9]
    },
    {
        "where": "Layer",
        "if": {
            "Datasource.type": "postgis"
        },
        "then": {
            "Datasource.dbname": "gis",
            "Datasource.password": "",
            "Datasource.user": "osm",
            "Datasource.host": "postgres-osm"
        }
    },
    {
        "where": "Layer",
        "if": {
            "id": "hillshade"
        },
        "then": {
            "Datasource.file": "/data/layers/hillshade.vrt"
        }
    }
]

Example of a js module

exports.LocalConfig = function (localizer, project) {
    localizer.where('center').then([29.9377, -3.4216, 9]);
    localizer.where('Layer').if({'Datasource.type': 'postgis'}).then({
        "Datasource.dbname": "gis",
        "Datasource.password": "",
        "Datasource.user": "osm",
        "Datasource.host": "postgres-osm"
    });
    // You can also do it in pure JS
    project.mml.bounds = [1, 2, 3, 4];
};

About

Light docker for ksomtik https://github.com/kosmtik/kosmtik

License:Apache License 2.0


Languages

Language:Shell 100.0%