Appearance
Tile proxy
With the tile proxy the tiles of the maps come from your own server instead of from the tile provider. (from v5.0.0)
- Privacy: the IP address of the visitor never reaches the tile provider, only your server talks to it.
- API keys stay on the server: the keys of e.g. Thunderforest, Stadia Maps or MapTiler are not in the page anymore.
- Fast and within the limits: every tile is fetched once and then served by your web server from the tiles folder. This also keeps a busy site within the tile usage policy of OpenStreetMap.
Turn it on in the settings (Tile proxy). The map tag needs no changes.
TIP
The tile proxy works for every tile with a tile server (OpenStreetMap, OpenTopoMap, Thunderforest, Stadia Maps, MapTiler, CARTO, Mapbox, ...). Google Maps and Apple Maps load their own script and can't be proxied.
How it works
- The map asks the tile from the tiles folder, e.g.
/images/reinos_maps_tiles/openstreetmap/10/525/337.png. When it is there, your web server serves it, without PHP or ExpressionEngine. - When it is not there yet, the map asks it from the tile action of Maps. Maps fetches it from the provider, saves it in the tiles folder and sends it to the visitor.
- Once a day the tiles older than the Tile cache time (default 30 days) are deleted, so they are fetched again.
The tile action only fetches the tiles that are enabled in the CP, for the maps of your own site, with a limit of 600 new tiles per IP address per minute, so it can't be used as an open proxy.
The server rule
Without a rule on the web server, a tile that is not cached yet is first asked from the tiles folder (a 404 in the console of the browser) and then from the tile action. The map works, but with a rule the web server sends it to the tile action right away:
- Apache: Maps puts a
.htaccesswith the rule in the tiles folder (it needsmod_rewrite). - nginx: add the rule to the server block of your site. The Diagnostics page shows it with the action id of your site, e.g.:
nginx
location ^~ /images/reinos_maps_tiles/ {
try_files $uri @reinos_maps_tiles;
}
location @reinos_maps_tiles {
rewrite ^/images/reinos_maps_tiles/([a-z0-9_]+)/([0-9]+)/([0-9]+)/([0-9]+)(@2x)?\.(png|jpe?g|webp)$ /index.php?ACT=12&tile=$1&z=$2&x=$3&y=$4&r=$5 last;
}The Diagnostics page checks whether the rule works.
The tiles folder
By default the tiles are saved in the images folder of ExpressionEngine: images/reinos_maps_tiles/. That folder is public and writable for ExpressionEngine, and an update of Maps keeps it. Change the folder with the Tiles folder and Tiles URL settings; the folder must be writable by the web server and served as is (no PHP).
The Diagnostics page shows whether the folder is writable and how many tiles are cached, with a Clear button to delete them. Delete Cache on the Cache page deletes the tiles as well.
Consent
With the tile proxy the tiles don't reach a third party anymore, so the maps may not need the consent of the visitor. Check it with your privacy policy: markers or layers from other servers (e.g. an icon from a CDN or a KML file) still go to that server.
