From 4f8ff34cb01cbfc478afb20c9323d1e16af4af05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9e=20Martel?= Date: Wed, 15 Apr 2020 15:00:35 -0400 Subject: [PATCH 1/4] fix(QueryService) : create geom when is null --- .../geo/src/lib/query/shared/query.service.ts | 192 ++++++++++++------ 1 file changed, 135 insertions(+), 57 deletions(-) diff --git a/packages/geo/src/lib/query/shared/query.service.ts b/packages/geo/src/lib/query/shared/query.service.ts index 0fb8c20cc3..dd3decdc6f 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -270,6 +270,15 @@ export class QueryService { break; } + if (features.length > 0 && features[0].geometry == null) { + console.log('geom est null!!'); + const geomToAdd = this.createGeometryFromUrlClick(url); + + for (const feature of features) { + feature.geometry = geomToAdd; + } + } + return features.map((feature: Feature, index: number) => { const mapLabel = feature.properties[queryDataSource.mapLabel]; @@ -306,6 +315,72 @@ export class QueryService { }); } + private createGeometryFromUrlClick(url) { + + const searchParams: any = this.getQueryParams(url.toLowerCase()); + const bboxRaw = searchParams.bbox; + const width = parseInt(searchParams.width, 10); + const height = parseInt(searchParams.height, 10); + const xPosition = parseInt(searchParams.i || searchParams.x, 10); + const yPosition = parseInt(searchParams.j || searchParams.y, 10); + const projection = searchParams.crs || searchParams.srs || 'EPSG:3857'; + + const bbox = bboxRaw.split(','); + let threshold = + (Math.abs(parseFloat(bbox[0])) - Math.abs(parseFloat(bbox[2]))) * 0.05; + + // for context in degree (EPSG:4326,4269...) + if (Math.abs(parseFloat(bbox[0])) < 180) { + threshold = 0.045; + } + const clickx = + parseFloat(bbox[0]) + + (Math.abs(parseFloat(bbox[0]) - parseFloat(bbox[2])) * xPosition) / + width - + threshold; + const clicky = + parseFloat(bbox[1]) + + (Math.abs(parseFloat(bbox[1]) - parseFloat(bbox[3])) * yPosition) / + height - + threshold; + const clickx1 = clickx + threshold * 2; + const clicky1 = clicky + threshold * 2; + + const wktPoly = + 'POLYGON((' + + clickx + + ' ' + + clicky + + ', ' + + clickx + + ' ' + + clicky1 + + ', ' + + clickx1 + + ' ' + + clicky1 + + ', ' + + clickx1 + + ' ' + + clicky + + ', ' + + clickx + + ' ' + + clicky + + '))'; + + const format = new olformat.WKT(); + const tenPercentWidthGeom = format.readFeature(wktPoly); + const f = tenPercentWidthGeom.getGeometry() as any; + + const newGeom = { + type: f.getType(), + coordinates: f.getCoordinates() + }; + + return newGeom; + } + private extractGML2Data(res, zIndex, allowedFieldsAndAlias?) { let parser = new olFormatGML2(); let features = parser.readFeatures(res); @@ -364,61 +439,63 @@ export class QueryService { ) { // _blank , iframe or undefined const searchParams: any = this.getQueryParams(url.toLowerCase()); - const bboxRaw = searchParams.bbox; - const width = parseInt(searchParams.width, 10); - const height = parseInt(searchParams.height, 10); - const xPosition = parseInt(searchParams.i || searchParams.x, 10); - const yPosition = parseInt(searchParams.j || searchParams.y, 10); + // const bboxRaw = searchParams.bbox; + // const width = parseInt(searchParams.width, 10); + // const height = parseInt(searchParams.height, 10); + // const xPosition = parseInt(searchParams.i || searchParams.x, 10); + // const yPosition = parseInt(searchParams.j || searchParams.y, 10); const projection = searchParams.crs || searchParams.srs || 'EPSG:3857'; - const bbox = bboxRaw.split(','); - let threshold = - (Math.abs(parseFloat(bbox[0])) - Math.abs(parseFloat(bbox[2]))) * 0.05; - - // for context in degree (EPSG:4326,4269...) - if (Math.abs(parseFloat(bbox[0])) < 180) { - threshold = 0.045; - } - - const clickx = - parseFloat(bbox[0]) + - (Math.abs(parseFloat(bbox[0]) - parseFloat(bbox[2])) * xPosition) / - width - - threshold; - const clicky = - parseFloat(bbox[1]) + - (Math.abs(parseFloat(bbox[1]) - parseFloat(bbox[3])) * yPosition) / - height - - threshold; - const clickx1 = clickx + threshold * 2; - const clicky1 = clicky + threshold * 2; - - const wktPoly = - 'POLYGON((' + - clickx + - ' ' + - clicky + - ', ' + - clickx + - ' ' + - clicky1 + - ', ' + - clickx1 + - ' ' + - clicky1 + - ', ' + - clickx1 + - ' ' + - clicky + - ', ' + - clickx + - ' ' + - clicky + - '))'; - - const format = new olformat.WKT(); - const tenPercentWidthGeom = format.readFeature(wktPoly); - const f = tenPercentWidthGeom.getGeometry() as any; + // const bbox = bboxRaw.split(','); + // let threshold = + // (Math.abs(parseFloat(bbox[0])) - Math.abs(parseFloat(bbox[2]))) * 0.05; + + // // for context in degree (EPSG:4326,4269...) + // if (Math.abs(parseFloat(bbox[0])) < 180) { + // threshold = 0.045; + // } + + // const clickx = + // parseFloat(bbox[0]) + + // (Math.abs(parseFloat(bbox[0]) - parseFloat(bbox[2])) * xPosition) / + // width - + // threshold; + // const clicky = + // parseFloat(bbox[1]) + + // (Math.abs(parseFloat(bbox[1]) - parseFloat(bbox[3])) * yPosition) / + // height - + // threshold; + // const clickx1 = clickx + threshold * 2; + // const clicky1 = clicky + threshold * 2; + + // const wktPoly = + // 'POLYGON((' + + // clickx + + // ' ' + + // clicky + + // ', ' + + // clickx + + // ' ' + + // clicky1 + + // ', ' + + // clickx1 + + // ' ' + + // clicky1 + + // ', ' + + // clickx1 + + // ' ' + + // clicky + + // ', ' + + // clickx + + // ' ' + + // clicky + + // '))'; + + // const format = new olformat.WKT(); + // const tenPercentWidthGeom = format.readFeature(wktPoly); + // const f = tenPercentWidthGeom.getGeometry() as any; + + const geomToAdd = this.createGeometryFromUrlClick(url); if ( htmlTarget !== QueryHtmlTarget.BLANK && @@ -440,10 +517,11 @@ export class QueryService { type: FEATURE, projection, properties: { target: htmlTarget, body: res, url }, - geometry: imposedGeometry || { - type: f.getType(), - coordinates: f.getCoordinates() - } + geometry: imposedGeometry || geomToAdd + // { + // type: f.getType(), + // coordinates: f.getCoordinates() + // } } ]; } From de3878cea37ffec1b1b13f8a4fe978fcff40c236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9e=20Martel?= Date: Thu, 16 Apr 2020 10:04:53 -0400 Subject: [PATCH 2/4] withdraw comment + add EX in query component --- demo/src/app/geo/query/query.component.ts | 30 +++++++-- .../geo/src/lib/query/shared/query.service.ts | 61 +------------------ 2 files changed, 27 insertions(+), 64 deletions(-) diff --git a/demo/src/app/geo/query/query.component.ts b/demo/src/app/geo/query/query.component.ts index 7a96927923..efc3b57c67 100644 --- a/demo/src/app/geo/query/query.component.ts +++ b/demo/src/app/geo/query/query.component.ts @@ -67,11 +67,12 @@ export class AppQueryComponent { this.dataSourceService .createAsyncDataSource({ type: 'wms', - url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', + url: 'https://servicescarto.mern.gouv.qc.ca/pes/services/Forets/STF_WMS/MapServer/WMSServer', queryable: true, - queryTitle: 'num_rts', + queryFormat: QueryFormat.GEOJSON, + queryTitle: 'Numéro', params: { - layers: 'bgr_v_sous_route_res_sup_act', + layers: 'Refuge biologique - p', version: '1.3.0' } } as QueryableDataSourceOptions) @@ -83,7 +84,28 @@ export class AppQueryComponent { sourceOptions: dataSource.options }) ); - }); + }); + + // this.dataSourceService + // .createAsyncDataSource({ + // type: 'wms', + // url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', + // queryable: true, + // queryTitle: 'num_rts', + // params: { + // layers: 'bgr_v_sous_route_res_sup_act', + // version: '1.3.0' + // } + // } as QueryableDataSourceOptions) + // .subscribe(dataSource => { + // this.map.addLayer( + // this.layerService.createLayer({ + // title: 'WMS', + // source: dataSource, + // sourceOptions: dataSource.options + // }) + // ); + // }); this.dataSourceService .createAsyncDataSource({ diff --git a/packages/geo/src/lib/query/shared/query.service.ts b/packages/geo/src/lib/query/shared/query.service.ts index dd3decdc6f..28f3538cb2 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -437,64 +437,9 @@ export class QueryService { url, imposedGeometry? ) { - // _blank , iframe or undefined + const searchParams: any = this.getQueryParams(url.toLowerCase()); - // const bboxRaw = searchParams.bbox; - // const width = parseInt(searchParams.width, 10); - // const height = parseInt(searchParams.height, 10); - // const xPosition = parseInt(searchParams.i || searchParams.x, 10); - // const yPosition = parseInt(searchParams.j || searchParams.y, 10); const projection = searchParams.crs || searchParams.srs || 'EPSG:3857'; - - // const bbox = bboxRaw.split(','); - // let threshold = - // (Math.abs(parseFloat(bbox[0])) - Math.abs(parseFloat(bbox[2]))) * 0.05; - - // // for context in degree (EPSG:4326,4269...) - // if (Math.abs(parseFloat(bbox[0])) < 180) { - // threshold = 0.045; - // } - - // const clickx = - // parseFloat(bbox[0]) + - // (Math.abs(parseFloat(bbox[0]) - parseFloat(bbox[2])) * xPosition) / - // width - - // threshold; - // const clicky = - // parseFloat(bbox[1]) + - // (Math.abs(parseFloat(bbox[1]) - parseFloat(bbox[3])) * yPosition) / - // height - - // threshold; - // const clickx1 = clickx + threshold * 2; - // const clicky1 = clicky + threshold * 2; - - // const wktPoly = - // 'POLYGON((' + - // clickx + - // ' ' + - // clicky + - // ', ' + - // clickx + - // ' ' + - // clicky1 + - // ', ' + - // clickx1 + - // ' ' + - // clicky1 + - // ', ' + - // clickx1 + - // ' ' + - // clicky + - // ', ' + - // clickx + - // ' ' + - // clicky + - // '))'; - - // const format = new olformat.WKT(); - // const tenPercentWidthGeom = format.readFeature(wktPoly); - // const f = tenPercentWidthGeom.getGeometry() as any; - const geomToAdd = this.createGeometryFromUrlClick(url); if ( @@ -518,10 +463,6 @@ export class QueryService { projection, properties: { target: htmlTarget, body: res, url }, geometry: imposedGeometry || geomToAdd - // { - // type: f.getType(), - // coordinates: f.getCoordinates() - // } } ]; } From b1f977b9997323aa76755664bd7000dd1624127a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9e=20Martel?= Date: Thu, 16 Apr 2020 11:20:33 -0400 Subject: [PATCH 3/4] withdraw comment --- packages/geo/src/lib/query/shared/query.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/geo/src/lib/query/shared/query.service.ts b/packages/geo/src/lib/query/shared/query.service.ts index 28f3538cb2..35f1c368dd 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -271,7 +271,6 @@ export class QueryService { } if (features.length > 0 && features[0].geometry == null) { - console.log('geom est null!!'); const geomToAdd = this.createGeometryFromUrlClick(url); for (const feature of features) { From 9a9f80aa9b5abc67efa86d5b3c67a8f9cd7b55f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Thu, 30 Apr 2020 13:58:06 -0400 Subject: [PATCH 4/4] restore demo --- demo/src/app/geo/query/query.component.ts | 30 +++-------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/demo/src/app/geo/query/query.component.ts b/demo/src/app/geo/query/query.component.ts index efc3b57c67..7a96927923 100644 --- a/demo/src/app/geo/query/query.component.ts +++ b/demo/src/app/geo/query/query.component.ts @@ -67,12 +67,11 @@ export class AppQueryComponent { this.dataSourceService .createAsyncDataSource({ type: 'wms', - url: 'https://servicescarto.mern.gouv.qc.ca/pes/services/Forets/STF_WMS/MapServer/WMSServer', + url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', queryable: true, - queryFormat: QueryFormat.GEOJSON, - queryTitle: 'Numéro', + queryTitle: 'num_rts', params: { - layers: 'Refuge biologique - p', + layers: 'bgr_v_sous_route_res_sup_act', version: '1.3.0' } } as QueryableDataSourceOptions) @@ -84,28 +83,7 @@ export class AppQueryComponent { sourceOptions: dataSource.options }) ); - }); - - // this.dataSourceService - // .createAsyncDataSource({ - // type: 'wms', - // url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/swtq', - // queryable: true, - // queryTitle: 'num_rts', - // params: { - // layers: 'bgr_v_sous_route_res_sup_act', - // version: '1.3.0' - // } - // } as QueryableDataSourceOptions) - // .subscribe(dataSource => { - // this.map.addLayer( - // this.layerService.createLayer({ - // title: 'WMS', - // source: dataSource, - // sourceOptions: dataSource.options - // }) - // ); - // }); + }); this.dataSourceService .createAsyncDataSource({