Skip to content

Commit

Permalink
49 great circle annotations (#2875)
Browse files Browse the repository at this point in the history
* fix #49 maintain great circle in annotations

* clean up code
  • Loading branch information
MV88 authored May 16, 2018
1 parent 9be3635 commit 5c35a67
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions web/client/components/map/leaflet/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class MeasurementSupport extends React.Component {
this.lastLayer = evt.layer;

let feature = this.lastLayer && this.lastLayer.toGeoJSON() || {};
if (this.props.measurement.geomType === 'LineString') {
feature = 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'};
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
7 changes: 7 additions & 0 deletions web/client/components/map/openlayers/MeasurementSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ 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");
if (this.props.measurement.geomType === 'LineString') {
feature = assign({}, feature, {
geometry: assign({}, feature.geometry, {
coordinates: transformLineToArcs(feature.geometry.coordinates)
})
});
}

let newMeasureState = assign({}, this.props.measurement,
{
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 5c35a67

Please sign in to comment.