Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions
+9 -9
View File
@@ -14,9 +14,9 @@ import Interaction from '../interaction/Interaction.js';
* @param {olx.interaction.DoubleClickZoomOptions=} opt_options Options.
* @api
*/
var DoubleClickZoom = function(opt_options) {
const DoubleClickZoom = function(opt_options) {
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @private
@@ -48,15 +48,15 @@ inherits(DoubleClickZoom, Interaction);
* @api
*/
DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
var browserEvent = mapBrowserEvent.originalEvent;
let stopEvent = false;
const browserEvent = mapBrowserEvent.originalEvent;
if (mapBrowserEvent.type == MapBrowserEventType.DBLCLICK) {
var map = mapBrowserEvent.map;
var anchor = mapBrowserEvent.coordinate;
var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
var view = map.getView();
const map = mapBrowserEvent.map;
const anchor = mapBrowserEvent.coordinate;
const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
const view = map.getView();
Interaction.zoomByDelta(
view, delta, anchor, this.duration_);
view, delta, anchor, this.duration_);
mapBrowserEvent.preventDefault();
stopEvent = true;
}
+24 -24
View File
@@ -21,9 +21,9 @@ import {get as getProjection} from '../proj.js';
* @param {olx.interaction.DragAndDropOptions=} opt_options Options.
* @api
*/
var DragAndDrop = function(opt_options) {
const DragAndDrop = function(opt_options) {
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
Interaction.call(this, {
handleEvent: DragAndDrop.handleEvent
@@ -72,13 +72,13 @@ inherits(DragAndDrop, Interaction);
* @private
*/
DragAndDrop.handleDrop_ = function(event) {
var files = event.dataTransfer.files;
var i, ii, file;
const files = event.dataTransfer.files;
let i, ii, file;
for (i = 0, ii = files.length; i < ii; ++i) {
file = files.item(i);
var reader = new FileReader();
const reader = new FileReader();
reader.addEventListener(EventType.LOAD,
this.handleResult_.bind(this, file));
this.handleResult_.bind(this, file));
reader.readAsText(file);
}
};
@@ -101,27 +101,27 @@ DragAndDrop.handleStop_ = function(event) {
* @private
*/
DragAndDrop.prototype.handleResult_ = function(file, event) {
var result = event.target.result;
var map = this.getMap();
var projection = this.projection_;
const result = event.target.result;
const map = this.getMap();
let projection = this.projection_;
if (!projection) {
var view = map.getView();
const view = map.getView();
projection = view.getProjection();
}
var formatConstructors = this.formatConstructors_;
var features = [];
var i, ii;
const formatConstructors = this.formatConstructors_;
let features = [];
let i, ii;
for (i = 0, ii = formatConstructors.length; i < ii; ++i) {
/**
* Avoid "cannot instantiate abstract class" error.
* @type {Function}
*/
var formatConstructor = formatConstructors[i];
const formatConstructor = formatConstructors[i];
/**
* @type {ol.format.Feature}
*/
var format = new formatConstructor();
const format = new formatConstructor();
features = this.tryReadFeatures_(format, result, {
featureProjection: projection
});
@@ -134,9 +134,9 @@ DragAndDrop.prototype.handleResult_ = function(file, event) {
this.source_.addFeatures(features);
}
this.dispatchEvent(
new DragAndDrop.Event(
DragAndDrop.EventType_.ADD_FEATURES, file,
features, projection));
new DragAndDrop.Event(
DragAndDrop.EventType_.ADD_FEATURES, file,
features, projection));
};
@@ -155,18 +155,18 @@ DragAndDrop.handleEvent = TRUE;
* @private
*/
DragAndDrop.prototype.registerListeners_ = function() {
var map = this.getMap();
const map = this.getMap();
if (map) {
var dropArea = this.target ? this.target : map.getViewport();
const dropArea = this.target ? this.target : map.getViewport();
this.dropListenKeys_ = [
_ol_events_.listen(dropArea, EventType.DROP,
DragAndDrop.handleDrop_, this),
DragAndDrop.handleDrop_, this),
_ol_events_.listen(dropArea, EventType.DRAGENTER,
DragAndDrop.handleStop_, this),
DragAndDrop.handleStop_, this),
_ol_events_.listen(dropArea, EventType.DRAGOVER,
DragAndDrop.handleStop_, this),
DragAndDrop.handleStop_, this),
_ol_events_.listen(dropArea, EventType.DROP,
DragAndDrop.handleStop_, this)
DragAndDrop.handleStop_, this)
];
}
};
+8 -8
View File
@@ -25,7 +25,7 @@ import _ol_render_Box_ from '../render/Box.js';
* @param {olx.interaction.DragBoxOptions=} opt_options Options.
* @api
*/
var DragBox = function(opt_options) {
const DragBox = function(opt_options) {
PointerInteraction.call(this, {
handleDownEvent: DragBox.handleDownEvent_,
@@ -33,7 +33,7 @@ var DragBox = function(opt_options) {
handleUpEvent: DragBox.handleUpEvent_
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @type {ol.render.Box}
@@ -82,8 +82,8 @@ inherits(DragBox, PointerInteraction);
* @this {ol.interaction.DragBox}
*/
DragBox.defaultBoxEndCondition = function(mapBrowserEvent, startPixel, endPixel) {
var width = endPixel[0] - startPixel[0];
var height = endPixel[1] - startPixel[1];
const width = endPixel[0] - startPixel[0];
const height = endPixel[1] - startPixel[1];
return width * width + height * height >= this.minArea_;
};
@@ -101,7 +101,7 @@ DragBox.handleDragEvent_ = function(mapBrowserEvent) {
this.box_.setPixels(this.startPixel_, mapBrowserEvent.pixel);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXDRAG,
mapBrowserEvent.coordinate, mapBrowserEvent));
mapBrowserEvent.coordinate, mapBrowserEvent));
};
@@ -138,10 +138,10 @@ DragBox.handleUpEvent_ = function(mapBrowserEvent) {
this.box_.setMap(null);
if (this.boxEndCondition_(mapBrowserEvent,
this.startPixel_, mapBrowserEvent.pixel)) {
this.startPixel_, mapBrowserEvent.pixel)) {
this.onBoxEnd(mapBrowserEvent);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXEND,
mapBrowserEvent.coordinate, mapBrowserEvent));
mapBrowserEvent.coordinate, mapBrowserEvent));
}
return false;
};
@@ -164,7 +164,7 @@ DragBox.handleDownEvent_ = function(mapBrowserEvent) {
this.box_.setMap(mapBrowserEvent.map);
this.box_.setPixels(this.startPixel_, this.startPixel_);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXSTART,
mapBrowserEvent.coordinate, mapBrowserEvent));
mapBrowserEvent.coordinate, mapBrowserEvent));
return true;
} else {
return false;
+19 -19
View File
@@ -18,7 +18,7 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {olx.interaction.DragPanOptions=} opt_options Options.
* @api
*/
var DragPan = function(opt_options) {
const DragPan = function(opt_options) {
PointerInteraction.call(this, {
handleDownEvent: DragPan.handleDownEvent_,
@@ -26,7 +26,7 @@ var DragPan = function(opt_options) {
handleUpEvent: DragPan.handleUpEvent_
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @private
@@ -68,20 +68,20 @@ inherits(DragPan, PointerInteraction);
* @private
*/
DragPan.handleDragEvent_ = function(mapBrowserEvent) {
var targetPointers = this.targetPointers;
var centroid =
const targetPointers = this.targetPointers;
const centroid =
PointerInteraction.centroid(targetPointers);
if (targetPointers.length == this.lastPointersCount_) {
if (this.kinetic_) {
this.kinetic_.update(centroid[0], centroid[1]);
}
if (this.lastCentroid) {
var deltaX = this.lastCentroid[0] - centroid[0];
var deltaY = centroid[1] - this.lastCentroid[1];
var map = mapBrowserEvent.map;
var view = map.getView();
var viewState = view.getState();
var center = [deltaX, deltaY];
const deltaX = this.lastCentroid[0] - centroid[0];
const deltaY = centroid[1] - this.lastCentroid[1];
const map = mapBrowserEvent.map;
const view = map.getView();
const viewState = view.getState();
let center = [deltaX, deltaY];
_ol_coordinate_.scale(center, viewState.resolution);
_ol_coordinate_.rotate(center, viewState.rotation);
_ol_coordinate_.add(center, viewState.center);
@@ -105,15 +105,15 @@ DragPan.handleDragEvent_ = function(mapBrowserEvent) {
* @private
*/
DragPan.handleUpEvent_ = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
if (this.targetPointers.length === 0) {
if (!this.noKinetic_ && this.kinetic_ && this.kinetic_.end()) {
var distance = this.kinetic_.getDistance();
var angle = this.kinetic_.getAngle();
var center = /** @type {!ol.Coordinate} */ (view.getCenter());
var centerpx = map.getPixelFromCoordinate(center);
var dest = map.getCoordinateFromPixel([
const distance = this.kinetic_.getDistance();
const angle = this.kinetic_.getAngle();
const center = /** @type {!ol.Coordinate} */ (view.getCenter());
const centerpx = map.getPixelFromCoordinate(center);
const dest = map.getCoordinateFromPixel([
centerpx[0] - distance * Math.cos(angle),
centerpx[1] - distance * Math.sin(angle)
]);
@@ -145,8 +145,8 @@ DragPan.handleUpEvent_ = function(mapBrowserEvent) {
*/
DragPan.handleDownEvent_ = function(mapBrowserEvent) {
if (this.targetPointers.length > 0 && this.condition_(mapBrowserEvent)) {
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
this.lastCentroid = null;
if (!this.handlingDownUpSequence) {
view.setHint(ViewHint.INTERACTING, 1);
+15 -15
View File
@@ -22,9 +22,9 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {olx.interaction.DragRotateOptions=} opt_options Options.
* @api
*/
var DragRotate = function(opt_options) {
const DragRotate = function(opt_options) {
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
PointerInteraction.call(this, {
handleDownEvent: DragRotate.handleDownEvent_,
@@ -65,20 +65,20 @@ DragRotate.handleDragEvent_ = function(mapBrowserEvent) {
return;
}
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
if (view.getConstraints().rotation === RotationConstraint.disable) {
return;
}
var size = map.getSize();
var offset = mapBrowserEvent.pixel;
var theta =
const size = map.getSize();
const offset = mapBrowserEvent.pixel;
const theta =
Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
if (this.lastAngle_ !== undefined) {
var delta = theta - this.lastAngle_;
var rotation = view.getRotation();
const delta = theta - this.lastAngle_;
const rotation = view.getRotation();
Interaction.rotateWithoutConstraints(
view, rotation - delta);
view, rotation - delta);
}
this.lastAngle_ = theta;
};
@@ -95,12 +95,12 @@ DragRotate.handleUpEvent_ = function(mapBrowserEvent) {
return true;
}
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1);
var rotation = view.getRotation();
const rotation = view.getRotation();
Interaction.rotate(view, rotation,
undefined, this.duration_);
undefined, this.duration_);
return false;
};
@@ -118,7 +118,7 @@ DragRotate.handleDownEvent_ = function(mapBrowserEvent) {
if (_ol_events_condition_.mouseActionButton(mapBrowserEvent) &&
this.condition_(mapBrowserEvent)) {
var map = mapBrowserEvent.map;
const map = mapBrowserEvent.map;
map.getView().setHint(ViewHint.INTERACTING, 1);
this.lastAngle_ = undefined;
return true;
+17 -17
View File
@@ -23,9 +23,9 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {olx.interaction.DragRotateAndZoomOptions=} opt_options Options.
* @api
*/
var DragRotateAndZoom = function(opt_options) {
const DragRotateAndZoom = function(opt_options) {
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
PointerInteraction.call(this, {
handleDownEvent: DragRotateAndZoom.handleDownEvent_,
@@ -79,22 +79,22 @@ DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) {
return;
}
var map = mapBrowserEvent.map;
var size = map.getSize();
var offset = mapBrowserEvent.pixel;
var deltaX = offset[0] - size[0] / 2;
var deltaY = size[1] / 2 - offset[1];
var theta = Math.atan2(deltaY, deltaX);
var magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
var view = map.getView();
const map = mapBrowserEvent.map;
const size = map.getSize();
const offset = mapBrowserEvent.pixel;
const deltaX = offset[0] - size[0] / 2;
const deltaY = size[1] / 2 - offset[1];
const theta = Math.atan2(deltaY, deltaX);
const magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
const view = map.getView();
if (view.getConstraints().rotation !== RotationConstraint.disable && this.lastAngle_ !== undefined) {
var angleDelta = theta - this.lastAngle_;
const angleDelta = theta - this.lastAngle_;
Interaction.rotateWithoutConstraints(
view, view.getRotation() - angleDelta);
view, view.getRotation() - angleDelta);
}
this.lastAngle_ = theta;
if (this.lastMagnitude_ !== undefined) {
var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
Interaction.zoomWithoutConstraints(view, resolution);
}
if (this.lastMagnitude_ !== undefined) {
@@ -115,13 +115,13 @@ DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) {
return true;
}
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1);
var direction = this.lastScaleDelta_ - 1;
const direction = this.lastScaleDelta_ - 1;
Interaction.rotate(view, view.getRotation());
Interaction.zoom(view, view.getResolution(),
undefined, this.duration_, direction);
undefined, this.duration_, direction);
this.lastScaleDelta_ = 0;
return false;
};
+13 -13
View File
@@ -21,10 +21,10 @@ import DragBox from '../interaction/DragBox.js';
* @param {olx.interaction.DragZoomOptions=} opt_options Options.
* @api
*/
var DragZoom = function(opt_options) {
var options = opt_options ? opt_options : {};
const DragZoom = function(opt_options) {
const options = opt_options ? opt_options : {};
var condition = options.condition ?
const condition = options.condition ?
options.condition : _ol_events_condition_.shiftKeyOnly;
/**
@@ -53,29 +53,29 @@ inherits(DragZoom, DragBox);
* @inheritDoc
*/
DragZoom.prototype.onBoxEnd = function() {
var map = this.getMap();
const map = this.getMap();
var view = /** @type {!ol.View} */ (map.getView());
const view = /** @type {!ol.View} */ (map.getView());
var size = /** @type {!ol.Size} */ (map.getSize());
const size = /** @type {!ol.Size} */ (map.getSize());
var extent = this.getGeometry().getExtent();
let extent = this.getGeometry().getExtent();
if (this.out_) {
var mapExtent = view.calculateExtent(size);
var boxPixelExtent = createOrUpdateFromCoordinates([
const mapExtent = view.calculateExtent(size);
const boxPixelExtent = createOrUpdateFromCoordinates([
map.getPixelFromCoordinate(getBottomLeft(extent)),
map.getPixelFromCoordinate(getTopRight(extent))]);
var factor = view.getResolutionForExtent(boxPixelExtent, size);
const factor = view.getResolutionForExtent(boxPixelExtent, size);
scaleFromCenter(mapExtent, 1 / factor);
extent = mapExtent;
}
var resolution = view.constrainResolution(
view.getResolutionForExtent(extent, size));
const resolution = view.constrainResolution(
view.getResolutionForExtent(extent, size));
var center = getCenter(extent);
let center = getCenter(extent);
center = view.constrainCenter(center);
view.animate({
+68 -68
View File
@@ -36,7 +36,7 @@ import Style from '../style/Style.js';
* @param {olx.interaction.DrawOptions} options Options.
* @api
*/
var Draw = function(options) {
const Draw = function(options) {
PointerInteraction.call(this, {
handleDownEvent: Draw.handleDownEvent_,
@@ -131,7 +131,7 @@ var Draw = function(options) {
*/
this.finishCondition_ = options.finishCondition ? options.finishCondition : TRUE;
var geometryFunction = options.geometryFunction;
let geometryFunction = options.geometryFunction;
if (!geometryFunction) {
if (this.type_ === GeometryType.CIRCLE) {
/**
@@ -141,16 +141,16 @@ var Draw = function(options) {
* @return {ol.geom.SimpleGeometry} A geometry.
*/
geometryFunction = function(coordinates, opt_geometry) {
var circle = opt_geometry ? /** @type {ol.geom.Circle} */ (opt_geometry) :
const circle = opt_geometry ? /** @type {ol.geom.Circle} */ (opt_geometry) :
new Circle([NaN, NaN]);
var squaredLength = _ol_coordinate_.squaredDistance(
coordinates[0], coordinates[1]);
const squaredLength = _ol_coordinate_.squaredDistance(
coordinates[0], coordinates[1]);
circle.setCenterAndRadius(coordinates[0], Math.sqrt(squaredLength));
return circle;
};
} else {
var Constructor;
var mode = this.mode_;
let Constructor;
const mode = this.mode_;
if (mode === Draw.Mode_.POINT) {
Constructor = Point;
} else if (mode === Draw.Mode_.LINE_STRING) {
@@ -165,7 +165,7 @@ var Draw = function(options) {
* @return {ol.geom.SimpleGeometry} A geometry.
*/
geometryFunction = function(coordinates, opt_geometry) {
var geometry = opt_geometry;
let geometry = opt_geometry;
if (geometry) {
if (mode === Draw.Mode_.POLYGON) {
if (coordinates[0].length) {
@@ -285,8 +285,8 @@ var Draw = function(options) {
}
_ol_events_.listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
this.updateState_, this);
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
this.updateState_, this);
};
@@ -297,7 +297,7 @@ inherits(Draw, PointerInteraction);
* @return {ol.StyleFunction} Styles.
*/
Draw.getDefaultStyleFunction = function() {
var styles = Style.createDefaultEditing();
const styles = Style.createDefaultEditing();
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};
@@ -323,7 +323,7 @@ Draw.prototype.setMap = function(map) {
*/
Draw.handleEvent = function(event) {
this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event);
var pass = true;
let pass = true;
if (this.freehand_ &&
event.type === MapBrowserEventType.POINTERDRAG &&
this.sketchFeature_ !== null) {
@@ -372,11 +372,11 @@ Draw.handleDownEvent_ = function(event) {
* @private
*/
Draw.handleUpEvent_ = function(event) {
var pass = true;
let pass = true;
this.handlePointerMove_(event);
var circleMode = this.mode_ === Draw.Mode_.CIRCLE;
const circleMode = this.mode_ === Draw.Mode_.CIRCLE;
if (this.shouldHandle_) {
if (!this.finishCoordinate_) {
@@ -415,11 +415,11 @@ Draw.prototype.handlePointerMove_ = function(event) {
if (this.downPx_ &&
((!this.freehand_ && this.shouldHandle_) ||
(this.freehand_ && !this.shouldHandle_))) {
var downPx = this.downPx_;
var clickPx = event.pixel;
var dx = downPx[0] - clickPx[0];
var dy = downPx[1] - clickPx[1];
var squaredDistance = dx * dx + dy * dy;
const downPx = this.downPx_;
const clickPx = event.pixel;
const dx = downPx[0] - clickPx[0];
const dy = downPx[1] - clickPx[1];
const squaredDistance = dx * dx + dy * dy;
this.shouldHandle_ = this.freehand_ ?
squaredDistance > this.squaredClickTolerance_ :
squaredDistance <= this.squaredClickTolerance_;
@@ -441,10 +441,10 @@ Draw.prototype.handlePointerMove_ = function(event) {
* @private
*/
Draw.prototype.atFinish_ = function(event) {
var at = false;
let at = false;
if (this.sketchFeature_) {
var potentiallyDone = false;
var potentiallyFinishCoordinates = [this.finishCoordinate_];
let potentiallyDone = false;
let potentiallyFinishCoordinates = [this.finishCoordinate_];
if (this.mode_ === Draw.Mode_.LINE_STRING) {
potentiallyDone = this.sketchCoords_.length > this.minPoints_;
} else if (this.mode_ === Draw.Mode_.POLYGON) {
@@ -454,14 +454,14 @@ Draw.prototype.atFinish_ = function(event) {
this.sketchCoords_[0][this.sketchCoords_[0].length - 2]];
}
if (potentiallyDone) {
var map = event.map;
for (var i = 0, ii = potentiallyFinishCoordinates.length; i < ii; i++) {
var finishCoordinate = potentiallyFinishCoordinates[i];
var finishPixel = map.getPixelFromCoordinate(finishCoordinate);
var pixel = event.pixel;
var dx = pixel[0] - finishPixel[0];
var dy = pixel[1] - finishPixel[1];
var snapTolerance = this.freehand_ ? 1 : this.snapTolerance_;
const map = event.map;
for (let i = 0, ii = potentiallyFinishCoordinates.length; i < ii; i++) {
const finishCoordinate = potentiallyFinishCoordinates[i];
const finishPixel = map.getPixelFromCoordinate(finishCoordinate);
const pixel = event.pixel;
const dx = pixel[0] - finishPixel[0];
const dy = pixel[1] - finishPixel[1];
const snapTolerance = this.freehand_ ? 1 : this.snapTolerance_;
at = Math.sqrt(dx * dx + dy * dy) <= snapTolerance;
if (at) {
this.finishCoordinate_ = finishCoordinate;
@@ -479,12 +479,12 @@ Draw.prototype.atFinish_ = function(event) {
* @private
*/
Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
var coordinates = event.coordinate.slice();
const coordinates = event.coordinate.slice();
if (!this.sketchPoint_) {
this.sketchPoint_ = new Feature(new Point(coordinates));
this.updateSketchFeatures_();
} else {
var sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
const sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
sketchPointGeom.setCoordinates(coordinates);
}
};
@@ -496,7 +496,7 @@ Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
* @private
*/
Draw.prototype.startDrawing_ = function(event) {
var start = event.coordinate;
const start = event.coordinate;
this.finishCoordinate_ = start;
if (this.mode_ === Draw.Mode_.POINT) {
this.sketchCoords_ = start.slice();
@@ -511,9 +511,9 @@ Draw.prototype.startDrawing_ = function(event) {
}
if (this.sketchLineCoords_) {
this.sketchLine_ = new Feature(
new LineString(this.sketchLineCoords_));
new LineString(this.sketchLineCoords_));
}
var geometry = this.geometryFunction_(this.sketchCoords_);
const geometry = this.geometryFunction_(this.sketchCoords_);
this.sketchFeature_ = new Feature();
if (this.geometryName_) {
this.sketchFeature_.setGeometryName(this.geometryName_);
@@ -530,9 +530,9 @@ Draw.prototype.startDrawing_ = function(event) {
* @private
*/
Draw.prototype.modifyDrawing_ = function(event) {
var coordinate = event.coordinate;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, last;
let coordinate = event.coordinate;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let coordinates, last;
if (this.mode_ === Draw.Mode_.POINT) {
last = this.sketchCoords_;
} else if (this.mode_ === Draw.Mode_.POLYGON) {
@@ -550,19 +550,19 @@ Draw.prototype.modifyDrawing_ = function(event) {
last[1] = coordinate[1];
this.geometryFunction_(/** @type {!Array.<ol.Coordinate>} */ (this.sketchCoords_), geometry);
if (this.sketchPoint_) {
var sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
const sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
sketchPointGeom.setCoordinates(coordinate);
}
var sketchLineGeom;
let sketchLineGeom;
if (geometry instanceof Polygon &&
this.mode_ !== Draw.Mode_.POLYGON) {
if (!this.sketchLine_) {
this.sketchLine_ = new Feature(new LineString(null));
}
var ring = geometry.getLinearRing(0);
const ring = geometry.getLinearRing(0);
sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
sketchLineGeom.setFlatCoordinates(
ring.getLayout(), ring.getFlatCoordinates());
ring.getLayout(), ring.getFlatCoordinates());
} else if (this.sketchLineCoords_) {
sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
sketchLineGeom.setCoordinates(this.sketchLineCoords_);
@@ -577,10 +577,10 @@ Draw.prototype.modifyDrawing_ = function(event) {
* @private
*/
Draw.prototype.addToDrawing_ = function(event) {
var coordinate = event.coordinate;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var done;
var coordinates;
const coordinate = event.coordinate;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let done;
let coordinates;
if (this.mode_ === Draw.Mode_.LINE_STRING) {
this.finishCoordinate_ = coordinate.slice();
coordinates = this.sketchCoords_;
@@ -623,8 +623,8 @@ Draw.prototype.removeLastPoint = function() {
if (!this.sketchFeature_) {
return;
}
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, sketchLineGeom;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let coordinates, sketchLineGeom;
if (this.mode_ === Draw.Mode_.LINE_STRING) {
coordinates = this.sketchCoords_;
coordinates.splice(-2, 1);
@@ -655,9 +655,9 @@ Draw.prototype.removeLastPoint = function() {
* @api
*/
Draw.prototype.finishDrawing = function() {
var sketchFeature = this.abortDrawing_();
var coordinates = this.sketchCoords_;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
const sketchFeature = this.abortDrawing_();
let coordinates = this.sketchCoords_;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
if (this.mode_ === Draw.Mode_.LINE_STRING) {
// remove the redundant last point
coordinates.pop();
@@ -698,7 +698,7 @@ Draw.prototype.finishDrawing = function() {
*/
Draw.prototype.abortDrawing_ = function() {
this.finishCoordinate_ = null;
var sketchFeature = this.sketchFeature_;
const sketchFeature = this.sketchFeature_;
if (sketchFeature) {
this.sketchFeature_ = null;
this.sketchPoint_ = null;
@@ -717,11 +717,11 @@ Draw.prototype.abortDrawing_ = function() {
* @api
*/
Draw.prototype.extend = function(feature) {
var geometry = feature.getGeometry();
var lineString = /** @type {ol.geom.LineString} */ (geometry);
const geometry = feature.getGeometry();
const lineString = /** @type {ol.geom.LineString} */ (geometry);
this.sketchFeature_ = feature;
this.sketchCoords_ = lineString.getCoordinates();
var last = this.sketchCoords_[this.sketchCoords_.length - 1];
const last = this.sketchCoords_[this.sketchCoords_.length - 1];
this.finishCoordinate_ = last.slice();
this.sketchCoords_.push(last.slice());
this.updateSketchFeatures_();
@@ -740,7 +740,7 @@ Draw.prototype.shouldStopEvent = FALSE;
* @private
*/
Draw.prototype.updateSketchFeatures_ = function() {
var sketchFeatures = [];
const sketchFeatures = [];
if (this.sketchFeature_) {
sketchFeatures.push(this.sketchFeature_);
}
@@ -750,7 +750,7 @@ Draw.prototype.updateSketchFeatures_ = function() {
if (this.sketchPoint_) {
sketchFeatures.push(this.sketchPoint_);
}
var overlaySource = this.overlay_.getSource();
const overlaySource = this.overlay_.getSource();
overlaySource.clear(true);
overlaySource.addFeatures(sketchFeatures);
};
@@ -760,8 +760,8 @@ Draw.prototype.updateSketchFeatures_ = function() {
* @private
*/
Draw.prototype.updateState_ = function() {
var map = this.getMap();
var active = this.getActive();
const map = this.getMap();
const active = this.getActive();
if (!map || !active) {
this.abortDrawing_();
}
@@ -790,13 +790,13 @@ Draw.createRegularPolygon = function(opt_sides, opt_angle) {
* @return {ol.geom.SimpleGeometry}
*/
function(coordinates, opt_geometry) {
var center = coordinates[0];
var end = coordinates[1];
var radius = Math.sqrt(
_ol_coordinate_.squaredDistance(center, end));
var geometry = opt_geometry ? /** @type {ol.geom.Polygon} */ (opt_geometry) :
const center = coordinates[0];
const end = coordinates[1];
const radius = Math.sqrt(
_ol_coordinate_.squaredDistance(center, end));
const geometry = opt_geometry ? /** @type {ol.geom.Polygon} */ (opt_geometry) :
fromCircle(new Circle(center), opt_sides);
var angle = opt_angle ? opt_angle :
const angle = opt_angle ? opt_angle :
Math.atan((end[1] - center[1]) / (end[0] - center[0]));
makeRegular(geometry, center, radius, angle);
return geometry;
@@ -820,8 +820,8 @@ Draw.createBox = function() {
* @return {ol.geom.SimpleGeometry}
*/
function(coordinates, opt_geometry) {
var extent = boundingExtent(coordinates);
var geometry = opt_geometry || new Polygon(null);
const extent = boundingExtent(coordinates);
const geometry = opt_geometry || new Polygon(null);
geometry.setCoordinates([[
getBottomLeft(extent),
getBottomRight(extent),
@@ -843,7 +843,7 @@ Draw.createBox = function() {
* @private
*/
Draw.getMode_ = function(type) {
var mode;
let mode;
if (type === GeometryType.POINT ||
type === GeometryType.MULTI_POINT) {
mode = Draw.Mode_.POINT;
+38 -38
View File
@@ -29,9 +29,9 @@ import Style from '../style/Style.js';
* @param {olx.interaction.ExtentOptions=} opt_options Options.
* @api
*/
var ExtentInteraction = function(opt_options) {
const ExtentInteraction = function(opt_options) {
var options = opt_options || {};
const options = opt_options || {};
/**
* Extent of the drawn box
@@ -152,16 +152,16 @@ ExtentInteraction.handleEvent_ = function(mapBrowserEvent) {
* @private
*/
ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
var pixel = mapBrowserEvent.pixel;
var map = mapBrowserEvent.map;
const pixel = mapBrowserEvent.pixel;
const map = mapBrowserEvent.map;
var extent = this.getExtent();
var vertex = this.snapToVertex_(pixel, map);
const extent = this.getExtent();
let vertex = this.snapToVertex_(pixel, map);
//find the extent corner opposite the passed corner
var getOpposingPoint = function(point) {
var x_ = null;
var y_ = null;
const getOpposingPoint = function(point) {
let x_ = null;
let y_ = null;
if (point[0] == extent[0]) {
x_ = extent[2];
} else if (point[0] == extent[2]) {
@@ -178,8 +178,8 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
return null;
};
if (vertex && extent) {
var x = (vertex[0] == extent[0] || vertex[0] == extent[2]) ? vertex[0] : null;
var y = (vertex[1] == extent[1] || vertex[1] == extent[3]) ? vertex[1] : null;
const x = (vertex[0] == extent[0] || vertex[0] == extent[2]) ? vertex[0] : null;
const y = (vertex[1] == extent[1] || vertex[1] == extent[3]) ? vertex[1] : null;
//snap to point
if (x !== null && y !== null) {
@@ -187,13 +187,13 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
//snap to edge
} else if (x !== null) {
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_(
getOpposingPoint([x, extent[1]]),
getOpposingPoint([x, extent[3]])
getOpposingPoint([x, extent[1]]),
getOpposingPoint([x, extent[3]])
);
} else if (y !== null) {
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_(
getOpposingPoint([extent[0], y]),
getOpposingPoint([extent[2], y])
getOpposingPoint([extent[0], y]),
getOpposingPoint([extent[2], y])
);
}
//no snap - new bbox
@@ -213,7 +213,7 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
*/
ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) {
if (this.pointerHandler_) {
var pixelCoordinate = mapBrowserEvent.coordinate;
const pixelCoordinate = mapBrowserEvent.coordinate;
this.setExtent(this.pointerHandler_(pixelCoordinate));
this.createOrUpdatePointerFeature_(pixelCoordinate);
}
@@ -229,7 +229,7 @@ ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) {
ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
this.pointerHandler_ = null;
//If bbox is zero area, set to null;
var extent = this.getExtent();
const extent = this.getExtent();
if (!extent || getArea(extent) === 0) {
this.setExtent(null);
}
@@ -243,7 +243,7 @@ ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
* @private
*/
ExtentInteraction.getDefaultExtentStyleFunction_ = function() {
var style = Style.createDefaultEditing();
const style = Style.createDefaultEditing();
return function(feature, resolution) {
return style[GeometryType.POLYGON];
};
@@ -256,7 +256,7 @@ ExtentInteraction.getDefaultExtentStyleFunction_ = function() {
* @private
*/
ExtentInteraction.getDefaultPointerStyleFunction_ = function() {
var style = Style.createDefaultEditing();
const style = Style.createDefaultEditing();
return function(feature, resolution) {
return style[GeometryType.POINT];
};
@@ -314,30 +314,30 @@ ExtentInteraction.getSegments_ = function(extent) {
* @private
*/
ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
var pixelCoordinate = map.getCoordinateFromPixel(pixel);
var sortByDistance = function(a, b) {
const pixelCoordinate = map.getCoordinateFromPixel(pixel);
const sortByDistance = function(a, b) {
return _ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, a) -
_ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, b);
};
var extent = this.getExtent();
const extent = this.getExtent();
if (extent) {
//convert extents to line segments and find the segment closest to pixelCoordinate
var segments = ExtentInteraction.getSegments_(extent);
const segments = ExtentInteraction.getSegments_(extent);
segments.sort(sortByDistance);
var closestSegment = segments[0];
const closestSegment = segments[0];
var vertex = (_ol_coordinate_.closestOnSegment(pixelCoordinate,
closestSegment));
var vertexPixel = map.getPixelFromCoordinate(vertex);
let vertex = (_ol_coordinate_.closestOnSegment(pixelCoordinate,
closestSegment));
const vertexPixel = map.getPixelFromCoordinate(vertex);
//if the distance is within tolerance, snap to the segment
if (_ol_coordinate_.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
//test if we should further snap to a vertex
var pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
var pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
var squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
var squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
var dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
const squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
const squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
const dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
this.snappedToVertex_ = dist <= this.pixelTolerance_;
if (this.snappedToVertex_) {
vertex = squaredDist1 > squaredDist2 ?
@@ -354,10 +354,10 @@ ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
* @private
*/
ExtentInteraction.prototype.handlePointerMove_ = function(mapBrowserEvent) {
var pixel = mapBrowserEvent.pixel;
var map = mapBrowserEvent.map;
const pixel = mapBrowserEvent.pixel;
const map = mapBrowserEvent.map;
var vertex = this.snapToVertex_(pixel, map);
let vertex = this.snapToVertex_(pixel, map);
if (!vertex) {
vertex = map.getCoordinateFromPixel(pixel);
}
@@ -370,7 +370,7 @@ ExtentInteraction.prototype.handlePointerMove_ = function(mapBrowserEvent) {
* @private
*/
ExtentInteraction.prototype.createOrUpdateExtentFeature_ = function(extent) {
var extentFeature = this.extentFeature_;
let extentFeature = this.extentFeature_;
if (!extentFeature) {
if (!extent) {
@@ -397,13 +397,13 @@ ExtentInteraction.prototype.createOrUpdateExtentFeature_ = function(extent) {
* @private
*/
ExtentInteraction.prototype.createOrUpdatePointerFeature_ = function(vertex) {
var vertexFeature = this.vertexFeature_;
let vertexFeature = this.vertexFeature_;
if (!vertexFeature) {
vertexFeature = new Feature(new Point(vertex));
this.vertexFeature_ = vertexFeature;
this.vertexOverlay_.getSource().addFeature(vertexFeature);
} else {
var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
const geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
geometry.setCoordinates(vertex);
}
return vertexFeature;
+21 -21
View File
@@ -12,7 +12,7 @@ import {clamp} from '../math.js';
* Object literal with config options for interactions.
* @typedef {{handleEvent: function(ol.MapBrowserEvent):boolean}}
*/
export var InteractionOptions;
export let InteractionOptions;
/**
@@ -38,7 +38,7 @@ export var InteractionOptions;
* @extends {ol.Object}
* @api
*/
var Interaction = function(options) {
const Interaction = function(options) {
BaseObject.call(this);
@@ -109,10 +109,10 @@ Interaction.prototype.setMap = function(map) {
* @param {number=} opt_duration Duration.
*/
Interaction.pan = function(view, delta, opt_duration) {
var currentCenter = view.getCenter();
const currentCenter = view.getCenter();
if (currentCenter) {
var center = view.constrainCenter(
[currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
const center = view.constrainCenter(
[currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
if (opt_duration) {
view.animate({
duration: opt_duration,
@@ -135,7 +135,7 @@ Interaction.pan = function(view, delta, opt_duration) {
Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) {
rotation = view.constrainRotation(rotation, 0);
Interaction.rotateWithoutConstraints(
view, rotation, opt_anchor, opt_duration);
view, rotation, opt_anchor, opt_duration);
};
@@ -147,8 +147,8 @@ Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) {
*/
Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_duration) {
if (rotation !== undefined) {
var currentRotation = view.getRotation();
var currentCenter = view.getCenter();
const currentRotation = view.getRotation();
const currentCenter = view.getCenter();
if (currentRotation !== undefined && currentCenter && opt_duration > 0) {
view.animate({
rotation: rotation,
@@ -180,7 +180,7 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_
Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_direction) {
resolution = view.constrainResolution(resolution, 0, opt_direction);
Interaction.zoomWithoutConstraints(
view, resolution, opt_anchor, opt_duration);
view, resolution, opt_anchor, opt_duration);
};
@@ -191,23 +191,23 @@ Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_dire
* @param {number=} opt_duration Duration.
*/
Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
var currentResolution = view.getResolution();
var resolution = view.constrainResolution(currentResolution, delta, 0);
const currentResolution = view.getResolution();
let resolution = view.constrainResolution(currentResolution, delta, 0);
if (resolution !== undefined) {
var resolutions = view.getResolutions();
const resolutions = view.getResolutions();
resolution = clamp(
resolution,
view.getMinResolution() || resolutions[resolutions.length - 1],
view.getMaxResolution() || resolutions[0]);
resolution,
view.getMinResolution() || resolutions[resolutions.length - 1],
view.getMaxResolution() || resolutions[0]);
}
// If we have a constraint on center, we need to change the anchor so that the
// new center is within the extent. We first calculate the new center, apply
// the constraint to it, and then calculate back the anchor
if (opt_anchor && resolution !== undefined && resolution !== currentResolution) {
var currentCenter = view.getCenter();
var center = view.calculateCenterZoom(resolution, opt_anchor);
const currentCenter = view.getCenter();
let center = view.calculateCenterZoom(resolution, opt_anchor);
center = view.constrainCenter(center);
opt_anchor = [
@@ -219,7 +219,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
}
Interaction.zoomWithoutConstraints(
view, resolution, opt_anchor, opt_duration);
view, resolution, opt_anchor, opt_duration);
};
@@ -231,8 +231,8 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
*/
Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_duration) {
if (resolution) {
var currentResolution = view.getResolution();
var currentCenter = view.getCenter();
const currentResolution = view.getResolution();
const currentCenter = view.getCenter();
if (currentResolution !== undefined && currentCenter &&
resolution !== currentResolution && opt_duration) {
view.animate({
@@ -243,7 +243,7 @@ Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_
});
} else {
if (opt_anchor) {
var center = view.calculateCenterZoom(resolution, opt_anchor);
const center = view.calculateCenterZoom(resolution, opt_anchor);
view.setCenter(center);
}
view.setResolution(resolution);
+10 -10
View File
@@ -25,13 +25,13 @@ import Interaction from '../interaction/Interaction.js';
* @param {olx.interaction.KeyboardPanOptions=} opt_options Options.
* @api
*/
var KeyboardPan = function(opt_options) {
const KeyboardPan = function(opt_options) {
Interaction.call(this, {
handleEvent: KeyboardPan.handleEvent
});
var options = opt_options || {};
const options = opt_options || {};
/**
* @private
@@ -77,19 +77,19 @@ inherits(KeyboardPan, Interaction);
* @api
*/
KeyboardPan.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
let stopEvent = false;
if (mapBrowserEvent.type == EventType.KEYDOWN) {
var keyEvent = mapBrowserEvent.originalEvent;
var keyCode = keyEvent.keyCode;
const keyEvent = mapBrowserEvent.originalEvent;
const keyCode = keyEvent.keyCode;
if (this.condition_(mapBrowserEvent) &&
(keyCode == _ol_events_KeyCode_.DOWN ||
keyCode == _ol_events_KeyCode_.LEFT ||
keyCode == _ol_events_KeyCode_.RIGHT ||
keyCode == _ol_events_KeyCode_.UP)) {
var map = mapBrowserEvent.map;
var view = map.getView();
var mapUnitsDelta = view.getResolution() * this.pixelDelta_;
var deltaX = 0, deltaY = 0;
const map = mapBrowserEvent.map;
const view = map.getView();
const mapUnitsDelta = view.getResolution() * this.pixelDelta_;
let deltaX = 0, deltaY = 0;
if (keyCode == _ol_events_KeyCode_.DOWN) {
deltaY = -mapUnitsDelta;
} else if (keyCode == _ol_events_KeyCode_.LEFT) {
@@ -99,7 +99,7 @@ KeyboardPan.handleEvent = function(mapBrowserEvent) {
} else {
deltaY = mapUnitsDelta;
}
var delta = [deltaX, deltaY];
const delta = [deltaX, deltaY];
_ol_coordinate_.rotate(delta, view.getRotation());
Interaction.pan(view, delta, this.duration_);
mapBrowserEvent.preventDefault();
+9 -9
View File
@@ -23,13 +23,13 @@ import Interaction from '../interaction/Interaction.js';
* @extends {ol.interaction.Interaction}
* @api
*/
var KeyboardZoom = function(opt_options) {
const KeyboardZoom = function(opt_options) {
Interaction.call(this, {
handleEvent: KeyboardZoom.handleEvent
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @private
@@ -65,18 +65,18 @@ inherits(KeyboardZoom, Interaction);
* @api
*/
KeyboardZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
let stopEvent = false;
if (mapBrowserEvent.type == EventType.KEYDOWN ||
mapBrowserEvent.type == EventType.KEYPRESS) {
var keyEvent = mapBrowserEvent.originalEvent;
var charCode = keyEvent.charCode;
const keyEvent = mapBrowserEvent.originalEvent;
const charCode = keyEvent.charCode;
if (this.condition_(mapBrowserEvent) &&
(charCode == '+'.charCodeAt(0) || charCode == '-'.charCodeAt(0))) {
var map = mapBrowserEvent.map;
var delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_;
var view = map.getView();
const map = mapBrowserEvent.map;
const delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_;
const view = map.getView();
Interaction.zoomByDelta(
view, delta, undefined, this.duration_);
view, delta, undefined, this.duration_);
mapBrowserEvent.preventDefault();
stopEvent = true;
}
+122 -122
View File
@@ -43,7 +43,7 @@ import Style from '../style/Style.js';
* @fires ol.interaction.Modify.Event
* @api
*/
var Modify = function(options) {
const Modify = function(options) {
PointerInteraction.call(this, {
handleDownEvent: Modify.handleDownEvent_,
@@ -192,14 +192,14 @@ var Modify = function(options) {
*/
this.source_ = null;
var features;
let features;
if (options.source) {
this.source_ = options.source;
features = new Collection(this.source_.getFeatures());
_ol_events_.listen(this.source_, VectorEventType.ADDFEATURE,
this.handleSourceAdd_, this);
this.handleSourceAdd_, this);
_ol_events_.listen(this.source_, VectorEventType.REMOVEFEATURE,
this.handleSourceRemove_, this);
this.handleSourceRemove_, this);
} else {
features = options.features;
}
@@ -215,9 +215,9 @@ var Modify = function(options) {
this.features_.forEach(this.addFeature_.bind(this));
_ol_events_.listen(this.features_, CollectionEventType.ADD,
this.handleFeatureAdd_, this);
this.handleFeatureAdd_, this);
_ol_events_.listen(this.features_, CollectionEventType.REMOVE,
this.handleFeatureRemove_, this);
this.handleFeatureRemove_, this);
/**
* @type {ol.MapBrowserPointerEvent}
@@ -248,16 +248,16 @@ Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX = 1;
* @private
*/
Modify.prototype.addFeature_ = function(feature) {
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
if (geometry && geometry.getType() in this.SEGMENT_WRITERS_) {
this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry);
}
var map = this.getMap();
const map = this.getMap();
if (map && map.isRendered() && this.getActive()) {
this.handlePointerAtPixel_(this.lastPixel_, map);
}
_ol_events_.listen(feature, EventType.CHANGE,
this.handleFeatureChange_, this);
this.handleFeatureChange_, this);
};
@@ -269,7 +269,7 @@ Modify.prototype.willModifyFeatures_ = function(evt) {
if (!this.modified_) {
this.modified_ = true;
this.dispatchEvent(new Modify.Event(
ModifyEventType.MODIFYSTART, this.features_, evt));
ModifyEventType.MODIFYSTART, this.features_, evt));
}
};
@@ -287,7 +287,7 @@ Modify.prototype.removeFeature_ = function(feature) {
this.vertexFeature_ = null;
}
_ol_events_.unlisten(feature, EventType.CHANGE,
this.handleFeatureChange_, this);
this.handleFeatureChange_, this);
};
@@ -296,18 +296,18 @@ Modify.prototype.removeFeature_ = function(feature) {
* @private
*/
Modify.prototype.removeFeatureSegmentData_ = function(feature) {
var rBush = this.rBush_;
var /** @type {Array.<ol.ModifySegmentDataType>} */ nodesToRemove = [];
const rBush = this.rBush_;
const /** @type {Array.<ol.ModifySegmentDataType>} */ nodesToRemove = [];
rBush.forEach(
/**
/**
* @param {ol.ModifySegmentDataType} node RTree node.
*/
function(node) {
if (feature === node.feature) {
nodesToRemove.push(node);
}
});
for (var i = nodesToRemove.length - 1; i >= 0; --i) {
function(node) {
if (feature === node.feature) {
nodesToRemove.push(node);
}
});
for (let i = nodesToRemove.length - 1; i >= 0; --i) {
rBush.remove(nodesToRemove[i]);
}
};
@@ -371,7 +371,7 @@ Modify.prototype.handleFeatureAdd_ = function(evt) {
*/
Modify.prototype.handleFeatureChange_ = function(evt) {
if (!this.changingFeature_) {
var feature = /** @type {ol.Feature} */ (evt.target);
const feature = /** @type {ol.Feature} */ (evt.target);
this.removeFeature_(feature);
this.addFeature_(feature);
}
@@ -383,7 +383,7 @@ Modify.prototype.handleFeatureChange_ = function(evt) {
* @private
*/
Modify.prototype.handleFeatureRemove_ = function(evt) {
var feature = /** @type {ol.Feature} */ (evt.element);
const feature = /** @type {ol.Feature} */ (evt.element);
this.removeFeature_(feature);
};
@@ -394,8 +394,8 @@ Modify.prototype.handleFeatureRemove_ = function(evt) {
* @private
*/
Modify.prototype.writePointGeometry_ = function(feature, geometry) {
var coordinates = geometry.getCoordinates();
var segmentData = /** @type {ol.ModifySegmentDataType} */ ({
const coordinates = geometry.getCoordinates();
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
feature: feature,
geometry: geometry,
segment: [coordinates, coordinates]
@@ -410,8 +410,8 @@ Modify.prototype.writePointGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
var points = geometry.getCoordinates();
var coordinates, i, ii, segmentData;
const points = geometry.getCoordinates();
let coordinates, i, ii, segmentData;
for (i = 0, ii = points.length; i < ii; ++i) {
coordinates = points[i];
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
@@ -432,8 +432,8 @@ Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
var coordinates = geometry.getCoordinates();
var i, ii, segment, segmentData;
const coordinates = geometry.getCoordinates();
let i, ii, segment, segmentData;
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
segment = coordinates.slice(i, i + 2);
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
@@ -453,8 +453,8 @@ Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
var lines = geometry.getCoordinates();
var coordinates, i, ii, j, jj, segment, segmentData;
const lines = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData;
for (j = 0, jj = lines.length; j < jj; ++j) {
coordinates = lines[j];
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
@@ -478,8 +478,8 @@ Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
var rings = geometry.getCoordinates();
var coordinates, i, ii, j, jj, segment, segmentData;
const rings = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData;
for (j = 0, jj = rings.length; j < jj; ++j) {
coordinates = rings[j];
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
@@ -503,8 +503,8 @@ Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
var polygons = geometry.getCoordinates();
var coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
const polygons = geometry.getCoordinates();
let coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
for (k = 0, kk = polygons.length; k < kk; ++k) {
rings = polygons[k];
for (j = 0, jj = rings.length; j < jj; ++j) {
@@ -537,20 +537,20 @@ Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeCircleGeometry_ = function(feature, geometry) {
var coordinates = geometry.getCenter();
var centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
const coordinates = geometry.getCenter();
const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
feature: feature,
geometry: geometry,
index: Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX,
segment: [coordinates, coordinates]
});
var circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
feature: feature,
geometry: geometry,
index: Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX,
segment: [coordinates, coordinates]
});
var featureSegments = [centerSegmentData, circumferenceSegmentData];
const featureSegments = [centerSegmentData, circumferenceSegmentData];
centerSegmentData.featureSegments = circumferenceSegmentData.featureSegments = featureSegments;
this.rBush_.insert(createOrUpdateFromCoordinate(coordinates), centerSegmentData);
this.rBush_.insert(geometry.getExtent(), circumferenceSegmentData);
@@ -563,10 +563,10 @@ Modify.prototype.writeCircleGeometry_ = function(feature, geometry) {
* @private
*/
Modify.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
var i, geometries = geometry.getGeometriesArray();
for (i = 0; i < geometries.length; ++i) {
const geometries = geometry.getGeometriesArray();
for (let i = 0; i < geometries.length; ++i) {
this.SEGMENT_WRITERS_[geometries[i].getType()].call(
this, feature, geometries[i]);
this, feature, geometries[i]);
}
};
@@ -577,13 +577,13 @@ Modify.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry)
* @private
*/
Modify.prototype.createOrUpdateVertexFeature_ = function(coordinates) {
var vertexFeature = this.vertexFeature_;
let vertexFeature = this.vertexFeature_;
if (!vertexFeature) {
vertexFeature = new Feature(new Point(coordinates));
this.vertexFeature_ = vertexFeature;
this.overlay_.getSource().addFeature(vertexFeature);
} else {
var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
const geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
geometry.setCoordinates(coordinates);
}
return vertexFeature;
@@ -612,23 +612,23 @@ Modify.handleDownEvent_ = function(evt) {
return false;
}
this.handlePointerAtPixel_(evt.pixel, evt.map);
var pixelCoordinate = evt.map.getCoordinateFromPixel(evt.pixel);
const pixelCoordinate = evt.map.getCoordinateFromPixel(evt.pixel);
this.dragSegments_.length = 0;
this.modified_ = false;
var vertexFeature = this.vertexFeature_;
const vertexFeature = this.vertexFeature_;
if (vertexFeature) {
var insertVertices = [];
var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
var vertex = geometry.getCoordinates();
var vertexExtent = boundingExtent([vertex]);
var segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
var componentSegments = {};
const insertVertices = [];
const geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
const vertex = geometry.getCoordinates();
const vertexExtent = boundingExtent([vertex]);
const segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
const componentSegments = {};
segmentDataMatches.sort(Modify.compareIndexes_);
for (var i = 0, ii = segmentDataMatches.length; i < ii; ++i) {
var segmentDataMatch = segmentDataMatches[i];
var segment = segmentDataMatch.segment;
var uid = getUid(segmentDataMatch.feature);
var depth = segmentDataMatch.depth;
for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) {
const segmentDataMatch = segmentDataMatches[i];
const segment = segmentDataMatch.segment;
let uid = getUid(segmentDataMatch.feature);
const depth = segmentDataMatch.depth;
if (depth) {
uid += '-' + depth.join('-'); // separate feature components
}
@@ -638,7 +638,7 @@ Modify.handleDownEvent_ = function(evt) {
if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
var closestVertex = Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch);
const closestVertex = Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch);
if (_ol_coordinate_.equals(closestVertex, vertex) && !componentSegments[uid][0]) {
this.dragSegments_.push([segmentDataMatch, 0]);
componentSegments[uid][0] = segmentDataMatch;
@@ -670,7 +670,7 @@ Modify.handleDownEvent_ = function(evt) {
if (insertVertices.length) {
this.willModifyFeatures_(evt);
}
for (var j = insertVertices.length - 1; j >= 0; --j) {
for (let j = insertVertices.length - 1; j >= 0; --j) {
this.insertVertex_.apply(this, insertVertices[j]);
}
}
@@ -687,15 +687,15 @@ Modify.handleDragEvent_ = function(evt) {
this.ignoreNextSingleClick_ = false;
this.willModifyFeatures_(evt);
var vertex = evt.coordinate;
for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
var dragSegment = this.dragSegments_[i];
var segmentData = dragSegment[0];
var depth = segmentData.depth;
var geometry = segmentData.geometry;
var coordinates;
var segment = segmentData.segment;
var index = dragSegment[1];
const vertex = evt.coordinate;
for (let i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
const dragSegment = this.dragSegments_[i];
const segmentData = dragSegment[0];
const depth = segmentData.depth;
const geometry = segmentData.geometry;
let coordinates;
const segment = segmentData.segment;
const index = dragSegment[1];
while (vertex.length < geometry.getStride()) {
vertex.push(segment[index][vertex.length]);
@@ -762,28 +762,28 @@ Modify.handleDragEvent_ = function(evt) {
* @private
*/
Modify.handleUpEvent_ = function(evt) {
var segmentData;
var geometry;
for (var i = this.dragSegments_.length - 1; i >= 0; --i) {
let segmentData;
let geometry;
for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
segmentData = this.dragSegments_[i][0];
geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE) {
// Update a circle object in the R* bush:
var coordinates = geometry.getCenter();
var centerSegmentData = segmentData.featureSegments[0];
var circumferenceSegmentData = segmentData.featureSegments[1];
const coordinates = geometry.getCenter();
const centerSegmentData = segmentData.featureSegments[0];
const circumferenceSegmentData = segmentData.featureSegments[1];
centerSegmentData.segment[0] = centerSegmentData.segment[1] = coordinates;
circumferenceSegmentData.segment[0] = circumferenceSegmentData.segment[1] = coordinates;
this.rBush_.update(createOrUpdateFromCoordinate(coordinates), centerSegmentData);
this.rBush_.update(geometry.getExtent(), circumferenceSegmentData);
} else {
this.rBush_.update(boundingExtent(segmentData.segment),
segmentData);
segmentData);
}
}
if (this.modified_) {
this.dispatchEvent(new Modify.Event(
ModifyEventType.MODIFYEND, this.features_, evt));
ModifyEventType.MODIFYEND, this.features_, evt));
this.modified_ = false;
}
return false;
@@ -804,7 +804,7 @@ Modify.handleEvent = function(mapBrowserEvent) {
}
this.lastPointerEvent_ = mapBrowserEvent;
var handled;
let handled;
if (!mapBrowserEvent.map.getView().getInteracting() &&
mapBrowserEvent.type == MapBrowserEventType.POINTERMOVE &&
!this.handlingDownUpSequence) {
@@ -844,26 +844,26 @@ Modify.prototype.handlePointerMove_ = function(evt) {
* @private
*/
Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
var pixelCoordinate = map.getCoordinateFromPixel(pixel);
var sortByDistance = function(a, b) {
const pixelCoordinate = map.getCoordinateFromPixel(pixel);
const sortByDistance = function(a, b) {
return Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, a) -
Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, b);
};
var box = buffer(createOrUpdateFromCoordinate(pixelCoordinate),
map.getView().getResolution() * this.pixelTolerance_);
const box = buffer(createOrUpdateFromCoordinate(pixelCoordinate),
map.getView().getResolution() * this.pixelTolerance_);
var rBush = this.rBush_;
var nodes = rBush.getInExtent(box);
const rBush = this.rBush_;
const nodes = rBush.getInExtent(box);
if (nodes.length > 0) {
nodes.sort(sortByDistance);
var node = nodes[0];
var closestSegment = node.segment;
var vertex = Modify.closestOnSegmentData_(pixelCoordinate, node);
var vertexPixel = map.getPixelFromCoordinate(vertex);
var dist = _ol_coordinate_.distance(pixel, vertexPixel);
const node = nodes[0];
const closestSegment = node.segment;
let vertex = Modify.closestOnSegmentData_(pixelCoordinate, node);
const vertexPixel = map.getPixelFromCoordinate(vertex);
let dist = _ol_coordinate_.distance(pixel, vertexPixel);
if (dist <= this.pixelTolerance_) {
var vertexSegments = {};
const vertexSegments = {};
if (node.geometry.getType() === GeometryType.CIRCLE &&
node.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
@@ -871,10 +871,10 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
this.snappedToVertex_ = true;
this.createOrUpdateVertexFeature_(vertex);
} else {
var pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
var pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
var squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
var squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
const squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
const squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
this.snappedToVertex_ = dist <= this.pixelTolerance_;
if (this.snappedToVertex_) {
@@ -882,8 +882,8 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
closestSegment[1] : closestSegment[0];
}
this.createOrUpdateVertexFeature_(vertex);
var segment;
for (var i = 1, ii = nodes.length; i < ii; ++i) {
let segment;
for (let i = 1, ii = nodes.length; i < ii; ++i) {
segment = nodes[i].segment;
if ((_ol_coordinate_.equals(closestSegment[0], segment[0]) &&
_ol_coordinate_.equals(closestSegment[1], segment[1]) ||
@@ -918,15 +918,15 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
* @return {number} The square of the distance between a point and a line segment.
*/
Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentData) {
var geometry = segmentData.geometry;
const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE) {
var circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
const circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
var distanceToCenterSquared =
const distanceToCenterSquared =
_ol_coordinate_.squaredDistance(circleGeometry.getCenter(), pointCoordinates);
var distanceToCircumference =
const distanceToCircumference =
Math.sqrt(distanceToCenterSquared) - circleGeometry.getRadius();
return distanceToCircumference * distanceToCircumference;
}
@@ -944,7 +944,7 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa
* @return {ol.Coordinate} The point closest to the specified line segment.
*/
Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) {
var geometry = segmentData.geometry;
const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE &&
segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
@@ -960,12 +960,12 @@ Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) {
* @private
*/
Modify.prototype.insertVertex_ = function(segmentData, vertex) {
var segment = segmentData.segment;
var feature = segmentData.feature;
var geometry = segmentData.geometry;
var depth = segmentData.depth;
var index = /** @type {number} */ (segmentData.index);
var coordinates;
const segment = segmentData.segment;
const feature = segmentData.feature;
const geometry = segmentData.geometry;
const depth = segmentData.depth;
const index = /** @type {number} */ (segmentData.index);
let coordinates;
while (vertex.length < geometry.getStride()) {
vertex.push(0);
@@ -993,10 +993,10 @@ Modify.prototype.insertVertex_ = function(segmentData, vertex) {
}
this.setGeometryCoordinates_(geometry, coordinates);
var rTree = this.rBush_;
const rTree = this.rBush_;
rTree.remove(segmentData);
this.updateSegmentIndices_(geometry, index, depth, 1);
var newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
const newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
segment: [segment[0], vertex],
feature: feature,
geometry: geometry,
@@ -1004,10 +1004,10 @@ Modify.prototype.insertVertex_ = function(segmentData, vertex) {
index: index
});
rTree.insert(boundingExtent(newSegmentData.segment),
newSegmentData);
newSegmentData);
this.dragSegments_.push([newSegmentData, 1]);
var newSegmentData2 = /** @type {ol.ModifySegmentDataType} */ ({
const newSegmentData2 = /** @type {ol.ModifySegmentDataType} */ ({
segment: [vertex, segment[1]],
feature: feature,
geometry: geometry,
@@ -1015,7 +1015,7 @@ Modify.prototype.insertVertex_ = function(segmentData, vertex) {
index: index + 1
});
rTree.insert(boundingExtent(newSegmentData2.segment),
newSegmentData2);
newSegmentData2);
this.dragSegments_.push([newSegmentData2, 0]);
this.ignoreNextSingleClick_ = true;
};
@@ -1027,11 +1027,11 @@ Modify.prototype.insertVertex_ = function(segmentData, vertex) {
*/
Modify.prototype.removePoint = function() {
if (this.lastPointerEvent_ && this.lastPointerEvent_.type != MapBrowserEventType.POINTERDRAG) {
var evt = this.lastPointerEvent_;
const evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt);
this.removeVertex_();
this.dispatchEvent(new Modify.Event(
ModifyEventType.MODIFYEND, this.features_, evt));
ModifyEventType.MODIFYEND, this.features_, evt));
this.modified_ = false;
return true;
}
@@ -1044,11 +1044,11 @@ Modify.prototype.removePoint = function() {
* @private
*/
Modify.prototype.removeVertex_ = function() {
var dragSegments = this.dragSegments_;
var segmentsByFeature = {};
var deleted = false;
var component, coordinates, dragSegment, geometry, i, index, left;
var newIndex, right, segmentData, uid;
const dragSegments = this.dragSegments_;
const segmentsByFeature = {};
let deleted = false;
let component, coordinates, dragSegment, geometry, i, index, left;
let newIndex, right, segmentData, uid;
for (i = dragSegments.length - 1; i >= 0; --i) {
dragSegment = dragSegments[i];
segmentData = dragSegment[0];
@@ -1124,7 +1124,7 @@ Modify.prototype.removeVertex_ = function() {
if (deleted) {
this.setGeometryCoordinates_(geometry, coordinates);
var segments = [];
const segments = [];
if (left !== undefined) {
this.rBush_.remove(left);
segments.push(left.segment[0]);
@@ -1134,7 +1134,7 @@ Modify.prototype.removeVertex_ = function() {
segments.push(right.segment[1]);
}
if (left !== undefined && right !== undefined) {
var newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
const newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
depth: segmentData.depth,
feature: segmentData.feature,
geometry: segmentData.geometry,
@@ -1142,7 +1142,7 @@ Modify.prototype.removeVertex_ = function() {
segment: segments
});
this.rBush_.insert(boundingExtent(newSegmentData.segment),
newSegmentData);
newSegmentData);
}
this.updateSegmentIndices_(geometry, index, segmentData.depth, -1);
if (this.vertexFeature_) {
@@ -1177,7 +1177,7 @@ Modify.prototype.setGeometryCoordinates_ = function(geometry, coordinates) {
* @private
*/
Modify.prototype.updateSegmentIndices_ = function(
geometry, index, depth, delta) {
geometry, index, depth, delta) {
this.rBush_.forEachInExtent(geometry.getExtent(), function(segmentDataMatch) {
if (segmentDataMatch.geometry === geometry &&
(depth === undefined || segmentDataMatch.depth === undefined ||
@@ -1193,7 +1193,7 @@ Modify.prototype.updateSegmentIndices_ = function(
* @return {ol.StyleFunction} Styles.
*/
Modify.getDefaultStyleFunction = function() {
var style = Style.createDefaultEditing();
const style = Style.createDefaultEditing();
return function(feature, resolution) {
return style[GeometryType.POINT];
};
+20 -20
View File
@@ -14,7 +14,7 @@ import {clamp} from '../math.js';
/**
* @type {number} Maximum mouse wheel delta.
*/
var MAX_DELTA = 1;
const MAX_DELTA = 1;
/**
@@ -26,13 +26,13 @@ var MAX_DELTA = 1;
* @param {olx.interaction.MouseWheelZoomOptions=} opt_options Options.
* @api
*/
var MouseWheelZoom = function(opt_options) {
const MouseWheelZoom = function(opt_options) {
Interaction.call(this, {
handleEvent: MouseWheelZoom.handleEvent
});
var options = opt_options || {};
const options = opt_options || {};
/**
* @private
@@ -137,15 +137,15 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
if (!this.condition_(mapBrowserEvent)) {
return true;
}
var type = mapBrowserEvent.type;
const type = mapBrowserEvent.type;
if (type !== EventType.WHEEL && type !== EventType.MOUSEWHEEL) {
return true;
}
mapBrowserEvent.preventDefault();
var map = mapBrowserEvent.map;
var wheelEvent = /** @type {WheelEvent} */ (mapBrowserEvent.originalEvent);
const map = mapBrowserEvent.map;
const wheelEvent = /** @type {WheelEvent} */ (mapBrowserEvent.originalEvent);
if (this.useAnchor_) {
this.lastAnchor_ = mapBrowserEvent.coordinate;
@@ -153,7 +153,7 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
// Delta normalisation inspired by
// https://github.com/mapbox/mapbox-gl-js/blob/001c7b9/js/ui/handler/scroll_zoom.js
var delta;
let delta;
if (mapBrowserEvent.type == EventType.WHEEL) {
delta = wheelEvent.deltaY;
if (_ol_has_.FIREFOX &&
@@ -174,7 +174,7 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
return false;
}
var now = Date.now();
const now = Date.now();
if (this.startTime_ === undefined) {
this.startTime_ = now;
@@ -187,17 +187,17 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
}
if (this.mode_ === MouseWheelZoom.Mode_.TRACKPAD) {
var view = map.getView();
const view = map.getView();
if (this.trackpadTimeoutId_) {
clearTimeout(this.trackpadTimeoutId_);
} else {
view.setHint(ViewHint.INTERACTING, 1);
}
this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_);
var resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_);
var minResolution = view.getMinResolution();
var maxResolution = view.getMaxResolution();
var rebound = 0;
let resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_);
const minResolution = view.getMinResolution();
const maxResolution = view.getMaxResolution();
let rebound = 0;
if (resolution < minResolution) {
resolution = Math.max(resolution, minResolution / this.trackpadZoomBuffer_);
rebound = 1;
@@ -206,7 +206,7 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
rebound = -1;
}
if (this.lastAnchor_) {
var center = view.calculateCenterZoom(resolution, this.lastAnchor_);
const center = view.calculateCenterZoom(resolution, this.lastAnchor_);
view.setCenter(view.constrainCenter(center));
}
view.setResolution(resolution);
@@ -241,7 +241,7 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
this.delta_ += delta;
var timeLeft = Math.max(this.timeout_ - (now - this.startTime_), 0);
const timeLeft = Math.max(this.timeout_ - (now - this.startTime_), 0);
clearTimeout(this.timeoutId_);
this.timeoutId_ = setTimeout(this.handleWheelZoom_.bind(this, map), timeLeft);
@@ -255,7 +255,7 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
*/
MouseWheelZoom.prototype.decrementInteractingHint_ = function() {
this.trackpadTimeoutId_ = undefined;
var view = this.getMap().getView();
const view = this.getMap().getView();
view.setHint(ViewHint.INTERACTING, -1);
};
@@ -265,14 +265,14 @@ MouseWheelZoom.prototype.decrementInteractingHint_ = function() {
* @param {ol.PluggableMap} map Map.
*/
MouseWheelZoom.prototype.handleWheelZoom_ = function(map) {
var view = map.getView();
const view = map.getView();
if (view.getAnimating()) {
view.cancelAnimations();
}
var maxDelta = MAX_DELTA;
var delta = clamp(this.delta_, -maxDelta, maxDelta);
const maxDelta = MAX_DELTA;
const delta = clamp(this.delta_, -maxDelta, maxDelta);
Interaction.zoomByDelta(view, -delta, this.lastAnchor_,
this.duration_);
this.duration_);
this.mode_ = undefined;
this.delta_ = 0;
this.lastAnchor_ = null;
+20 -20
View File
@@ -18,7 +18,7 @@ import RotationConstraint from '../RotationConstraint.js';
* @param {olx.interaction.PinchRotateOptions=} opt_options Options.
* @api
*/
var PinchRotate = function(opt_options) {
const PinchRotate = function(opt_options) {
PointerInteraction.call(this, {
handleDownEvent: PinchRotate.handleDownEvent_,
@@ -26,7 +26,7 @@ var PinchRotate = function(opt_options) {
handleUpEvent: PinchRotate.handleUpEvent_
});
var options = opt_options || {};
const options = opt_options || {};
/**
* @private
@@ -75,18 +75,18 @@ inherits(PinchRotate, PointerInteraction);
* @private
*/
PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
var rotationDelta = 0.0;
let rotationDelta = 0.0;
var touch0 = this.targetPointers[0];
var touch1 = this.targetPointers[1];
const touch0 = this.targetPointers[0];
const touch1 = this.targetPointers[1];
// angle between touches
var angle = Math.atan2(
touch1.clientY - touch0.clientY,
touch1.clientX - touch0.clientX);
const angle = Math.atan2(
touch1.clientY - touch0.clientY,
touch1.clientX - touch0.clientX);
if (this.lastAngle_ !== undefined) {
var delta = angle - this.lastAngle_;
const delta = angle - this.lastAngle_;
this.rotationDelta_ += delta;
if (!this.rotating_ &&
Math.abs(this.rotationDelta_) > this.threshold_) {
@@ -96,8 +96,8 @@ PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
}
this.lastAngle_ = angle;
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
if (view.getConstraints().rotation === RotationConstraint.disable) {
return;
}
@@ -105,18 +105,18 @@ PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
// rotate anchor point.
// FIXME: should be the intersection point between the lines:
// touch0,touch1 and previousTouch0,previousTouch1
var viewportPosition = map.getViewport().getBoundingClientRect();
var centroid = PointerInteraction.centroid(this.targetPointers);
const viewportPosition = map.getViewport().getBoundingClientRect();
const centroid = PointerInteraction.centroid(this.targetPointers);
centroid[0] -= viewportPosition.left;
centroid[1] -= viewportPosition.top;
this.anchor_ = map.getCoordinateFromPixel(centroid);
// rotate
if (this.rotating_) {
var rotation = view.getRotation();
const rotation = view.getRotation();
map.render();
Interaction.rotateWithoutConstraints(view,
rotation + rotationDelta, this.anchor_);
rotation + rotationDelta, this.anchor_);
}
};
@@ -129,13 +129,13 @@ PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
*/
PinchRotate.handleUpEvent_ = function(mapBrowserEvent) {
if (this.targetPointers.length < 2) {
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1);
if (this.rotating_) {
var rotation = view.getRotation();
const rotation = view.getRotation();
Interaction.rotate(
view, rotation, this.anchor_, this.duration_);
view, rotation, this.anchor_, this.duration_);
}
return false;
} else {
@@ -152,7 +152,7 @@ PinchRotate.handleUpEvent_ = function(mapBrowserEvent) {
*/
PinchRotate.handleDownEvent_ = function(mapBrowserEvent) {
if (this.targetPointers.length >= 2) {
var map = mapBrowserEvent.map;
const map = mapBrowserEvent.map;
this.anchor_ = null;
this.lastAngle_ = undefined;
this.rotating_ = false;
+22 -22
View File
@@ -17,7 +17,7 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {olx.interaction.PinchZoomOptions=} opt_options Options.
* @api
*/
var PinchZoom = function(opt_options) {
const PinchZoom = function(opt_options) {
PointerInteraction.call(this, {
handleDownEvent: PinchZoom.handleDownEvent_,
@@ -25,7 +25,7 @@ var PinchZoom = function(opt_options) {
handleUpEvent: PinchZoom.handleUpEvent_
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @private
@@ -68,15 +68,15 @@ inherits(PinchZoom, PointerInteraction);
* @private
*/
PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
var scaleDelta = 1.0;
let scaleDelta = 1.0;
var touch0 = this.targetPointers[0];
var touch1 = this.targetPointers[1];
var dx = touch0.clientX - touch1.clientX;
var dy = touch0.clientY - touch1.clientY;
const touch0 = this.targetPointers[0];
const touch1 = this.targetPointers[1];
const dx = touch0.clientX - touch1.clientX;
const dy = touch0.clientY - touch1.clientY;
// distance between touches
var distance = Math.sqrt(dx * dx + dy * dy);
const distance = Math.sqrt(dx * dx + dy * dy);
if (this.lastDistance_ !== undefined) {
scaleDelta = this.lastDistance_ / distance;
@@ -84,12 +84,12 @@ PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
this.lastDistance_ = distance;
var map = mapBrowserEvent.map;
var view = map.getView();
var resolution = view.getResolution();
var maxResolution = view.getMaxResolution();
var minResolution = view.getMinResolution();
var newResolution = resolution * scaleDelta;
const map = mapBrowserEvent.map;
const view = map.getView();
const resolution = view.getResolution();
const maxResolution = view.getMaxResolution();
const minResolution = view.getMinResolution();
let newResolution = resolution * scaleDelta;
if (newResolution > maxResolution) {
scaleDelta = maxResolution / resolution;
newResolution = maxResolution;
@@ -103,8 +103,8 @@ PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
}
// scale anchor point.
var viewportPosition = map.getViewport().getBoundingClientRect();
var centroid = PointerInteraction.centroid(this.targetPointers);
const viewportPosition = map.getViewport().getBoundingClientRect();
const centroid = PointerInteraction.centroid(this.targetPointers);
centroid[0] -= viewportPosition.left;
centroid[1] -= viewportPosition.top;
this.anchor_ = map.getCoordinateFromPixel(centroid);
@@ -123,19 +123,19 @@ PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
*/
PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
if (this.targetPointers.length < 2) {
var map = mapBrowserEvent.map;
var view = map.getView();
const map = mapBrowserEvent.map;
const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1);
var resolution = view.getResolution();
const resolution = view.getResolution();
if (this.constrainResolution_ ||
resolution < view.getMinResolution() ||
resolution > view.getMaxResolution()) {
// Zoom to final resolution, with an animation, and provide a
// direction not to zoom out/in if user was pinching in/out.
// Direction is > 0 if pinching out, and < 0 if pinching in.
var direction = this.lastScaleDelta_ - 1;
const direction = this.lastScaleDelta_ - 1;
Interaction.zoom(view, resolution,
this.anchor_, this.duration_, direction);
this.anchor_, this.duration_, direction);
}
return false;
} else {
@@ -152,7 +152,7 @@ PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
*/
PinchZoom.handleDownEvent_ = function(mapBrowserEvent) {
if (this.targetPointers.length >= 2) {
var map = mapBrowserEvent.map;
const map = mapBrowserEvent.map;
this.anchor_ = null;
this.lastDistance_ = undefined;
this.lastScaleDelta_ = 1;
+13 -13
View File
@@ -23,11 +23,11 @@ import _ol_obj_ from '../obj.js';
* @extends {ol.interaction.Interaction}
* @api
*/
var PointerInteraction = function(opt_options) {
const PointerInteraction = function(opt_options) {
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
var handleEvent = options.handleEvent ?
const handleEvent = options.handleEvent ?
options.handleEvent : PointerInteraction.handleEvent;
Interaction.call(this, {
@@ -90,10 +90,10 @@ inherits(PointerInteraction, Interaction);
* @return {ol.Pixel} Centroid pixel.
*/
PointerInteraction.centroid = function(pointerEvents) {
var length = pointerEvents.length;
var clientX = 0;
var clientY = 0;
for (var i = 0; i < length; i++) {
const length = pointerEvents.length;
let clientX = 0;
let clientY = 0;
for (let i = 0; i < length; i++) {
clientX += pointerEvents[i].clientX;
clientY += pointerEvents[i].clientY;
}
@@ -108,7 +108,7 @@ PointerInteraction.centroid = function(pointerEvents) {
* @private
*/
PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent) {
var type = mapBrowserEvent.type;
const type = mapBrowserEvent.type;
return type === MapBrowserEventType.POINTERDOWN ||
type === MapBrowserEventType.POINTERDRAG ||
type === MapBrowserEventType.POINTERUP;
@@ -121,9 +121,9 @@ PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent)
*/
PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
if (this.isPointerDraggingEvent_(mapBrowserEvent)) {
var event = mapBrowserEvent.pointerEvent;
const event = mapBrowserEvent.pointerEvent;
var id = event.pointerId.toString();
const id = event.pointerId.toString();
if (mapBrowserEvent.type == MapBrowserEventType.POINTERUP) {
delete this.trackedPointers_[id];
} else if (mapBrowserEvent.type ==
@@ -182,18 +182,18 @@ PointerInteraction.handleEvent = function(mapBrowserEvent) {
return true;
}
var stopEvent = false;
let stopEvent = false;
this.updateTrackedPointers_(mapBrowserEvent);
if (this.handlingDownUpSequence) {
if (mapBrowserEvent.type == MapBrowserEventType.POINTERDRAG) {
this.handleDragEvent_(mapBrowserEvent);
} else if (mapBrowserEvent.type == MapBrowserEventType.POINTERUP) {
var handledUp = this.handleUpEvent_(mapBrowserEvent);
const handledUp = this.handleUpEvent_(mapBrowserEvent);
this.handlingDownUpSequence = handledUp && this.targetPointers.length > 0;
}
} else {
if (mapBrowserEvent.type == MapBrowserEventType.POINTERDOWN) {
var handled = this.handleDownEvent_(mapBrowserEvent);
const handled = this.handleDownEvent_(mapBrowserEvent);
this.handlingDownUpSequence = handled;
stopEvent = this.shouldStopEvent(handled);
} else if (mapBrowserEvent.type == MapBrowserEventType.POINTERMOVE) {
+58 -58
View File
@@ -33,13 +33,13 @@ import Style from '../style/Style.js';
* @fires ol.interaction.Select.Event
* @api
*/
var Select = function(opt_options) {
const Select = function(opt_options) {
Interaction.call(this, {
handleEvent: Select.handleEvent
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @private
@@ -87,7 +87,7 @@ var Select = function(opt_options) {
*/
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
var featureOverlay = new VectorLayer({
const featureOverlay = new VectorLayer({
source: new VectorSource({
useSpatialIndex: false,
features: options.features,
@@ -106,12 +106,12 @@ var Select = function(opt_options) {
this.featureOverlay_ = featureOverlay;
/** @type {function(ol.layer.Layer): boolean} */
var layerFilter;
let layerFilter;
if (options.layers) {
if (typeof options.layers === 'function') {
layerFilter = options.layers;
} else {
var layers = options.layers;
const layers = options.layers;
layerFilter = function(layer) {
return includes(layers, layer);
};
@@ -134,11 +134,11 @@ var Select = function(opt_options) {
*/
this.featureLayerAssociation_ = {};
var features = this.featureOverlay_.getSource().getFeaturesCollection();
const features = this.featureOverlay_.getSource().getFeaturesCollection();
_ol_events_.listen(features, CollectionEventType.ADD,
this.addFeature_, this);
this.addFeature_, this);
_ol_events_.listen(features, CollectionEventType.REMOVE,
this.removeFeature_, this);
this.removeFeature_, this);
};
@@ -151,7 +151,7 @@ inherits(Select, Interaction);
* @private
*/
Select.prototype.addFeatureLayerAssociation_ = function(feature, layer) {
var key = getUid(feature);
const key = getUid(feature);
this.featureLayerAssociation_[key] = layer;
};
@@ -186,7 +186,7 @@ Select.prototype.getHitTolerance = function() {
* @api
*/
Select.prototype.getLayer = function(feature) {
var key = getUid(feature);
const key = getUid(feature);
return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
};
@@ -203,40 +203,40 @@ Select.handleEvent = function(mapBrowserEvent) {
if (!this.condition_(mapBrowserEvent)) {
return true;
}
var add = this.addCondition_(mapBrowserEvent);
var remove = this.removeCondition_(mapBrowserEvent);
var toggle = this.toggleCondition_(mapBrowserEvent);
var set = !add && !remove && !toggle;
var map = mapBrowserEvent.map;
var features = this.featureOverlay_.getSource().getFeaturesCollection();
var deselected = [];
var selected = [];
const add = this.addCondition_(mapBrowserEvent);
const remove = this.removeCondition_(mapBrowserEvent);
const toggle = this.toggleCondition_(mapBrowserEvent);
const set = !add && !remove && !toggle;
const map = mapBrowserEvent.map;
const features = this.featureOverlay_.getSource().getFeaturesCollection();
const deselected = [];
const selected = [];
if (set) {
// Replace the currently selected feature(s) with the feature(s) at the
// pixel, or clear the selected feature(s) if there is no feature at
// the pixel.
_ol_obj_.clear(this.featureLayerAssociation_);
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
(
/**
(
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
* @return {boolean|undefined} Continue to iterate over the features.
*/
function(feature, layer) {
if (this.filter_(feature, layer)) {
selected.push(feature);
this.addFeatureLayerAssociation_(feature, layer);
return !this.multi_;
}
}).bind(this), {
layerFilter: this.layerFilter_,
hitTolerance: this.hitTolerance_
});
var i;
function(feature, layer) {
if (this.filter_(feature, layer)) {
selected.push(feature);
this.addFeatureLayerAssociation_(feature, layer);
return !this.multi_;
}
}).bind(this), {
layerFilter: this.layerFilter_,
hitTolerance: this.hitTolerance_
});
let i;
for (i = features.getLength() - 1; i >= 0; --i) {
var feature = features.item(i);
var index = selected.indexOf(feature);
const feature = features.item(i);
const index = selected.indexOf(feature);
if (index > -1) {
// feature is already selected
selected.splice(index, 1);
@@ -251,28 +251,28 @@ Select.handleEvent = function(mapBrowserEvent) {
} else {
// Modify the currently selected feature(s).
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
(
/**
(
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
* @return {boolean|undefined} Continue to iterate over the features.
*/
function(feature, layer) {
if (this.filter_(feature, layer)) {
if ((add || toggle) && !includes(features.getArray(), feature)) {
selected.push(feature);
this.addFeatureLayerAssociation_(feature, layer);
} else if ((remove || toggle) && includes(features.getArray(), feature)) {
deselected.push(feature);
this.removeFeatureLayerAssociation_(feature);
}
return !this.multi_;
function(feature, layer) {
if (this.filter_(feature, layer)) {
if ((add || toggle) && !includes(features.getArray(), feature)) {
selected.push(feature);
this.addFeatureLayerAssociation_(feature, layer);
} else if ((remove || toggle) && includes(features.getArray(), feature)) {
deselected.push(feature);
this.removeFeatureLayerAssociation_(feature);
}
}).bind(this), {
layerFilter: this.layerFilter_,
hitTolerance: this.hitTolerance_
});
var j;
return !this.multi_;
}
}).bind(this), {
layerFilter: this.layerFilter_,
hitTolerance: this.hitTolerance_
});
let j;
for (j = deselected.length - 1; j >= 0; --j) {
features.remove(deselected[j]);
}
@@ -280,8 +280,8 @@ Select.handleEvent = function(mapBrowserEvent) {
}
if (selected.length > 0 || deselected.length > 0) {
this.dispatchEvent(
new Select.Event(Select.EventType_.SELECT,
selected, deselected, mapBrowserEvent));
new Select.Event(Select.EventType_.SELECT,
selected, deselected, mapBrowserEvent));
}
return _ol_events_condition_.pointerMove(mapBrowserEvent);
};
@@ -307,8 +307,8 @@ Select.prototype.setHitTolerance = function(hitTolerance) {
* @api
*/
Select.prototype.setMap = function(map) {
var currentMap = this.getMap();
var selectedFeatures =
const currentMap = this.getMap();
const selectedFeatures =
this.featureOverlay_.getSource().getFeaturesCollection();
if (currentMap) {
selectedFeatures.forEach(currentMap.unskipFeature.bind(currentMap));
@@ -325,7 +325,7 @@ Select.prototype.setMap = function(map) {
* @return {ol.StyleFunction} Styles.
*/
Select.getDefaultStyleFunction = function() {
var styles = Style.createDefaultEditing();
const styles = Style.createDefaultEditing();
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]);
@@ -343,7 +343,7 @@ Select.getDefaultStyleFunction = function() {
* @private
*/
Select.prototype.addFeature_ = function(evt) {
var map = this.getMap();
const map = this.getMap();
if (map) {
map.skipFeature(/** @type {ol.Feature} */ (evt.element));
}
@@ -355,7 +355,7 @@ Select.prototype.addFeature_ = function(evt) {
* @private
*/
Select.prototype.removeFeature_ = function(evt) {
var map = this.getMap();
const map = this.getMap();
if (map) {
map.unskipFeature(/** @type {ol.Feature} */ (evt.element));
}
@@ -367,7 +367,7 @@ Select.prototype.removeFeature_ = function(evt) {
* @private
*/
Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
var key = getUid(feature);
const key = getUid(feature);
delete this.featureLayerAssociation_[key];
};
+68 -68
View File
@@ -39,7 +39,7 @@ import RBush from '../structs/RBush.js';
* @param {olx.interaction.SnapOptions=} opt_options Options.
* @api
*/
var Snap = function(opt_options) {
const Snap = function(opt_options) {
PointerInteraction.call(this, {
handleEvent: Snap.handleEvent_,
@@ -47,7 +47,7 @@ var Snap = function(opt_options) {
handleUpEvent: Snap.handleUpEvent_
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* @type {ol.source.Vector}
@@ -160,11 +160,11 @@ inherits(Snap, PointerInteraction);
* @api
*/
Snap.prototype.addFeature = function(feature, opt_listen) {
var listen = opt_listen !== undefined ? opt_listen : true;
var feature_uid = getUid(feature);
var geometry = feature.getGeometry();
const listen = opt_listen !== undefined ? opt_listen : true;
const feature_uid = getUid(feature);
const geometry = feature.getGeometry();
if (geometry) {
var segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()];
const segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()];
if (segmentWriter) {
this.indexedFeaturesExtents_[feature_uid] = geometry.getExtent(createEmpty());
segmentWriter.call(this, feature, geometry);
@@ -173,9 +173,9 @@ Snap.prototype.addFeature = function(feature, opt_listen) {
if (listen) {
this.featureChangeListenerKeys_[feature_uid] = _ol_events_.listen(
feature,
EventType.CHANGE,
this.handleFeatureChange_, this);
feature,
EventType.CHANGE,
this.handleFeatureChange_, this);
}
};
@@ -203,7 +203,7 @@ Snap.prototype.forEachFeatureRemove_ = function(feature) {
* @private
*/
Snap.prototype.getFeatures_ = function() {
var features;
let features;
if (this.features_) {
features = this.features_;
} else if (this.source_) {
@@ -218,7 +218,7 @@ Snap.prototype.getFeatures_ = function() {
* @private
*/
Snap.prototype.handleFeatureAdd_ = function(evt) {
var feature;
let feature;
if (evt instanceof VectorSource.Event) {
feature = evt.feature;
} else if (evt instanceof Collection.Event) {
@@ -233,7 +233,7 @@ Snap.prototype.handleFeatureAdd_ = function(evt) {
* @private
*/
Snap.prototype.handleFeatureRemove_ = function(evt) {
var feature;
let feature;
if (evt instanceof VectorSource.Event) {
feature = evt.feature;
} else if (evt instanceof Collection.Event) {
@@ -248,9 +248,9 @@ Snap.prototype.handleFeatureRemove_ = function(evt) {
* @private
*/
Snap.prototype.handleFeatureChange_ = function(evt) {
var feature = /** @type {ol.Feature} */ (evt.target);
const feature = /** @type {ol.Feature} */ (evt.target);
if (this.handlingDownUpSequence) {
var uid = getUid(feature);
const uid = getUid(feature);
if (!(uid in this.pendingFeatures_)) {
this.pendingFeatures_[uid] = feature;
}
@@ -268,18 +268,18 @@ Snap.prototype.handleFeatureChange_ = function(evt) {
* @api
*/
Snap.prototype.removeFeature = function(feature, opt_unlisten) {
var unlisten = opt_unlisten !== undefined ? opt_unlisten : true;
var feature_uid = getUid(feature);
var extent = this.indexedFeaturesExtents_[feature_uid];
const unlisten = opt_unlisten !== undefined ? opt_unlisten : true;
const feature_uid = getUid(feature);
const extent = this.indexedFeaturesExtents_[feature_uid];
if (extent) {
var rBush = this.rBush_;
var i, nodesToRemove = [];
const rBush = this.rBush_;
const nodesToRemove = [];
rBush.forEachInExtent(extent, function(node) {
if (feature === node.feature) {
nodesToRemove.push(node);
}
});
for (i = nodesToRemove.length - 1; i >= 0; --i) {
for (let i = nodesToRemove.length - 1; i >= 0; --i) {
rBush.remove(nodesToRemove[i]);
}
}
@@ -295,9 +295,9 @@ Snap.prototype.removeFeature = function(feature, opt_unlisten) {
* @inheritDoc
*/
Snap.prototype.setMap = function(map) {
var currentMap = this.getMap();
var keys = this.featuresListenerKeys_;
var features = this.getFeatures_();
const currentMap = this.getMap();
const keys = this.featuresListenerKeys_;
const features = this.getFeatures_();
if (currentMap) {
keys.forEach(_ol_events_.unlistenByKey);
@@ -309,17 +309,17 @@ Snap.prototype.setMap = function(map) {
if (map) {
if (this.features_) {
keys.push(
_ol_events_.listen(this.features_, CollectionEventType.ADD,
this.handleFeatureAdd_, this),
_ol_events_.listen(this.features_, CollectionEventType.REMOVE,
this.handleFeatureRemove_, this)
_ol_events_.listen(this.features_, CollectionEventType.ADD,
this.handleFeatureAdd_, this),
_ol_events_.listen(this.features_, CollectionEventType.REMOVE,
this.handleFeatureRemove_, this)
);
} else if (this.source_) {
keys.push(
_ol_events_.listen(this.source_, VectorEventType.ADDFEATURE,
this.handleFeatureAdd_, this),
_ol_events_.listen(this.source_, VectorEventType.REMOVEFEATURE,
this.handleFeatureRemove_, this)
_ol_events_.listen(this.source_, VectorEventType.ADDFEATURE,
this.handleFeatureAdd_, this),
_ol_events_.listen(this.source_, VectorEventType.REMOVEFEATURE,
this.handleFeatureRemove_, this)
);
}
features.forEach(this.forEachFeatureAdd_.bind(this));
@@ -341,13 +341,13 @@ Snap.prototype.shouldStopEvent = FALSE;
*/
Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
var lowerLeft = map.getCoordinateFromPixel(
[pixel[0] - this.pixelTolerance_, pixel[1] + this.pixelTolerance_]);
var upperRight = map.getCoordinateFromPixel(
[pixel[0] + this.pixelTolerance_, pixel[1] - this.pixelTolerance_]);
var box = boundingExtent([lowerLeft, upperRight]);
const lowerLeft = map.getCoordinateFromPixel(
[pixel[0] - this.pixelTolerance_, pixel[1] + this.pixelTolerance_]);
const upperRight = map.getCoordinateFromPixel(
[pixel[0] + this.pixelTolerance_, pixel[1] - this.pixelTolerance_]);
const box = boundingExtent([lowerLeft, upperRight]);
var segments = this.rBush_.getInExtent(box);
let segments = this.rBush_.getInExtent(box);
// If snapping on vertices only, don't consider circles
if (this.vertex_ && !this.edge_) {
@@ -357,16 +357,16 @@ Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
});
}
var snappedToVertex = false;
var snapped = false;
var vertex = null;
var vertexPixel = null;
var dist, pixel1, pixel2, squaredDist1, squaredDist2;
let snappedToVertex = false;
let snapped = false;
let vertex = null;
let vertexPixel = null;
let dist, pixel1, pixel2, squaredDist1, squaredDist2;
if (segments.length > 0) {
this.pixelCoordinate_ = pixelCoordinate;
segments.sort(this.sortByDistance_);
var closestSegment = segments[0].segment;
var isCircle = segments[0].feature.getGeometry().getType() ===
const closestSegment = segments[0].segment;
const isCircle = segments[0].feature.getGeometry().getType() ===
GeometryType.CIRCLE;
if (this.vertex_ && !this.edge_) {
pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
@@ -384,10 +384,10 @@ Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
} else if (this.edge_) {
if (isCircle) {
vertex = _ol_coordinate_.closestOnCircle(pixelCoordinate,
/** @type {ol.geom.Circle} */ (segments[0].feature.getGeometry()));
/** @type {ol.geom.Circle} */ (segments[0].feature.getGeometry()));
} else {
vertex = (_ol_coordinate_.closestOnSegment(pixelCoordinate,
closestSegment));
closestSegment));
}
vertexPixel = map.getPixelFromCoordinate(vertex);
if (_ol_coordinate_.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
@@ -435,9 +435,9 @@ Snap.prototype.updateFeature_ = function(feature) {
* @private
*/
Snap.prototype.writeCircleGeometry_ = function(feature, geometry) {
var polygon = fromCircle(geometry);
var coordinates = polygon.getCoordinates()[0];
var i, ii, segment, segmentData;
const polygon = fromCircle(geometry);
const coordinates = polygon.getCoordinates()[0];
let i, ii, segment, segmentData;
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
segment = coordinates.slice(i, i + 2);
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
@@ -455,9 +455,9 @@ Snap.prototype.writeCircleGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
var i, geometries = geometry.getGeometriesArray();
for (i = 0; i < geometries.length; ++i) {
var segmentWriter = this.SEGMENT_WRITERS_[geometries[i].getType()];
const geometries = geometry.getGeometriesArray();
for (let i = 0; i < geometries.length; ++i) {
const segmentWriter = this.SEGMENT_WRITERS_[geometries[i].getType()];
if (segmentWriter) {
segmentWriter.call(this, feature, geometries[i]);
}
@@ -471,8 +471,8 @@ Snap.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) {
var coordinates = geometry.getCoordinates();
var i, ii, segment, segmentData;
const coordinates = geometry.getCoordinates();
let i, ii, segment, segmentData;
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
segment = coordinates.slice(i, i + 2);
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
@@ -490,8 +490,8 @@ Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
var lines = geometry.getCoordinates();
var coordinates, i, ii, j, jj, segment, segmentData;
const lines = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData;
for (j = 0, jj = lines.length; j < jj; ++j) {
coordinates = lines[j];
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
@@ -512,8 +512,8 @@ Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
var points = geometry.getCoordinates();
var coordinates, i, ii, segmentData;
const points = geometry.getCoordinates();
let coordinates, i, ii, segmentData;
for (i = 0, ii = points.length; i < ii; ++i) {
coordinates = points[i];
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
@@ -531,8 +531,8 @@ Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
var polygons = geometry.getCoordinates();
var coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
const polygons = geometry.getCoordinates();
let coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
for (k = 0, kk = polygons.length; k < kk; ++k) {
rings = polygons[k];
for (j = 0, jj = rings.length; j < jj; ++j) {
@@ -556,8 +556,8 @@ Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writePointGeometry_ = function(feature, geometry) {
var coordinates = geometry.getCoordinates();
var segmentData = /** @type {ol.SnapSegmentDataType} */ ({
const coordinates = geometry.getCoordinates();
const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature,
segment: [coordinates, coordinates]
});
@@ -571,8 +571,8 @@ Snap.prototype.writePointGeometry_ = function(feature, geometry) {
* @private
*/
Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
var rings = geometry.getCoordinates();
var coordinates, i, ii, j, jj, segment, segmentData;
const rings = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData;
for (j = 0, jj = rings.length; j < jj; ++j) {
coordinates = rings[j];
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
@@ -595,7 +595,7 @@ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
* @private
*/
Snap.handleEvent_ = function(evt) {
var result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
if (result.snapped) {
evt.coordinate = result.vertex.slice(0, 2);
evt.pixel = result.vertexPixel;
@@ -611,7 +611,7 @@ Snap.handleEvent_ = function(evt) {
* @private
*/
Snap.handleUpEvent_ = function(evt) {
var featuresToUpdate = _ol_obj_.getValues(this.pendingFeatures_);
const featuresToUpdate = _ol_obj_.getValues(this.pendingFeatures_);
if (featuresToUpdate.length) {
featuresToUpdate.forEach(this.updateFeature_.bind(this));
this.pendingFeatures_ = {};
@@ -629,8 +629,8 @@ Snap.handleUpEvent_ = function(evt) {
*/
Snap.sortByDistance = function(a, b) {
return _ol_coordinate_.squaredDistanceToSegment(
this.pixelCoordinate_, a.segment) -
this.pixelCoordinate_, a.segment) -
_ol_coordinate_.squaredDistanceToSegment(
this.pixelCoordinate_, b.segment);
this.pixelCoordinate_, b.segment);
};
export default Snap;
+35 -35
View File
@@ -22,7 +22,7 @@ import TranslateEventType from '../interaction/TranslateEventType.js';
* @param {olx.interaction.TranslateOptions=} opt_options Options.
* @api
*/
var _ol_interaction_Translate_ = function(opt_options) {
const _ol_interaction_Translate_ = function(opt_options) {
PointerInteraction.call(this, {
handleDownEvent: _ol_interaction_Translate_.handleDownEvent_,
handleDragEvent: _ol_interaction_Translate_.handleDragEvent_,
@@ -30,7 +30,7 @@ var _ol_interaction_Translate_ = function(opt_options) {
handleUpEvent: _ol_interaction_Translate_.handleUpEvent_
});
var options = opt_options ? opt_options : {};
const options = opt_options ? opt_options : {};
/**
* The last position we translated to.
@@ -47,12 +47,12 @@ var _ol_interaction_Translate_ = function(opt_options) {
this.features_ = options.features !== undefined ? options.features : null;
/** @type {function(ol.layer.Layer): boolean} */
var layerFilter;
let layerFilter;
if (options.layers) {
if (typeof options.layers === 'function') {
layerFilter = options.layers;
} else {
var layers = options.layers;
const layers = options.layers;
layerFilter = function(layer) {
return includes(layers, layer);
};
@@ -80,8 +80,8 @@ var _ol_interaction_Translate_ = function(opt_options) {
this.lastFeature_ = null;
_ol_events_.listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
this.handleActiveChanged_, this);
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
this.handleActiveChanged_, this);
};
@@ -100,12 +100,12 @@ _ol_interaction_Translate_.handleDownEvent_ = function(event) {
this.lastCoordinate_ = event.coordinate;
_ol_interaction_Translate_.handleMoveEvent_.call(this, event);
var features = this.features_ || new Collection([this.lastFeature_]);
const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent(
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATESTART, features,
event.coordinate));
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATESTART, features,
event.coordinate));
return true;
}
return false;
@@ -123,12 +123,12 @@ _ol_interaction_Translate_.handleUpEvent_ = function(event) {
this.lastCoordinate_ = null;
_ol_interaction_Translate_.handleMoveEvent_.call(this, event);
var features = this.features_ || new Collection([this.lastFeature_]);
const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent(
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATEEND, features,
event.coordinate));
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATEEND, features,
event.coordinate));
return true;
}
return false;
@@ -142,23 +142,23 @@ _ol_interaction_Translate_.handleUpEvent_ = function(event) {
*/
_ol_interaction_Translate_.handleDragEvent_ = function(event) {
if (this.lastCoordinate_) {
var newCoordinate = event.coordinate;
var deltaX = newCoordinate[0] - this.lastCoordinate_[0];
var deltaY = newCoordinate[1] - this.lastCoordinate_[1];
const newCoordinate = event.coordinate;
const deltaX = newCoordinate[0] - this.lastCoordinate_[0];
const deltaY = newCoordinate[1] - this.lastCoordinate_[1];
var features = this.features_ || new Collection([this.lastFeature_]);
const features = this.features_ || new Collection([this.lastFeature_]);
features.forEach(function(feature) {
var geom = feature.getGeometry();
const geom = feature.getGeometry();
geom.translate(deltaX, deltaY);
feature.setGeometry(geom);
});
this.lastCoordinate_ = newCoordinate;
this.dispatchEvent(
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATING, features,
newCoordinate));
new _ol_interaction_Translate_.Event(
TranslateEventType.TRANSLATING, features,
newCoordinate));
}
};
@@ -169,7 +169,7 @@ _ol_interaction_Translate_.handleDragEvent_ = function(event) {
* @private
*/
_ol_interaction_Translate_.handleMoveEvent_ = function(event) {
var elem = event.map.getViewport();
const elem = event.map.getViewport();
// Change the cursor to grab/grabbing if hovering any of the features managed
// by the interaction
@@ -193,14 +193,14 @@ _ol_interaction_Translate_.handleMoveEvent_ = function(event) {
*/
_ol_interaction_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_
});
function(feature) {
if (!this.features_ || includes(this.features_.getArray(), feature)) {
return feature;
}
}.bind(this), {
layerFilter: this.layerFilter_,
hitTolerance: this.hitTolerance_
});
};
@@ -230,7 +230,7 @@ _ol_interaction_Translate_.prototype.setHitTolerance = function(hitTolerance) {
* @inheritDoc
*/
_ol_interaction_Translate_.prototype.setMap = function(map) {
var oldMap = this.getMap();
const oldMap = this.getMap();
PointerInteraction.prototype.setMap.call(this, map);
this.updateState_(oldMap);
};
@@ -249,12 +249,12 @@ _ol_interaction_Translate_.prototype.handleActiveChanged_ = function() {
* @private
*/
_ol_interaction_Translate_.prototype.updateState_ = function(oldMap) {
var map = this.getMap();
var active = this.getActive();
let map = this.getMap();
const active = this.getActive();
if (!map || !active) {
map = map || oldMap;
if (map) {
var elem = map.getViewport();
const elem = map.getViewport();
elem.classList.remove('ol-grab', 'ol-grabbing');
}
}