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

49 great circle annotations #2875

Merged
Merged
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
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);
});
});