Skip to content

Commit

Permalink
Merge pull request #1114 from geoadmin/pb-980-single-request-getmap
Browse files Browse the repository at this point in the history
PB-980: use single OpenLayersWMSLayer for WMS group to reduce the number of GetMap request.
  • Loading branch information
ismailsunni authored Nov 11, 2024
2 parents a20fe74 + 680db1d commit bfefb64
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 150 deletions.
3 changes: 1 addition & 2 deletions src/api/features/features.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import GeoJSON from 'ol/format/GeoJSON'
import proj4 from 'proj4'

import LayerFeature from '@/api/features/LayerFeature.class'
import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class'
import ExternalLayer from '@/api/layers/ExternalLayer.class'
import ExternalWMSLayer from '@/api/layers/ExternalWMSLayer.class'
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class'
Expand Down Expand Up @@ -263,7 +262,7 @@ async function identifyOnExternalLayer(config) {
// If we use different projection, we also need to project out initial coordinate
requestedCoordinate = proj4(projection.epsg, requestProjection.epsg, coordinate)
}
if (layer instanceof ExternalWMSLayer || layer instanceof ExternalGroupOfLayers) {
if (layer instanceof ExternalWMSLayer) {
return await identifyOnExternalWmsLayer({
coordinate: requestedCoordinate,
projection: requestProjection,
Expand Down
100 changes: 0 additions & 100 deletions src/api/layers/ExternalGroupOfLayers.class.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/api/layers/ExternalWMSLayer.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default class ExternalWMSLayer extends ExternalLayer {
* Default is `true`
* @param {String} externalWmsData.baseUrl Base URL to build WMS requests (no endpoint / URL
* param defined)
* @param {ExternalWMSLayer[]} externalLayerData.layers Description of the layers being part of
* this WMS layer (they will all be displayed at the same time, in contrast to an aggregate
* layer)
* @param {String} [externalWmsData.wmsVersion='1.3.0'] WMS protocol version to be used when
* querying this server. Default is `'1.3.0'`
* @param {LayerAttribution[]} [externalWmsData.attributions=null] Description of the data
Expand Down Expand Up @@ -90,6 +93,7 @@ export default class ExternalWMSLayer extends ExternalLayer {
opacity = 1.0,
visible = true,
baseUrl = null,
layers = [],
attributions = null,
wmsVersion = '1.3.0',
format = 'png',
Expand Down Expand Up @@ -127,5 +131,6 @@ export default class ExternalWMSLayer extends ExternalLayer {
this.wmsVersion = wmsVersion
this.format = format
this.dimensions = dimensions
this.layers = [...layers]
}
}
24 changes: 4 additions & 20 deletions src/api/layers/WMSCapabilitiesParser.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { WMSCapabilities } from 'ol/format'
import proj4 from 'proj4'

import { LayerAttribution } from '@/api/layers/AbstractLayer.class'
import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class'
import { LayerLegend } from '@/api/layers/ExternalLayer.class'
import ExternalWMSLayer, { WMSDimension } from '@/api/layers/ExternalWMSLayer.class'
import { CapabilitiesError } from '@/api/layers/layers-external.api'
Expand Down Expand Up @@ -177,8 +176,7 @@ export default class WMSCapabilitiesParser {
* @param {Object | null} [params=null] URL parameters to pass to WMS server. Default is `null`
* @param {boolean} ignoreError Don't throw exception in case of error, but return a default
* value or null
* @returns {[ExternalWMSLayer | ExternalGroupOfLayers]} List of
* ExternalWMSLayer|ExternalGroupOfLayers objects
* @returns {[ExternalWMSLayer]} List of ExternalWMSLayer objects
*/
getAllExternalLayerObjects(
projection,
Expand Down Expand Up @@ -232,8 +230,9 @@ export default class WMSCapabilitiesParser {
}

// Go through the child to get valid layers
let layers = []
if (layer.Layer?.length) {
const layers = layer.Layer.map((l) =>
layers = layer.Layer.map((l) =>
this._getExternalLayerObject(
l,
[layer, ...parents],
Expand All @@ -245,29 +244,14 @@ export default class WMSCapabilitiesParser {
ignoreError
)
).filter((layer) => !!layer)
return new ExternalGroupOfLayers({
id: layerId,
name: title,
opacity,
visible,
baseUrl: url,
layers,
attributions,
abstract,
extent,
legends,
isLoading: false,
availableProjections,
getFeatureInfoCapability: this.getFeatureInfoCapability(ignoreError),
currentYear,
})
}
return new ExternalWMSLayer({
id: layerId,
name: title,
opacity,
visible,
baseUrl: url,
layers,
attributions,
wmsVersion: version,
format: 'png',
Expand Down
9 changes: 4 additions & 5 deletions src/api/layers/__tests__/WMSCapabitliesParser.class.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readFile } from 'fs/promises'
import { beforeAll, describe, expect, expectTypeOf, it } from 'vitest'

import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class'
import { LayerLegend } from '@/api/layers/ExternalLayer.class'
import ExternalWMSLayer from '@/api/layers/ExternalWMSLayer.class'
import WMSCapabilitiesParser from '@/api/layers/WMSCapabilitiesParser.class'
Expand Down Expand Up @@ -582,7 +581,7 @@ describe('EX_GeographicBoundingBox - Group of layers', () => {
let layers = capabilities.getAllExternalLayerObjects(LV95)
expect(layers.length).toBe(1)
expect(layers[0].id).toBe('ch.swisstopo-vd.official-survey')
expect(layers[0]).toBeInstanceOf(ExternalGroupOfLayers)
expect(layers[0]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers.length).toBe(3)
expect(layers[0].layers[0]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[0].id).toBe('ch.swisstopo-vd.official-survey-1')
Expand Down Expand Up @@ -646,21 +645,21 @@ describe('EX_GeographicBoundingBox - Group of layers', () => {
let layers = capabilities.getAllExternalLayerObjects(LV95)
expect(layers.length).toBe(1)
expect(layers[0].id).toBe('ch.swisstopo-vd.official-survey')
expect(layers[0]).toBeInstanceOf(ExternalGroupOfLayers)
expect(layers[0]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers.length).toBe(3)
expect(layers[0].layers[0]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[0].id).toBe('ch.swisstopo-vd.official-survey-1')

expect(layers[0].layers[1]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[1].id).toBe('ch.swisstopo-vd.official-survey-2')

expect(layers[0].layers[2]).toBeInstanceOf(ExternalGroupOfLayers)
expect(layers[0].layers[2]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[2].id).toBe('ch.swisstopo-vd.official-survey-3')

expect(layers[0].layers[2].layers[0]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[2].layers[0].id).toBe('ch.swisstopo-vd.official-survey-3-sub-1')

expect(layers[0].layers[2].layers[1]).toBeInstanceOf(ExternalGroupOfLayers)
expect(layers[0].layers[2].layers[1]).toBeInstanceOf(ExternalWMSLayer)
expect(layers[0].layers[2].layers[1].id).toBe('ch.swisstopo-vd.official-survey-3-sub-2')

expect(layers[0].layers[2].layers[1].layers[0]).toBeInstanceOf(ExternalWMSLayer)
Expand Down
3 changes: 1 addition & 2 deletions src/router/storeSync/__tests__/layersParamParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from 'chai'
import { beforeEach, describe, it } from 'vitest'

import { LayerAttribution } from '@/api/layers/AbstractLayer.class'
import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class.js'
import ExternalWMSLayer from '@/api/layers/ExternalWMSLayer.class.js'
import ExternalWMTSLayer from '@/api/layers/ExternalWMTSLayer.class.js'
import GeoAdminAggregateLayer from '@/api/layers/GeoAdminAggregateLayer.class.js'
Expand Down Expand Up @@ -323,7 +322,7 @@ describe('Testing layersParamParser', () => {
testFeaturePreSelection: true,
},
{
pristineLayer: new ExternalGroupOfLayers({
pristineLayer: new ExternalWMSLayer({
id: 'fake.external.group',
name: 'Fake external group',
baseUrl: 'https://fake.wms.url?',
Expand Down
12 changes: 2 additions & 10 deletions src/store/plugins/external-layers.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* external resources like the GetCapabilities endpoint of the external layer
*/

import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class'
import ExternalWMSLayer from '@/api/layers/ExternalWMSLayer.class'
import ExternalWMTSLayer from '@/api/layers/ExternalWMTSLayer.class'
import { readWmsCapabilities, readWmtsCapabilities } from '@/api/layers/layers-external.api'
Expand All @@ -25,9 +24,7 @@ export default function loadExternalLayerAttributes(store) {
const externalLayers = layers.filter(
(layer) =>
layer.isLoading &&
(layer instanceof ExternalWMSLayer ||
layer instanceof ExternalGroupOfLayers ||
layer instanceof ExternalWMTSLayer)
(layer instanceof ExternalWMSLayer || layer instanceof ExternalWMTSLayer)
)
if (externalLayers.length > 0) {
// We get first the capabilities
Expand Down Expand Up @@ -67,12 +64,7 @@ function getWMSCababilitiesForLayers(layers) {
// here we use a Set to take the unique URL to avoid loading multiple times the get capabilities
// for example when adding several layers from the same source.
new Set(
layers
.filter(
(layer) =>
layer instanceof ExternalWMSLayer || layer instanceof ExternalGroupOfLayers
)
.map((layer) => layer.baseUrl)
layers.filter((layer) => layer instanceof ExternalWMSLayer).map((layer) => layer.baseUrl)
).forEach((url) => {
capabilities[url] = readWmsCapabilities(url)
})
Expand Down
13 changes: 2 additions & 11 deletions tests/cypress/tests-e2e/importToolMaps.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('The Import Maps Tool', () => {

//---------------------------------------------------------------------------------
cy.log('Check that the group of layer has been added to the map')
cy.checkOlLayer([bgLayer, `${itemId}-1`, `${itemId}-2`, `${itemId}-3`])
cy.checkOlLayer([bgLayer, itemId])

//---------------------------------------------------------------------------------
cy.log('Toggle the sub layers')
Expand Down Expand Up @@ -272,16 +272,7 @@ describe('The Import Maps Tool', () => {

//---------------------------------------------------------------------------------
cy.log('Check that the single layer has been added to the map')
// NOTE here below itemId-1 should be present twice, one from the group of layer itemId and
// once as single layer
cy.checkOlLayer([
bgLayer,
`${itemId}-1`,
`${itemId}-2`,
`${itemId}-3`,
`${itemId}-1`,
singleLayerId,
])
cy.checkOlLayer([bgLayer, itemId, `${itemId}-1`, singleLayerId])

//-----------------------------------------------------------------------------------------
cy.log('Toggle import menu')
Expand Down

0 comments on commit bfefb64

Please sign in to comment.