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

#9031 GetMap format list in GetCapabilities not respected #9054

Merged
merged 9 commits into from
Mar 29, 2023
Prev Previous commit
Next Next commit
remove get capabilities root function
allyoucanmap committed Mar 27, 2023
commit 6db1ff90fee8a91d6d260222883703e1105cc012
2 changes: 1 addition & 1 deletion web/client/api/CSW.js
Original file line number Diff line number Diff line change
@@ -207,7 +207,7 @@ const addCapabilitiesToRecords = (_dcRef, result, options) => {
isCached
? cached
: WMS.getCapabilities(parsedUrl + '?version=')
.then((caps)=> WMS.flatLayers(WMS.getCapabilityRoot(caps)?.Capability))
.then((caps)=> WMS.flatLayers(caps.Capability))
.catch(()=> []))
.then((layers) => {
if (!isCached) {
15 changes: 6 additions & 9 deletions web/client/api/WMS.js
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ const capabilitiesCache = {};
export const WMS_GET_CAPABILITIES_VERSION = '1.3.0';
export const WMS_DESCRIBE_LAYER_VERSION = '1.1.1';

export const getCapabilityRoot = (json) => (json.WMS_Capabilities || json.WMT_MS_Capabilities || {});

export const parseUrl = (
urls,
query = {
@@ -181,8 +179,8 @@ export const getOnlineResource = (c) => {
return c.Request && c.Request.GetMap && c.Request.GetMap.DCPType && c.Request.GetMap.DCPType.HTTP && c.Request.GetMap.DCPType.HTTP.Get && c.Request.GetMap.DCPType.HTTP.Get.OnlineResource && c.Request.GetMap.DCPType.HTTP.Get.OnlineResource.$ || undefined;
};
export const searchAndPaginate = (json = {}, startPosition, maxRecords, text) => {
allyoucanmap marked this conversation as resolved.
Show resolved Hide resolved
const root = getCapabilityRoot(json).Capability;
const service = getCapabilityRoot(json).Service;
const root = json.Capability;
const service = json.Service;
const onlineResource = getOnlineResource(root);
const SRSList = root.Layer && (root.Layer.SRS || root.Layer.CRS)?.map((crs) => crs.toUpperCase()) || [];
const credits = root.Layer && root.Layer.Attribution && extractCredits(root.Layer.Attribution);
@@ -198,7 +196,7 @@ export const searchAndPaginate = (json = {}, startPosition, maxRecords, text) =>
nextRecord: startPosition + Math.min(maxRecords, filteredLayers.length) + 1,
service,
layerOptions: {
version: getCapabilityRoot(json)?.$?.version || WMS_GET_CAPABILITIES_VERSION
version: json?.$?.version || WMS_GET_CAPABILITIES_VERSION
},
records: filteredLayers
.filter((layer, index) => index >= startPosition - 1 && index < startPosition - 1 + maxRecords)
@@ -236,7 +234,7 @@ export const getCapabilities = (url) => {
xml2js.parseString(response.data, {explicitArray: false}, (ignore, result) => {
json = result;
});
return json;
return (json.WMS_Capabilities || json.WMT_MS_Capabilities || {});
});
};

@@ -346,7 +344,7 @@ export const textSearch = (url, startPosition, maxRecords, text) => {
return getRecords(url, startPosition, maxRecords, text);
};
export const parseLayerCapabilities = (json, layer) => {
const root = getCapabilityRoot(json).Capability;
const root = json.Capability;
const layersCapabilities = flatLayers(root);
return layersCapabilities.find((layerCapability) => {
const capabilityName = layerCapability.Name;
@@ -414,7 +412,7 @@ export const reset = () => {
export const getSupportedFormat = (url, includeGFIFormats = false) => {
return getCapabilities(url)
.then((response) => {
const root = getCapabilityRoot(response).Capability;
const root = response.Capability;
const imageFormats = castArray(root?.Request?.GetMap?.Format || []).filter(isValidGetMapFormat);
if (includeGFIFormats) {
const infoFormats = castArray(root?.Request?.GetFeatureInfo?.Format || []).filter(isValidGetInfoFormat);
@@ -426,7 +424,6 @@ export const getSupportedFormat = (url, includeGFIFormats = false) => {
};

const Api = {
getCapabilityRoot,
flatLayers,
parseUrl,
getDimensions,
4 changes: 2 additions & 2 deletions web/client/epics/catalog.js
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ import {
buildSRSMap,
extractOGCServicesReferences
} from '../utils/CatalogUtils';
import { getSupportedFormat, getCapabilities, describeLayers, flatLayers, getCapabilityRoot } from '../api/WMS';
import { getSupportedFormat, getCapabilities, describeLayers, flatLayers } from '../api/WMS';
import CoordinatesUtils from '../utils/CoordinatesUtils';
import ConfigUtils from '../utils/ConfigUtils';
import {getCapabilitiesUrl, getLayerId, getLayerUrl, removeWorkspace} from '../utils/LayersUtils';
@@ -363,7 +363,7 @@ export default (API) => ({

return Rx.Observable.defer(() => getCapabilities(getCapabilitiesUrl(layer)))
.switchMap((caps) => {
const layersXml = flatLayers(getCapabilityRoot(caps)?.Capability);
const layersXml = flatLayers(caps?.Capability);
const metadataUrls = castArray((layersXml.length === 1
? layersXml[0].MetadataURL
: find(layersXml, l => removeWorkspace(l.Name) === removeWorkspace(layer.name))?.MetadataURL)
2 changes: 1 addition & 1 deletion web/client/epics/layers.js
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ export const refresh = action$ =>
Rx.Observable.forkJoin(
Api.getCapabilities(getCapabilitiesUrl(layer))
.then( (json) => {
const root = Api.getCapabilityRoot(json)?.Capability;
const root = json?.Capability;
const layersObj = Api.flatLayers(root);
const layers = isArray(layersObj) ? layersObj : [layersObj];
return head(layers.filter((l) => l.Name === removeWorkspace(layer.name) || l.Name === layer.name));