From 79b504f853a7b17a72bff08da69cbb6475e2b0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= <7397743+pelord@users.noreply.github.com> Date: Thu, 18 Feb 2021 14:44:26 -0500 Subject: [PATCH] feat(portal) refactor method to add layers by url (#587) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(portal) refactor method to add layers by url * lint * refactor(*) modified url * Update portal.component.ts Co-authored-by: Pierre-Étienne Lord Co-authored-by: Marc-André Barbeau --- docs/config_json.rst | 2 +- src/app/pages/portal/portal.component.ts | 202 +++++++++++------------ src/contexts/layerSync.json | 10 +- src/contexts/ogcFilters.json | 4 +- src/contexts/testExport.json | 2 +- src/contexts/variousFormats.json | 6 +- src/contexts/workspace.json | 10 +- src/environments/environment.ts | 8 +- 8 files changed, 116 insertions(+), 128 deletions(-) diff --git a/docs/config_json.rst b/docs/config_json.rst index dd68cef10..a7b970d20 100644 --- a/docs/config_json.rst +++ b/docs/config_json.rst @@ -406,7 +406,7 @@ Exemples "composite": [ { "id": "tq_swtq", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "regFilters": ["zpegt"], "groupImpose": {"id": "zpegt", "title": "zpegt"} }, diff --git a/src/app/pages/portal/portal.component.ts b/src/app/pages/portal/portal.component.ts index b077a589e..77c64608a 100644 --- a/src/app/pages/portal/portal.component.ts +++ b/src/app/pages/portal/portal.component.ts @@ -51,10 +51,6 @@ import { CapabilitiesService, sourceCanSearch, sourceCanReverseSearch, - generateWMSIdFromSourceOptions, - generateWMTSIdFromSourceOptions, - WMSDataSourceOptions, - WMTSDataSourceOptions, FEATURE, ImportService, handleFileImportError, @@ -62,7 +58,8 @@ import { featureFromOl, QueryService, WfsWorkspace, - FeatureWorkspace + FeatureWorkspace, + generateIdFromSourceOptions } from '@igo2/geo'; import { @@ -88,6 +85,7 @@ import { HttpClient } from '@angular/common/http'; import { WelcomeWindowComponent } from './welcome-window/welcome-window.component'; import { WelcomeWindowService } from './welcome-window/welcome-window.service'; import { MatPaginator } from '@angular/material/paginator'; +import { ObjectUtils } from '@igo2/utils'; @Component({ selector: 'app-portal', @@ -980,72 +978,80 @@ export class PortalComponent implements OnInit, OnDestroy { } private readLayersQueryParams(params: Params) { - this.readLayersQueryParamsWMS(params); - this.readLayersQueryParamsWMTS(params); + this.readLayersQueryParamsByType(params, 'wms'); + this.readLayersQueryParamsByType(params, 'wmts'); + this.readLayersQueryParamsByType(params, 'arcgisrest'); + this.readLayersQueryParamsByType(params, 'imagearcgisrest'); + this.readLayersQueryParamsByType(params, 'tilearcgisrest'); this.readVectorQueryParams(params); } - private readLayersQueryParamsWMS(params: Params) { - if ((params['layers'] || params['wmsLayers']) && params['wmsUrl']) { - const nameParamLayers = params['wmsLayers'] ? 'wmsLayers' : 'layers'; // for maintain compatibility - const layersByService = params[nameParamLayers].split('),('); - const urls = params['wmsUrl'].split(','); - let cnt = 0; - urls.forEach((url) => { - const currentLayersByService = this.extractLayersByService( - layersByService[cnt] - ); - currentLayersByService.forEach((layer) => { - const layerFromUrl = layer.split(':igoz'); - const layerOptions = { - url: url, - params: { LAYERS: layerFromUrl[0] } - }; - const id = generateWMSIdFromSourceOptions( - layerOptions as WMSDataSourceOptions - ); - const visibility = this.computeLayerVisibilityFromUrl(params, id); - this.addWmsLayerByName( - url, - layerFromUrl[0], - visibility, - parseInt(layerFromUrl[1] || 1000, 10) - ); - }); - cnt += 1; - }); + private readLayersQueryParamsByType(params: Params, type) { + let nameParamLayersKey; + let urlsKey; + switch (type) { + case 'wms': + if ((params['layers'] || params['wmsLayers']) && params['wmsUrl']) { + urlsKey = 'wmsUrl'; + nameParamLayersKey = params['wmsLayers'] ? 'wmsLayers' : 'layers'; // for maintain compatibility + } + break; + case 'wmts': + if (params['wmtsLayers'] && params['wmtsUrl']) { + urlsKey = 'wmtsUrl'; + nameParamLayersKey = 'wmtsLayers'; + } + break; + case 'arcgisrest': + if (params['arcgisLayers'] && params['arcgisUrl']) { + urlsKey = 'arcgisUrl'; + nameParamLayersKey = 'arcgisLayers'; + } + break; + case 'imagearcgisrest': + if (params['iarcgisLayers'] && params['iarcgisUrl']) { + urlsKey = 'iarcgisUrl'; + nameParamLayersKey = 'iarcgisLayers'; + } + break; + case 'tilearcgisrest': + if (params['tarcgisLayers'] && params['tarcgisUrl']) { + urlsKey = 'tarcgisUrl'; + nameParamLayersKey = 'tarcgisLayers'; + } + break; } - } + if (!nameParamLayersKey || !urlsKey) { + return; + } + const layersByService = params[nameParamLayersKey].split('),('); + const urls = params[urlsKey].split(','); - private readLayersQueryParamsWMTS(params: Params) { - if (params['wmtsLayers'] && params['wmtsUrl']) { - const layersByService = params['wmtsLayers'].split('),('); - const urls = params['wmtsUrl'].split(','); - let cnt = 0; - urls.forEach((url) => { - const currentLayersByService = this.extractLayersByService( - layersByService[cnt] - ); - currentLayersByService.forEach((layer) => { - const layerFromUrl = layer.split(':igoz'); - const layerOptions = { - url: url, - layer: layerFromUrl[0] - }; - const id = generateWMTSIdFromSourceOptions( - layerOptions as WMTSDataSourceOptions - ); - const visibility = this.computeLayerVisibilityFromUrl(params, id); - this.addWmtsLayerByName( - url, - layerFromUrl[0], - visibility, - parseInt(layerFromUrl[1] || 1000, 10) - ); + let cnt = 0; + urls.forEach((url) => { + const currentLayersByService = this.extractLayersByService( + layersByService[cnt] + ); + currentLayersByService.forEach((layer) => { + const layerFromUrl = layer.split(':igoz'); + const layerOptions = ObjectUtils.removeUndefined({ + type, + url: url, + layer: layerFromUrl[0], + params: type === 'wms' ? { LAYERS: layerFromUrl[0] } : undefined }); - cnt += 1; + const id = generateIdFromSourceOptions(layerOptions); + const visibility = this.computeLayerVisibilityFromUrl(params, id); + this.addLayerFromURL( + url, + layerFromUrl[0], + type, + visibility, + parseInt(layerFromUrl[1] || 1000, 10) + ); }); - } + cnt += 1; + }); } private readVectorQueryParams(params: Params) { @@ -1096,61 +1102,43 @@ export class PortalComponent implements OnInit, OnDestroy { : outLayersByService; return outLayersByService.split(','); } - - private addWmsLayerByName( + private addLayerFromURL( url: string, name: string, + type: 'wms' | 'wmts' | 'arcgisrest'| 'imagearcgisrest' | 'tilearcgisrest', visibility: boolean = true, zIndex: number = 100000 ) { if (!this.contextLoaded) { return; } - this.addedLayers$$.push( - this.layerService - .createAsyncLayer({ - zIndex: zIndex, - visible: visibility, - sourceOptions: { - optionsFromCapabilities: true, - optionsFromApi: true, - type: 'wms', - url: url, - params: { - layers: name - } - } - }) - .subscribe((l) => { - this.map.addLayer(l); - }) - ); - } - - private addWmtsLayerByName( - url: string, - name: string, - visibility: boolean = true, - zIndex: number = 100000 - ) { - if (!this.contextLoaded) { - return; + const commonSourceOptions = { + optionsFromCapabilities: true, + optionsFromApi: true, + crossOrigin: true, + type, + url + }; + const arcgisClause = (type === 'arcgisrest' || type === 'imagearcgisrest' || type === 'tilearcgisrest'); + let sourceOptions = { + version: type === 'wmts' ? '1.0.0' : undefined, + queryable: arcgisClause ? true : false, + queryFormat: arcgisClause ? 'esrijson' : undefined, + layer: name + }; + if (type === 'wms') { + sourceOptions = { params: {LAYERS: name}} as any; } + + sourceOptions = ObjectUtils.removeUndefined(Object.assign({}, sourceOptions, commonSourceOptions)); + this.addedLayers$$.push( this.layerService .createAsyncLayer({ zIndex: zIndex, visible: visibility, - sourceOptions: { - optionsFromCapabilities: true, - type: 'wmts', - url: url, - crossOrigin: true, - // matrixSet: 'GoogleMapsCompatibleExt2:epsg:3857', - version: '1.0.0', - layer: name - } - } as any) + sourceOptions + }) .subscribe((l) => { this.map.addLayer(l); }) @@ -1189,10 +1177,10 @@ export class PortalComponent implements OnInit, OnDestroy { // After, managing named layer by id (context.json OR id from datasource) visiblelayers = visibleOnLayersParams.split(','); invisiblelayers = visibleOffLayersParams.split(','); - if (visiblelayers.indexOf(currentLayerid) > -1) { + if (visiblelayers.indexOf(currentLayerid) > -1 || visiblelayers.indexOf(currentLayerid.toString()) > -1) { visible = true; } - if (invisiblelayers.indexOf(currentLayerid) > -1) { + if (invisiblelayers.indexOf(currentLayerid) > -1 || invisiblelayers.indexOf(currentLayerid.toString()) > -1) { visible = false; } return visible; diff --git a/src/contexts/layerSync.json b/src/contexts/layerSync.json index 038df30dc..f7fede4cf 100644 --- a/src/contexts/layerSync.json +++ b/src/contexts/layerSync.json @@ -68,8 +68,8 @@ "sourceOptions": { "queryable": true, "type": "wms", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", - "urlWfs": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", + "urlWfs": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "params": { "layers": "radars_photos" }, @@ -99,8 +99,8 @@ "sourceOptions": { "queryable": true, "type": "wms", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", - "urlWfs": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", + "urlWfs": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "params": { "layers": "radars_photos" }, @@ -239,7 +239,7 @@ "version": "2.0.0" }, "type": "wfs", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq" + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq" } } ], diff --git a/src/contexts/ogcFilters.json b/src/contexts/ogcFilters.json index 7538dd576..b81d32141 100644 --- a/src/contexts/ogcFilters.json +++ b/src/contexts/ogcFilters.json @@ -63,8 +63,8 @@ "title": "Filterable WMS layers with predefined filters (buttons)", "sourceOptions": { "type": "wms", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", - "urlWfs": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", + "urlWfs": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "queryable": true, "params": { "layers": "radars_photos" diff --git a/src/contexts/testExport.json b/src/contexts/testExport.json index 01ae602ce..fdb4f7392 100644 --- a/src/contexts/testExport.json +++ b/src/contexts/testExport.json @@ -17,7 +17,7 @@ "version": "2.0.0" }, "type": "wfs", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq" + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq" } }, { diff --git a/src/contexts/variousFormats.json b/src/contexts/variousFormats.json index 1c318ecf8..47b6ac752 100644 --- a/src/contexts/variousFormats.json +++ b/src/contexts/variousFormats.json @@ -23,7 +23,7 @@ "queryable": true, "queryTitle": "nomcartrou", "type": "mvt", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq?mode=tile&tilemode=gmap&tile={x}+{y}+{z}&layers=lieuhabite&map.imagetype=mvt" + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq?mode=tile&tilemode=gmap&tile={x}+{y}+{z}&layers=lieuhabite&map.imagetype=mvt" } }, { @@ -62,7 +62,7 @@ "sourceOptions": { "queryable": true, "queryTitle": "identificationDesTravaux", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=chantiers_mtmdet&outputFormat=geojson", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=chantiers_mtmdet&outputFormat=geojson", "type": "cluster", "distance": 50 } @@ -113,7 +113,7 @@ "id": "vector2", "sourceOptions": { "type": "vector", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=aeroport_piste&outputFormat=geojson", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=aeroport_piste&outputFormat=geojson", "queryable": true, "queryFormat": "geojson", "queryTitle": "desclocal" diff --git a/src/contexts/workspace.json b/src/contexts/workspace.json index 43e7b2fe9..14d01601f 100644 --- a/src/contexts/workspace.json +++ b/src/contexts/workspace.json @@ -15,8 +15,8 @@ "queryable": true, "queryTitle": "nometablis", "type": "wms", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", - "urlWfs": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", + "urlWfs": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "params": { "layers": "etablissement_mtq" }, @@ -40,7 +40,7 @@ "sourceOptions": { "queryable": true, "queryTitle": "nomnavcana", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=aeroport_piste&outputFormat=geojson", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=aeroport_piste&outputFormat=geojson", "type": "vector" } }, @@ -50,7 +50,7 @@ "sourceOptions": { "queryable": true, "queryTitle": "identificationDesTravaux", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=chantiers_mtmdet&outputFormat=geojson", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq?service=WFS&request=GetFeature&version=1.1.0&typename=chantiers_mtmdet&outputFormat=geojson", "type": "cluster", "distance": 50 } @@ -60,7 +60,7 @@ "visible": true, "sourceOptions": { "type": "wfs", - "url": "https://geoegl.msp.gouv.qc.ca/apis/ws/swtq", + "url": "https://ws.mapserver.transports.gouv.qc.ca/swtq", "queryable": true, "queryTitle": "desclocal", "params": { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 72356ac85..c358d1e40 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -79,7 +79,7 @@ export const environment: Environment = { composite: [ { id: 'tq_swtq', - url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq' + url: 'https://ws.mapserver.transports.gouv.qc.ca/swtq' }, { id: 'rn_wmts', @@ -112,7 +112,7 @@ export const environment: Environment = { }, { id: 'forcedProperties_wms', - url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', + url: 'https://ws.mapserver.transports.gouv.qc.ca/swtq', type: 'wms', forcedProperties: [{ layerName: 'lieuhabite', @@ -138,7 +138,7 @@ export const environment: Environment = { composite: [ { id: 'tq_swtq', - url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', + url: 'https://ws.mapserver.transports.gouv.qc.ca/swtq', regFilters: ['zpegt'], groupImpose: { id: 'zpegt', title: 'zpegt' } }, @@ -176,7 +176,7 @@ export const environment: Environment = { composite: [ { id: 'tq_swtq', - url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', + url: 'https://ws.mapserver.transports.gouv.qc.ca/swtq', regFilters: ['limtn_charg'], groupImpose: { id: 'mix_swtq_gouv',