How to add WMTS layer from geo.admin.ch in a Open Layers 3 app

1,260 views
Skip to first unread message

bjoern.s...@gmail.com

unread,
Jul 25, 2014, 9:35:24 AM7/25/14
to geoadm...@googlegroups.com
Dear all

I'm not using the Geoadmin API, but the Open Layers 3 Library. But I didn't found a more appropriate forum to ask my question.

In the attached map.php I'm using the following code to get an WMTS Layer from geo.admin.ch in my OpenLayers3-App. I created this code by adapting a working OpenLayers2-solution to examples from other WMTS-providers and the OL3-Apidoc. I tried several variants, but I don't suceed in getting a working map. The map display is empty and in the console of the Google Chrome developer tools I only get the following information: "Resource interpreted as Image but transfered with MIME type application/xml: 'http://wmts3.geo.admin.ch/'."

Has anyone a working example for loading a WMTS layer?

Kind regards
Björn



new ol.layer.Tile({
      source
: new ol.source.WMTS({
        attributions
: [new ol.Attribution({
        html
: '© ' +
           
'<a href="http://www.geo.admin.ch/internet/geoportal/' +
           
'en/home.html">' +
           
'Pixelmap / geo.admin.ch</a>'
     
})],
        urls
: ['http://wmts0.geo.admin.ch/',
           
'http://wmts1.geo.admin.ch/',  
           
'http://wmts2.geo.admin.ch/',
           
'http://wmts3.geo.admin.ch/',
           
'http://wmts4.geo.admin.ch/'],
        layer
: 'ch.swisstopo.pixelkarte-farbe',
        matrixSet
: 'EPSG:21781',
        format
: 'image/jpeg',
        opacity
: 1.0,
        crossOrigin
: 'anonymous',
        requestEncoding
: "REST",
        version
: '1.0.0',
        dimensions
: ['TIME'],
       
params: {'time': '20111206'}, // wird ohne Fehlermeldung akzeptiert, obwohl dieser parameter eigentlich nur in OL2 existierte
        projection
: projection,
        tileGrid
: new ol.tilegrid.WMTS({
          origin
: [420000, 30000],
          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],
          matrixIds
: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
       
}),
        style
: 'default'
     
})
   
})


map.php

Marc Monnerat

unread,
Jul 26, 2014, 6:21:32 AM7/26/14
to geoadmin-api
Hello Björn,

No, I think this is the right place to ask this question.

The key for REST request is to provide a template to build the tile request, which in this case will be somehting like:

'http://wmts{5-9}.geo.admin.ch/1.0.0/{Layer}/default/'+  timestamp + '/21781/' +  '{TileMatrix}/{TileRow}/{TileCol}.jpeg'

The 'TileMatrixSet' is always '21781' in our case.

Here is a codepen example. It uses OL3 provided by the geo.admin.ch API, but it's pure OL3, and it uses the latest available timestamp, as you may recognise the new map signature for the Aarau area:


To find out the latest available timestamps, look at the WMTS GetCapabilities document:


Regards,

Marc



-- 
-- Τα πάντα ῥεῖ καὶ οὐδὲν μένει




--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Björn Scheppler

unread,
Aug 11, 2014, 2:22:04 AM8/11/14
to geoadm...@googlegroups.com
Hi Marc

Thank you very much for your answer. I will try this next week and will update, if it worked for me.

Kind regards
Björn

Loïc Gasser

unread,
Aug 11, 2014, 3:32:03 AM8/11/14
to geoadm...@googlegroups.com

Hi,
you can also have a look at Geoadmin source code to see how you have to use the parameter dimensions in ol.Source.WMTS

https://github.com/geoadmin/mf-geoadmin3/blob/master/src/components/map/MapService.js

I would like to point out the fact that "pixelkarte" is freely available on localhost, but you ll need to create a WMTS account at Swisstopo if you want to deploy your solution in production.
http://www.swisstopo.admin.ch/internet/swisstopo/en/home/products/services/web_services/webaccess.html

Best Regards,
Loïc Gasser

pw.r...@gmail.com

unread,
Jul 22, 2015, 5:46:23 AM7/22/15
to geoadm...@googlegroups.com
On Saturday, 26 July 2014 11:21:32 UTC+1, Marc Monnerat wrote:
Hello Björn,

No, I think this is the right place to ask this question.

The key for REST request is to provide a template to build the tile request, which in this case will be somehting like:

'http://wmts{5-9}.geo.admin.ch/1.0.0/{Layer}/default/'+  timestamp + '/21781/' +  '{TileMatrix}/{TileRow}/{TileCol}.jpeg'

The 'TileMatrixSet' is always '21781' in our case.

Here is a codepen example. It uses OL3 provided by the geo.admin.ch API, but it's pure OL3, and it uses the latest available timestamp, as you may recognise the new map signature for the Aarau area:


To find out the latest available timestamps, look at the WMTS GetCapabilities document:



how do I request the default timestamp? This is defined in the capabilities as the latest, which is what most users are going to want. I tried various things, such as putting the word 'default' in the REST template, or leaving it blank, but these don't appear to work.

Marc Monnerat

unread,
Jul 22, 2015, 7:33:26 AM7/22/15
to geoadmin-api
Hello Björn,

We did not currently have the default keywords 'default' or 'current', as defined in the WMTS standard. You have to use an actual value for timestamp.

OpenLayers 3 is able to parse the WMTS GetCapabilities document, but if I recall correctly, the last time I did check, it has trouble with dimensions. I don't know if the situation has improved since.

Three layers which are constantly updated, ch.swisstopo.swissimage, ch.swisstopo.pixelkarte-farbe and ch.swisstopo.pixelkarte-grau, all have a timestamp set to '20151231' (last day of year). 


Regards,

Marc

--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-- Τα πάντα ῥεῖ καὶ οὐδὲν μένει

pw.r...@gmail.com

unread,
Jul 22, 2015, 8:41:59 AM7/22/15
to GeoAdmin API
On Wednesday, 22 July 2015 12:33:26 UTC+1, Marc Monnerat wrote:
We did not currently have the default keywords 'default' or 'current', as defined in the WMTS standard. You have to use an actual value for timestamp.

Thanks for the reply. 

the capabilities defines the default along with the valid values for each layer, for example for ch.swisstopo.pixelkarte-farbe:

<Dimension>
<ows:Identifier>Time</ows:Identifier>
<Default>20151231</Default>
<Value>20151231</Value>
<Value>20140520</Value>
...
</Dimension>

With KVP access, you simply leave out the dimensions parameter to get the default, but I don't know how this can be defined in your template with REST.

OpenLayers 3 is able to parse the WMTS GetCapabilities document
 
yes, but it doesn't make sense to consult the capabilities document every time you access the server just to see if there is a new timestamp value. If you can define the default in the template, then you will automatically get the latest timestamp.

Marc Monnerat

unread,
Jul 22, 2015, 9:03:00 AM7/22/15
to geoadmin-api
Hello,

If you look at:

<Dimension>
<ows:Identifier>Time</ows:Identifier>
<Default>20151231</Default>
<Value>20151231</Value>
<Value>20140520</Value>
<Value>20140106</Value>
<Value>20130903</Value>
<Value>20130213</Value>
<Value>20120809</Value>
<Value>20111206</Value>
<Value>20111027</Value>
<Value>20110401</Value>
</Dimension>

The default (or preferred value) is '20151231'. Then, to build a GetTile request using the following template:


A valid GetTile request will look like:


You can't leave out the {Time} parameter. You have to give one of the defined value (i.e. 20151231, 20140520, etc.). I know it is 100% standard compliant, but our current setting is like that.

Regards,

Marc





--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages