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

Fix #9999 Measures distance and area now supports all operations as geodeics features #10009

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@ export default class MeasurementSupport extends React.Component {
clonedNewFeature = set("geometry.coordinates", newCoords, clonedNewFeature);
} else if (!this.props.measurement.disableLabels && this.props.measurement.areaMeasureEnabled) {
// the one before the last is a dummy
let oldCoords = clonedNewFeature.geometry.coordinates;
let newCoords = transformLineToArcs(oldCoords[0]);
clonedNewFeature = set("geometry.coordinates", [newCoords], clonedNewFeature);

// edit geom for drawing geodesic lines
this.textLabels.splice(this.segmentOverlays.length - 2, 1);
this.props.map.removeOverlay(this.segmentOverlays[this.segmentOverlays.length - 2]);
this.segmentOverlayElements[this.segmentOverlays.length - 2].parentNode.removeChild(
Expand Down
36 changes: 34 additions & 2 deletions web/client/plugins/Annotations/utils/AnnotationsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
import uuidv1 from 'uuid/v1';
import { slice, head, last, get, isNaN, isEqual, isNumber } from 'lodash';
import turfBbox from '@turf/bbox';
import { measureIcons } from '../../../utils/MeasureUtils';
import {
MeasureTypes,
measureIcons
} from '../../../utils/MeasureUtils';
import {
getMeasureType
} from '../../../utils/MeasurementUtils';

import {
transformLineToArcs
} from '../../../utils/CoordinatesUtils';

// legacy style
export const STYLE_CIRCLE = {
Expand Down Expand Up @@ -405,6 +415,9 @@ export const updateAnnotationsLayer = (layer = {}) => {
}
return [];
};

export const isGeodesicMeasure = (measureType) => [MeasureTypes.LENGTH, MeasureTypes.AREA].includes(measureType);

/**
* This function takes an annotations layer and converts it to valid GeoJSON Feature Collection usable for export
* @param {array} annotations annotations layers
Expand All @@ -415,10 +428,21 @@ export const annotationsToGeoJSON = (annotations) => {
return [
...acc,
...(annotation.features || []).map((feature) => {
const measureType = getMeasureType(feature);
const isGeodesic = isGeodesicMeasure(measureType);
let newGeom = feature.geometry;
if (isGeodesic) {
newGeom = {
type: feature.geometry.type,
coordinates: [MeasureTypes.LENGTH].includes(measureType) ? transformLineToArcs(feature.geometry.coordinates) : [transformLineToArcs(feature.geometry.coordinates[0])]
};
}
return {
...feature,
geometry: newGeom,
properties: {
...feature.properties,
...(isGeodesic ? {originalGeom: feature.geometry} : {}),
annotationLayerId: annotation.id,
annotationLayerTitle: annotation.title,
annotationLayerDescription: annotation.description
Expand Down Expand Up @@ -452,7 +476,15 @@ export const geoJSONToAnnotations = (json) => {
const layers = (json?.annotations || [])
.map((annotation) => {
const features = (json?.features || [])
.filter((feature) => feature?.properties?.annotationLayerId === annotation.id);
.filter((feature) => feature?.properties?.annotationLayerId === annotation.id)
.map(feature => {
const measureType = getMeasureType(feature);
const isGeodesic = isGeodesicMeasure(measureType);
return isGeodesic && feature.properties.originalGeom ? {
...feature,
geometry: feature.properties.originalGeom
} : feature;
});
const {
annotationLayerTitle: title,
annotationLayerDescription: description
Expand Down
19 changes: 16 additions & 3 deletions web/client/utils/MeasurementUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const getGeomTypeSelected = (features = []) =>{
}));
};

const getMeasureType = (feature) => {
export const getMeasureType = (feature) => {
if (feature?.properties?.measureType) {
return feature.properties.measureType;
}
Expand Down Expand Up @@ -257,7 +257,8 @@ const convertMeasureToFeatureCollection = (geometricFeatures, textLabels = [], u
properties: {
...properties,
label: infoLabelText,
geodesic: measureType === MeasureTypes.LENGTH,
geodesic: measureType === MeasureTypes.LENGTH || measureType === MeasureTypes.AREA,
...(measureType === MeasureTypes.LENGTH || measureType === MeasureTypes.AREA ? { originalGeom: geometry} : {}),
...parseProperties(values, uom),
type: [MeasureTypes.POINT_COORDINATES].includes(measureType)
? 'position'
Expand Down Expand Up @@ -422,6 +423,9 @@ export const convertMeasuresToAnnotation = (geometricFeatures, textLabels, uom,
{
symbolizerId: uuidv1(),
kind: 'Fill',
msGeometry: {
name: 'lineToArc'
},
color: '#ffffff',
fillOpacity: 0.5,
outlineColor: '#33A8FF',
Expand Down Expand Up @@ -543,7 +547,16 @@ export const convertMeasuresToGeoJSON = (geometricFeatures, textLabels = [], uom

return {
type: 'FeatureCollection',
features,
features: features.map(ft => {
const measureType = getMeasureType(ft);
return measureType === MeasureTypes.LENGTH || measureType === MeasureTypes.AREA ? {
...ft,
geometry: {
...ft.geometry,
coordinates: measureType === MeasureTypes.LENGTH ? transformLineToArcs(ft.geometry.coordinates) : ft.geometry.coordinates.map(transformLineToArcs)
}
} : ft;
}),
style: {
metadata: { editorType: 'visual' },
format: 'geostyler',
Expand Down
10 changes: 7 additions & 3 deletions web/client/utils/styleparser/CesiumStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,10 @@ const symbolizerToPrimitives = {
}] : [])
];
},
Fill: ({ parsedSymbolizer, globalOpacity }) => {
Fill: ({ parsedSymbolizer, feature, globalOpacity }) => {
const isExtruded = !parsedSymbolizer.msClampToGround && !!parsedSymbolizer.msExtrudedHeight;
const geometryFunction = getGeometryFunction(parsedSymbolizer);
const additionalOptions = geometryFunction ? geometryFunction(feature) : {};
return [
{
type: 'polygon',
Expand All @@ -870,7 +872,8 @@ const symbolizerToPrimitives = {
Cesium.ClassificationType.BOTH} ),
arcType: parsedSymbolizer.msClampToGround
? Cesium.ArcType.GEODESIC
: undefined
: undefined,
...additionalOptions
}
}
},
Expand Down Expand Up @@ -902,7 +905,8 @@ const symbolizerToPrimitives = {
Cesium.ClassificationType.BOTH} ),
arcType: parsedSymbolizer.msClampToGround
? Cesium.ArcType.GEODESIC
: Cesium.ArcType.NONE
: Cesium.ArcType.NONE,
...additionalOptions
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions web/client/utils/styleparser/GeometryFunctionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ export const geometryFunctionsLibrary = {
* @param {object} options
* @param {class} options.Point ol/geom/Point class
* @param {class} options.LineString ol/geom/LineString class
* @param {class} options.Polygon ol/geom/Polygon class
* @param {class} options.GeoJSON ol/format/GeoJSON class
* @param {function} options.getCenter from ol/extent
* @returns {function} geometry function utils for OpenLayers
*/
openlayers: ({
Point,
LineString,
Polygon,
GeoJSON,
getCenter
}) => {
Expand Down Expand Up @@ -176,6 +178,17 @@ export const geometryFunctionsLibrary = {
return [point.x, point .y];
}));
}
if (type === 'Polygon') {
let coordinates = feature.getGeometry().getCoordinates()[0]; // not managing holes
coordinates = transformLineToArcs(coordinates.map(c => {
const point = reproject(c, mapProjection, 'EPSG:4326');
return [point.x, point .y];
}));
return new Polygon([coordinates.map(c => {
const point = reproject(c, 'EPSG:4326', mapProjection);
return [point.x, point .y];
})]);
}
return feature.getGeometry();
},
startPoint: () => (feature) => {
Expand Down
14 changes: 13 additions & 1 deletion web/client/utils/styleparser/LeafletStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
return style;
}
if (firstValidSymbolizer.kind === 'Fill') {
return {
const geometryFunction = getGeometryFunction(firstValidSymbolizer);
const style = {
fill: true,
stroke: true,
fillColor: firstValidSymbolizer.color,
Expand All @@ -310,6 +311,17 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
weight: firstValidSymbolizer.outlineWidth ?? 0,
...(firstValidSymbolizer.outlineDasharray && { dashArray: firstValidSymbolizer.outlineDasharray.join(' ') })
};
if (geometryFunction && feature.geometry.type === 'Polygon') {
const coordinates = geometryFunction(feature);
const geoJSONLayer = L.geoJSON({ ...feature, geometry: { type: 'Polygon', coordinates }});
geoJSONLayer.setStyle(style);
layer._msAdditionalLayers.push(geoJSONLayer);
layer.addLayer(geoJSONLayer);
return {
stroke: false,
fill: false
};
}
}
return {
stroke: false,
Expand Down
3 changes: 3 additions & 0 deletions web/client/utils/styleparser/OLStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { geometryFunctionsLibrary } from './GeometryFunctionsUtils';
const getGeometryFunction = geometryFunctionsLibrary.openlayers({
Point: OlGeomPoint,
LineString: OlGeomLineString,
Polygon: OlGeomPolygon,
GeoJSON,
getCenter
});
Expand Down Expand Up @@ -716,6 +717,7 @@ export class OlStyleParser {
symbolizer[key] = expressionsUtils.evaluateFunction(symbolizer[key], feat);
}
}
const geometryFunc = getGeometryFunction(symbolizer, feat, this._getMap());

const color = symbolizer.color;
// fillOpacity is needed for legacy support
Expand All @@ -741,6 +743,7 @@ export class OlStyleParser {
}) : undefined;

const olStyle = new this.OlStyleConstructor({
...geometryFunc,
fill,
stroke
});
Expand Down
4 changes: 2 additions & 2 deletions web/client/utils/styleparser/PrintStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ export const getPrintStyleFuncFromRules = (geoStylerStyle) => {

let geometry = feature.geometry;
const geometryFunction = getGeometryFunction(symbolizer);
if (geometryFunction && geometryType === 'LineString') {
if (geometryFunction && (geometryType === 'LineString' || geometryType === 'Polygon')) {
geometry = {
type: 'LineString',
type: geometryType,
coordinates: geometryFunction(feature)
};
}
Expand Down
Loading