Viglino / ol-ext

Cool extensions for Openlayers (ol) - animated clusters, CSS popup, Font Awesome symbol renderer, charts for statistical map (pie/bar), layer switcher, wikipedia layer, animations, canvas filters.
https://viglino.github.io/ol-ext/
Other
1.25k stars 463 forks source link

Transform drag handle is not precise #993

Closed MichalK6677 closed 12 months ago

MichalK6677 commented 1 year ago

I want to use Transform interaction toghether with Snap. Snap works based on cursor position so cursor should always drag center of the handle. It's not the case for Transform interaction and it's even more visible with hitTolerance.

Scenario: I want to resize polygon and snap to predefined points. With hitTolerance e.g. 40, I can drag 40 pixels out of the drag handle. Hence, openlayers does not snap to drag handle but to cursor and it's 40 pixes out. wrongSnap

How it should/could work: When I start drag out of the handle (because of hitTolerance), the drag handle is automatically moved to cursor position. goodSnap

Here is code example: https://codesandbox.io/s/snap-forked-kpf56q?file=/main.js

You just need to coment/uncoment this section to see the difference: image

This is change in code: image

Viglino commented 1 year ago

You're right. I fix it to center the handle on the cursor.

MichalK6677 commented 1 year ago

There is a problem with solution this.coordinate_ = feature.getGeometry().getCoordinates(); //evt.coordinate when there is translateFeature: true

Check it here (when you drag the rectangle then it disappears): https://codesandbox.io/s/snap-forked-4ktwhr?file=/main.js

Maybe center or topLeft of the feature extent could be used when translateFeature: true?

Viglino commented 1 year ago

I fall back to the previous method when clicking on the feature to move it (i.e. use the pointer position)