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 class="container">
  <div class="row">
    <div class="col-md-6">
      <h2>WMTS</h2>
      <div id="mapLeft" class="map"></div>
    </div>
    <div class="col-md-6">
      <h2>Tiled WMS</h2>
      <div id="mapRight" class="map"></div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <p>
        This examples shows how to use geo.admin.ch CadastralWebMap WMTS layers. The WMTS tiles are generated <em>on-the-fly</em> by a MapProxy service and hold in cache for one hour. The only value for the <em>timestamp</em> dimension is <em>current</em>. Not other values are possible as outlined in  the <a href="../1.0.0/WMTSCapabilities.xml" target="_blank">WMTS GetCapabilities</a>.
      </p>
      <p>Have a look at what <a href="../services/sdiservices.html#other-projections" target="_blank" >projections are available</a>.</p>
    </div>
  </div> 
</div>

            
          
!
            
              body{
  margin: 0;
  padding: 0;
}
.map {
  height:350px;
}
.ol-attribution.ol-uncollapsible {
  height: 1.5em;
}
            
          
!
            
              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 = [420000, 30000, 900000, 350000];
var projection = ol.proj.get('EPSG:21781');
projection.setExtent(extent);

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

var attributions = [
  new ol.Attribution({
    html: '<a href="http://www.geo.admin.ch/internet/geoportal/en/home.html">' +
      '&copy swisstopo / Amtliche Vermessung Schweiz/FL</a>'
  })
];

var wmtsCadastre = new ol.layer.Tile({
  source: new ol.source.WMTS(({
    layer: 'ch.kantone.cadastralwebmap-farbe',
    crossOrigin: 'anonymous',
    attributions: attributions,
    url:'//wmts10.geo.admin.ch/1.0.0/{Layer}/default/current/21781/{TileMatrix}/{TileCol}/{TileRow}.png',
    tileGrid: new ol.tilegrid.WMTS({
      origin: [extent[0], extent[3]],
      resolutions: resolutions,
      matrixIds: matrixIds
    }),
    requestEncoding: 'REST'
  }))
});

var wmsCadastre = new ol.layer.Tile({
  extent: extent,
  source: new ol.source.TileWMS({
    url: 'https://wms.geo.admin.ch/',
    crossOrigin: 'anonymous',
    attributions: attributions,
    params: {
      'LAYERS': 'ch.kantone.cadastralwebmap-farbe',
      'FORMAT': 'image/png',
      'TILED': true,
      'VERSION': '1.1.1'
    },
    serverType: 'mapserver'
  })
});

var mapLeft = new ol.Map({
  target: 'mapLeft',
  layers: [wmtsCadastre],
  view: new ol.View({
    center: [502160, 125800],
    projection: projection,
    resolution: 1
  }),
  controls: ol.control.defaults({
    attributionOptions: ({
      collapsible: false
    })
  }),
  logo: false
});

var mapRight = new ol.Map({
  target: 'mapRight',
  layers: [wmsCadastre],
  view: mapLeft.getView(),
  controls: ol.control.defaults({
    attributionOptions: ({
      collapsible: false
    })
  }),
  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