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

To determine whether the mouse landed on the overlay or the feature w… #15476

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 24 additions & 23 deletions src/ol/interaction.js
@@ -1,26 +1,27 @@
/**
* @module ol/interaction
*/
export {default as DoubleClickZoom} from './interaction/DoubleClickZoom.js';
export {default as DblClickDragZoom} from './interaction/DblClickDragZoom.js';
export {default as DragAndDrop} from './interaction/DragAndDrop.js';
export {default as DragBox} from './interaction/DragBox.js';
export {default as DragPan} from './interaction/DragPan.js';
export {default as DragRotate} from './interaction/DragRotate.js';
export {default as DragRotateAndZoom} from './interaction/DragRotateAndZoom.js';
export {default as DragZoom} from './interaction/DragZoom.js';
export {default as Draw} from './interaction/Draw.js';
export {default as Extent} from './interaction/Extent.js';
export {default as Interaction} from './interaction/Interaction.js';
export {default as KeyboardPan} from './interaction/KeyboardPan.js';
export {default as KeyboardZoom} from './interaction/KeyboardZoom.js';
export {default as Link} from './interaction/Link.js';
export {default as Modify} from './interaction/Modify.js';
export {default as MouseWheelZoom} from './interaction/MouseWheelZoom.js';
export {default as PinchRotate} from './interaction/PinchRotate.js';
export {default as PinchZoom} from './interaction/PinchZoom.js';
export {default as Pointer} from './interaction/Pointer.js';
export {default as Select} from './interaction/Select.js';
export {default as Snap} from './interaction/Snap.js';
export {default as Translate} from './interaction/Translate.js';
export {defaults} from './interaction/defaults.js';
export { default as DoubleClickZoom } from './interaction/DoubleClickZoom.js';
export { default as DblClickDragZoom } from './interaction/DblClickDragZoom.js';
export { default as DragAndDrop } from './interaction/DragAndDrop.js';
export { default as DragBox } from './interaction/DragBox.js';
export { default as DragPan } from './interaction/DragPan.js';
export { default as DragRotate } from './interaction/DragRotate.js';
export { default as DragRotateAndZoom } from './interaction/DragRotateAndZoom.js';
export { default as DragZoom } from './interaction/DragZoom.js';
export { default as Draw } from './interaction/Draw.js';
export { default as Extent } from './interaction/Extent.js';
export { default as Interaction } from './interaction/Interaction.js';
export { default as KeyboardPan } from './interaction/KeyboardPan.js';
export { default as KeyboardZoom } from './interaction/KeyboardZoom.js';
export { default as Link } from './interaction/Link.js';
export { default as Modify } from './interaction/Modify.js';
export { default as MouseWheelZoom } from './interaction/MouseWheelZoom.js';
export { default as PinchRotate } from './interaction/PinchRotate.js';
export { default as PinchZoom } from './interaction/PinchZoom.js';
export { default as Pointer } from './interaction/Pointer.js';
export { default as Select } from './interaction/Select.js';
export { default as Snap } from './interaction/Snap.js';
export { default as Translate } from './interaction/Translate.js';
export { default as SegmentFilter } from './interaction/SegmentFilter.js';
export { defaults } from './interaction/defaults.js';
43 changes: 43 additions & 0 deletions src/ol/interaction/SegmentFilter.js
@@ -0,0 +1,43 @@
/**
* @module ol/interaction/SegmentFilter
*/
import { distance } from '../coordinate';

/**
* @classdesc
* Recognizes the mouse hover state when the mouse pointer overlaps with a feature or overlay.
* Allows the user to identify the state by hovering over the elements.
* @api
*/
class SegmentFilter {
/**
* Determine if the mouse coordinates fall on the endpoints of a straight line overlay
* @param {import("../coordinate.js").Coordinate} start Segment start coordinate.
* @param {import("../coordinate.js").Coordinate} end Segment end coordinate.
* @param {string} type The type of feature.
* @param {import("../coordinate.js").Coordinate} mousepoint Segment mouse coordinate.
* @param {number} overlayradius
* @return {boolean} `true` if the line segment should be selected, `false` otherwise.
*/
lineFilter(start, end, type, mousepoint, overlayradius) {
if (type === 'MultiLineString' || type === 'LineString') {
const startDistance = distance(mousepoint, start);
const endDistance = distance(mousepoint, end);
if (startDistance < endDistance) {
if (startDistance <= overlayradius) {
return false;
} else {
return true;
}
} else if (startDistance > endDistance) {
if (endDistance <= overlayradius) {
return false;
} else {
return true;
}
}
}
}
}

export default SegmentFilter;