UNPKG

1.14 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.format.WMTSCapabilities');
4goog.require('ol.has');
5goog.require('ol.layer.Tile');
6goog.require('ol.source.WMTS');
7
8
9var capabilitiesUrl = 'https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml';
10
11// HiDPI support:
12// * Use 'bmaphidpi' layer (pixel ratio 2) for device pixel ratio > 1
13// * Use 'geolandbasemap' layer (pixel ratio 1) for device pixel ratio == 1
14var hiDPI = ol.has.DEVICE_PIXEL_RATIO > 1;
15var layer = hiDPI ? 'bmaphidpi' : 'geolandbasemap';
16var tilePixelRatio = hiDPI ? 2 : 1;
17
18var map = new ol.Map({
19 target: 'map',
20 view: new ol.View({
21 center: [1823849, 6143760],
22 zoom: 11
23 })
24});
25
26fetch(capabilitiesUrl).then(function(response) {
27 return response.text();
28}).then(function(text) {
29 var result = new ol.format.WMTSCapabilities().read(text);
30 var options = ol.source.WMTS.optionsFromCapabilities(result, {
31 layer: layer,
32 matrixSet: 'google3857',
33 style: 'normal'
34 });
35 options.tilePixelRatio = tilePixelRatio;
36 map.addLayer(new ol.layer.Tile({
37 source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (options))
38 }));
39});