Skip to content

Commit

Permalink
Snap initial coordinate when drawing through PickDraw
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 14, 2024
1 parent 533c6a2 commit 36885ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions components/map/OlMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ class OlMap extends React.Component {
MapUtils.registerHook(MapUtils.GET_COORDINATES_FROM_PIXEL_HOOK, (pixel) => {
return this.map.getCoordinateFromPixel(pixel);
});
MapUtils.registerHook(MapUtils.GET_SNAPPED_COORDINATES_FROM_PIXEL_HOOK, (pixel) => {
return this.map.getCoordinateFromPixel(pixel);
});
MapUtils.registerHook(MapUtils.GET_NATIVE_LAYER, (id) => {
return this.map.getLayers().getArray().find(layer => layer.get('id') === id);
});
Expand Down
2 changes: 1 addition & 1 deletion plugins/map/RedliningSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class RedliningSupport extends React.Component {
this.interactions.push(drawInteraction);
this.picking = false;

const clickCoord = MapUtils.getHook(MapUtils.GET_COORDINATES_FROM_PIXEL_HOOK)(ev.pixel);
const clickCoord = MapUtils.getHook(MapUtils.GET_SNAPPED_COORDINATES_FROM_PIXEL_HOOK)(ev.pixel);
drawInteraction.appendCoordinates([clickCoord]);
if (this.props.redlining.geomType === 'Point') {
drawInteraction.finishDrawing();
Expand Down
5 changes: 5 additions & 0 deletions plugins/map/SnappingSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class SnappingSupport extends React.Component {

props.map.getInteractions().on('add', this.handleInteractionAdded);
props.map.getInteractions().on('remove', this.handleInteractionRemoved);
MapUtils.registerHook(MapUtils.GET_SNAPPED_COORDINATES_FROM_PIXEL_HOOK, (pixel) => {
const coo = props.map.getCoordinateFromPixel(pixel);
const snapResult = this.snapInteraction.snapTo(pixel, coo, props.map);
return snapResult ? props.map.getCoordinateFromPixel(snapResult.vertexPixel) : coo;
});
}
componentDidUpdate(prevProps, prevState) {
if (this.state.drawing && (this.props.mapObj.bbox !== prevProps.mapObj.bbox || this.props.theme !== prevProps.theme)) {
Expand Down

0 comments on commit 36885ac

Please sign in to comment.