cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div id="map" class="map"></div>
<div id="mousePosition"></div>
<div>
  <div>
    This examples shows how to use geo.admin.ch WMTS tiles in the new LV95 frame (<a href="http://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="http://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>
  </div>
</div> 
            
          
!
            
              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');
projection.setExtent(extent);


var matrixIds = [];
for (var i = 0; i < RESOLUTIONS.length; i++) {
  matrixIds.push(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="http://www.swisstopo.admin.ch/' +
      'internet/swisstopo/en/home.html">swisstopo</a>'
    })],
    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 http://api3.geo.admin.ch/rest/services/api/MapServer/layersConfig
var layerConfig = {
  "attribution": "swisstopo",
  "format": "jpeg",
  "serverLayerName": "ch.swisstopo.swissimage",
  "attributionUrl": "http://www.swisstopo.admin.ch/internet/swisstopo/fr/home.html",
  "label": "SWISSIMAGE",
  // Use 'current', if you are only interested in the latest data.
  "timestamps": [
    "current",
    "20140620",
    "20131107",
    "20130916",
    "20130422",
    "20120809",
    "20120225",
    "20110914",
    "20110228"
  ]
};

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

var wmsLayer = new ol.layer.Image({
  extent: extent,
  source: new ol.source.ImageWMS({
    url: 'http://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
    })
  }).extend([
    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,
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console