Skip to content

Commit

Permalink
geosolutions-it#8723 Fix for WMTS background issues due to `attributi…
Browse files Browse the repository at this point in the history
…on` parameter; geosolutions-it#8724 WMTS request identify flow fixes (geosolutions-it#8725)
  • Loading branch information
alex-fko authored Oct 26, 2022
1 parent 99132d4 commit 88c7ad8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PropertiesViewer from './PropertiesViewer';
import { getRowViewer } from '../../../../../utils/MapInfoUtils';
import { ANNOTATIONS } from '../../../../../utils/AnnotationsUtils';
import PropTypes from 'prop-types';
import {omit} from "lodash/object";

const defaultRowViewerOptions = {
// we need some default options for annotations
Expand Down Expand Up @@ -41,7 +42,7 @@ function RowViewer({
const Row = layerRowViewer || component || PropertiesViewer;
return (
<Row
{...feature.properties}
{...omit(feature.properties, ['ref'])}
feature={feature}
labelIds={labelIds}
exclude={excludeProperties}
Expand Down
5 changes: 3 additions & 2 deletions web/client/utils/leaflet/WMTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var WMTS = L.TileLayer.extend({
wmtsParams.width = wmtsParams.height = tileSize;
}
for (let i in options) {
// all keys that are not TileLayer options go to WMS params
if (!this.options.hasOwnProperty(i) && i !== 'crs') {
// all keys that are not TileLayer options go to WMTS params
// skip attribution parameter, html content of it make requests fail
if (!this.options.hasOwnProperty(i) && i !== 'crs' && i !== 'attribution') {
wmtsParams[i] = options[i];
}
}
Expand Down
53 changes: 53 additions & 0 deletions web/client/utils/mapinfo/__tests__/wmts-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import expect from 'expect';

import axios from '../../../libs/ajax';
import MockAdapter from "axios-mock-adapter";
import {INFO_FORMATS} from "../../FeatureInfoUtils";
import {getFeatureInfo} from "../../../api/identify";

describe('mapinfo wmts utils', () => {
let mockAxios;
beforeEach((done) => {
mockAxios = new MockAdapter(axios);
setTimeout(done);
});
afterEach((done) => {
if (mockAxios) {
mockAxios.restore();
}
mockAxios = null;
setTimeout(done);
});

it('should return the response object from getIdentifyFlow in case of 400 error, TileOutOfRange', (done) => {
const SAMPLE_LAYER = {
type: "wmts",
name: "test_layer"
};
mockAxios.onGet().reply(() => {
return [400, '<?xml version="1.0" encoding="UTF-8"?><ExceptionReport version="1.1.0" xmlns="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://geowebcache.org/schema/ows/1.1.0/owsExceptionReport.xsd"> <Exception exceptionCode="TileOutOfRange" locator="TILEROW"> <ExceptionText>Row 84 is out of range, min: 85 max:87</ExceptionText> </Exception></ExceptionReport>'];
});
getFeatureInfo(
"TEST_URL", {
info_format: INFO_FORMATS.PROPERTIES
}, SAMPLE_LAYER
).subscribe(
n => {
expect(n.data.features).toEqual([]);
expect(n.features).toEqual([]);
done();
},
error => {
return done(error);
}
);
});
});
28 changes: 26 additions & 2 deletions web/client/utils/mapinfo/wmts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import {
import {getLayerUrl} from '../LayersUtils';
import {optionsToVendorParams} from '../VendorParamsUtils';

import {isObject, isNil} from 'lodash';
import {isObject, isNil, get} from 'lodash';

import assign from 'object-assign';
import Rx, {Observable} from "rxjs";
import axios from "../../libs/ajax";
import {parseString} from "xml2js";
import {stripPrefix} from "xml2js/lib/processors";

export default {
buildRequest: (layer, props) => {
Expand Down Expand Up @@ -78,5 +82,25 @@ export default {
},
url: getLayerUrl(layer).replace(/[?].*$/g, '')
};
}
},
getIdentifyFlow: (layer, basePath, params) =>
Observable.defer(() => axios.get(basePath, { params }))
.catch((e) => {
if (e.data.indexOf("ExceptionReport") > 0) {
return Rx.Observable.bindNodeCallback( (data, callback) => parseString(data, {
tagNameProcessors: [stripPrefix],
explicitArray: false,
mergeAttrs: true
}, callback))(e.data).map(data => {
const code = get(data, "ExceptionReport.Exception.exceptionCode");
if (code === 'TileOutOfRange') {
return params.infoformat === 'text/plain' ? {data: 'no features were found'} : { data: { features: []}};
}
return e;
});

}
return e;
})

};

0 comments on commit 88c7ad8

Please sign in to comment.