Requires Leaflet version 1.x
The quick start example is a good place to start.
- Leaflet library, see Leaflet quick start guide
- Swisstopo web access if you want to publish your application
Put a div element with a certain id where you want your map to be:
Make sure the map container has a defined height, for example by setting it in CSS:
Set up the Swiss map:
// Create mapvar map = L;// Add Swiss layer with default optionsvar swissLayer = LtileLayer;// Center the map on Switzerlandmap;// Add a marker with a popup in BernL;
Options are shown with their default values.
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;var swissLayer = LtileLayer;map;
Swisstopo web access
You will need to register with Swisstopo if you want to publish an application that displays base map layers from Swisstopo.
If you have your own domain (e.g. example.com), you can sign up for Swisstopo web access. There is a free tier (no credit card required) limited to 25 gigapixels of map tiles per year, and there are paid options if you need more.
If you do not have your own domain, sadly you are out of luck, as Swisstopo currently does not provide any other way to sign up for access to the map tiles.
The usage restriction is enforced by checking the HTTP Referer header, so your application will automatically work once you have signed up.
You will probably also want to test your application locally before publishing it.
localhost is also accepted
as a Referer, so if you
run a local web server, you should be able to access the map tiles.
Swisstopo also provides some overlay layers which are freely accessible, see list of layers and their accessiblity.
Swisstopo, like most map tile providers, requires that you display a copyright attribution below the map.
The terms of service suggest using the phrase "Source: Federal Topographical Office (agreement no.)", which you may want to use if you have an agreement number from Swisstopo. You will probably get such a number if you sign up for paid access to the map tiles.
This plugin is licensed under the MIT license, see the LICENSE file.