Skip to content

Commit 12ccf52

Browse files
committed
wegue-oss#124 TileGrid support - Dutch Tilegrid WMTS example - Unit tests
1 parent 2bbb63c commit 12ccf52

File tree

5 files changed

+148
-246
lines changed

5 files changed

+148
-246
lines changed

src/components/ol/Map.vue

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SelectInteraction from 'ol/interaction/Select';
1111
import {defaults as defaultInteractions} from 'ol/interaction';
1212
import RotateControl from 'ol/control/Rotate';
1313
import Projection from 'ol/proj/Projection';
14+
import TileGrid from 'ol/tilegrid/TileGrid';
1415
import {register as olproj4} from 'ol/proj/proj4';
1516
import proj4 from 'proj4'
1617
import Overlay from 'ol/Overlay';
@@ -31,7 +32,9 @@ export default {
3132
zoom: this.$appConfig.mapZoom,
3233
center: this.$appConfig.mapCenter,
3334
projection: this.$appConfig.mapProjection,
34-
projectionDefs: this.$appConfig.projectionDefs
35+
projectionDefs: this.$appConfig.projectionDefs,
36+
tileGridDefs: this.$appConfig.tileGridDefs || {},
37+
tileGrids: {}
3538
}
3639
},
3740
mounted () {
@@ -87,6 +90,11 @@ export default {
8790
}
8891
const projection = new Projection(me.projection);
8992
93+
// Optional TileGrid definitions by name, for ref in Layers
94+
Object.keys(me.tileGridDefs).map(name => {
95+
me.tileGrids[name] = new TileGrid(me.tileGridDefs[name]);
96+
});
97+
9098
me.map = new Map({
9199
layers: [],
92100
controls: controls,
@@ -114,6 +122,9 @@ export default {
114122
const appConfig = this.$appConfig;
115123
const mapLayersConfig = appConfig.mapLayers || [];
116124
mapLayersConfig.reverse().forEach(function (lConf) {
125+
// Some Layers may require a TileGrid object
126+
lConf.tileGrid = lConf.tileGridRef ? me.tileGrids[lConf.tileGridRef] : null;
127+
117128
let layer = LayerFactory.getInstance(lConf);
118129
layers.push(layer);
119130

src/factory/Layer.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export const LayerFactory = {
7979
'TILED': lConf.tiled
8080
},
8181
serverType: lConf.serverType,
82-
attributions: lConf.attributions
82+
attributions: lConf.attributions,
83+
tileGrid: lConf.tileGrid,
84+
projection: lConf.projection
8385
})
8486
});
8587

@@ -101,7 +103,9 @@ export const LayerFactory = {
101103
opacity: lConf.opacity,
102104
source: new XyzSource({
103105
url: lConf.url,
104-
attributions: lConf.attributions
106+
attributions: lConf.attributions,
107+
tileGrid: lConf.tileGrid,
108+
projection: lConf.projection
105109
})
106110
});
107111

@@ -170,7 +174,9 @@ export const LayerFactory = {
170174
source: new VectorTileSource({
171175
url: lConf.url,
172176
format: new this.formatMapping[lConf.format](),
173-
attributions: lConf.attributions
177+
attributions: lConf.attributions,
178+
tileGrid: lConf.tileGrid,
179+
projection: lConf.projection
174180
}),
175181
style: OlStyleFactory.getInstance(lConf.style),
176182
hoverable: lConf.hoverable,

static/app-conf-projected.json

+24-3
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@
2727
]
2828
],
2929

30+
"tileGridDefs": {
31+
"dutch_rd": {
32+
"extent": [-285401.920, 22598.080, 595401.920, 903401.920],
33+
"resolutions": [3440.640, 1720.320, 860.160, 430.080, 215.040, 107.520, 53.760, 26.880, 13.440, 6.720, 3.360, 1.680, 0.840, 0.420, 0.210],
34+
"tileSize": [256, 256]
35+
}
36+
},
37+
3038
"mapLayers": [
3139
{
3240
"type": "WMS",
3341
"lid": "pdok-natura2000-wms",
34-
"name": "WMS (Natura 2000 Areas PDOK)",
42+
"name": "WMS - Natura 2000 Areas - PDOK",
3543
"format": "image/png",
3644
"layers": "natura2000",
3745
"url": "https://geodata.nationaalgeoregister.nl/natura2000/wms",
3846
"transparent": true,
3947
"singleTile": false,
4048
"projection": "EPSG:28992",
49+
"tileGridRef": "dutch_rd",
4150
"attributions": "<a href='https://www.pdok.nl' target='_blank'>PDOK</a> by Dutch Kadaster",
4251
"isBaseLayer": false,
4352
"visible": false,
@@ -46,17 +55,29 @@
4655
{
4756
"type": "WMS",
4857
"lid": "pdok-lufo-wms",
49-
"name": "WMS (Dutch Arial Map PDOK)",
58+
"name": "WMS - Dutch Arial Map - PDOK",
5059
"format": "image/jpeg",
5160
"layers": "2018_ortho25",
5261
"url": "http://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms",
5362
"transparent": false,
5463
"singleTile": false,
5564
"projection": "EPSG:28992",
65+
"tileGridRef": "dutch_rd",
5666
"attributions": "<a href='https://www.pdok.nl' target='_blank'>PDOK</a> by Dutch Kadaster",
5767
"isBaseLayer": true,
58-
"visible": true,
68+
"visible": false,
5969
"displayInLayerList": true
70+
},
71+
{
72+
"type": "XYZ",
73+
"lid": "brtachtergrondkaart",
74+
"name": "WMTS - Topo Basemap - PDOK",
75+
"url": "https://geodata.nationaalgeoregister.nl/tiles/service/wmts/brtachtergrondkaart/EPSG:28992/{z}/{x}/{y}.png",
76+
"attributions": "<a href='https://www.pdok.nl' target='_blank'>PDOK</a> by Dutch Kadaster",
77+
"projection": "EPSG:28992",
78+
"tileGridRef": "dutch_rd",
79+
"displayInLayerList": true,
80+
"visible": true
6081
}
6182
],
6283

test/unit/specs/components/ol/Map.spec.js

+103-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import VectorSource from 'ol/source/Vector';
88
import Point from 'ol/geom/Point';
99
import SelectInteraction from 'ol/interaction/Select';
1010

11+
// Used several times, so make const
12+
const epsg28992Extent = [-285401.920, 22598.080, 595401.920, 903401.920];
13+
const tileGridDefs = {
14+
'dutch_rd': {
15+
'extent': epsg28992Extent,
16+
'resolutions': [3440.640, 1720.320, 860.160, 430.080, 215.040, 107.520, 53.760, 26.880, 13.440, 6.720, 3.360, 1.680, 0.840, 0.420, 0.210],
17+
'tileSize': [256, 256]
18+
}
19+
};
20+
1121
describe('ol/Map.vue', () => {
1222
// Inspect the raw component options
1323
it('is defined', () => {
@@ -49,11 +59,55 @@ describe('ol/Map.vue', () => {
4959
it('has correct default data', () => {
5060
expect(vm.zoom).to.equal(undefined);
5161
expect(vm.center).to.equal(undefined);
62+
expect(vm.tileGridDefs).to.be.empty;
63+
expect(vm.tileGrids).to.be.empty;
64+
expect(vm.projection).to.deep.equal({code: 'EPSG:3857', units: 'm'});
65+
expect(vm.map.getView().getProjection().getCode()).to.equal('EPSG:3857');
5266
});
67+
});
5368

54-
it('has correct default data', () => {
55-
expect(vm.zoom).to.equal(undefined);
56-
expect(vm.center).to.equal(undefined);
69+
describe('data - TileGrid Definitions', () => {
70+
let comp;
71+
let vm;
72+
beforeEach(() => {
73+
Vue.prototype.$appConfig = { tileGridDefs: tileGridDefs };
74+
comp = shallowMount(Map);
75+
vm = comp.vm;
76+
});
77+
78+
it('has instantiated TileGridDefs', () => {
79+
expect(vm.tileGridDefs).to.not.be.empty;
80+
expect(vm.tileGrids).to.not.be.empty;
81+
expect(vm.tileGridDefs['dutch_rd']).to.deep.equal(tileGridDefs['dutch_rd']);
82+
expect(vm.tileGrids['dutch_rd']).to.not.be.empty;
83+
});
84+
});
85+
86+
describe('data - Projection Definitions', () => {
87+
let comp;
88+
let vm;
89+
beforeEach(() => {
90+
Vue.prototype.$appConfig = {
91+
mapProjection: {
92+
'code': 'EPSG:28992',
93+
'units': 'm',
94+
'extent': epsg28992Extent
95+
},
96+
projectionDefs: [
97+
['EPSG:28992', '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs']
98+
]
99+
};
100+
comp = shallowMount(Map);
101+
vm = comp.vm;
102+
});
103+
104+
it('has instantiated Projection for Map View', () => {
105+
expect(vm.projectionDefs).to.not.be.empty;
106+
expect(vm.projection).to.not.be.empty;
107+
108+
const mapProjection = vm.map.getView().getProjection();
109+
expect(mapProjection).to.not.be.empty;
110+
expect(mapProjection.getCode()).to.equal('EPSG:28992');
57111
});
58112
});
59113

@@ -233,4 +287,50 @@ describe('ol/Map.vue', () => {
233287
expect(vm.overlay.getPosition()).to.equal(undefined);
234288
});
235289
});
290+
291+
describe('methods - TileGrids and Projections', () => {
292+
let comp;
293+
let vm;
294+
beforeEach(() => {
295+
Vue.prototype.$appConfig = {
296+
mapZoom: 3,
297+
mapCenter: [155000, 463000],
298+
mapProjection: {
299+
'code': 'EPSG:28992',
300+
'units': 'm',
301+
'extent': epsg28992Extent
302+
},
303+
projectionDefs: [
304+
['EPSG:28992', '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs']
305+
],
306+
tileGridDefs: tileGridDefs,
307+
mapLayers: [{
308+
'type': 'XYZ',
309+
'lid': 'brtachtergrondkaart',
310+
'name': 'BRTAchtergrondKaart',
311+
'url': 'https://geodata.nationaalgeoregister.nl/tiles/service/wmts/brtachtergrondkaart/EPSG:28992/{z}/{x}/{y}.png',
312+
'attributions': '<a href="https://www.pdok.nl" target="_blank">PDOK</a> by Dutch Kadaster',
313+
'projection': 'EPSG:28992',
314+
'tileGridRef': 'dutch_rd',
315+
'displayInLayerList': true,
316+
'visible': true
317+
}]
318+
};
319+
comp = shallowMount(Map);
320+
vm = comp.vm;
321+
});
322+
323+
it('createLayers assigns TileGrid to Layer Sources', () => {
324+
const layers = vm.createLayers();
325+
const tileGrid = layers[0].getSource().getTileGrid();
326+
expect(tileGrid).to.be.not.empty;
327+
expect(tileGrid.getResolutions()[0]).to.equal(3440.640);
328+
});
329+
330+
it('createLayers assigns Projection to Layer Sources', () => {
331+
const layers = vm.createLayers();
332+
const source = layers[0].getSource();
333+
expect(source.getProjection().getCode()).to.equal('EPSG:28992');
334+
});
335+
});
236336
});

0 commit comments

Comments
 (0)