css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="map" class="map"></div>
<div id="mousePosition"></div>
    This examples shows how to use geo.admin.ch WMTS tiles in the new LV95 frame (<a href="https://epsg.io/2056" target="_blank">EPSG:2056</a>).<br>
    <p>The WMTS tiles are reframed <em>on-the-fly</em> using <a href="http://mapproxy.org">MapProxy</a> and the NTv2 <a href="https://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/lv95/lv03-lv95/chenyx06.html"> CHENyx06 triangular transformation network </a>. Hence the accuracy is well beyond the resolution of the displayed layers. Without this you would see in region like the south Ticino and the Poschiavo area, a shift up to 1.5 meters between the old and the new frame. See <a href="//map.geo.admin.ch/?layers=ch.swisstopo.koordinatenaenderung&layers_opacity=0.75&lang=en" target="_blank">LV95 Coordinate changes</a> for some background informations.</p>
    <p>Have a look at what <a href="//api3.geo.admin.ch/services/sdiservices.html#other-projections" target="_blank" >projections are available</a>.</p>
              body {
  margin: 0;
  padding: 0;

.map {
  height: 350px;

.ol-attribution.ol-uncollapsible {
  height: 1.5em;

#mousePosition {
  position: relative;
  height: 20px;
  width: 100%;
              var RESOLUTIONS = [
  4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250,
  1000, 750, 650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5
var extent = [2420000, 130000, 2900000, 1350000];
var projection = ol.proj.get('EPSG:2056');

var matrixIds = [];
for (var i = 0; i < RESOLUTIONS.length; i++) {

var wmtsSource = function(layerConfig) {
  var resolutions = layerConfig.resolutions || RESOLUTIONS;
  var tileGrid = new ol.tilegrid.WMTS({
    origin: [extent[0], extent[3]],
    resolutions: resolutions,
    matrixIds: matrixIds
  var extension = layerConfig.format || 'png';
  var timestamp = layerConfig['timestamps'][0];
  return new ol.source.WMTS(({
    attributions: [new ol.Attribution({
      html: '<a target="new" href="https://www.swisstopo.admin.ch/' +
    url: '//wmts10.geo.admin.ch/1.0.0/{Layer}/default/' + timestamp + '/2056/{TileMatrix}/{TileCol}/{TileRow}.'+ extension,
    tileGrid: tileGrid,
    projection: projection,
    layer: layerConfig.serverLayerName,
    requestEncoding: 'REST'

// See https://api3.geo.admin.ch/rest/services/api/MapServer/layersConfig
var layerConfig = {
  "attribution": "swisstopo",
  "format": "jpeg",
  "serverLayerName": "ch.swisstopo.swissimage",
  "attributionUrl": "https://www.swisstopo.admin.ch/internet/swisstopo/fr/home.html",
  "label": "SWISSIMAGE",
  // Use 'current', if you are only interested in the latest data.
  "timestamps": [

var wmtsLayer = new ol.layer.Tile({
  source: wmtsSource(layerConfig)

var wmsLayer = new ol.layer.Image({
  extent: extent,
  source: new ol.source.ImageWMS({
    url: 'https://wms.geo.admin.ch/',
    ratio: 1.0,
    projection: 'EPSG:2056',
    params: {
      'LAYERS': ['org.epsg.grid_21781,org.epsg.grid_4326'],
      'FORMAT': 'image/png',
      'TILED': false
    serverType: 'mapserver'

var map = new ol.Map({
  layers: [wmtsLayer, wmsLayer],
  target: 'map',
  view: new ol.View({
    center: [2720000, 1095000],
    projection: projection,
    resolution: 100
  controls: ol.control.defaults({
    attributionOptions: ({
      collapsible: false
    new ol.control.ScaleLine({
      units: 'metric'
    new ol.control.MousePosition({
      coordinateFormat: ol.coordinate.createStringXY(4),
      //projection: 'EPSG:2056',
      target: document.getElementById('mousePosition'),
      undefinedHTML: '&nbsp;'
  logo: false,
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................