LV95 WMTS in Openlayers 3 - Example is not working

283 views
Skip to first unread message

marco.s...@googlemail.com

unread,
Feb 16, 2016, 6:53:38 AM2/16/16
to GeoAdmin API
hi,

I'm trying to get wmts in lv95 working in OL3.11.2.

I found two type of codes and both do not work.

first way is form the api site: https://api3.geo.admin.ch/examples/ol3_lv95.js

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 tileGrid = new ol.tilegrid.WMTS({
origin: [extent[0], extent[3]],
resolutions: RESOLUTIONS,
matrixIds: matrixIds
});


var swisstopo = new ol.layer.Tile({
source: ol.source.WMTS({
attributions: [new ol.Attribution({
html: "swisstopo"
})
],
url: "http://wmts10.geo.admin.ch/1.0.0/{Layer}/default/20140620/2056/{TileMatrix}/{TileCol}/{TileRow}.jpeg",
tileGrid: tileGrid,
projection: projection,
layer: "ch.swisstopo.swissimage",
requestEncoding: "REST"
})
});


this throws an OL Error:

Uncaught TypeError: this.resetCoordKeyPrefix_ is not a function
ol.source.WMTS@ol-debug.js:119271


secod way is from this group: https://groups.google.com/forum/#!searchin/geoadmin-api/wmts/geoadmin-api/0qOo0gV7f_w/86YlgpriXj8J

var swisstopo = new ol.layer.Tile({
source: new ol.source.WMTS({
attributions: [new ol.Attribution({
html: 'Pixelmap / geo.admin.ch</a>'
})],
urls: ['http://wmts10.geo.admin.ch/'],
layer: 'ch.swisstopo.swissimage',
matrixSet: 'EPSG:2056',
format: 'image/jpeg',
opacity: 1.0,
crossOrigin: 'anonymous',
requestEncoding: "REST",
version: '1.0.0',
dimensions: ['TIME'],
params: {'time': '20140620'},
projection: projection,
tileGrid: tileGrid,
style: 'default'
})
});


this way OL doesn't complain, but the requests don't have query-params:



Anyone can help me get this working? or any hints?
Auto Generated Inline Image 1

Loïc Gasser

unread,
Feb 16, 2016, 8:31:36 AM2/16/16
to geoadm...@googlegroups.com
Hi,

the example makes also use of http://api3.geo.admin.ch/examples/utils.js

URL of ol.source.WMTS should be

url: (getWMTSSource() + '/1.0.0/{Layer}/default/' +
            timestamp + '/2056/' +
            '{TileMatrix}/{TileCol}/{TileRow}.').replace('http:', location.protocol) + extension,

Please create a codepen or someting similar if you still have issues so that we can help you debug it.

Kind Regards,

Loïc Gasser

--
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.

marco.s...@googlemail.com

unread,
Feb 17, 2016, 5:41:09 AM2/17/16
to GeoAdmin API
Hi Loic,

thanks for your Reply. I generated a codepen. See:
https://codepen.io/anon/pen/bEJqmB?editors=1011

The codepen-example is working local on my machine, but not in codepen. There I don't have access to the requested tiles.

I solved the problem wih ol.source.TileImage. This works fine for me. And a second tiled layer overlayed looks really good.
(see image below, left side is the overlay, right side swisstopo)




So I have two questions right now:
1. why isn't the codepen example working? Will the same happen when I deploy my application to the webserver?
2. Is the way I compute the third tile-parameter ok (see code below)? I'm wondering why I have to shift a bit, to fit it with the overlaying layer?

Regards, Marco

return new ol.source.TileImage({
projection: projection,
tileUrlFunction: function(tileParams){
return "http://wmts10.geo.admin.ch/1.0.0/ch.swisstopo.swissimage/default/20140620/2056/" +
tileParams[0] + "/"+ tileParams[1] +"/" + ( ( tileParams[2] * -1) - 1 ) + ".jpeg";
},
tileGrid: tileGrid
});
Auto Generated Inline Image 1

Marc Monnerat

unread,
Feb 17, 2016, 7:34:35 AM2/17/16
to geoadmin-api
Hello Marco

I think it's better to use the 'ol.source.WMTS'. Here is a "simple" example with OL 3.11.2 (but should work with pretty all versions)


Concerning the missing WMTS tiles in codepen.io, what headers are sent with the tile requests ? 'codepen.io' is a valid referrer.


Regards,

Marc





marco.s...@googlemail.com

unread,
Feb 17, 2016, 9:31:27 AM2/17/16
to GeoAdmin API
Hi Marc,

thanks for your reply. With ol.source.WMTS I didn't get it to work. I always get the error described in the initial question. So I had to do it with ol.source.TileImage.

Below see the header from codepen.

kind regards, Marco


Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages