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.
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.
You will need a webserver supporting PHP, including php-imagick (imagemagick).
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;
}
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();
$style_osm->setEffectModulate(100, 50, 100);
Result:
$style_osm->setEffectModulate(100, 20, 100);
$style_osm->setEffectNegate();
Result:
$style_osm->setEffectModulate(100, 0, 100);
$style_osm->setEffectNegate();
Result:
$style_osm->setEffectSepia(90);
Result:
$style_osm->setEffectModulate(100, 160, 25);
$style_osm->setEffectNegate();
Result:
$tileproxy->setCacheDir(string $path_to_cache_dir>);
The directory under which tiles are cached.
$tileproxy->setLogDir(string $path_to_log_dir);
The directory proxy.log is writen to.
$tileproxy->setLogLevel(\com\augmentedlogic\OsmMapProxy\TileProxy::LOGLEVEL_DEBUG);
Available loglevels are LOGLEVEL_OFF, LOGLEVEL_INFO and LOGLEVEL_DEBUG. The default is LOGLEVEL_OFF.
setRefresh(int $days);
setBrowserCacheExpire(int $hours);
$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.
osm-tile-proxy is published under MIT License.
Hosted on https://github.com/augmentedlogic/osm-tile-proxy
git clone https://github.com/augmentedlogic/osm-tile-proxy.git