Replace instanceof checks with other logic
This commit is contained in:
@@ -56,7 +56,7 @@ import {createEditingStyle} from '../style/Style.js';
|
||||
* @property {import("../events/condition.js").Condition} [finishCondition] A function
|
||||
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
||||
* boolean to indicate whether the drawing can be finished.
|
||||
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style]
|
||||
* @property {import("../style/Style.js").StyleLike} [style]
|
||||
* Style for sketch features.
|
||||
* @property {GeometryFunction} [geometryFunction]
|
||||
* Function that is called when a geometry's coordinates are updated.
|
||||
@@ -206,7 +206,7 @@ class Draw extends PointerInteraction {
|
||||
this.downPx_ = null;
|
||||
|
||||
/**
|
||||
* @type {any}
|
||||
* @type {?}
|
||||
* @private
|
||||
*/
|
||||
this.downTimeout_;
|
||||
@@ -734,12 +734,12 @@ class Draw extends PointerInteraction {
|
||||
}
|
||||
/** @type {LineString} */
|
||||
let sketchLineGeom;
|
||||
if (geometry instanceof Polygon &&
|
||||
if (geometry.getType() == GeometryType.POLYGON &&
|
||||
this.mode_ !== Mode.POLYGON) {
|
||||
if (!this.sketchLine_) {
|
||||
this.sketchLine_ = new Feature();
|
||||
}
|
||||
const ring = geometry.getLinearRing(0);
|
||||
const ring = /** @type {Polygon} */ (geometry).getLinearRing(0);
|
||||
sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry());
|
||||
if (!sketchLineGeom) {
|
||||
sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
|
||||
import {squaredDistanceToSegment, closestOnSegment, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
|
||||
import Event from '../events/Event.js';
|
||||
import {boundingExtent, getArea} from '../extent.js';
|
||||
@@ -20,12 +19,12 @@ import {createEditingStyle} from '../style/Style.js';
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../extent.js").Extent} [extent] Initial extent. Defaults to no
|
||||
* initial extent.
|
||||
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [boxStyle]
|
||||
* @property {import("../style/Style.js").StyleLike} [boxStyle]
|
||||
* Style for the drawn extent box. Defaults to
|
||||
* {@link module:ol/style/Style~createEditing()['Polygon']}
|
||||
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the
|
||||
* pointer close enough to a segment or vertex for editing.
|
||||
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [pointerStyle]
|
||||
* @property {import("../style/Style.js").StyleLike} [pointerStyle]
|
||||
* Style for the cursor used to draw the extent. Defaults to
|
||||
* {@link module:ol/style/Style~createEditing()['Point']}
|
||||
* @property {boolean} [wrapX=false] Wrap the drawn extent across multiple maps
|
||||
@@ -276,7 +275,7 @@ class ExtentInteraction extends PointerInteraction {
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleEvent(mapBrowserEvent) {
|
||||
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
||||
if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
|
||||
return true;
|
||||
}
|
||||
//display pointer (if not dragging)
|
||||
|
||||
@@ -6,7 +6,6 @@ import Collection from '../Collection.js';
|
||||
import CollectionEventType from '../CollectionEventType.js';
|
||||
import Feature from '../Feature.js';
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
|
||||
import {equals} from '../array.js';
|
||||
import {equals as coordinatesEqual, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, squaredDistanceToSegment, closestOnSegment} from '../coordinate.js';
|
||||
import {listen, unlisten} from '../events.js';
|
||||
@@ -87,7 +86,7 @@ const ModifyEventType = {
|
||||
* features. Default is {@link module:ol/events/condition~always}.
|
||||
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the
|
||||
* pointer close enough to a segment or vertex for editing.
|
||||
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style]
|
||||
* @property {import("../style/Style.js").StyleLike} [style]
|
||||
* Style used for the features being modified. By default the default edit
|
||||
* style is used (see {@link module:ol/style}).
|
||||
* @property {VectorSource} [source] The vector source with
|
||||
@@ -111,7 +110,7 @@ export class ModifyEvent extends Event {
|
||||
* @param {ModifyEventType} type Type.
|
||||
* @param {Collection<Feature>} features
|
||||
* The features modified.
|
||||
* @param {MapBrowserPointerEvent} mapBrowserPointerEvent
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserPointerEvent
|
||||
* Associated {@link module:ol/MapBrowserPointerEvent}.
|
||||
*/
|
||||
constructor(type, features, mapBrowserPointerEvent) {
|
||||
@@ -324,7 +323,7 @@ class Modify extends PointerInteraction {
|
||||
this.handleFeatureRemove_, this);
|
||||
|
||||
/**
|
||||
* @type {MapBrowserPointerEvent}
|
||||
* @type {import("../MapBrowserPointerEvent.js").default}
|
||||
* @private
|
||||
*/
|
||||
this.lastPointerEvent_ = null;
|
||||
@@ -349,7 +348,7 @@ class Modify extends PointerInteraction {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MapBrowserPointerEvent} evt Map browser event
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} evt Map browser event
|
||||
* @private
|
||||
*/
|
||||
willModifyFeatures_(evt) {
|
||||
@@ -666,7 +665,7 @@ class Modify extends PointerInteraction {
|
||||
* @override
|
||||
*/
|
||||
handleEvent(mapBrowserEvent) {
|
||||
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
||||
if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
|
||||
return true;
|
||||
}
|
||||
this.lastPointerEvent_ = mapBrowserEvent;
|
||||
|
||||
@@ -108,7 +108,7 @@ class MouseWheelZoom extends Interaction {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {any}
|
||||
* @type {?}
|
||||
*/
|
||||
this.timeoutId_;
|
||||
|
||||
@@ -126,7 +126,7 @@ class MouseWheelZoom extends Interaction {
|
||||
this.trackpadEventGap_ = 400;
|
||||
|
||||
/**
|
||||
* @type {any}
|
||||
* @type {?}
|
||||
*/
|
||||
this.trackpadTimeoutId_;
|
||||
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
* @module ol/interaction/Pointer
|
||||
*/
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
|
||||
import Interaction from '../interaction/Interaction.js';
|
||||
import {getValues} from '../obj.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {function(MapBrowserPointerEvent):boolean} [handleDownEvent]
|
||||
* @property {function(import("../MapBrowserPointerEvent.js").default):boolean} [handleDownEvent]
|
||||
* Function handling "down" events. If the function returns `true` then a drag
|
||||
* sequence is started.
|
||||
* @property {function(MapBrowserPointerEvent)} [handleDragEvent]
|
||||
* @property {function(import("../MapBrowserPointerEvent.js").default)} [handleDragEvent]
|
||||
* Function handling "drag" events. This function is called on "move" events
|
||||
* during a drag sequence.
|
||||
* @property {function(import("../MapBrowserEvent.js").default):boolean} [handleEvent]
|
||||
@@ -20,11 +19,11 @@ import {getValues} from '../obj.js';
|
||||
* dispatched to the map. The function may return `false` to prevent the
|
||||
* propagation of the event to other interactions in the map's interactions
|
||||
* chain.
|
||||
* @property {function(MapBrowserPointerEvent)} [handleMoveEvent]
|
||||
* @property {function(import("../MapBrowserPointerEvent.js").default)} [handleMoveEvent]
|
||||
* Function handling "move" events. This function is called on "move" events,
|
||||
* also during a drag sequence (so during a drag sequence both the
|
||||
* `handleDragEvent` function and this function are called).
|
||||
* @property {function(MapBrowserPointerEvent):boolean} [handleUpEvent]
|
||||
* @property {function(import("../MapBrowserPointerEvent.js").default):boolean} [handleUpEvent]
|
||||
* Function handling "up" events. If the function returns `false` then the
|
||||
* current drag sequence is stopped.
|
||||
* @property {function(boolean):boolean} [stopDown]
|
||||
@@ -96,7 +95,7 @@ class PointerInteraction extends Interaction {
|
||||
|
||||
/**
|
||||
* Handle pointer down events.
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} If the event was consumed.
|
||||
* @protected
|
||||
*/
|
||||
@@ -106,7 +105,7 @@ class PointerInteraction extends Interaction {
|
||||
|
||||
/**
|
||||
* Handle pointer drag events.
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
handleDragEvent(mapBrowserEvent) {}
|
||||
@@ -119,7 +118,7 @@ class PointerInteraction extends Interaction {
|
||||
* @api
|
||||
*/
|
||||
handleEvent(mapBrowserEvent) {
|
||||
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
||||
if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,14 +148,14 @@ class PointerInteraction extends Interaction {
|
||||
|
||||
/**
|
||||
* Handle pointer move events.
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
handleMoveEvent(mapBrowserEvent) {}
|
||||
|
||||
/**
|
||||
* Handle pointer up events.
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} If the event was consumed.
|
||||
* @protected
|
||||
*/
|
||||
@@ -175,7 +174,7 @@ class PointerInteraction extends Interaction {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @private
|
||||
*/
|
||||
updateTrackedPointers_(mapBrowserEvent) {
|
||||
@@ -216,7 +215,7 @@ export function centroid(pointerEvents) {
|
||||
|
||||
|
||||
/**
|
||||
* @param {MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} Whether the event is a pointerdown, pointerdrag
|
||||
* or pointerup event.
|
||||
*/
|
||||
|
||||
@@ -60,7 +60,7 @@ const SelectEventType = {
|
||||
* in the map and should return `true` for layers that you want to be
|
||||
* selectable. If the option is absent, all visible layers will be considered
|
||||
* selectable.
|
||||
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style]
|
||||
* @property {import("../style/Style.js").StyleLike} [style]
|
||||
* Style for the selected features. By default the default edit style is used
|
||||
* (see {@link module:ol/style}).
|
||||
* @property {import("../events/condition.js").Condition} [removeCondition] A function
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/interaction/Snap
|
||||
*/
|
||||
import {getUid} from '../util.js';
|
||||
import {CollectionEvent} from '../Collection.js';
|
||||
import CollectionEventType from '../CollectionEventType.js';
|
||||
import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
@@ -13,7 +12,6 @@ import GeometryType from '../geom/GeometryType.js';
|
||||
import {fromCircle} from '../geom/Polygon.js';
|
||||
import PointerInteraction from '../interaction/Pointer.js';
|
||||
import {getValues} from '../obj.js';
|
||||
import {VectorSourceEvent} from '../source/Vector.js';
|
||||
import VectorEventType from '../source/VectorEventType.js';
|
||||
import RBush from '../structs/RBush.js';
|
||||
|
||||
@@ -44,6 +42,19 @@ import RBush from '../structs/RBush.js';
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../source/Vector.js").VectorSourceEvent|import("../Collection.js").CollectionEvent} evt Event.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
function getFeatureFromEvent(evt) {
|
||||
if (/** @type {import("../source/Vector.js").VectorSourceEvent} */ (evt).feature) {
|
||||
return /** @type {import("../source/Vector.js").VectorSourceEvent} */ (evt).feature;
|
||||
} else if (/** @type {import("../Collection.js").CollectionEvent} */ (evt).element) {
|
||||
return /** @type {import("../Feature.js").default} */ (/** @type {import("../Collection.js").CollectionEvent} */ (evt).element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Handles snapping of vector features while modifying or drawing them. The
|
||||
@@ -259,12 +270,7 @@ class Snap extends PointerInteraction {
|
||||
* @private
|
||||
*/
|
||||
handleFeatureAdd_(evt) {
|
||||
let feature;
|
||||
if (evt instanceof VectorSourceEvent) {
|
||||
feature = evt.feature;
|
||||
} else if (evt instanceof CollectionEvent) {
|
||||
feature = /** @type {import("../Feature.js").default} */ (evt.element);
|
||||
}
|
||||
const feature = getFeatureFromEvent(evt);
|
||||
this.addFeature(feature);
|
||||
}
|
||||
|
||||
@@ -273,12 +279,7 @@ class Snap extends PointerInteraction {
|
||||
* @private
|
||||
*/
|
||||
handleFeatureRemove_(evt) {
|
||||
let feature;
|
||||
if (evt instanceof VectorSourceEvent) {
|
||||
feature = evt.feature;
|
||||
} else if (evt instanceof CollectionEvent) {
|
||||
feature = /** @type {import("../Feature.js").default} */ (evt.element);
|
||||
}
|
||||
const feature = getFeatureFromEvent(evt);
|
||||
this.removeFeature(feature);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user