From 10d02fdb0e3ee301210a1ab8ea89bbd8fd4bddff Mon Sep 17 00:00:00 2001 From: sronveaux Date: Thu, 7 Sep 2023 11:58:03 +0200 Subject: [PATCH 1/3] Added custom layer properties support inside Map component --- src/components/ol/Map.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/ol/Map.vue b/src/components/ol/Map.vue index 2ee18ed6..99cdaa40 100644 --- a/src/components/ol/Map.vue +++ b/src/components/ol/Map.vue @@ -197,6 +197,7 @@ export default { const layers = []; const appConfig = this.$appConfig; const mapLayersConfig = appConfig.mapLayers || []; + const customLayerProperties = appConfig.customLayerProperties || []; mapLayersConfig.reverse().forEach(function (lConf) { // Some Layers may require a TileGrid object // Remarks: Passing null instead of undefined as parameters into the @@ -211,6 +212,7 @@ export default { lConf.supportsPermalink = lConf.supportsPermalink ?? true; const layer = LayerFactory.getInstance(lConf, me.map); + me.addCustomLayerProperties(layer, lConf, customLayerProperties) layers.push(layer); // if layer is selectable register a select interaction @@ -228,6 +230,18 @@ export default { return layers; }, + /** + * Adds properties listed in the "customLayerProperties" array in app config to the layer. + * They are added only if defined in the layer configuration. + */ + addCustomLayerProperties (layer, lConf, customProperties) { + for (const property of customProperties) { + if (lConf[property]) { + layer.set(property, lConf[property]) + } + } + }, + /** * Hook up events to process newly added and modified OL layers. * This is currently used to update locale specific layer properties. From c9efa20b7116c14a4fc09f166946d66ae36731b5 Mon Sep 17 00:00:00 2001 From: sronveaux Date: Thu, 7 Sep 2023 12:04:54 +0200 Subject: [PATCH 2/3] Added unit tests for custom layer properties --- tests/unit/specs/components/ol/Map.spec.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/unit/specs/components/ol/Map.spec.js b/tests/unit/specs/components/ol/Map.spec.js index 5a2d5e61..fc8078a1 100644 --- a/tests/unit/specs/components/ol/Map.spec.js +++ b/tests/unit/specs/components/ol/Map.spec.js @@ -160,8 +160,11 @@ describe('ol/Map.vue', () => { isBaseLayer: false, visible: true, selectable: true, - displayInLayerList: true - }] + displayInLayerList: true, + customProp: true, + otherCustomProp: true + }], + customLayerProperties: ['customProp'] }; comp = mount(Map, { vuetify }); vm = comp.vm; @@ -184,6 +187,16 @@ describe('ol/Map.vue', () => { expect(typeof selectIa).to.not.equal('undefined'); }); + it('createLayers adds customLayerProperties if configured', () => { + const layers = vm.createLayers(); + expect(layers[0].get('customProp')).to.be.true + }); + + it('createLayers ignores non configured layer properties', () => { + const layers = vm.createLayers(); + expect(layers[0].get('otherCustomProp')).to.be.undefined + }); + it('setOlButtonColor applies Vuetify color to OL buttons', () => { // mock a OL zoom button const mockZoomDiv = document.createElement('div'); From a0078c14242bf29ef025e161f46acd84c8e72f46 Mon Sep 17 00:00:00 2001 From: sronveaux Date: Thu, 7 Sep 2023 12:05:39 +0200 Subject: [PATCH 3/3] Added documentation for custom layer properties --- docs/map-layer-configuration.md | 2 ++ docs/wegue-configuration.md | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/map-layer-configuration.md b/docs/map-layer-configuration.md index 3b460b4a..0d85a7ea 100644 --- a/docs/map-layer-configuration.md +++ b/docs/map-layer-configuration.md @@ -25,6 +25,8 @@ The following properties can be applied to all map layer types | legendUrl | URL to a legend image. This value is required to produce a legend, if the layer is not a WMS layer. The URL may contain format placeholders corresponding to the parameters `language`, `scale` or any of the additional options given among `legendOptions`. A placeholder is delimited by `{{` and `}}` – i.e. `{{VAR_NAME}}`. | `"legendUrl": "static/icon/my-layer-legend-{{LANGUAGE}}.png"` | legendOptions | An object, containing additional parameters to request the legend image. Supported options may be vendor specific, e.g. see [GeoServer Docs](https://docs.geoserver.org/latest/en/user/services/wms/get_legend_graphic/index.html) for the options supported for WMS layers in GeoServer. | `"legendOptions": {"transparent": true, "width": 14 }` +All map layer types can also make use of the properties listed in `customLayerProperties` in the main Wegue application configuration object. This is useful if specific configuration is needed on all layers by a custom module. See [Wegue configuration](wegue-configuration?id=general) for more details. + ## OSM diff --git a/docs/wegue-configuration.md b/docs/wegue-configuration.md index cce40eaf..c2282860 100644 --- a/docs/wegue-configuration.md +++ b/docs/wegue-configuration.md @@ -28,6 +28,7 @@ This describes the Wegue application configuration, which is modelled as JSON do | viewAnimation | Configuration object for view animations | See [viewAnimation](wegue-configuration?id=viewAnimation) | | sidebar | Configuration object for the application sidebar. | See [sidebar](wegue-configuration?id=sidebar) | | legend | Configuration object containing application wide parameters for layer legends. | See [legend](wegue-configuration?id=legend) | +| customLayerProperties | Array of custom property names that can be defined inside `mapLayers`. Properties which are not known by `Wegue` are silently discarded when layers are created. See [mapLayers](map-layer-configuration?id=general) for more information. | `["myCustomProperty", "anotherCustomProperty"]` | ### colorTheme