Skip to content

Commit

Permalink
add SnapEvent types
Browse files Browse the repository at this point in the history
  • Loading branch information
fmg-lydonchandra committed Jul 2, 2023
1 parent 2f3a1ad commit 5922e5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
35 changes: 33 additions & 2 deletions src/ol/events/SnapEvent.js
@@ -1,10 +1,41 @@
import BaseEvent from './Event.js';
/**
* @module ol/events/SnapEvent
*/
import Event from './Event.js';

export class SnapEvent extends BaseEvent {
/**
* @classdesc
* Events emitted by {@link module:ol/interaction/Snap~Snap} instances are instances of this
*/
class SnapEvent extends Event {
/**
* @param {Object} options Options.
* @param {import("../coordinate.js").Coordinate} options.vertex The snapped vertex.
* @param {import("../coordinate.js").Coordinate} options.vertexPixel The pixel of the snapped vertex.
* @param {import("../Feature.js").default} options.feature The feature being snapped.
*
*/
constructor(options) {
super('snap');
/**
* The Map coordinate of the snapped point.
* @type {import("../coordinate.js").Coordinate}
* @api
*/
this.vertex = options.vertex;
/**
* The Map pixel of the snapped point.
* @type {Array<number>&Array<number>}
* @api
*/
this.vertexPixel = options.vertexPixel;
/**
* The feature closest to the snapped point.
* @type {import("../Feature.js").default<import("../geom/Geometry.js").default>}
* @api
*/
this.feature = options.feature;
}
}

export default SnapEvent;
7 changes: 5 additions & 2 deletions src/ol/interaction/Snap.js
Expand Up @@ -5,9 +5,9 @@ import CollectionEventType from '../CollectionEventType.js';
import EventType from '../events/EventType.js';
import PointerInteraction from './Pointer.js';
import RBush from '../structs/RBush.js';
import SnapEvent from '../events/SnapEvent.js';
import VectorEventType from '../source/VectorEventType.js';
import {FALSE, TRUE} from '../functions.js';
import {SnapEvent} from '../events/SnapEvent.js';
import {boundingExtent, buffer, createEmpty} from '../extent.js';
import {
closestOnCircle,
Expand Down Expand Up @@ -103,6 +103,7 @@ const tempSegment = [];
*
* map.addInteraction(snap);
*
* @fires SnapEvent
* @api
*/
class Snap extends PointerInteraction {
Expand Down Expand Up @@ -137,7 +138,7 @@ class Snap extends PointerInteraction {
this.once;

/***
* @type {SnapOnSignature<import("../events").EventsKey>}
* @type {SnapOnSignature<void>}
*/
this.un;

Expand Down Expand Up @@ -290,6 +291,8 @@ class Snap extends PointerInteraction {
/**
* @param {import("../MapBrowserEvent.js").default} evt Map browser event.
* @return {boolean} `false` to stop event propagation.
* @fires SnapEvent
* @api
*/
handleEvent(evt) {
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
Expand Down

0 comments on commit 5922e5b

Please sign in to comment.