Skip to content

Commit

Permalink
fix geosolutions-it#49 maintain great circle in annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed May 8, 2018
1 parent e262ccc commit e62a9bd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
12 changes: 10 additions & 2 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ class MeasurementSupport extends React.Component {
this.lastLayer = evt.layer;

let feature = this.lastLayer && this.lastLayer.toGeoJSON() || {};
let newFeature = feature;
if (this.props.measurement.geomType === 'LineString') {
newFeature = assign({}, feature, {
geometry: assign({}, feature.geometry, {
coordinates: transformLineToArcs(feature.geometry.coordinates)
})
});
}
if (this.props.measurement.geomType === 'Point') {
let pos = this.drawControl._marker.getLatLng();
let point = {x: pos.lng, y: pos.lat, srs: 'EPSG:4326'};
let newMeasureState = assign({}, this.props.measurement, {point: point, feature});
let newMeasureState = assign({}, this.props.measurement, {point: point, feature: newFeature});
this.props.changeMeasurementState(newMeasureState);
} else {
let newMeasureState = assign({}, this.props.measurement, {feature});
let newMeasureState = assign({}, this.props.measurement, {feature: newFeature});
this.props.changeMeasurementState(newMeasureState);
}
if (this.props.measurement.lineMeasureEnabled && this.lastLayer) {
Expand Down
6 changes: 4 additions & 2 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,12 @@ class DrawSupport extends React.Component {
if (g.getType() !== "Circle") {
return g;
}
if (feature.getProperties().circles.indexOf(i) !== -1) {
if (feature.getProperties() && feature.getProperties().circles && feature.getProperties().circles.indexOf(i) !== -1) {
const center = g.getCenter();
const radius = g.getRadius();
return this.polygonFromCircle(center, radius);
}
return g;
});
}
/**
Expand All @@ -953,12 +954,13 @@ class DrawSupport extends React.Component {
if (g.getType() !== "Polygon") {
return g;
}
if (feature.getProperties().circles.indexOf(i) !== -1) {
if (feature.getProperties() && feature.getProperties().circles && feature.getProperties().circles.indexOf(i) !== -1) {
const extent = g.getExtent();
const center = ol.extent.getCenter(extent);
const radius = this.calculateRadius(center, g.getCoordinates());
return new ol.geom.Circle(center, radius);
}
return g;
});
}

Expand Down
10 changes: 9 additions & 1 deletion web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ class MeasurementSupport extends React.Component {
}
const geojsonFormat = new ol.format.GeoJSON();
let feature = reprojectGeoJson(geojsonFormat.writeFeatureObject(this.sketchFeature.clone()), this.props.map.getView().getProjection().getCode(), "EPSG:4326");
let newFeature = feature;
if (this.props.measurement.geomType === 'LineString') {
newFeature = assign({}, feature, {
geometry: assign({}, feature.geometry, {
coordinates: transformLineToArcs(feature.geometry.coordinates)
})
});
}

let newMeasureState = assign({}, this.props.measurement,
{
Expand All @@ -284,7 +292,7 @@ class MeasurementSupport extends React.Component {
bearing: this.props.measurement.geomType === 'Bearing' ? bearing : 0,
lenUnit: this.props.measurement.lenUnit,
areaUnit: this.props.measurement.areaUnit,
feature
feature: newFeature
}
);
this.props.changeMeasurementState(newMeasureState);
Expand Down
6 changes: 4 additions & 2 deletions web/client/utils/CoordinatesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,10 @@ const CoordinatesUtils = {
const p2 = coordinates[i + 1];
const start = toPoint(p1);
const end = toPoint(p2);
const grCircle = greatCircle(start, end, options);
arcs = [...arcs, ...grCircle.geometry.coordinates];
if (!(p1[0] === p2[0] && p1[1] === p2[1])) {
let grCircle = greatCircle(start, end, options);
arcs = [...arcs, ...grCircle.geometry.coordinates];
}
}
return arcs;
},
Expand Down
4 changes: 4 additions & 0 deletions web/client/utils/__tests__/CoordinatesUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,8 @@ describe('CoordinatesUtils', () => {
expect(CoordinatesUtils.transformLineToArcs([[1, 1], [2, 2]] )).toNotBe(null);
expect(CoordinatesUtils.transformLineToArcs([[1, 1], [2, 2]] ).length).toBe(100);
});
it('test transformLineToArcs with 2 equal points', () => {
expect(CoordinatesUtils.transformLineToArcs([[1, 1], [1, 1]] )).toNotBe(null);
expect(CoordinatesUtils.transformLineToArcs([[1, 1], [1, 1]] ).length).toBe(0);
});
});

0 comments on commit e62a9bd

Please sign in to comment.