Skip to content

Commit

Permalink
feat(QueryService): Add create geom for mapTag when geom is null on e…
Browse files Browse the repository at this point in the history
…xtractData #617 (#618)

* fix(QueryService) : create geom when is null

* withdraw comment + add EX in query component

* withdraw comment

* restore demo

Co-authored-by: Josée Martel <josee.martel.9@ulaval.ca>
  • Loading branch information
2 people authored and mbarbeau committed May 11, 2020
1 parent 111f8fc commit 8c07a9f
Showing 1 changed file with 77 additions and 59 deletions.
136 changes: 77 additions & 59 deletions packages/geo/src/lib/query/shared/query.service.ts
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 &&
Expand All @@ -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
}
];
}
Expand Down

0 comments on commit 8c07a9f

Please sign in to comment.