Skip to content

Commit

Permalink
refactor(query): Manage WMS feature info content based on number of r…
Browse files Browse the repository at this point in the history
…equests made

Replace for single, append multiple
  • Loading branch information
FilipLeitner committed Dec 16, 2024
1 parent 97b49f7 commit cc9fb06
Showing 2 changed files with 55 additions and 29 deletions.
47 changes: 36 additions & 11 deletions projects/hslayers/components/query/query-wms.service.ts
Original file line number Diff line number Diff line change
@@ -75,6 +75,11 @@ export class HsQueryWmsService {
coordinate: number[],
layer: Layer<Source>,
): Promise<void> {
this.infoCounter++;
if (this.infoCounter > 1) {
this.hsQueryBaseService.multiWmsQuery = true;
}

const req_url = this.hsUtilsService.proxify(url);
const reqHash = this.hsQueryBaseService.currentQuery;
try {
@@ -132,12 +137,19 @@ export class HsQueryWmsService {
}
if (infoFormat.includes('html')) {
if (response.length <= 1) {
this.infoCounter--;
if (this.infoCounter === 0) {
this.queriesCollected(coordinate);
}
return;
}
if (getFeatureInfoTarget(layer) == 'info-panel') {
if (getFeatureInfoTarget(layer) === 'info-panel') {
this.hsQueryBaseService.pushFeatureInfoHtml(response);
} else {
this.hsQueryBaseService.fillIframeAndResize(response, true);
this.hsQueryBaseService.fillIframeAndResize(
response,
this.hsQueryBaseService.multiWmsQuery,
);
if (getPopupClass(layer) != undefined) {
this.hsQueryBaseService.popupClassname =
'ol-popup ' + getPopupClass(layer);
@@ -231,6 +243,9 @@ export class HsQueryWmsService {
* @param coordinate - Clicked coordinates
*/
queriesCollected(coordinate: number[]): void {
this.hsQueryBaseService.multiWmsQuery = false;
this.hsQueryBaseService.wmsFeatureInfoLoading = false;

const invisiblePopup: any = this.hsQueryBaseService.getInvisiblePopup();
if (
this.hsQueryBaseService.features.length > 0 ||
@@ -250,12 +265,25 @@ export class HsQueryWmsService {
coordinate: number[],
): void {
if (this.isLayerWmsQueryable(layer)) {
/**
* Reset info panel before new request/set of requests.
* To prevent appending to previous query results
*/
if (this.infoCounter === 0) {
const invisiblePopup: any = this.hsQueryBaseService.getInvisiblePopup();
if (invisiblePopup) {
invisiblePopup.contentDocument.body.innerHTML = '';
}
if (getFeatureInfoTarget(layer) === 'info-panel') {
this.hsQueryBaseService.wmsFeatureInfoLoading = true;
}
this.hsQueryBaseService.featureInfoHtmls = [];
}
if (instOf(layer.getSource(), WMTS)) {
this.hsQueryWmtsService
.parseRequestURL(layer as Layer<WMTS>, coordinate)
.then((res) => {
console.log(res);
this.infoCounter++;
this.request(res.url, res.format, coordinate, layer);
});
return;
@@ -267,6 +295,8 @@ export class HsQueryWmsService {
} else if (instOf(layer.getSource(), TileWMS)) {
source = layer.getSource() as TileWMS;
}

const info_format = source.getParams().INFO_FORMAT;
const map = this.hsMapService.getMap();
const viewResolution = map.getView().getResolution();
let url = source.getFeatureInfoUrl(
@@ -276,7 +306,7 @@ export class HsQueryWmsService {
? source.getProjection()
: this.hsMapService.getCurrentProj(),
{
INFO_FORMAT: source.getParams().INFO_FORMAT,
INFO_FORMAT: info_format,
/**
* FIXME: Might return multiple results for the same layer not always 1 of each
*/
@@ -301,15 +331,10 @@ export class HsQueryWmsService {
}
if (url) {
this.hsLogService.log(url);

if (
source.getParams().INFO_FORMAT.includes('xml') ||
source.getParams().INFO_FORMAT.includes('html') ||
source.getParams().INFO_FORMAT.includes('gml') ||
source.getParams().INFO_FORMAT.includes('json')
['xml', 'html', 'json', 'gml'].some((o) => info_format.includes(o))
) {
this.infoCounter++;
this.request(url, source.getParams().INFO_FORMAT, coordinate, layer);
this.request(url, info_format, coordinate, layer);
}
}
}
37 changes: 19 additions & 18 deletions projects/hslayers/services/query/query-base.service.ts
Original file line number Diff line number Diff line change
@@ -76,6 +76,9 @@ export class HsQueryBaseService {
queryStatusChanges: Subject<boolean> = new Subject();
vectorSelectorCreated: Subject<Select> = new Subject();

multiWmsQuery = false;
wmsFeatureInfoLoading = false;

constructor(
private hsMapService: HsMapService,
private hsConfig: HsConfig,
@@ -163,7 +166,12 @@ export class HsQueryBaseService {
* @param html - Feature info html content
*/
pushFeatureInfoHtml(html: string): void {
this.featureInfoHtmls.push(this.domSanitizer.bypassSecurityTrustHtml(html));
const sanitizedHtml = this.domSanitizer.bypassSecurityTrustHtml(html);
if (this.multiWmsQuery) {
this.featureInfoHtmls.push(sanitizedHtml);
} else {
this.featureInfoHtmls = [sanitizedHtml];
}
this.dataCleared = false;
}

@@ -179,23 +187,16 @@ export class HsQueryBaseService {
} else {
iframe.contentDocument.body.innerHTML = response;
}
let tmp_width = iframe.contentWindow.innerWidth;
if (
tmp_width >
this.hsLayoutService.contentWrapper.querySelector('.hs-ol-map')
.clientWidth -
60
) {
tmp_width =
this.hsLayoutService.contentWrapper.querySelector('.hs-ol-map')
.clientWidth - 60;
}
iframe.style.width = tmp_width + 'px';
let tmp_height = iframe.contentWindow.innerHeight;
if (tmp_height > 700) {
tmp_height = 700;
}
iframe.style.height = tmp_height + 'px';
const mapElement =
this.hsLayoutService.contentWrapper.querySelector('.hs-ol-map');
const maxWidth = mapElement.clientWidth - 60;
const maxHeight = 700;

const tmp_width = Math.min(iframe.contentWindow.innerWidth, maxWidth);
const tmp_height = Math.min(iframe.contentWindow.innerHeight, maxHeight);

iframe.style.width = `${tmp_width}px`;
iframe.style.height = `${tmp_height}px`;
}

/**

0 comments on commit cc9fb06

Please sign in to comment.