Skip to content

Commit

Permalink
Merge pull request #7194 from TerriaJS/wps-bbox
Browse files Browse the repository at this point in the history
Wps bbox
  • Loading branch information
na9da authored Jun 18, 2024
2 parents 2ff66c3 + ebcfa57 commit dbde419
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- TSify some `js` and `jsx` files and provide `.d.ts` ambient type files for a few others. This is so that running `tsc` on an external project that imports Terria code will typecheck successfully.
- Upgraded a bunch of d3 dependencies for fixing security errors.
- [The next improvement]
- Show rectangle selector for WPS bounding box parameter
- Fix `store` and `status` values send in WPS Execute request.

#### 8.7.4 - 2024-06-07

Expand Down
23 changes: 12 additions & 11 deletions lib/Models/Catalog/Ows/WebProcessingServiceCatalogFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,13 @@ class WpsLoadableStratum extends LoadableStratum(
}

get storeSupported() {
return Boolean(this.processDescription.storeSupported);
const value = this.processDescription.storeSupported?.toLowerCase();
return value === "true" ? true : value === "false" ? false : undefined;
}

get statusSupported() {
return Boolean(this.processDescription.statusSupported);
const value = this.processDescription.statusSupported?.toLowerCase();
return value === "true" ? true : value === "false" ? false : undefined;
}
}

Expand Down Expand Up @@ -572,7 +574,6 @@ const RectangleConverter = {
parameterToInput: function (functionParameter: FunctionParameter) {
const parameter = functionParameter as RectangleParameter;
const value = parameter.value;

if (!isDefined(value)) {
return;
}
Expand All @@ -581,21 +582,21 @@ const RectangleConverter = {
// We only support CRS84 and EPSG:4326
if (parameter.crs.indexOf("crs84") !== -1) {
// CRS84 uses long, lat rather that lat, long order.
bboxMinCoord1 = CesiumMath.toDegrees(value.west);
bboxMinCoord2 = CesiumMath.toDegrees(value.south);
bboxMaxCoord1 = CesiumMath.toDegrees(value.east);
bboxMaxCoord2 = CesiumMath.toDegrees(value.north);
bboxMinCoord1 = value.west;
bboxMinCoord2 = value.south;
bboxMaxCoord1 = value.east;
bboxMaxCoord2 = value.north;
// Comfortingly known as WGS 84 longitude-latitude according to Table 3 in OGC 07-092r1.
urn = "urn:ogc:def:crs:OGC:1.3:CRS84";
} else {
// The URN value urn:ogc:def:crs:EPSG:6.6:4326 shall mean the Coordinate Reference System (CRS) with code
// 4326 specified in version 6.6 of the EPSG database available at http://www.epsg.org/. That CRS specifies
// the axis order as Latitude followed by Longitude.
// We don't know about other URN versions, so are going to return 6.6 regardless of what was requested.
bboxMinCoord1 = CesiumMath.toDegrees(value.south);
bboxMinCoord2 = CesiumMath.toDegrees(value.west);
bboxMaxCoord1 = CesiumMath.toDegrees(value.north);
bboxMaxCoord2 = CesiumMath.toDegrees(value.east);
bboxMinCoord1 = value.south;
bboxMinCoord2 = value.west;
bboxMaxCoord1 = value.north;
bboxMaxCoord2 = value.east;
urn = "urn:ogc:def:crs:EPSG:6.6:4326";
}

Expand Down
43 changes: 22 additions & 21 deletions lib/ReactViews/Analytics/ParameterEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PropTypes from "prop-types";
import PointParameterEditor from "./PointParameterEditor";
import LineParameterEditor from "./LineParameterEditor";
import PolygonParameterEditor from "./PolygonParameterEditor";
import RectangleParameterEditor from "./RectangleParameterEditor";
import RegionParameterEditor from "./RegionParameterEditor";
import RegionTypeParameterEditor from "./RegionTypeParameterEditor";
import BooleanParameterEditor from "./BooleanParameterEditor";
Expand Down Expand Up @@ -142,27 +143,27 @@ ParameterEditor.parameterTypeConverters = [
}
}
},
// {
// id: "rectangle",
// parameterTypeToDiv: function RectangleParameterToDiv(
// type,
// parameterEditor
// ) {
// if (type === this.id) {
// return (
// <div>
// {parameterEditor.renderLabel()}
// <RectangleParameterEditor
// previewed={parameterEditor.props.previewed}
// viewState={parameterEditor.props.viewState}
// parameter={parameterEditor.props.parameter}
// parameterViewModel={parameterEditor.props.parameterViewModel}
// />
// </div>
// );
// }
// }
// },
{
id: "rectangle",
parameterTypeToDiv: function RectangleParameterToDiv(
type,
parameterEditor
) {
if (type === this.id) {
return (
<div>
{parameterEditor.renderLabel()}
<RectangleParameterEditor
previewed={parameterEditor.props.previewed}
viewState={parameterEditor.props.viewState}
parameter={parameterEditor.props.parameter}
parameterViewModel={parameterEditor.props.parameterViewModel}
/>
</div>
);
}
}
},
{
id: "polygon",
parameterTypeToDiv: function PolygonParameterToDiv(type, parameterEditor) {
Expand Down
126 changes: 126 additions & 0 deletions lib/ReactViews/Analytics/RectangleParameterEditor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"use strict";

import React from "react";

import PropTypes from "prop-types";

import defined from "terriajs-cesium/Source/Core/defined";

import Styles from "./parameter-editors.scss";

import CesiumMath from "terriajs-cesium/Source/Core/Math";
import Cartographic from "terriajs-cesium/Source/Core/Cartographic";
import Ellipsoid from "terriajs-cesium/Source/Core/Ellipsoid";
import UserDrawing from "../../Models/UserDrawing";
import { withTranslation } from "react-i18next";
import { observer } from "mobx-react";
import { runInAction } from "mobx";
import CommonStrata from "../../Models/Definition/CommonStrata";
import { t } from "i18next";

@observer
class RectangleParameterEditor extends React.Component {
static propTypes = {
previewed: PropTypes.object,
parameter: PropTypes.object,
viewState: PropTypes.object,
t: PropTypes.func.isRequired
};

setValueFromText(e) {
RectangleParameterEditor.setValueFromText(e, this.props.parameter);
}

selectPolygonOnMap() {
selectOnMap(
this.props.previewed.terria,
this.props.viewState,
this.props.parameter
);
}

render() {
const { t } = this.props;
return (
<div>
<input
className={Styles.field}
type="text"
onChange={this.setValueFromText.bind(this)}
value={getDisplayValue(this.props.parameter.value)}
/>
<button
type="button"
onClick={this.selectPolygonOnMap.bind(this)}
className={Styles.btnSelector}
>
{t("analytics.clickToDrawRectangle")}
</button>
</div>
);
}
}

/**
* Triggered when user types value directly into field.
* @param {String} e Text that user has entered manually.
* @param {FunctionParameter} parameter Parameter to set value on.
*/
RectangleParameterEditor.setValueFromText = function (e, parameter) {
parameter.setValue(CommonStrata.user, [JSON.parse(e.target.value)]);
};

/**
* Given a value, return it in human readable form for display.
* @param {Object} value Native format of parameter value.
* @return {String} String for display
*/
export function getDisplayValue(value) {
if (!defined(value)) {
return "";
}
return `${value.east}, ${value.north}, ${value.west}, ${value.south}`;
}

/**
* Prompt user to select/draw on map in order to define parameter.
* @param {Terria} terria Terria instance.
* @param {Object} viewState ViewState.
* @param {FunctionParameter} parameter Parameter.
*/
export function selectOnMap(terria, viewState, parameter) {
const userDrawing = new UserDrawing({
terria: terria,
drawRectangle: true,
onCleanUp: function () {
viewState.openAddData();
},
onDrawingComplete: function (params) {
if (params.points) {
const cartographicPoints = params.points.map((point) => {
const cartographic = Cartographic.fromCartesian(
point,
Ellipsoid.WGS84
);
return {
latitude: CesiumMath.toDegrees(cartographic.latitude),
longitude: CesiumMath.toDegrees(cartographic.longitude)
};
});
const rectangle = {
west: cartographicPoints[0].longitude,
south: cartographicPoints[0].latitude,
east: cartographicPoints[1].longitude,
north: cartographicPoints[1].latitude
};
runInAction(() => {
parameter.setValue(CommonStrata.user, rectangle);
});
}
}
});

userDrawing.enterDrawMode();
}

export default withTranslation()(RectangleParameterEditor);

0 comments on commit dbde419

Please sign in to comment.