Skip to content

Commit b5b4e89

Browse files
committed
read singleWMS option from map state instead from the config object directly, update js-unit option config test
1 parent 9117d70 commit b5b4e89

File tree

9 files changed

+114
-46
lines changed

9 files changed

+114
-46
lines changed

assets/src/modules/Config.js

-10
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class Config {
6868
this._hasFormFilterLayers = true;
6969
this._hasLoginFilteredLayers = true;
7070
this._hasDatavizConfig = true;
71-
this._singleWMSLayer = null;
7271

7372
const theConfig = deepFreeze(cfg);
7473

@@ -97,7 +96,6 @@ export class Config {
9796
}
9897
this._theConfig = theConfig;
9998
this._theWmsCapabilities = theWmsCapabilities;
100-
this._singleWMSLayer = theConfig.options?.wms_single_request_for_all_layers == "True" ? true : false;
10199

102100
const optionalConfigProperties = [
103101
'metadata',
@@ -421,12 +419,4 @@ export class Config {
421419
}
422420
return this._datavizOptions;
423421
}
424-
/**
425-
* Config singleWMSLayer
426-
*
427-
* @type {Boolean}
428-
*/
429-
get singleWMSLayer(){
430-
return this._singleWMSLayer;
431-
}
432422
}

assets/src/modules/SingleWMSLayer.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class SingleWMSLayer {
1919
*/
2020
//constructor(singleWMSLayerList) {
2121
constructor(mainMapInstance) {
22-
if (!mainLizmap.initialConfig.singleWMSLayer || !mainMapInstance || !(mainMapInstance instanceof map) || mainMapInstance.statesSingleWMSLayers.size == 0) {
22+
if (!mainLizmap.state.map.singleWMSLayer || !mainMapInstance || !(mainMapInstance instanceof map) || mainMapInstance.statesSingleWMSLayers.size == 0) {
2323
throw new ValidationError('The Configuration is not valid, could not load the map as single WMS Layer');
2424
}
2525

@@ -104,7 +104,7 @@ export default class SingleWMSLayer {
104104
* the WMS Ratio.
105105
* @type {number}
106106
*/
107-
this._WMSRatio = 1.1;
107+
this._WMSRatio = mainMapInstance._WMSRatio;
108108

109109
/**
110110
* the image format
@@ -364,5 +364,4 @@ export default class SingleWMSLayer {
364364
}
365365
})
366366
}
367-
368367
}

assets/src/modules/State.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class State extends EventDispatcher {
2525
constructor(initialCfg, startupFeatures) {
2626
super()
2727
this._initialConfig = initialCfg;
28-
this._map = new MapState(startupFeatures);
28+
this._map = new MapState(initialCfg.options, startupFeatures);
2929
this._map.addListener(this.dispatch.bind(this), 'map.state.changed');
3030
this._baseLayers = null;
3131
this._collection = null;

assets/src/modules/config/Options.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const optionalProperties = {
3232
'use_native_zoom_levels': {type: 'boolean', nullable: true, default: null},
3333
'hide_numeric_scale_value': {type: 'boolean', default: false},
3434
'hideGroupCheckbox': { type: 'boolean', default: false },
35-
'wms_single_request_for_all_layers' : { type:'string', default: false }
35+
'wms_single_request_for_all_layers' : { type:'boolean', default: false }
3636
};
3737

3838
/**
@@ -44,26 +44,26 @@ export class OptionsConfig extends BaseObjectConfig {
4444

4545
/**
4646
* Create an options config instance based on a config object
47-
* @param {object} cfg - the lizmap config object for options
48-
* @param {number[]} cfg.bbox - the project and web services max extent
49-
* @param {number[]} cfg.initialExtent - the map extent at the loading page
50-
* @param {number[]} cfg.mapScales - the map scales
51-
* @param {number} cfg.minScale - the map's min scale
52-
* @param {number} cfg.maxScale - the map's max scale
53-
* @param {object} cfg.projection - the web map projection
54-
* @param {number} cfg.pointTolerance - the point tolerance for QGIS Server WMS GetFeatureInfo request
55-
* @param {number} cfg.lineTolerance - the line tolerance for QGIS Server WMS GetFeatureInfo request
56-
* @param {number} cfg.polygonTolerance - the polygon tolerance for QGIS Server WMS GetFeatureInfo request
57-
* @param {string} cfg.popupLocation - the popup location in the User interface: dock, bottom-dock, right-dock, mini-dock, map
58-
* @param {string} cfg.datavizLocation - the popup location in the User interface: dock, bottom-dock, right-dock
59-
* @param {boolean} [cfg.hideProject] - is the project hidden in user interface ? Only services are available.
60-
* @param {number} [cfg.wmsMaxHeight] - the image max height for WMS GetMap request
61-
* @param {number} [cfg.wmsMaxWidth] - the image max width for WMS GetMap request
62-
* @param {boolean} [cfg.fixed_scale_overview_map] - does the Overview map have fixed scale ?
63-
* @param {boolean} [cfg.use_native_zoom_levels] - does the map use native zoom levels ?
64-
* @param {boolean} [cfg.hide_numeric_scale_value] - does the scale line hide numeric scale value ?
65-
* @param {boolean} [cfg.hideGroupCheckbox] - are groups checkbox hidden ?
66-
* @param {string} [cfg.wms_single_request_for_all_layers] - are layers loaded as single WMS image ?
47+
* @param {object} cfg - the lizmap config object for options
48+
* @param {number[]} cfg.bbox - the project and web services max extent
49+
* @param {number[]} cfg.initialExtent - the map extent at the loading page
50+
* @param {number[]} cfg.mapScales - the map scales
51+
* @param {number} cfg.minScale - the map's min scale
52+
* @param {number} cfg.maxScale - the map's max scale
53+
* @param {object} cfg.projection - the web map projection
54+
* @param {number} cfg.pointTolerance - the point tolerance for QGIS Server WMS GetFeatureInfo request
55+
* @param {number} cfg.lineTolerance - the line tolerance for QGIS Server WMS GetFeatureInfo request
56+
* @param {number} cfg.polygonTolerance - the polygon tolerance for QGIS Server WMS GetFeatureInfo request
57+
* @param {string} cfg.popupLocation - the popup location in the User interface: dock, bottom-dock, right-dock, mini-dock, map
58+
* @param {string} cfg.datavizLocation - the popup location in the User interface: dock, bottom-dock, right-dock
59+
* @param {boolean} [cfg.hideProject] - is the project hidden in user interface ? Only services are available.
60+
* @param {number} [cfg.wmsMaxHeight] - the image max height for WMS GetMap request
61+
* @param {number} [cfg.wmsMaxWidth] - the image max width for WMS GetMap request
62+
* @param {boolean} [cfg.fixed_scale_overview_map] - does the Overview map have fixed scale ?
63+
* @param {boolean} [cfg.use_native_zoom_levels] - does the map use native zoom levels ?
64+
* @param {boolean} [cfg.hide_numeric_scale_value] - does the scale line hide numeric scale value ?
65+
* @param {boolean} [cfg.hideGroupCheckbox] - are groups checkbox hidden ?
66+
* @param {boolean} [cfg.wms_single_request_for_all_layers] - are layers loaded as single WMS image ?
6767
*/
6868
constructor(cfg) {
6969
if (!cfg || typeof cfg !== "object") {
@@ -239,7 +239,7 @@ export class OptionsConfig extends BaseObjectConfig {
239239

240240
/**
241241
* The layers are loaded as a single WMS image
242-
* @type {string}
242+
* @type {boolean}
243243
*/
244244
get wms_single_request_for_all_layers() {
245245
return this._wms_single_request_for_all_layers;

assets/src/modules/map.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import DragZoom from 'ol/interaction/DragZoom.js';
3535
import { defaults as defaultInteractions } from 'ol/interaction.js';
3636
import { always } from 'ol/events/condition.js';
3737
import SingleWMSLayer from './SingleWMSLayer.js';
38+
import { Tile } from 'ol';
3839

3940
/**
4041
* Class initializing Openlayers Map.
@@ -136,7 +137,6 @@ export default class map extends olMap {
136137
// Get pixel ratio, if High DPI is disabled do not use device pixel ratio
137138
const pixelRatio = this._hidpi ? this.pixelRatio_ : 1;
138139

139-
this._useTileWms = this.getSize().reduce(
140140
this._useTileWms = this.getSize().reduce(
141141
(r /*accumulator*/, x /*currentValue*/, i /*currentIndex*/) => r || Math.ceil(x*this._WMSRatio*pixelRatio) > wmsMaxSize[i],
142142
false,
@@ -243,7 +243,7 @@ export default class map extends olMap {
243243
});
244244
}
245245
} else {
246-
if(mainLizmap.initialConfig.singleWMSLayer){
246+
if(mainLizmap.state.map.singleWMSLayer){
247247
this._statesSingleWMSLayers.set(node.name,node);
248248
node.singleWMSLayer = true;
249249
return
@@ -461,7 +461,7 @@ export default class map extends olMap {
461461
source: new WMTS(options)
462462
});
463463
} else {
464-
if(mainLizmap.initialConfig.singleWMSLayer){
464+
if(mainLizmap.state.map.singleWMSLayer){
465465
baseLayerState.singleWMSLayer = true;
466466
this._statesSingleWMSLayers.set(baseLayerState.name, baseLayerState);
467467
} else {
@@ -749,19 +749,31 @@ export default class map extends olMap {
749749
get overlayLayersGroup(){
750750
return this._overlayLayersGroup;
751751
}
752-
752+
/**
753+
* Key (name) / value (state) Map of layers loaded in a single WMS image
754+
* @type {Map}
755+
*/
753756
get statesSingleWMSLayers(){
754757
return this._statesSingleWMSLayers;
755758
}
756-
759+
/**
760+
* Map and base Layers are loaded as TileWMS
761+
* @type {Boolean}
762+
*/
757763
get useTileWms(){
758764
return this._useTileWms;
759765
}
760-
766+
/**
767+
* TileGrid configuration when layers is loaded as TileWMS
768+
* @type {null|TileGrid}
769+
*/
761770
get customTileGrid(){
762771
return this._customTileGrid;
763772
}
764-
773+
/**
774+
* WMS/TileWMS high dpi support
775+
* @type {Boolean}
776+
*/
765777
get hidpi(){
766778
return this._hidpi;
767779
}

assets/src/modules/state/BaseLayer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ export class BaseLayerState extends EventDispatcher {
3535
}
3636

3737
/**
38-
* set if the base layer is loaded in a single layer ImageLayer or not
38+
* Set if the base layer is loaded in a single WMS Layer or not
3939
* @param {boolean} val
4040
*/
4141
set singleWMSLayer(val){
4242
this._singleWMSLayer = val;
4343
}
4444
/**
45+
* The base layer is loaded in a single WMS Layer or not
4546
* @type {boolean}
4647
*/
4748
get singleWMSLayer(){

assets/src/modules/state/Map.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ export class MapState extends EventDispatcher {
5454

5555
/**
5656
* Creating the map state
57+
* @param {OptionConfig} [options] - main configuration options
5758
* @param {string|undefined} [startupFeatures] - The features to highlight at startup in GeoJSON
5859
*/
59-
constructor(startupFeatures) {
60+
constructor(options, startupFeatures) {
6061
super();
6162
this._ready = false;
6263
// default values
@@ -68,6 +69,13 @@ export class MapState extends EventDispatcher {
6869
this._scaleDenominator = -1;
6970
this._pointResolution = -1;
7071
this._pointScaleDenominator = -1;
72+
73+
// Values from options
74+
this._singleWMSLayer = false;
75+
if (options) {
76+
this._singleWMSLayer = options.wms_single_request_for_all_layers; // default value is defined as false
77+
}
78+
7179
this._startupFeatures = startupFeatures;
7280
}
7381

@@ -234,4 +242,13 @@ export class MapState extends EventDispatcher {
234242
get startupFeatures() {
235243
return this._startupFeatures;
236244
}
245+
246+
/**
247+
* Config singleWMSLayer
248+
*
249+
* @type {Boolean}
250+
*/
251+
get singleWMSLayer(){
252+
return this._singleWMSLayer;
253+
}
237254
}

tests/js-units/node/config.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('Config', function () {
140140
const initialConfig = new Config(config, capabilities);
141141

142142
expect(initialConfig.options).to.be.instanceOf(OptionsConfig)
143-
expect(initialConfig.options.wms_single_request_for_all_layers).to.be.eq("True")
143+
expect(initialConfig.options.wms_single_request_for_all_layers).to.be.eq(true)
144144
})
145145

146146
})

tests/js-units/node/config/options.test.js

+49
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ describe('OptionsConfig', function () {
7474
expect(opt.hideGroupCheckbox).to.be.eq(false)
7575
// Default value for multiple mapScales without use_native_zoom_levels defined
7676
expect(opt.use_native_zoom_levels).to.be.eq(false)
77+
// Default value for singleWMS option is false (option wms_single_request_for_all_layers not defined)
78+
expect(opt.wms_single_request_for_all_layers).to.be.eq(false)
7779
})
7880

7981
it('use_native_zoom_levels', function () {
@@ -171,6 +173,53 @@ describe('OptionsConfig', function () {
171173
expect(opt.use_native_zoom_levels).to.be.eq(true)
172174
})
173175

176+
it('wms_single_request_for_all_layers', function () {
177+
let opt = new OptionsConfig({
178+
"projection": {
179+
"proj4": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs",
180+
"ref": "EPSG:3857"
181+
},
182+
"bbox": [
183+
"414463.27939999999944121",
184+
"5394742.82330000028014183",
185+
"452853.33649999997578561",
186+
"5416679.9988000001758337"
187+
],
188+
"mapScales": [
189+
1,
190+
1000000000
191+
],
192+
"minScale": 1,
193+
"maxScale": 1000000000,
194+
"use_native_zoom_levels": true,
195+
"hide_numeric_scale_value": true,
196+
"initialExtent": [
197+
414463.2794,
198+
5394742.8233,
199+
452853.3365,
200+
5416679.9988
201+
],
202+
"popupLocation": "dock",
203+
"draw": "True",
204+
"measure": "True",
205+
"zoomHistory": "True",
206+
"pointTolerance": 25,
207+
"lineTolerance": 10,
208+
"polygonTolerance": 5,
209+
"wms_single_request_for_all_layers": "True",
210+
"tmTimeFrameSize": 10,
211+
"tmTimeFrameType": "seconds",
212+
"tmAnimationFrameLength": 1000,
213+
"datavizLocation": "dock",
214+
"theme": "dark",
215+
"fixed_scale_overview_map": true,
216+
"dataviz_drag_drop": []
217+
})
218+
219+
// Load layers as a single WMS image
220+
expect(opt.wms_single_request_for_all_layers).to.be.eq(true)
221+
})
222+
174223
it('ValidationError', function () {
175224
try {
176225
new OptionsConfig()

0 commit comments

Comments
 (0)