Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
+140
-144
@@ -89,47 +89,156 @@ inherits(DragAndDropEvent, Event);
|
||||
* @param {module:ol/interaction/DragAndDrop~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const DragAndDrop = function(opt_options) {
|
||||
class DragAndDrop {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
Interaction.call(this, {
|
||||
handleEvent: TRUE
|
||||
});
|
||||
Interaction.call(this, {
|
||||
handleEvent: TRUE
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<function(new: module:ol/format/Feature)>}
|
||||
*/
|
||||
this.formatConstructors_ = options.formatConstructors ?
|
||||
options.formatConstructors : [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.projection_ = options.projection ?
|
||||
getProjection(options.projection) : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/events~EventsKey>}
|
||||
*/
|
||||
this.dropListenKeys_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/source/Vector}
|
||||
*/
|
||||
this.source_ = options.source || null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.target = options.target ? options.target : null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {File} file File.
|
||||
* @param {Event} event Load event.
|
||||
* @private
|
||||
*/
|
||||
handleResult_(file, event) {
|
||||
const result = event.target.result;
|
||||
const map = this.getMap();
|
||||
let projection = this.projection_;
|
||||
if (!projection) {
|
||||
const view = map.getView();
|
||||
projection = view.getProjection();
|
||||
}
|
||||
|
||||
const formatConstructors = this.formatConstructors_;
|
||||
let features = [];
|
||||
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||
/**
|
||||
* Avoid "cannot instantiate abstract class" error.
|
||||
* @type {Function}
|
||||
*/
|
||||
const formatConstructor = formatConstructors[i];
|
||||
/**
|
||||
* @type {module:ol/format/Feature}
|
||||
*/
|
||||
const format = new formatConstructor();
|
||||
features = this.tryReadFeatures_(format, result, {
|
||||
featureProjection: projection
|
||||
});
|
||||
if (features && features.length > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.source_) {
|
||||
this.source_.clear();
|
||||
this.source_.addFeatures(features);
|
||||
}
|
||||
this.dispatchEvent(
|
||||
new DragAndDropEvent(
|
||||
DragAndDropEventType.ADD_FEATURES, file,
|
||||
features, projection));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<function(new: module:ol/format/Feature)>}
|
||||
*/
|
||||
this.formatConstructors_ = options.formatConstructors ?
|
||||
options.formatConstructors : [];
|
||||
registerListeners_() {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
const dropArea = this.target ? this.target : map.getViewport();
|
||||
this.dropListenKeys_ = [
|
||||
listen(dropArea, EventType.DROP, handleDrop, this),
|
||||
listen(dropArea, EventType.DRAGENTER, handleStop, this),
|
||||
listen(dropArea, EventType.DRAGOVER, handleStop, this),
|
||||
listen(dropArea, EventType.DROP, handleStop, this)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
setActive(active) {
|
||||
Interaction.prototype.setActive.call(this, active);
|
||||
if (active) {
|
||||
this.registerListeners_();
|
||||
} else {
|
||||
this.unregisterListeners_();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
setMap(map) {
|
||||
this.unregisterListeners_();
|
||||
Interaction.prototype.setMap.call(this, map);
|
||||
if (this.getActive()) {
|
||||
this.registerListeners_();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/format/Feature} format Format.
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions} options Read options.
|
||||
* @private
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
tryReadFeatures_(format, text, options) {
|
||||
try {
|
||||
return format.readFeatures(text, options);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.projection_ = options.projection ?
|
||||
getProjection(options.projection) : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/events~EventsKey>}
|
||||
*/
|
||||
this.dropListenKeys_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/source/Vector}
|
||||
*/
|
||||
this.source_ = options.source || null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.target = options.target ? options.target : null;
|
||||
|
||||
};
|
||||
unregisterListeners_() {
|
||||
if (this.dropListenKeys_) {
|
||||
this.dropListenKeys_.forEach(unlistenByKey);
|
||||
this.dropListenKeys_ = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(DragAndDrop, Interaction);
|
||||
|
||||
@@ -159,117 +268,4 @@ function handleStop(event) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {File} file File.
|
||||
* @param {Event} event Load event.
|
||||
* @private
|
||||
*/
|
||||
DragAndDrop.prototype.handleResult_ = function(file, event) {
|
||||
const result = event.target.result;
|
||||
const map = this.getMap();
|
||||
let projection = this.projection_;
|
||||
if (!projection) {
|
||||
const view = map.getView();
|
||||
projection = view.getProjection();
|
||||
}
|
||||
|
||||
const formatConstructors = this.formatConstructors_;
|
||||
let features = [];
|
||||
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||
/**
|
||||
* Avoid "cannot instantiate abstract class" error.
|
||||
* @type {Function}
|
||||
*/
|
||||
const formatConstructor = formatConstructors[i];
|
||||
/**
|
||||
* @type {module:ol/format/Feature}
|
||||
*/
|
||||
const format = new formatConstructor();
|
||||
features = this.tryReadFeatures_(format, result, {
|
||||
featureProjection: projection
|
||||
});
|
||||
if (features && features.length > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.source_) {
|
||||
this.source_.clear();
|
||||
this.source_.addFeatures(features);
|
||||
}
|
||||
this.dispatchEvent(
|
||||
new DragAndDropEvent(
|
||||
DragAndDropEventType.ADD_FEATURES, file,
|
||||
features, projection));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DragAndDrop.prototype.registerListeners_ = function() {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
const dropArea = this.target ? this.target : map.getViewport();
|
||||
this.dropListenKeys_ = [
|
||||
listen(dropArea, EventType.DROP, handleDrop, this),
|
||||
listen(dropArea, EventType.DRAGENTER, handleStop, this),
|
||||
listen(dropArea, EventType.DRAGOVER, handleStop, this),
|
||||
listen(dropArea, EventType.DROP, handleStop, this)
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
DragAndDrop.prototype.setActive = function(active) {
|
||||
Interaction.prototype.setActive.call(this, active);
|
||||
if (active) {
|
||||
this.registerListeners_();
|
||||
} else {
|
||||
this.unregisterListeners_();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
DragAndDrop.prototype.setMap = function(map) {
|
||||
this.unregisterListeners_();
|
||||
Interaction.prototype.setMap.call(this, map);
|
||||
if (this.getActive()) {
|
||||
this.registerListeners_();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/format/Feature} format Format.
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions} options Read options.
|
||||
* @private
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
DragAndDrop.prototype.tryReadFeatures_ = function(format, text, options) {
|
||||
try {
|
||||
return format.readFeatures(text, options);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DragAndDrop.prototype.unregisterListeners_ = function() {
|
||||
if (this.dropListenKeys_) {
|
||||
this.dropListenKeys_.forEach(unlistenByKey);
|
||||
this.dropListenKeys_ = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default DragAndDrop;
|
||||
|
||||
@@ -110,47 +110,58 @@ inherits(DragBoxEvent, Event);
|
||||
* @param {module:ol/interaction/DragBox~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const DragBox = function(opt_options) {
|
||||
class DragBox {
|
||||
constructor(opt_options) {
|
||||
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @type {module:ol/render/Box}
|
||||
* @private
|
||||
*/
|
||||
this.box_ = new RenderBox(options.className || 'ol-dragbox');
|
||||
/**
|
||||
* @type {module:ol/render/Box}
|
||||
* @private
|
||||
*/
|
||||
this.box_ = new RenderBox(options.className || 'ol-dragbox');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.minArea_ = options.minArea !== undefined ? options.minArea : 64;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.minArea_ = options.minArea !== undefined ? options.minArea : 64;
|
||||
|
||||
/**
|
||||
* @type {module:ol~Pixel}
|
||||
* @private
|
||||
*/
|
||||
this.startPixel_ = null;
|
||||
/**
|
||||
* @type {module:ol~Pixel}
|
||||
* @private
|
||||
*/
|
||||
this.startPixel_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : always;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : always;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/DragBox~EndCondition}
|
||||
*/
|
||||
this.boxEndCondition_ = options.boxEndCondition ?
|
||||
options.boxEndCondition : defaultBoxEndCondition;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/DragBox~EndCondition}
|
||||
*/
|
||||
this.boxEndCondition_ = options.boxEndCondition ?
|
||||
options.boxEndCondition : defaultBoxEndCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns geometry of last drawn box.
|
||||
* @return {module:ol/geom/Polygon} Geometry.
|
||||
* @api
|
||||
*/
|
||||
getGeometry() {
|
||||
return this.box_.getGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(DragBox, PointerInteraction);
|
||||
|
||||
@@ -188,16 +199,6 @@ function handleDragEvent(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns geometry of last drawn box.
|
||||
* @return {module:ol/geom/Polygon} Geometry.
|
||||
* @api
|
||||
*/
|
||||
DragBox.prototype.getGeometry = function() {
|
||||
return this.box_.getGeometry();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* To be overridden by child classes.
|
||||
* FIXME: use constructor option instead of relying on overriding.
|
||||
|
||||
@@ -35,68 +35,71 @@ import DragBox from '../interaction/DragBox.js';
|
||||
* @param {module:ol/interaction/DragZoom~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const DragZoom = function(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
class DragZoom {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const condition = options.condition ? options.condition : shiftKeyOnly;
|
||||
const condition = options.condition ? options.condition : shiftKeyOnly;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 200;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.out_ = options.out !== undefined ? options.out : false;
|
||||
|
||||
DragBox.call(this, {
|
||||
condition: condition,
|
||||
className: options.className || 'ol-dragzoom'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 200;
|
||||
onBoxEnd() {
|
||||
const map = this.getMap();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.out_ = options.out !== undefined ? options.out : false;
|
||||
const view = /** @type {!module:ol/View} */ (map.getView());
|
||||
|
||||
DragBox.call(this, {
|
||||
condition: condition,
|
||||
className: options.className || 'ol-dragzoom'
|
||||
});
|
||||
const size = /** @type {!module:ol/size~Size} */ (map.getSize());
|
||||
|
||||
};
|
||||
let extent = this.getGeometry().getExtent();
|
||||
|
||||
if (this.out_) {
|
||||
const mapExtent = view.calculateExtent(size);
|
||||
const boxPixelExtent = createOrUpdateFromCoordinates([
|
||||
map.getPixelFromCoordinate(getBottomLeft(extent)),
|
||||
map.getPixelFromCoordinate(getTopRight(extent))]);
|
||||
const factor = view.getResolutionForExtent(boxPixelExtent, size);
|
||||
|
||||
scaleFromCenter(mapExtent, 1 / factor);
|
||||
extent = mapExtent;
|
||||
}
|
||||
|
||||
const resolution = view.constrainResolution(
|
||||
view.getResolutionForExtent(extent, size));
|
||||
|
||||
let center = getCenter(extent);
|
||||
center = view.constrainCenter(center);
|
||||
|
||||
view.animate({
|
||||
resolution: resolution,
|
||||
center: center,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
inherits(DragZoom, DragBox);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
DragZoom.prototype.onBoxEnd = function() {
|
||||
const map = this.getMap();
|
||||
|
||||
const view = /** @type {!module:ol/View} */ (map.getView());
|
||||
|
||||
const size = /** @type {!module:ol/size~Size} */ (map.getSize());
|
||||
|
||||
let extent = this.getGeometry().getExtent();
|
||||
|
||||
if (this.out_) {
|
||||
const mapExtent = view.calculateExtent(size);
|
||||
const boxPixelExtent = createOrUpdateFromCoordinates([
|
||||
map.getPixelFromCoordinate(getBottomLeft(extent)),
|
||||
map.getPixelFromCoordinate(getTopRight(extent))]);
|
||||
const factor = view.getResolutionForExtent(boxPixelExtent, size);
|
||||
|
||||
scaleFromCenter(mapExtent, 1 / factor);
|
||||
extent = mapExtent;
|
||||
}
|
||||
|
||||
const resolution = view.constrainResolution(
|
||||
view.getResolutionForExtent(extent, size));
|
||||
|
||||
let center = getCenter(extent);
|
||||
center = view.constrainCenter(center);
|
||||
|
||||
view.animate({
|
||||
resolution: resolution,
|
||||
center: center,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
});
|
||||
|
||||
};
|
||||
export default DragZoom;
|
||||
|
||||
+606
-617
File diff suppressed because it is too large
Load Diff
+211
-211
@@ -82,98 +82,233 @@ inherits(ExtentInteractionEvent, Event);
|
||||
* @param {module:ol/interaction/Extent~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const ExtentInteraction = function(opt_options) {
|
||||
class ExtentInteraction {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options || {};
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* Extent of the drawn box
|
||||
* @type {module:ol/extent~Extent}
|
||||
* @private
|
||||
*/
|
||||
this.extent_ = null;
|
||||
/**
|
||||
* Extent of the drawn box
|
||||
* @type {module:ol/extent~Extent}
|
||||
* @private
|
||||
*/
|
||||
this.extent_ = null;
|
||||
|
||||
/**
|
||||
* Handler for pointer move events
|
||||
* @type {function (module:ol/coordinate~Coordinate): module:ol/extent~Extent|null}
|
||||
* @private
|
||||
*/
|
||||
this.pointerHandler_ = null;
|
||||
/**
|
||||
* Handler for pointer move events
|
||||
* @type {function (module:ol/coordinate~Coordinate): module:ol/extent~Extent|null}
|
||||
* @private
|
||||
*/
|
||||
this.pointerHandler_ = null;
|
||||
|
||||
/**
|
||||
* Pixel threshold to snap to extent
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.pixelTolerance_ = options.pixelTolerance !== undefined ?
|
||||
options.pixelTolerance : 10;
|
||||
/**
|
||||
* Pixel threshold to snap to extent
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.pixelTolerance_ = options.pixelTolerance !== undefined ?
|
||||
options.pixelTolerance : 10;
|
||||
|
||||
/**
|
||||
* Is the pointer snapped to an extent vertex
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.snappedToVertex_ = false;
|
||||
/**
|
||||
* Is the pointer snapped to an extent vertex
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.snappedToVertex_ = false;
|
||||
|
||||
/**
|
||||
* Feature for displaying the visible extent
|
||||
* @type {module:ol/Feature}
|
||||
* @private
|
||||
*/
|
||||
this.extentFeature_ = null;
|
||||
/**
|
||||
* Feature for displaying the visible extent
|
||||
* @type {module:ol/Feature}
|
||||
* @private
|
||||
*/
|
||||
this.extentFeature_ = null;
|
||||
|
||||
/**
|
||||
* Feature for displaying the visible pointer
|
||||
* @type {module:ol/Feature}
|
||||
* @private
|
||||
*/
|
||||
this.vertexFeature_ = null;
|
||||
/**
|
||||
* Feature for displaying the visible pointer
|
||||
* @type {module:ol/Feature}
|
||||
* @private
|
||||
*/
|
||||
this.vertexFeature_ = null;
|
||||
|
||||
if (!opt_options) {
|
||||
opt_options = {};
|
||||
if (!opt_options) {
|
||||
opt_options = {};
|
||||
}
|
||||
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleEvent: handleEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
|
||||
/**
|
||||
* Layer for the extentFeature
|
||||
* @type {module:ol/layer/Vector}
|
||||
* @private
|
||||
*/
|
||||
this.extentOverlay_ = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
wrapX: !!opt_options.wrapX
|
||||
}),
|
||||
style: opt_options.boxStyle ? opt_options.boxStyle : getDefaultExtentStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Layer for the vertexFeature
|
||||
* @type {module:ol/layer/Vector}
|
||||
* @private
|
||||
*/
|
||||
this.vertexOverlay_ = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
wrapX: !!opt_options.wrapX
|
||||
}),
|
||||
style: opt_options.pointerStyle ? opt_options.pointerStyle : getDefaultPointerStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
|
||||
if (opt_options.extent) {
|
||||
this.setExtent(opt_options.extent);
|
||||
}
|
||||
}
|
||||
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleEvent: handleEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
|
||||
/**
|
||||
* Layer for the extentFeature
|
||||
* @type {module:ol/layer/Vector}
|
||||
* @param {module:ol~Pixel} pixel cursor location
|
||||
* @param {module:ol/PluggableMap} map map
|
||||
* @returns {module:ol/coordinate~Coordinate|null} snapped vertex on extent
|
||||
* @private
|
||||
*/
|
||||
this.extentOverlay_ = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
wrapX: !!opt_options.wrapX
|
||||
}),
|
||||
style: opt_options.boxStyle ? opt_options.boxStyle : getDefaultExtentStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
snapToVertex_(pixel, map) {
|
||||
const pixelCoordinate = map.getCoordinateFromPixel(pixel);
|
||||
const sortByDistance = function(a, b) {
|
||||
return squaredDistanceToSegment(pixelCoordinate, a) -
|
||||
squaredDistanceToSegment(pixelCoordinate, b);
|
||||
};
|
||||
const extent = this.getExtent();
|
||||
if (extent) {
|
||||
//convert extents to line segments and find the segment closest to pixelCoordinate
|
||||
const segments = getSegments(extent);
|
||||
segments.sort(sortByDistance);
|
||||
const closestSegment = segments[0];
|
||||
|
||||
/**
|
||||
* Layer for the vertexFeature
|
||||
* @type {module:ol/layer/Vector}
|
||||
* @private
|
||||
*/
|
||||
this.vertexOverlay_ = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
wrapX: !!opt_options.wrapX
|
||||
}),
|
||||
style: opt_options.pointerStyle ? opt_options.pointerStyle : getDefaultPointerStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
let vertex = (closestOnSegment(pixelCoordinate,
|
||||
closestSegment));
|
||||
const vertexPixel = map.getPixelFromCoordinate(vertex);
|
||||
|
||||
if (opt_options.extent) {
|
||||
this.setExtent(opt_options.extent);
|
||||
//if the distance is within tolerance, snap to the segment
|
||||
if (coordinateDistance(pixel, vertexPixel) <= this.pixelTolerance_) {
|
||||
//test if we should further snap to a vertex
|
||||
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
|
||||
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
|
||||
const squaredDist1 = squaredCoordinateDistance(vertexPixel, pixel1);
|
||||
const squaredDist2 = squaredCoordinateDistance(vertexPixel, pixel2);
|
||||
const dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
|
||||
this.snappedToVertex_ = dist <= this.pixelTolerance_;
|
||||
if (this.snappedToVertex_) {
|
||||
vertex = squaredDist1 > squaredDist2 ?
|
||||
closestSegment[1] : closestSegment[0];
|
||||
}
|
||||
return vertex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {module:ol/MapBrowserEvent} mapBrowserEvent pointer move event
|
||||
* @private
|
||||
*/
|
||||
handlePointerMove_(mapBrowserEvent) {
|
||||
const pixel = mapBrowserEvent.pixel;
|
||||
const map = mapBrowserEvent.map;
|
||||
|
||||
let vertex = this.snapToVertex_(pixel, map);
|
||||
if (!vertex) {
|
||||
vertex = map.getCoordinateFromPixel(pixel);
|
||||
}
|
||||
this.createOrUpdatePointerFeature_(vertex);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/extent~Extent} extent extent
|
||||
* @returns {module:ol/Feature} extent as featrue
|
||||
* @private
|
||||
*/
|
||||
createOrUpdateExtentFeature_(extent) {
|
||||
let extentFeature = this.extentFeature_;
|
||||
|
||||
if (!extentFeature) {
|
||||
if (!extent) {
|
||||
extentFeature = new Feature({});
|
||||
} else {
|
||||
extentFeature = new Feature(polygonFromExtent(extent));
|
||||
}
|
||||
this.extentFeature_ = extentFeature;
|
||||
this.extentOverlay_.getSource().addFeature(extentFeature);
|
||||
} else {
|
||||
if (!extent) {
|
||||
extentFeature.setGeometry(undefined);
|
||||
} else {
|
||||
extentFeature.setGeometry(polygonFromExtent(extent));
|
||||
}
|
||||
}
|
||||
return extentFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/coordinate~Coordinate} vertex location of feature
|
||||
* @returns {module:ol/Feature} vertex as feature
|
||||
* @private
|
||||
*/
|
||||
createOrUpdatePointerFeature_(vertex) {
|
||||
let vertexFeature = this.vertexFeature_;
|
||||
if (!vertexFeature) {
|
||||
vertexFeature = new Feature(new Point(vertex));
|
||||
this.vertexFeature_ = vertexFeature;
|
||||
this.vertexOverlay_.getSource().addFeature(vertexFeature);
|
||||
} else {
|
||||
const geometry = /** @type {module:ol/geom/Point} */ (vertexFeature.getGeometry());
|
||||
geometry.setCoordinates(vertex);
|
||||
}
|
||||
return vertexFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
setMap(map) {
|
||||
this.extentOverlay_.setMap(map);
|
||||
this.vertexOverlay_.setMap(map);
|
||||
PointerInteraction.prototype.setMap.call(this, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current drawn extent in the view projection
|
||||
*
|
||||
* @return {module:ol/extent~Extent} Drawn extent in the view projection.
|
||||
* @api
|
||||
*/
|
||||
getExtent() {
|
||||
return this.extent_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually sets the drawn extent, using the view projection.
|
||||
*
|
||||
* @param {module:ol/extent~Extent} extent Extent
|
||||
* @api
|
||||
*/
|
||||
setExtent(extent) {
|
||||
//Null extent means no bbox
|
||||
this.extent_ = extent ? extent : null;
|
||||
this.createOrUpdateExtentFeature_(extent);
|
||||
this.dispatchEvent(new ExtentInteractionEvent(this.extent_));
|
||||
}
|
||||
}
|
||||
|
||||
inherits(ExtentInteraction, PointerInteraction);
|
||||
|
||||
@@ -350,140 +485,5 @@ function getSegments(extent) {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol~Pixel} pixel cursor location
|
||||
* @param {module:ol/PluggableMap} map map
|
||||
* @returns {module:ol/coordinate~Coordinate|null} snapped vertex on extent
|
||||
* @private
|
||||
*/
|
||||
ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
|
||||
const pixelCoordinate = map.getCoordinateFromPixel(pixel);
|
||||
const sortByDistance = function(a, b) {
|
||||
return squaredDistanceToSegment(pixelCoordinate, a) -
|
||||
squaredDistanceToSegment(pixelCoordinate, b);
|
||||
};
|
||||
const extent = this.getExtent();
|
||||
if (extent) {
|
||||
//convert extents to line segments and find the segment closest to pixelCoordinate
|
||||
const segments = getSegments(extent);
|
||||
segments.sort(sortByDistance);
|
||||
const closestSegment = segments[0];
|
||||
|
||||
let vertex = (closestOnSegment(pixelCoordinate,
|
||||
closestSegment));
|
||||
const vertexPixel = map.getPixelFromCoordinate(vertex);
|
||||
|
||||
//if the distance is within tolerance, snap to the segment
|
||||
if (coordinateDistance(pixel, vertexPixel) <= this.pixelTolerance_) {
|
||||
//test if we should further snap to a vertex
|
||||
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
|
||||
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
|
||||
const squaredDist1 = squaredCoordinateDistance(vertexPixel, pixel1);
|
||||
const squaredDist2 = squaredCoordinateDistance(vertexPixel, pixel2);
|
||||
const dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
|
||||
this.snappedToVertex_ = dist <= this.pixelTolerance_;
|
||||
if (this.snappedToVertex_) {
|
||||
vertex = squaredDist1 > squaredDist2 ?
|
||||
closestSegment[1] : closestSegment[0];
|
||||
}
|
||||
return vertex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {module:ol/MapBrowserEvent} mapBrowserEvent pointer move event
|
||||
* @private
|
||||
*/
|
||||
ExtentInteraction.prototype.handlePointerMove_ = function(mapBrowserEvent) {
|
||||
const pixel = mapBrowserEvent.pixel;
|
||||
const map = mapBrowserEvent.map;
|
||||
|
||||
let vertex = this.snapToVertex_(pixel, map);
|
||||
if (!vertex) {
|
||||
vertex = map.getCoordinateFromPixel(pixel);
|
||||
}
|
||||
this.createOrUpdatePointerFeature_(vertex);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {module:ol/extent~Extent} extent extent
|
||||
* @returns {module:ol/Feature} extent as featrue
|
||||
* @private
|
||||
*/
|
||||
ExtentInteraction.prototype.createOrUpdateExtentFeature_ = function(extent) {
|
||||
let extentFeature = this.extentFeature_;
|
||||
|
||||
if (!extentFeature) {
|
||||
if (!extent) {
|
||||
extentFeature = new Feature({});
|
||||
} else {
|
||||
extentFeature = new Feature(polygonFromExtent(extent));
|
||||
}
|
||||
this.extentFeature_ = extentFeature;
|
||||
this.extentOverlay_.getSource().addFeature(extentFeature);
|
||||
} else {
|
||||
if (!extent) {
|
||||
extentFeature.setGeometry(undefined);
|
||||
} else {
|
||||
extentFeature.setGeometry(polygonFromExtent(extent));
|
||||
}
|
||||
}
|
||||
return extentFeature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/coordinate~Coordinate} vertex location of feature
|
||||
* @returns {module:ol/Feature} vertex as feature
|
||||
* @private
|
||||
*/
|
||||
ExtentInteraction.prototype.createOrUpdatePointerFeature_ = function(vertex) {
|
||||
let vertexFeature = this.vertexFeature_;
|
||||
if (!vertexFeature) {
|
||||
vertexFeature = new Feature(new Point(vertex));
|
||||
this.vertexFeature_ = vertexFeature;
|
||||
this.vertexOverlay_.getSource().addFeature(vertexFeature);
|
||||
} else {
|
||||
const geometry = /** @type {module:ol/geom/Point} */ (vertexFeature.getGeometry());
|
||||
geometry.setCoordinates(vertex);
|
||||
}
|
||||
return vertexFeature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ExtentInteraction.prototype.setMap = function(map) {
|
||||
this.extentOverlay_.setMap(map);
|
||||
this.vertexOverlay_.setMap(map);
|
||||
PointerInteraction.prototype.setMap.call(this, map);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current drawn extent in the view projection
|
||||
*
|
||||
* @return {module:ol/extent~Extent} Drawn extent in the view projection.
|
||||
* @api
|
||||
*/
|
||||
ExtentInteraction.prototype.getExtent = function() {
|
||||
return this.extent_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manually sets the drawn extent, using the view projection.
|
||||
*
|
||||
* @param {module:ol/extent~Extent} extent Extent
|
||||
* @api
|
||||
*/
|
||||
ExtentInteraction.prototype.setExtent = function(extent) {
|
||||
//Null extent means no bbox
|
||||
this.extent_ = extent ? extent : null;
|
||||
this.createOrUpdateExtentFeature_(extent);
|
||||
this.dispatchEvent(new ExtentInteractionEvent(this.extent_));
|
||||
};
|
||||
|
||||
|
||||
export default ExtentInteraction;
|
||||
|
||||
@@ -36,71 +36,69 @@ import {clamp} from '../math.js';
|
||||
* @extends {module:ol/Object}
|
||||
* @api
|
||||
*/
|
||||
const Interaction = function(options) {
|
||||
class Interaction {
|
||||
constructor(options) {
|
||||
|
||||
BaseObject.call(this);
|
||||
BaseObject.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/PluggableMap}
|
||||
*/
|
||||
this.map_ = null;
|
||||
|
||||
this.setActive(true);
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserEvent):boolean}
|
||||
*/
|
||||
this.handleEvent = options.handleEvent;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/PluggableMap}
|
||||
* Return whether the interaction is currently active.
|
||||
* @return {boolean} `true` if the interaction is active, `false` otherwise.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
this.map_ = null;
|
||||
|
||||
this.setActive(true);
|
||||
getActive() {
|
||||
return /** @type {boolean} */ (this.get(InteractionProperty.ACTIVE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserEvent):boolean}
|
||||
* Get the map associated with this interaction.
|
||||
* @return {module:ol/PluggableMap} Map.
|
||||
* @api
|
||||
*/
|
||||
this.handleEvent = options.handleEvent;
|
||||
getMap() {
|
||||
return this.map_;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Activate or deactivate the interaction.
|
||||
* @param {boolean} active Active.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setActive(active) {
|
||||
this.set(InteractionProperty.ACTIVE, active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the interaction from its current map and attach it to the new map.
|
||||
* Subclasses may set up event handlers to get notified about changes to
|
||||
* the map here.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
*/
|
||||
setMap(map) {
|
||||
this.map_ = map;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Interaction, BaseObject);
|
||||
|
||||
|
||||
/**
|
||||
* Return whether the interaction is currently active.
|
||||
* @return {boolean} `true` if the interaction is active, `false` otherwise.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
Interaction.prototype.getActive = function() {
|
||||
return /** @type {boolean} */ (this.get(InteractionProperty.ACTIVE));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the map associated with this interaction.
|
||||
* @return {module:ol/PluggableMap} Map.
|
||||
* @api
|
||||
*/
|
||||
Interaction.prototype.getMap = function() {
|
||||
return this.map_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Activate or deactivate the interaction.
|
||||
* @param {boolean} active Active.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
Interaction.prototype.setActive = function(active) {
|
||||
this.set(InteractionProperty.ACTIVE, active);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove the interaction from its current map and attach it to the new map.
|
||||
* Subclasses may set up event handlers to get notified about changes to
|
||||
* the map here.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
*/
|
||||
Interaction.prototype.setMap = function(map) {
|
||||
this.map_ = map;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/View} view View.
|
||||
* @param {module:ol/coordinate~Coordinate} delta Delta.
|
||||
|
||||
+778
-802
File diff suppressed because it is too large
Load Diff
@@ -53,101 +53,144 @@ export const Mode = {
|
||||
* @param {module:ol/interaction/MouseWheelZoom~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const MouseWheelZoom = function(opt_options) {
|
||||
class MouseWheelZoom {
|
||||
constructor(opt_options) {
|
||||
|
||||
Interaction.call(this, {
|
||||
handleEvent: handleEvent
|
||||
});
|
||||
Interaction.call(this, {
|
||||
handleEvent: handleEvent
|
||||
});
|
||||
|
||||
const options = opt_options || {};
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.delta_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 250;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.timeout_ = options.timeout !== undefined ? options.timeout : 80;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.constrainResolution_ = options.constrainResolution || false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : always;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.lastAnchor_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.startTime_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.timeoutId_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/MouseWheelZoom~Mode|undefined}
|
||||
*/
|
||||
this.mode_ = undefined;
|
||||
|
||||
/**
|
||||
* Trackpad events separated by this delay will be considered separate
|
||||
* interactions.
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadEventGap_ = 400;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.trackpadTimeoutId_ = undefined;
|
||||
|
||||
/**
|
||||
* The number of delta values per zoom level
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadDeltaPerZoom_ = 300;
|
||||
|
||||
/**
|
||||
* The zoom factor by which scroll zooming is allowed to exceed the limits.
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadZoomBuffer_ = 1.5;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.delta_ = 0;
|
||||
decrementInteractingHint_() {
|
||||
this.trackpadTimeoutId_ = undefined;
|
||||
const view = this.getMap().getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 250;
|
||||
handleWheelZoom_(map) {
|
||||
const view = map.getView();
|
||||
if (view.getAnimating()) {
|
||||
view.cancelAnimations();
|
||||
}
|
||||
const maxDelta = MAX_DELTA;
|
||||
const delta = clamp(this.delta_, -maxDelta, maxDelta);
|
||||
zoomByDelta(view, -delta, this.lastAnchor_, this.duration_);
|
||||
this.mode_ = undefined;
|
||||
this.delta_ = 0;
|
||||
this.lastAnchor_ = null;
|
||||
this.startTime_ = undefined;
|
||||
this.timeoutId_ = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
* Enable or disable using the mouse's location as an anchor when zooming
|
||||
* @param {boolean} useAnchor true to zoom to the mouse's location, false
|
||||
* to zoom to the center of the map
|
||||
* @api
|
||||
*/
|
||||
this.timeout_ = options.timeout !== undefined ? options.timeout : 80;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.constrainResolution_ = options.constrainResolution || false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : always;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.lastAnchor_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.startTime_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.timeoutId_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/MouseWheelZoom~Mode|undefined}
|
||||
*/
|
||||
this.mode_ = undefined;
|
||||
|
||||
/**
|
||||
* Trackpad events separated by this delay will be considered separate
|
||||
* interactions.
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadEventGap_ = 400;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.trackpadTimeoutId_ = undefined;
|
||||
|
||||
/**
|
||||
* The number of delta values per zoom level
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadDeltaPerZoom_ = 300;
|
||||
|
||||
/**
|
||||
* The zoom factor by which scroll zooming is allowed to exceed the limits.
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.trackpadZoomBuffer_ = 1.5;
|
||||
|
||||
};
|
||||
setMouseAnchor(useAnchor) {
|
||||
this.useAnchor_ = useAnchor;
|
||||
if (!useAnchor) {
|
||||
this.lastAnchor_ = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(MouseWheelZoom, Interaction);
|
||||
|
||||
@@ -276,48 +319,4 @@ function handleEvent(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
MouseWheelZoom.prototype.decrementInteractingHint_ = function() {
|
||||
this.trackpadTimeoutId_ = undefined;
|
||||
const view = this.getMap().getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
*/
|
||||
MouseWheelZoom.prototype.handleWheelZoom_ = function(map) {
|
||||
const view = map.getView();
|
||||
if (view.getAnimating()) {
|
||||
view.cancelAnimations();
|
||||
}
|
||||
const maxDelta = MAX_DELTA;
|
||||
const delta = clamp(this.delta_, -maxDelta, maxDelta);
|
||||
zoomByDelta(view, -delta, this.lastAnchor_, this.duration_);
|
||||
this.mode_ = undefined;
|
||||
this.delta_ = 0;
|
||||
this.lastAnchor_ = null;
|
||||
this.startTime_ = undefined;
|
||||
this.timeoutId_ = undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Enable or disable using the mouse's location as an anchor when zooming
|
||||
* @param {boolean} useAnchor true to zoom to the mouse's location, false
|
||||
* to zoom to the center of the map
|
||||
* @api
|
||||
*/
|
||||
MouseWheelZoom.prototype.setMouseAnchor = function(useAnchor) {
|
||||
this.useAnchor_ = useAnchor;
|
||||
if (!useAnchor) {
|
||||
this.lastAnchor_ = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default MouseWheelZoom;
|
||||
|
||||
@@ -77,61 +77,102 @@ const handleMoveEvent = UNDEFINED;
|
||||
* @extends {module:ol/interaction/Interaction}
|
||||
* @api
|
||||
*/
|
||||
const PointerInteraction = function(opt_options) {
|
||||
class PointerInteraction {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
Interaction.call(this, {
|
||||
handleEvent: options.handleEvent || handleEvent
|
||||
});
|
||||
Interaction.call(this, {
|
||||
handleEvent: options.handleEvent || handleEvent
|
||||
});
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent):boolean}
|
||||
* @private
|
||||
*/
|
||||
this.handleDownEvent_ = options.handleDownEvent ?
|
||||
options.handleDownEvent : handleDownEvent;
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent)}
|
||||
* @private
|
||||
*/
|
||||
this.handleDragEvent_ = options.handleDragEvent ?
|
||||
options.handleDragEvent : handleDragEvent;
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent)}
|
||||
* @private
|
||||
*/
|
||||
this.handleMoveEvent_ = options.handleMoveEvent ?
|
||||
options.handleMoveEvent : handleMoveEvent;
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent):boolean}
|
||||
* @private
|
||||
*/
|
||||
this.handleUpEvent_ = options.handleUpEvent ?
|
||||
options.handleUpEvent : handleUpEvent;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @protected
|
||||
*/
|
||||
this.handlingDownUpSequence = false;
|
||||
|
||||
/**
|
||||
* @type {!Object.<string, module:ol/pointer/PointerEvent>}
|
||||
* @private
|
||||
*/
|
||||
this.trackedPointers_ = {};
|
||||
|
||||
/**
|
||||
* @type {Array.<module:ol/pointer/PointerEvent>}
|
||||
* @protected
|
||||
*/
|
||||
this.targetPointers = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent):boolean}
|
||||
* @param {module:ol/MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @private
|
||||
*/
|
||||
this.handleDownEvent_ = options.handleDownEvent ?
|
||||
options.handleDownEvent : handleDownEvent;
|
||||
updateTrackedPointers_(mapBrowserEvent) {
|
||||
if (isPointerDraggingEvent(mapBrowserEvent)) {
|
||||
const event = mapBrowserEvent.pointerEvent;
|
||||
|
||||
const id = event.pointerId.toString();
|
||||
if (mapBrowserEvent.type == MapBrowserEventType.POINTERUP) {
|
||||
delete this.trackedPointers_[id];
|
||||
} else if (mapBrowserEvent.type ==
|
||||
MapBrowserEventType.POINTERDOWN) {
|
||||
this.trackedPointers_[id] = event;
|
||||
} else if (id in this.trackedPointers_) {
|
||||
// update only when there was a pointerdown event for this pointer
|
||||
this.trackedPointers_[id] = event;
|
||||
}
|
||||
this.targetPointers = getValues(this.trackedPointers_);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent)}
|
||||
* @private
|
||||
*/
|
||||
this.handleDragEvent_ = options.handleDragEvent ?
|
||||
options.handleDragEvent : handleDragEvent;
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent)}
|
||||
* @private
|
||||
*/
|
||||
this.handleMoveEvent_ = options.handleMoveEvent ?
|
||||
options.handleMoveEvent : handleMoveEvent;
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/MapBrowserPointerEvent):boolean}
|
||||
* @private
|
||||
*/
|
||||
this.handleUpEvent_ = options.handleUpEvent ?
|
||||
options.handleUpEvent : handleUpEvent;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* This method is used to determine if "down" events should be propagated to
|
||||
* other interactions or should be stopped.
|
||||
*
|
||||
* The method receives the return code of the "handleDownEvent" function.
|
||||
*
|
||||
* By default this function is the "identity" function. It's overridden in
|
||||
* child classes.
|
||||
*
|
||||
* @param {boolean} handled Was the event handled by the interaction?
|
||||
* @return {boolean} Should the event be stopped?
|
||||
* @protected
|
||||
*/
|
||||
this.handlingDownUpSequence = false;
|
||||
|
||||
/**
|
||||
* @type {!Object.<string, module:ol/pointer/PointerEvent>}
|
||||
* @private
|
||||
*/
|
||||
this.trackedPointers_ = {};
|
||||
|
||||
/**
|
||||
* @type {Array.<module:ol/pointer/PointerEvent>}
|
||||
* @protected
|
||||
*/
|
||||
this.targetPointers = [];
|
||||
|
||||
};
|
||||
shouldStopEvent(handled) {
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(PointerInteraction, Interaction);
|
||||
|
||||
@@ -165,29 +206,6 @@ function isPointerDraggingEvent(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||
* @private
|
||||
*/
|
||||
PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
|
||||
if (isPointerDraggingEvent(mapBrowserEvent)) {
|
||||
const event = mapBrowserEvent.pointerEvent;
|
||||
|
||||
const id = event.pointerId.toString();
|
||||
if (mapBrowserEvent.type == MapBrowserEventType.POINTERUP) {
|
||||
delete this.trackedPointers_[id];
|
||||
} else if (mapBrowserEvent.type ==
|
||||
MapBrowserEventType.POINTERDOWN) {
|
||||
this.trackedPointers_[id] = event;
|
||||
} else if (id in this.trackedPointers_) {
|
||||
// update only when there was a pointerdown event for this pointer
|
||||
this.trackedPointers_[id] = event;
|
||||
}
|
||||
this.targetPointers = getValues(this.trackedPointers_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handles the {@link module:ol/MapBrowserEvent map browser event} and may call into
|
||||
* other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are
|
||||
@@ -224,21 +242,4 @@ export function handleEvent(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is used to determine if "down" events should be propagated to
|
||||
* other interactions or should be stopped.
|
||||
*
|
||||
* The method receives the return code of the "handleDownEvent" function.
|
||||
*
|
||||
* By default this function is the "identity" function. It's overridden in
|
||||
* child classes.
|
||||
*
|
||||
* @param {boolean} handled Was the event handled by the interaction?
|
||||
* @return {boolean} Should the event be stopped?
|
||||
* @protected
|
||||
*/
|
||||
PointerInteraction.prototype.shouldStopEvent = function(handled) {
|
||||
return handled;
|
||||
};
|
||||
|
||||
export default PointerInteraction;
|
||||
|
||||
+189
-196
@@ -156,162 +156,223 @@ inherits(SelectEvent, Event);
|
||||
* @fires SelectEvent
|
||||
* @api
|
||||
*/
|
||||
const Select = function(opt_options) {
|
||||
class Select {
|
||||
constructor(opt_options) {
|
||||
|
||||
Interaction.call(this, {
|
||||
handleEvent: handleEvent
|
||||
});
|
||||
Interaction.call(this, {
|
||||
handleEvent: handleEvent
|
||||
});
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : singleClick;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : singleClick;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.addCondition_ = options.addCondition ? options.addCondition : never;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.addCondition_ = options.addCondition ? options.addCondition : never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.removeCondition_ = options.removeCondition ? options.removeCondition : never;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.removeCondition_ = options.removeCondition ? options.removeCondition : never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.toggleCondition_ = options.toggleCondition ? options.toggleCondition : shiftKeyOnly;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/events/condition~Condition}
|
||||
*/
|
||||
this.toggleCondition_ = options.toggleCondition ? options.toggleCondition : shiftKeyOnly;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.multi_ = options.multi ? options.multi : false;
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.multi_ = options.multi ? options.multi : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/Select~FilterFunction}
|
||||
*/
|
||||
this.filter_ = options.filter ? options.filter : TRUE;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/interaction/Select~FilterFunction}
|
||||
*/
|
||||
this.filter_ = options.filter ? options.filter : TRUE;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
|
||||
const featureOverlay = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
features: options.features,
|
||||
wrapX: options.wrapX
|
||||
}),
|
||||
style: options.style ? options.style :
|
||||
getDefaultStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
const featureOverlay = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
features: options.features,
|
||||
wrapX: options.wrapX
|
||||
}),
|
||||
style: options.style ? options.style :
|
||||
getDefaultStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/layer/Vector}
|
||||
*/
|
||||
this.featureOverlay_ = featureOverlay;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/layer/Vector}
|
||||
*/
|
||||
this.featureOverlay_ = featureOverlay;
|
||||
|
||||
/** @type {function(module:ol/layer/Layer): boolean} */
|
||||
let layerFilter;
|
||||
if (options.layers) {
|
||||
if (typeof options.layers === 'function') {
|
||||
layerFilter = options.layers;
|
||||
/** @type {function(module:ol/layer/Layer): boolean} */
|
||||
let layerFilter;
|
||||
if (options.layers) {
|
||||
if (typeof options.layers === 'function') {
|
||||
layerFilter = options.layers;
|
||||
} else {
|
||||
const layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return includes(layers, layer);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
const layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return includes(layers, layer);
|
||||
};
|
||||
layerFilter = TRUE;
|
||||
}
|
||||
} else {
|
||||
layerFilter = TRUE;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(module:ol/layer/Layer): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
|
||||
/**
|
||||
* An association between selected feature (key)
|
||||
* and layer (value)
|
||||
* @private
|
||||
* @type {Object.<number, module:ol/layer/Layer>}
|
||||
*/
|
||||
this.featureLayerAssociation_ = {};
|
||||
|
||||
const features = this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
listen(features, CollectionEventType.ADD,
|
||||
this.addFeature_, this);
|
||||
listen(features, CollectionEventType.REMOVE,
|
||||
this.removeFeature_, this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
|
||||
* @param {module:ol/layer/Layer} layer Layer.
|
||||
* @private
|
||||
* @type {function(module:ol/layer/Layer): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
addFeatureLayerAssociation_(feature, layer) {
|
||||
const key = getUid(feature);
|
||||
this.featureLayerAssociation_[key] = layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* An association between selected feature (key)
|
||||
* and layer (value)
|
||||
* @private
|
||||
* @type {Object.<number, module:ol/layer/Layer>}
|
||||
* Get the selected features.
|
||||
* @return {module:ol/Collection.<module:ol/Feature>} Features collection.
|
||||
* @api
|
||||
*/
|
||||
this.featureLayerAssociation_ = {};
|
||||
getFeatures() {
|
||||
return this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
}
|
||||
|
||||
const features = this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
listen(features, CollectionEventType.ADD,
|
||||
this.addFeature_, this);
|
||||
listen(features, CollectionEventType.REMOVE,
|
||||
this.removeFeature_, this);
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
getHitTolerance() {
|
||||
return this.hitTolerance_;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Returns the associated {@link module:ol/layer/Vector~Vector vectorlayer} of
|
||||
* the (last) selected feature. Note that this will not work with any
|
||||
* programmatic method like pushing features to
|
||||
* {@link module:ol/interaction/Select~Select#getFeatures collection}.
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature
|
||||
* @return {module:ol/layer/Vector} Layer.
|
||||
* @api
|
||||
*/
|
||||
getLayer(feature) {
|
||||
const key = getUid(feature);
|
||||
return (
|
||||
/** @type {module:ol/layer/Vector} */ (this.featureLayerAssociation_[key])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
setHitTolerance(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the interaction from its current map, if any, and attach it to a new
|
||||
* map, if any. Pass `null` to just remove the interaction from the current map.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setMap(map) {
|
||||
const currentMap = this.getMap();
|
||||
const selectedFeatures =
|
||||
this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
if (currentMap) {
|
||||
selectedFeatures.forEach(currentMap.unskipFeature.bind(currentMap));
|
||||
}
|
||||
Interaction.prototype.setMap.call(this, map);
|
||||
this.featureOverlay_.setMap(map);
|
||||
if (map) {
|
||||
selectedFeatures.forEach(map.skipFeature.bind(map));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
addFeature_(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.skipFeature(/** @type {module:ol/Feature} */ (evt.element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
removeFeature_(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.unskipFeature(/** @type {module:ol/Feature} */ (evt.element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
|
||||
* @private
|
||||
*/
|
||||
removeFeatureLayerAssociation_(feature) {
|
||||
const key = getUid(feature);
|
||||
delete this.featureLayerAssociation_[key];
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Select, Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
|
||||
* @param {module:ol/layer/Layer} layer Layer.
|
||||
* @private
|
||||
*/
|
||||
Select.prototype.addFeatureLayerAssociation_ = function(feature, layer) {
|
||||
const key = getUid(feature);
|
||||
this.featureLayerAssociation_[key] = layer;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the selected features.
|
||||
* @return {module:ol/Collection.<module:ol/Feature>} Features collection.
|
||||
* @api
|
||||
*/
|
||||
Select.prototype.getFeatures = function() {
|
||||
return this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
Select.prototype.getHitTolerance = function() {
|
||||
return this.hitTolerance_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the associated {@link module:ol/layer/Vector~Vector vectorlayer} of
|
||||
* the (last) selected feature. Note that this will not work with any
|
||||
* programmatic method like pushing features to
|
||||
* {@link module:ol/interaction/Select~Select#getFeatures collection}.
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature
|
||||
* @return {module:ol/layer/Vector} Layer.
|
||||
* @api
|
||||
*/
|
||||
Select.prototype.getLayer = function(feature) {
|
||||
const key = getUid(feature);
|
||||
return (
|
||||
/** @type {module:ol/layer/Vector} */ (this.featureLayerAssociation_[key])
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handles the {@link module:ol/MapBrowserEvent map browser event} and may change the
|
||||
* selected state of features.
|
||||
@@ -405,40 +466,6 @@ function handleEvent(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
Select.prototype.setHitTolerance = function(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove the interaction from its current map, if any, and attach it to a new
|
||||
* map, if any. Pass `null` to just remove the interaction from the current map.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Select.prototype.setMap = function(map) {
|
||||
const currentMap = this.getMap();
|
||||
const selectedFeatures =
|
||||
this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
if (currentMap) {
|
||||
selectedFeatures.forEach(currentMap.unskipFeature.bind(currentMap));
|
||||
}
|
||||
Interaction.prototype.setMap.call(this, map);
|
||||
this.featureOverlay_.setMap(map);
|
||||
if (map) {
|
||||
selectedFeatures.forEach(map.skipFeature.bind(map));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {module:ol/style/Style~StyleFunction} Styles.
|
||||
*/
|
||||
@@ -456,38 +483,4 @@ function getDefaultStyleFunction() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
Select.prototype.addFeature_ = function(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.skipFeature(/** @type {module:ol/Feature} */ (evt.element));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
Select.prototype.removeFeature_ = function(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.unskipFeature(/** @type {module:ol/Feature} */ (evt.element));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
|
||||
* @private
|
||||
*/
|
||||
Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
|
||||
const key = getUid(feature);
|
||||
delete this.featureLayerAssociation_[key];
|
||||
};
|
||||
|
||||
|
||||
export default Select;
|
||||
|
||||
+466
-483
File diff suppressed because it is too large
Load Diff
+121
-125
@@ -96,68 +96,143 @@ inherits(TranslateEvent, Event);
|
||||
* @param {module:ol/interaction/Translate~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const Translate = function(opt_options) {
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleMoveEvent: handleMoveEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
class Translate {
|
||||
constructor(opt_options) {
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleMoveEvent: handleMoveEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* The last position we translated to.
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.lastCoordinate_ = null;
|
||||
/**
|
||||
* The last position we translated to.
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.lastCoordinate_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* @type {module:ol/Collection.<module:ol/Feature>}
|
||||
* @private
|
||||
*/
|
||||
this.features_ = options.features !== undefined ? options.features : null;
|
||||
/**
|
||||
* @type {module:ol/Collection.<module:ol/Feature>}
|
||||
* @private
|
||||
*/
|
||||
this.features_ = options.features !== undefined ? options.features : null;
|
||||
|
||||
/** @type {function(module:ol/layer/Layer): boolean} */
|
||||
let layerFilter;
|
||||
if (options.layers) {
|
||||
if (typeof options.layers === 'function') {
|
||||
layerFilter = options.layers;
|
||||
/** @type {function(module:ol/layer/Layer): boolean} */
|
||||
let layerFilter;
|
||||
if (options.layers) {
|
||||
if (typeof options.layers === 'function') {
|
||||
layerFilter = options.layers;
|
||||
} else {
|
||||
const layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return includes(layers, layer);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
const layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return includes(layers, layer);
|
||||
};
|
||||
layerFilter = TRUE;
|
||||
}
|
||||
} else {
|
||||
layerFilter = TRUE;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(module:ol/layer/Layer): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
|
||||
/**
|
||||
* @type {module:ol/Feature}
|
||||
* @private
|
||||
*/
|
||||
this.lastFeature_ = null;
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(InteractionProperty.ACTIVE),
|
||||
this.handleActiveChanged_, this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if the given coordinates intersects any of our selected
|
||||
* features.
|
||||
* @param {module:ol~Pixel} pixel Pixel coordinate to test for intersection.
|
||||
* @param {module:ol/PluggableMap} map Map to test the intersection on.
|
||||
* @return {module:ol/Feature} Returns the feature found at the specified pixel
|
||||
* coordinates.
|
||||
* @private
|
||||
*/
|
||||
featuresAtPixel_(pixel, map) {
|
||||
return map.forEachFeatureAtPixel(pixel,
|
||||
function(feature) {
|
||||
if (!this.features_ || includes(this.features_.getArray(), feature)) {
|
||||
return feature;
|
||||
}
|
||||
}.bind(this), {
|
||||
layerFilter: this.layerFilter_,
|
||||
hitTolerance: this.hitTolerance_
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
getHitTolerance() {
|
||||
return this.hitTolerance_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
setHitTolerance(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
setMap(map) {
|
||||
const oldMap = this.getMap();
|
||||
PointerInteraction.prototype.setMap.call(this, map);
|
||||
this.updateState_(oldMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(module:ol/layer/Layer): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
handleActiveChanged_() {
|
||||
this.updateState_(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
|
||||
/**
|
||||
* @type {module:ol/Feature}
|
||||
* @param {module:ol/PluggableMap} oldMap Old map.
|
||||
* @private
|
||||
*/
|
||||
this.lastFeature_ = null;
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(InteractionProperty.ACTIVE),
|
||||
this.handleActiveChanged_, this);
|
||||
|
||||
};
|
||||
updateState_(oldMap) {
|
||||
let map = this.getMap();
|
||||
const active = this.getActive();
|
||||
if (!map || !active) {
|
||||
map = map || oldMap;
|
||||
if (map) {
|
||||
const elem = map.getViewport();
|
||||
elem.classList.remove('ol-grab', 'ol-grabbing');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Translate, PointerInteraction);
|
||||
|
||||
@@ -252,83 +327,4 @@ function handleMoveEvent(event) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests to see if the given coordinates intersects any of our selected
|
||||
* features.
|
||||
* @param {module:ol~Pixel} pixel Pixel coordinate to test for intersection.
|
||||
* @param {module:ol/PluggableMap} map Map to test the intersection on.
|
||||
* @return {module:ol/Feature} Returns the feature found at the specified pixel
|
||||
* coordinates.
|
||||
* @private
|
||||
*/
|
||||
Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||
return map.forEachFeatureAtPixel(pixel,
|
||||
function(feature) {
|
||||
if (!this.features_ || includes(this.features_.getArray(), feature)) {
|
||||
return feature;
|
||||
}
|
||||
}.bind(this), {
|
||||
layerFilter: this.layerFilter_,
|
||||
hitTolerance: this.hitTolerance_
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
Translate.prototype.getHitTolerance = function() {
|
||||
return this.hitTolerance_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
Translate.prototype.setHitTolerance = function(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Translate.prototype.setMap = function(map) {
|
||||
const oldMap = this.getMap();
|
||||
PointerInteraction.prototype.setMap.call(this, map);
|
||||
this.updateState_(oldMap);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Translate.prototype.handleActiveChanged_ = function() {
|
||||
this.updateState_(null);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/PluggableMap} oldMap Old map.
|
||||
* @private
|
||||
*/
|
||||
Translate.prototype.updateState_ = function(oldMap) {
|
||||
let map = this.getMap();
|
||||
const active = this.getActive();
|
||||
if (!map || !active) {
|
||||
map = map || oldMap;
|
||||
if (map) {
|
||||
const elem = map.getViewport();
|
||||
elem.classList.remove('ol-grab', 'ol-grabbing');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default Translate;
|
||||
|
||||
Reference in New Issue
Block a user