Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(QueryService): Add create geom for mapTag when geom is null on extractData #617 #618

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 77 additions & 59 deletions packages/geo/src/lib/query/shared/query.service.ts
Original file line number Diff line number Diff line change
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