cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              <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="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>
  </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="https://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 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": [
    "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: '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
    })
  }).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
🕑 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 ..................

Console