From 8c07a9fb619e30e4846909aa2c0420f627696d96 Mon Sep 17 00:00:00 2001 From: josee666 Date: Thu, 30 Apr 2020 14:06:05 -0400 Subject: [PATCH] feat(QueryService): Add create geom for mapTag when geom is null on extractData #617 (#618) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(QueryService) : create geom when is null * withdraw comment + add EX in query component * withdraw comment * restore demo Co-authored-by: Josée Martel --- .../geo/src/lib/query/shared/query.service.ts | 136 ++++++++++-------- 1 file changed, 77 insertions(+), 59 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..35f1c368dd 100644 --- a/packages/geo/src/lib/query/shared/query.service.ts +++ b/packages/geo/src/lib/query/shared/query.service.ts @@ -270,6 +270,14 @@ export class QueryService { break; } + if (features.length > 0 && features[0].geometry == 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 +314,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); @@ -362,63 +436,10 @@ 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 ( htmlTarget !== QueryHtmlTarget.BLANK && @@ -440,10 +461,7 @@ export class QueryService { type: FEATURE, projection, properties: { target: htmlTarget, body: res, url }, - geometry: imposedGeometry || { - type: f.getType(), - coordinates: f.getCoordinates() - } + geometry: imposedGeometry || geomToAdd } ]; }