@@ -8,6 +8,16 @@ import VectorSource from 'ol/source/Vector';
8
8
import Point from 'ol/geom/Point' ;
9
9
import SelectInteraction from 'ol/interaction/Select' ;
10
10
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
+
11
21
describe ( 'ol/Map.vue' , ( ) => {
12
22
// Inspect the raw component options
13
23
it ( 'is defined' , ( ) => {
@@ -49,11 +59,55 @@ describe('ol/Map.vue', () => {
49
59
it ( 'has correct default data' , ( ) => {
50
60
expect ( vm . zoom ) . to . equal ( undefined ) ;
51
61
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' ) ;
52
66
} ) ;
67
+ } ) ;
53
68
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' ) ;
57
111
} ) ;
58
112
} ) ;
59
113
@@ -233,4 +287,50 @@ describe('ol/Map.vue', () => {
233
287
expect ( vm . overlay . getPosition ( ) ) . to . equal ( undefined ) ;
234
288
} ) ;
235
289
} ) ;
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
+ } ) ;
236
336
} ) ;
0 commit comments