Skip to content

Commit

Permalink
Fix #3243 circle radius problem for openlayers (#3246) (#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored Oct 19, 2018
1 parent ee3f7f6 commit e2dedc8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class DrawSupport extends React.Component {
const olFeature = this.replaceFeatures(newProps);
if (olFeature) {
const feature = this.fromOLFeature(olFeature);
if (newProps.drawMethod === "Circle" && newProps && newProps.features && newProps.features.length && newProps.features[0] && newProps.features[0].radius >= 0) {
// this prevents the radius coming from `fromOLFeature` to override the radius set from an external tool
// this is because `endDrawing` need to impose the radius value, without any re-calculation or approximation
feature.radius = newProps.features[0].radius;
}
this.props.onEndDrawing(feature, newProps.drawOwner);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const React = require('react');
const ReactDOM = require('react-dom');
const expect = require('expect');
const ol = require('openlayers');
const assign = require('object-assign');
const DrawSupport = require('../DrawSupport');

describe('Test DrawSupport', () => {
Expand Down Expand Up @@ -1258,6 +1259,52 @@ describe('Test DrawSupport', () => {
options={{geodesic: true}}/>, document.getElementById("container"));

expect(spyonEndDrawing).toHaveBeenCalled();

});

it('test endDrawing action clear', () => {
const fakeMap = {
addLayer: () => {},
removeLayer: () => {},
disableEventListener: () => {},
enableEventListener: () => {},
addInteraction: () => {},
removeInteraction: () => {},
getInteractions: () => ({
getLength: () => 0
}),
getView: () => ({
getProjection: () => ({
getCode: () => 'EPSG:3857'
})
})
};

const radius = 2000000;
let properties = {
drawMethod: "Circle",
map: fakeMap,
features: [],
onEndDrawing: (feature, owner) => {
expect(feature).toExist();
expect(owner).toNotExist();
expect(feature.radius).toBe(radius);
},
options: {geodesic: true}
};
ReactDOM.render(<DrawSupport {...properties}/>, document.getElementById("container"));

let newProps = assign({}, properties, {
features: [{
center: {x: -11271098, y: 7748880},
coordinates: [-11271098, 7748880],
projection: 'EPSG:3857',
radius,
type: 'Polygon'
}],
drawStatus: "endDrawing"
});
ReactDOM.render(<DrawSupport {...newProps}/>, document.getElementById("container"));
});

it('test endDrawing action without features', () => {
Expand Down

0 comments on commit e2dedc8

Please sign in to comment.