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

[Backport 2022.02.xx] #8781 Attribute table does not draw new features on layers with point geometries (#8789) #8809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
#8781 Attribute table does not draw new features on layers with point…
… geometries (#8789)
  • Loading branch information
allyoucanmap committed Nov 14, 2022
commit 2793b63ab9e78c141c8636e26a84013befd6c576
28 changes: 15 additions & 13 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,21 @@ export default class DrawSupport extends React.Component {
this.props.onEndDrawing(feature, this.props.drawOwner);
feature = reprojectGeoJson(feature, this.getMapCrs(), "EPSG:4326");

const newFeatures = isSimpleGeomType(this.props.drawMethod) && this.props.features[0].geometry.type !== "GeometryCollection" ?
this.props.features.map(feat => ({
...feat,
featureProjection: this.getMapCrs() // useful for reprojecting it after in replace method flow
})).concat([{
...feature,
type: "Feature",
geometry: {
type: feature.type,
coordinates: feature.coordinates
},
featureProjection: this.getMapCrs(), // useful for reprojecting it after in replace method flow
properties}]) :
const newFeatures = isSimpleGeomType(this.props.drawMethod) && this.props.features[0].geometry?.type !== "GeometryCollection" ?
this.props.features
.filter(feat => feat.geometry !== null)
.map(feat => ({
...feat,
featureProjection: this.getMapCrs() // useful for reprojecting it after in replace method flow
})).concat([{
...feature,
type: "Feature",
geometry: {
type: feature.type,
coordinates: feature.coordinates
},
featureProjection: this.getMapCrs(), // useful for reprojecting it after in replace method flow
properties}]) :
[{...feature, properties}];
if (this.props.options.stopAfterDrawing) {
this.props.onChangeDrawingStatus('stop', this.props.drawMethod, this.props.drawOwner, newFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2607,5 +2607,71 @@ describe('Test DrawSupport', () => {
const snappingInteraction = !!support?.snapInteraction;
expect(snappingInteraction).toBe(true);
});

it('should complete the draw or edit events for point layers even if the current GeoJSON feature geometry is null', () => {
const fakeMap = {
addLayer: () => {},
removeLayer: () => {},
disableEventListener: () => {},
enableEventListener: () => {},
addInteraction: () => {},
removeInteraction: () => {},
getInteractions: () => ({
getLength: () => 0
}),
getView: () => ({
getProjection: () => ({
getCode: () => 'EPSG:4326'
})
})
};
const geoJSON = {
type: 'Feature',
geometry: null,
properties: {
'name': "some name"
}
};
const feature = new Feature({
geometry: new Point(13.0, 43.0),
name: 'My Point'
});
const spyEnd = expect.spyOn(testHandlers, "onEndDrawing");
const spyChange = expect.spyOn(testHandlers, "onGeometryChanged");
const spyChangeStatus = expect.spyOn(testHandlers, "onStatusChange");

const support = ReactDOM.render(
<DrawSupport
features={[]}
map={fakeMap}
/>,
document.getElementById("container")
);

expect(support).toBeTruthy();

ReactDOM.render(
<DrawSupport
features={[geoJSON]}
map={fakeMap}
drawStatus="drawOrEdit"
drawMethod="Point"
options={{ drawEnabled: true }}
onEndDrawing={testHandlers.onEndDrawing}
onChangeDrawingStatus={testHandlers.onStatusChange}
onGeometryChanged={testHandlers.onGeometryChanged}
/>,
document.getElementById("container")
);

support.drawInteraction.dispatchEvent({
type: 'drawend',
feature: feature
});

expect(spyEnd.calls.length).toBe(1);
expect(spyChangeStatus.calls.length).toBe(1);
expect(spyChange.calls.length).toBe(1);
});
});