Skip to content
Leaflet.TileLayer.Swiss is a Leaflet plugin for displaying national maps of Switzerland using WMTS services of swisstopo.
Branch: master
Clone or download
Latest commit d59426f Oct 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Fix codepen JavaScript template Oct 12, 2018
.npmignore
LICENSE
Leaflet.TileLayer.Swiss.js
README.md
package.json

README.md

npm version

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

// Create a map with LV95 (EPSG:2056) CRS and default base map layer
var map = L.map('map', {
    crs: L.TileLayer.Swiss.EPSG_2056,
    layers: [L.tileLayer.swiss()],
    maxBounds: L.TileLayer.Swiss.latLngBounds
});

// Center on EPSG:2056 coordinates [2600000, 1200000]
map.setView(L.TileLayer.Swiss.unproject_2056(L.point([2600000, 1200000])), 16);

Options

Options are shown with their default values.

L.tileLayer.swiss({
    // Coordinate reference system. EPSG_2056 and EPSG_21871 are available.
    crs: L.TileLayer.Swiss.EPSG_2056
    // Image format (jpeg or png). Only one format is available per layer.
    format: 'jpeg',
    // Layer name.
    layer: 'ch.swisstopo.pixelkarte-farbe',
    // Maximum zoom. Availability of zoom levels depends on the layer.
    maxZoom: 27,
    // Timestamp. Most (but not all) layers have a 'current' timestamp.
    // Some layers have multiple timestamps.
    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

  • Documentation and source of the official swisstopo API based on OpenLayers 3
  • Terms of service for the free and paid tiers of swisstopo
You can’t perform that action at this time.