Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-tilelayer-swiss

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-tilelayer-swiss

Leaflet.TileLayer.Swiss is a Leaflet plugin for displaying national maps of Switzerland using WMTS services of swisstopo.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
136
decreased by-57.1%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 12 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc