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 1 commit
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you reassign feature directly? It's not a constant

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

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