menu
Developer
Projects
Repositories
Data Privacy
share

OSM Tile Proxy

Description

OSM Tile Proxy is a proxy/tile cache (written in PHP) for openstreetmap tiles which also can modify the tiles on the fly to create custom colorful maps.

Originally written for the "Verbrannte Orte/Scorched Places" project around 2017, updated and slighlty re-wroed in March 2020.

How it works

OSM Tile Proxy fetches tiles from any openstreepmap compatible tile server and caches them locally to be served to any openlayers map. Additionally, OSm Tile proxy can modify the tiles to create new styles by adjusting color or saturation. Multiple different styles in parallel are possible.

Prerequisites

You will need a webserver supporting PHP, including php-imagick (imagemagick).

Installation

  1. Clone the git repository
  2. Make sure cache/ and log/ are writable for your webserver
  3. Copy example/index.php-dist to public/
  4. Redirect all requests to index.php via your apache vhost or nginx host file.

Example for Apache:

          RewriteEngine on
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule . /index.php [L]
  
Example for nginx

    location /  {
            include /etc/nginx/fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME  $document_root/index.php;
            fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    }
  

Creating Styles - Examples

You can modify the tiles to create new map styles. There are three methods available: modulate, sepia and negate. You may also combine those methods, however the methods will always be executed in this order.

Example index.php with multiple styles:

    // create a style called "osm" with reduced saturation
    $style_osm = new \com\augmentedlogic\osmtileproxy\MapStyle("osm");
    $style_osm->setMirrors(array("http://a.tile.openstreetmap.org", 
                                 "http://b.tile.openstreetmap.org", 
                                 "http://c.tile.openstreetmap.org"));
    $style_osm->setEffectModulate(100, 50, 100);

    // create a second style called "osmnight"
    $style_osmnight = new \com\augmentedlogic\osmtileproxy\MapStyle("osmnight");
    $style_osmnight->setMirrors(array("http://a.tile.openstreetmap.org", 
                                      "http://b.tile.openstreetmap.org", 
                                      "http://c.tile.openstreetmap.org"));
    $style_osmnight->setEffectModulate(100, 50, 100);
    $style_osmnight->setEffectNegate();

    // add both styles to the proxy
    $tileproxy = new \com\augmentedlogic\osmtileproxy\TileProxy();
    $tileroxy->addStyle($style_osm);
    $tileproxy->addStyle($style_osmnight);
    $tileproxy->setLogLevel(\com\augmentedlogic\osmtileproxy\TileProxy::LOGLEVEL_DEBUG);
    $tileproxy->handle();

Standard OSM Tiles

Map with less Saturation


    $style_osm->setEffectModulate(100, 50, 100);

Result:

Night Mode


    $style_osm->setEffectModulate(100, 20, 100);
    $style_osm->setEffectNegate();

Result:

Grayscale and Negated


    $style_osm->setEffectModulate(100, 0, 100);
    $style_osm->setEffectNegate();

Result:

Sepia Style Map


 $style_osm->setEffectSepia(90);

Result:

Oversaturated Colors and Negated


    $style_osm->setEffectModulate(100, 160, 25);
    $style_osm->setEffectNegate();

Result:

Advanced Configuration

Setting the cache directory


   $tileproxy->setCacheDir(string $path_to_cache_dir>);
The directory under which tiles are cached.

Setting the log directory


   $tileproxy->setLogDir(string $path_to_log_dir);

The directory proxy.log is writen to.

Setting Log Levels


    $tileproxy->setLogLevel(\com\augmentedlogic\OsmMapProxy\TileProxy::LOGLEVEL_DEBUG);
Available loglevels are LOGLEVEL_OFF, LOGLEVEL_INFO and LOGLEVEL_DEBUG. The default is LOGLEVEL_OFF.

Tile Refresh

Setting the time (in days) after which new tiles will be requested from the original tile server:

   setRefresh(int $days);

Browser Cache Expiry Time

Setting the Browser Cache Expiry Time (in hours):

   setBrowserCacheExpire(int $hours);   

Limit Referrer


   $tileproxy->setReferrer(string $referrer)
Tiles will only be served if the referrer matches this string. the default is NULL, i.e. referrer is not checked.

License

osm-tile-proxy is published under MIT License.

Repository

Hosted on https://github.com/augmentedlogic/osm-tile-proxy


git clone https://github.com/augmentedlogic/osm-tile-proxy.git