UNPKG

1.92 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.extent');
4goog.require('ol.layer.Tile');
5goog.require('ol.proj');
6goog.require('ol.source.OSM');
7goog.require('ol.source.WMTS');
8goog.require('ol.tilegrid.WMTS');
9
10
11// create the WMTS tile grid in the google projection
12var projection = ol.proj.get('EPSG:3857');
13var tileSizePixels = 256;
14var tileSizeMtrs = ol.extent.getWidth(projection.getExtent()) / tileSizePixels;
15var matrixIds = [];
16var resolutions = [];
17for (var i = 0; i <= 14; i++) {
18 matrixIds[i] = i;
19 resolutions[i] = tileSizeMtrs / Math.pow(2, i);
20}
21var tileGrid = new ol.tilegrid.WMTS({
22 origin: ol.extent.getTopLeft(projection.getExtent()),
23 resolutions: resolutions,
24 matrixIds: matrixIds
25});
26
27var scalgoToken = 'CC5BF28A7D96B320C7DFBFD1236B5BEB';
28
29var wmtsSource = new ol.source.WMTS({
30 url: 'http://ts2.scalgo.com/olpatch/wmts?token=' + scalgoToken,
31 layer: 'SRTM_4_1:SRTM_4_1_flooded_sealevels',
32 format: 'image/png',
33 matrixSet: 'EPSG:3857',
34 attributions: [
35 '<a href="http://scalgo.com">SCALGO</a>',
36 '<a href="http://www.cgiar-csi.org/data/' +
37 'srtm-90m-digital-elevation-database-v4-1">CGIAR-CSI SRTM</a>'
38 ],
39 tileGrid: tileGrid,
40 style: 'default',
41 dimensions: {
42 'threshold': 100
43 }
44});
45
46var map = new ol.Map({
47 target: 'map',
48 view: new ol.View({
49 projection: projection,
50 center: [-9871995, 3566245],
51 zoom: 6
52 }),
53 layers: [
54 new ol.layer.Tile({
55 source: new ol.source.OSM()
56 }),
57 new ol.layer.Tile({
58 opacity: 0.5,
59 source: wmtsSource
60 })
61 ]
62});
63
64var updateSourceDimension = function(source, sliderVal) {
65 source.updateDimensions({'threshold': sliderVal});
66 document.getElementById('theinfo').innerHTML = sliderVal + ' meters';
67};
68
69updateSourceDimension(wmtsSource, 10);
70
71document.getElementById('slider').addEventListener('input', function() {
72 updateSourceDimension(wmtsSource, this.value);
73});