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

Make Modify hitdetect mode work with user projection #14638

Merged
merged 1 commit into from
Apr 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ol/interaction/Modify.js
Expand Up @@ -1184,14 +1184,19 @@ class Modify extends PointerInteraction {
map.forEachFeatureAtPixel(
pixel,
(feature, layer, geometry) => {
if (geometry) {
geometry = new Point(
toUserCoordinate(geometry.getCoordinates(), projection)
);
}
const geom = geometry || feature.getGeometry();
if (
geom.getType() === 'Point' &&
feature instanceof Feature &&
this.features_.getArray().includes(feature)
) {
hitPointGeometry = /** @type {Point} */ (geom);
const coordinate = hitPointGeometry
const coordinate = /** @type {Point} */ (feature.getGeometry())
.getFlatCoordinates()
.slice(0, 2);
nodes = [
Expand Down
43 changes: 41 additions & 2 deletions test/browser/spec/ol/interaction/modify.test.js
Expand Up @@ -19,6 +19,7 @@ import {MultiPoint} from '../../../../../src/ol/geom.js';
import {
clearUserProjection,
setUserProjection,
useGeographic,
} from '../../../../../src/ol/proj.js';
import {
click,
Expand Down Expand Up @@ -1155,9 +1156,47 @@ describe('ol.interaction.Modify', function () {
map.renderSync();
simulateEvent('pointermove', 10, -10, null, 0);
expect(modify.vertexFeature_.get('features')[0]).to.eql(pointFeature);
expect(modify.vertexFeature_.get('geometries')[0]).to.eql(
pointFeature.getGeometry()
expect(
modify.vertexFeature_.get('geometries')[0].getCoordinates()
).to.eql(pointFeature.getGeometry().getCoordinates());
});

it('works with hit detection of point features with userGeographic()', function () {
useGeographic();
const modify = new Modify({
hitDetection: layer,
source: source,
});
map.setView(
new View({
center: [16, 48],
zoom: map.getView().getZoom(),
})
);
map.addInteraction(modify);
source.clear();
const pointFeature = new Feature(new Point([16, 48]));
source.addFeature(pointFeature);
layer.setStyle(
new Style({
image: new CircleStyle({
radius: 30,
fill: new Fill({
color: 'fuchsia',
}),
}),
})
);
map.renderSync();
simulateEvent('pointermove', 10, -10, null, 0);
simulateEvent('pointerdown', 10, -10, null, 0);
simulateEvent('pointerdrag', 0, 0, null, 0);
simulateEvent('pointerup', 0, 0, null, 0);
expect(modify.vertexFeature_.get('features')[0]).to.eql(pointFeature);
expect(
modify.vertexFeature_.get('geometries')[0].getCoordinates()
).to.eql(pointFeature.getGeometry().getCoordinates());
clearUserProjection();
});

it('snaps to pointer by default', function () {
Expand Down