![npm version](https://img.shields.io/npm/v/leaflet-tilelayer-swiss.svg)
Leaflet.TileLayer.Swiss
Leaflet.TileLayer.Swiss is a Leaflet plugin for
displaying national maps of Switzerland using WMTS services of
swisstopo.
This plugin is not affiliated with or endorsed by swisstopo.
Requires Leaflet, Proj4js,
Proj4Leaflet. Tested with the
versions listed as peerDependencies in
package.json.
Demo
Usage
swisstopo web access
Most of the base map layers come with some usage restriction which is enforced
by checking the HTTP Referer of
map tile requests.
localhost
is always accepted as as a Referer.- In order to include a map on a website hosted at example.com, a
swisstopo web access
account for example.com is required. There is a free tier (no credit
card required) limited to 25 gigapixels per year.
Most overlay layers are freely accessible, see
list of layers and their accessiblity.
Basic example
var map = L.map('map', {
crs: L.TileLayer.Swiss.EPSG_2056,
layers: [L.tileLayer.swiss()],
maxBounds: L.TileLayer.Swiss.latLngBounds
});
map.setView(L.TileLayer.Swiss.unproject_2056(L.point([2600000, 1200000])), 16);
Options
Options are shown with their default values.
L.tileLayer.swiss({
crs: L.TileLayer.Swiss.EPSG_2056
format: 'jpeg',
layer: 'ch.swisstopo.pixelkarte-farbe',
maxZoom: 27,
timestamp: 'current'
});
A list with all available layers and corresponding options is available
here.
Coordinate reference systems (CRS)
Two CRS are commonly used in Switzerland:
In order to use EPSG:21781, both map and layer CRS have to be adapted:
var map = L.map('map', {
crs: L.TileLayer.Swiss.EPSG_21781,
layers: [L.tileLayer.swiss({
crs: L.TileLayer.Swiss.EPSG_21781
})],
maxBounds: L.TileLayer.Swiss.latLngBounds
});
map.setView(L.TileLayer.Swiss.unproject_21781(L.point([600000, 200000])), 16);
Attribution
This plugin adds a map attribution which links to
swisstopo, the same as it is done
by the official swisstopo API.
The
terms of service
suggest the phrase "Source: Federal Topographical Office (agreement no.)", which
you may want to use if you have an agreement number from swisstopo.
License
This plugin is licensed under the MIT license, see the LICENSE file.
Acknowledgements
Thanks to swisstopo and the
Geoinformation Act
for providing excellent geodata.
Thanks to @procrastinatio whose
blog post
taught me how to use swisstopo layers in Leaflet a few year ago.
See also