Skip to content
Open
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
77 changes: 68 additions & 9 deletions lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
// 3. Observable spaghetti
// Solution: think in terms of pipelines with computed observables, document patterns.
// 4. All code for all catalog item types needs to be loaded before we can do anything.
import { FeatureCollection } from "geojson";
import i18next from "i18next";
import { computed, makeObservable, override, runInAction } from "mobx";
import Cartesian3 from "terriajs-cesium/Source/Core/Cartesian3";
import Cartographic from "terriajs-cesium/Source/Core/Cartographic";
import GeographicProjection from "terriajs-cesium/Source/Core/GeographicProjection";
import GeographicTilingScheme from "terriajs-cesium/Source/Core/GeographicTilingScheme";
import JulianDate from "terriajs-cesium/Source/Core/JulianDate";
import MapProjection from "terriajs-cesium/Source/Core/MapProjection";
import WebMercatorTilingScheme from "terriajs-cesium/Source/Core/WebMercatorTilingScheme";
import combine from "terriajs-cesium/Source/Core/combine";
import GetFeatureInfoFormat from "terriajs-cesium/Source/Scene/GetFeatureInfoFormat";
import ImageryLayerFeatureInfo from "terriajs-cesium/Source/Scene/ImageryLayerFeatureInfo";
import WebMapServiceImageryProvider from "terriajs-cesium/Source/Scene/WebMapServiceImageryProvider";
import URI from "urijs";
import { JsonObject } from "../../../Core/Json";
Expand Down Expand Up @@ -616,15 +622,7 @@ class WebMapServiceCatalogItem
credit: this.attribution
// Note: we set enablePickFeatures in _currentImageryParts and _nextImageryParts
};

if (isDefined(this.getFeatureInfoFormat?.type)) {
imageryOptions.getFeatureInfoFormats = [
new GetFeatureInfoFormat(
this.getFeatureInfoFormat.type,
this.getFeatureInfoFormat.format
)
];
}
imageryOptions.getFeatureInfoFormats = this.getFeatureInfoFormats;

if (
imageryOptions.maximumLevel !== undefined &&
Expand Down Expand Up @@ -790,6 +788,31 @@ class WebMapServiceCatalogItem
if (this.getFeatureInfoFormat.format !== "text/csv") return () => ({});
return csvFeatureInfoContext(this);
}

@computed
get getFeatureInfoFormats() {
const customFormat = this.getFeatureInfoFormat;
if (customFormat) {
if (customFormat.type === "json") {
return [
new GetFeatureInfoFormat("json", "application/json", (json) =>
geoJsonToFeatureInfoWithProject(json, this.tilingScheme.projection)
)
];
} else {
return [
new GetFeatureInfoFormat(customFormat.type, customFormat.format)
];
}
}
return [
new GetFeatureInfoFormat("json", "application/json", (json) =>
geoJsonToFeatureInfoWithProject(json, this.tilingScheme.projection)
),
new GetFeatureInfoFormat("xml", "text/xml"),
new GetFeatureInfoFormat("csv", "text/csv")
];
}
}

/**
Expand Down Expand Up @@ -818,4 +841,40 @@ export function formatDimensionsForOws(
);
}

function geoJsonToFeatureInfoWithProject(
json: FeatureCollection,
projection: MapProjection
) {
const result = [];

const features = json.features;
for (let i = 0; i < features.length; ++i) {
const feature = features[i];

const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.properties = feature.properties;
featureInfo.configureNameFromProperties(feature.properties);
featureInfo.configureDescriptionFromProperties(feature.properties);

// If this is a point feature, use the coordinates of the point.
if (!!feature.geometry && feature.geometry.type === "Point") {
const x = feature.geometry.coordinates[0];
const y = feature.geometry.coordinates[1];

if (!projection || projection instanceof GeographicProjection) {
featureInfo.position = Cartographic.fromDegrees(x, y);
} else {
const positionInMeters = new Cartesian3(x, y, 0);
const cartographic = projection.unproject(positionInMeters);
featureInfo.position = cartographic;
}
}

result.push(featureInfo);
}

return result;
}

export default WebMapServiceCatalogItem;
Loading