Merge pull request #7817 from tschaub/unstatic-private

Remove more private static members
This commit is contained in:
Tim Schaub
2018-02-12 07:40:06 -07:00
committed by GitHub
30 changed files with 747 additions and 776 deletions
+4 -5
View File
@@ -76,10 +76,9 @@ inherits(BaseObject, Observable);
/** /**
* @private
* @type {Object.<string, string>} * @type {Object.<string, string>}
*/ */
BaseObject.changeEventTypeCache_ = {}; const changeEventTypeCache = {};
/** /**
@@ -87,9 +86,9 @@ BaseObject.changeEventTypeCache_ = {};
* @return {string} Change name. * @return {string} Change name.
*/ */
BaseObject.getChangeEventType = function(key) { BaseObject.getChangeEventType = function(key) {
return BaseObject.changeEventTypeCache_.hasOwnProperty(key) ? return changeEventTypeCache.hasOwnProperty(key) ?
BaseObject.changeEventTypeCache_[key] : changeEventTypeCache[key] :
(BaseObject.changeEventTypeCache_[key] = 'change:' + key); (changeEventTypeCache[key] = 'change:' + key);
}; };
+9 -12
View File
@@ -138,7 +138,7 @@ View.prototype.applyOptions_ = function(options) {
properties[ViewProperty.CENTER] = options.center !== undefined ? properties[ViewProperty.CENTER] = options.center !== undefined ?
options.center : null; options.center : null;
const resolutionConstraintInfo = View.createResolutionConstraint_( const resolutionConstraintInfo = createResolutionConstraint(
options); options);
/** /**
@@ -171,9 +171,9 @@ View.prototype.applyOptions_ = function(options) {
*/ */
this.minZoom_ = resolutionConstraintInfo.minZoom; this.minZoom_ = resolutionConstraintInfo.minZoom;
const centerConstraint = View.createCenterConstraint_(options); const centerConstraint = createCenterConstraint(options);
const resolutionConstraint = resolutionConstraintInfo.constraint; const resolutionConstraint = resolutionConstraintInfo.constraint;
const rotationConstraint = View.createRotationConstraint_(options); const rotationConstraint = createRotationConstraint(options);
/** /**
* @private * @private
@@ -1088,25 +1088,23 @@ View.prototype.setZoom = function(zoom) {
/** /**
* @param {olx.ViewOptions} options View options. * @param {olx.ViewOptions} options View options.
* @private
* @return {ol.CenterConstraintType} The constraint. * @return {ol.CenterConstraintType} The constraint.
*/ */
View.createCenterConstraint_ = function(options) { export function createCenterConstraint(options) {
if (options.extent !== undefined) { if (options.extent !== undefined) {
return CenterConstraint.createExtent(options.extent); return CenterConstraint.createExtent(options.extent);
} else { } else {
return CenterConstraint.none; return CenterConstraint.none;
} }
}; }
/** /**
* @private
* @param {olx.ViewOptions} options View options. * @param {olx.ViewOptions} options View options.
* @return {{constraint: ol.ResolutionConstraintType, maxResolution: number, * @return {{constraint: ol.ResolutionConstraintType, maxResolution: number,
* minResolution: number, zoomFactor: number}} The constraint. * minResolution: number, zoomFactor: number}} The constraint.
*/ */
View.createResolutionConstraint_ = function(options) { export function createResolutionConstraint(options) {
let resolutionConstraint; let resolutionConstraint;
let maxResolution; let maxResolution;
let minResolution; let minResolution;
@@ -1180,15 +1178,14 @@ View.createResolutionConstraint_ = function(options) {
} }
return {constraint: resolutionConstraint, maxResolution: maxResolution, return {constraint: resolutionConstraint, maxResolution: maxResolution,
minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor}; minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor};
}; }
/** /**
* @private
* @param {olx.ViewOptions} options View options. * @param {olx.ViewOptions} options View options.
* @return {ol.RotationConstraintType} Rotation constraint. * @return {ol.RotationConstraintType} Rotation constraint.
*/ */
View.createRotationConstraint_ = function(options) { export function createRotationConstraint(options) {
const enableRotation = options.enableRotation !== undefined ? const enableRotation = options.enableRotation !== undefined ?
options.enableRotation : true; options.enableRotation : true;
if (enableRotation) { if (enableRotation) {
@@ -1205,7 +1202,7 @@ View.createRotationConstraint_ = function(options) {
} else { } else {
return RotationConstraint.disable; return RotationConstraint.disable;
} }
}; }
/** /**
+24 -26
View File
@@ -11,6 +11,20 @@ import EventType from '../events/EventType.js';
import Interaction from '../interaction/Interaction.js'; import Interaction from '../interaction/Interaction.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
/**
* @enum {string}
*/
const DragAndDropEventType = {
/**
* Triggered when features are added
* @event ol.interaction.DragAndDrop.Event#addfeatures
* @api
*/
ADD_FEATURES: 'addfeatures'
};
/** /**
* @classdesc * @classdesc
* Handles input of vector data by drag and drop. * Handles input of vector data by drag and drop.
@@ -69,9 +83,8 @@ inherits(DragAndDrop, Interaction);
/** /**
* @param {Event} event Event. * @param {Event} event Event.
* @this {ol.interaction.DragAndDrop} * @this {ol.interaction.DragAndDrop}
* @private
*/ */
DragAndDrop.handleDrop_ = function(event) { function handleDrop(event) {
const files = event.dataTransfer.files; const files = event.dataTransfer.files;
let i, ii, file; let i, ii, file;
for (i = 0, ii = files.length; i < ii; ++i) { for (i = 0, ii = files.length; i < ii; ++i) {
@@ -81,18 +94,17 @@ DragAndDrop.handleDrop_ = function(event) {
this.handleResult_.bind(this, file)); this.handleResult_.bind(this, file));
reader.readAsText(file); reader.readAsText(file);
} }
}; }
/** /**
* @param {Event} event Event. * @param {Event} event Event.
* @private
*/ */
DragAndDrop.handleStop_ = function(event) { function handleStop(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
event.dataTransfer.dropEffect = 'copy'; event.dataTransfer.dropEffect = 'copy';
}; }
/** /**
@@ -135,7 +147,7 @@ DragAndDrop.prototype.handleResult_ = function(file, event) {
} }
this.dispatchEvent( this.dispatchEvent(
new DragAndDrop.Event( new DragAndDrop.Event(
DragAndDrop.EventType_.ADD_FEATURES, file, DragAndDropEventType.ADD_FEATURES, file,
features, projection)); features, projection));
}; };
@@ -160,13 +172,13 @@ DragAndDrop.prototype.registerListeners_ = function() {
const dropArea = this.target ? this.target : map.getViewport(); const dropArea = this.target ? this.target : map.getViewport();
this.dropListenKeys_ = [ this.dropListenKeys_ = [
listen(dropArea, EventType.DROP, listen(dropArea, EventType.DROP,
DragAndDrop.handleDrop_, this), handleDrop, this),
listen(dropArea, EventType.DRAGENTER, listen(dropArea, EventType.DRAGENTER,
DragAndDrop.handleStop_, this), handleStop, this),
listen(dropArea, EventType.DRAGOVER, listen(dropArea, EventType.DRAGOVER,
DragAndDrop.handleStop_, this), handleStop, this),
listen(dropArea, EventType.DROP, listen(dropArea, EventType.DROP,
DragAndDrop.handleStop_, this) handleStop, this)
]; ];
} }
}; };
@@ -224,20 +236,6 @@ DragAndDrop.prototype.unregisterListeners_ = function() {
}; };
/**
* @enum {string}
* @private
*/
DragAndDrop.EventType_ = {
/**
* Triggered when features are added
* @event ol.interaction.DragAndDrop.Event#addfeatures
* @api
*/
ADD_FEATURES: 'addfeatures'
};
/** /**
* @classdesc * @classdesc
* Events emitted by {@link ol.interaction.DragAndDrop} instances are instances * Events emitted by {@link ol.interaction.DragAndDrop} instances are instances
@@ -246,7 +244,7 @@ DragAndDrop.EventType_ = {
* @constructor * @constructor
* @extends {ol.events.Event} * @extends {ol.events.Event}
* @implements {oli.interaction.DragAndDropEvent} * @implements {oli.interaction.DragAndDropEvent}
* @param {ol.interaction.DragAndDrop.EventType_} type Type. * @param {ol.interaction.DragAndDropEventType} type Type.
* @param {File} file File. * @param {File} file File.
* @param {Array.<ol.Feature>=} opt_features Features. * @param {Array.<ol.Feature>=} opt_features Features.
* @param {ol.proj.Projection=} opt_projection Projection. * @param {ol.proj.Projection=} opt_projection Projection.
+40 -43
View File
@@ -8,6 +8,34 @@ import {always, mouseOnly, mouseActionButton} from '../events/condition.js';
import PointerInteraction from '../interaction/Pointer.js'; import PointerInteraction from '../interaction/Pointer.js';
import RenderBox from '../render/Box.js'; import RenderBox from '../render/Box.js';
/**
* @enum {string}
*/
const DragBoxEventType = {
/**
* Triggered upon drag box start.
* @event ol.interaction.DragBox.Event#boxstart
* @api
*/
BOXSTART: 'boxstart',
/**
* Triggered on drag when box is active.
* @event ol.interaction.DragBox.Event#boxdrag
* @api
*/
BOXDRAG: 'boxdrag',
/**
* Triggered upon drag box end.
* @event ol.interaction.DragBox.Event#boxend
* @api
*/
BOXEND: 'boxend'
};
/** /**
* @classdesc * @classdesc
* Allows the user to draw a vector box by clicking and dragging on the map, * Allows the user to draw a vector box by clicking and dragging on the map,
@@ -28,9 +56,9 @@ import RenderBox from '../render/Box.js';
const DragBox = function(opt_options) { const DragBox = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: DragBox.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: DragBox.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: DragBox.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -90,18 +118,17 @@ DragBox.defaultBoxEndCondition = function(mapBrowserEvent, startPixel, endPixel)
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.DragBox} * @this {ol.interaction.DragBox}
* @private
*/ */
DragBox.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return; return;
} }
this.box_.setPixels(this.startPixel_, mapBrowserEvent.pixel); this.box_.setPixels(this.startPixel_, mapBrowserEvent.pixel);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXDRAG, this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXDRAG,
mapBrowserEvent.coordinate, mapBrowserEvent)); mapBrowserEvent.coordinate, mapBrowserEvent));
}; }
/** /**
@@ -127,9 +154,8 @@ DragBox.prototype.onBoxEnd = nullFunction;
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.DragBox} * @this {ol.interaction.DragBox}
* @private
*/ */
DragBox.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return true; return true;
} }
@@ -139,20 +165,19 @@ DragBox.handleUpEvent_ = function(mapBrowserEvent) {
if (this.boxEndCondition_(mapBrowserEvent, if (this.boxEndCondition_(mapBrowserEvent,
this.startPixel_, mapBrowserEvent.pixel)) { this.startPixel_, mapBrowserEvent.pixel)) {
this.onBoxEnd(mapBrowserEvent); this.onBoxEnd(mapBrowserEvent);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXEND, this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXEND,
mapBrowserEvent.coordinate, mapBrowserEvent)); mapBrowserEvent.coordinate, mapBrowserEvent));
} }
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.DragBox} * @this {ol.interaction.DragBox}
* @private
*/ */
DragBox.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return false; return false;
} }
@@ -162,41 +187,13 @@ DragBox.handleDownEvent_ = function(mapBrowserEvent) {
this.startPixel_ = mapBrowserEvent.pixel; this.startPixel_ = mapBrowserEvent.pixel;
this.box_.setMap(mapBrowserEvent.map); this.box_.setMap(mapBrowserEvent.map);
this.box_.setPixels(this.startPixel_, this.startPixel_); this.box_.setPixels(this.startPixel_, this.startPixel_);
this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXSTART, this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXSTART,
mapBrowserEvent.coordinate, mapBrowserEvent)); mapBrowserEvent.coordinate, mapBrowserEvent));
return true; return true;
} else { } else {
return false; return false;
} }
}; }
/**
* @enum {string}
* @private
*/
DragBox.EventType_ = {
/**
* Triggered upon drag box start.
* @event ol.interaction.DragBox.Event#boxstart
* @api
*/
BOXSTART: 'boxstart',
/**
* Triggered on drag when box is active.
* @event ol.interaction.DragBox.Event#boxdrag
* @api
*/
BOXDRAG: 'boxdrag',
/**
* Triggered upon drag box end.
* @event ol.interaction.DragBox.Event#boxend
* @api
*/
BOXEND: 'boxend'
};
/** /**
+9 -12
View File
@@ -21,9 +21,9 @@ import PointerInteraction from '../interaction/Pointer.js';
const DragPan = function(opt_options) { const DragPan = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: DragPan.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: DragPan.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: DragPan.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -64,9 +64,8 @@ inherits(DragPan, PointerInteraction);
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.DragPan} * @this {ol.interaction.DragPan}
* @private
*/ */
DragPan.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
const targetPointers = this.targetPointers; const targetPointers = this.targetPointers;
const centroid = const centroid =
PointerInteraction.centroid(targetPointers); PointerInteraction.centroid(targetPointers);
@@ -94,16 +93,15 @@ DragPan.handleDragEvent_ = function(mapBrowserEvent) {
} }
this.lastCentroid = centroid; this.lastCentroid = centroid;
this.lastPointersCount_ = targetPointers.length; this.lastPointersCount_ = targetPointers.length;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.DragPan} * @this {ol.interaction.DragPan}
* @private
*/ */
DragPan.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
if (this.targetPointers.length === 0) { if (this.targetPointers.length === 0) {
@@ -133,16 +131,15 @@ DragPan.handleUpEvent_ = function(mapBrowserEvent) {
this.lastCentroid = null; this.lastCentroid = null;
return true; return true;
} }
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.DragPan} * @this {ol.interaction.DragPan}
* @private
*/ */
DragPan.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (this.targetPointers.length > 0 && this.condition_(mapBrowserEvent)) { if (this.targetPointers.length > 0 && this.condition_(mapBrowserEvent)) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
@@ -164,7 +161,7 @@ DragPan.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
return false; return false;
} }
}; }
/** /**
+9 -12
View File
@@ -27,9 +27,9 @@ const DragRotate = function(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: DragRotate.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: DragRotate.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: DragRotate.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
/** /**
@@ -57,9 +57,8 @@ inherits(DragRotate, PointerInteraction);
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.DragRotate} * @this {ol.interaction.DragRotate}
* @private
*/ */
DragRotate.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return; return;
} }
@@ -80,16 +79,15 @@ DragRotate.handleDragEvent_ = function(mapBrowserEvent) {
view, rotation - delta); view, rotation - delta);
} }
this.lastAngle_ = theta; this.lastAngle_ = theta;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.DragRotate} * @this {ol.interaction.DragRotate}
* @private
*/ */
DragRotate.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return true; return true;
} }
@@ -101,16 +99,15 @@ DragRotate.handleUpEvent_ = function(mapBrowserEvent) {
Interaction.rotate(view, rotation, Interaction.rotate(view, rotation,
undefined, this.duration_); undefined, this.duration_);
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.DragRotate} * @this {ol.interaction.DragRotate}
* @private
*/ */
DragRotate.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return false; return false;
} }
@@ -123,7 +120,7 @@ DragRotate.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
return false; return false;
} }
}; }
/** /**
+10 -12
View File
@@ -28,9 +28,9 @@ const DragRotateAndZoom = function(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: DragRotateAndZoom.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: DragRotateAndZoom.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: DragRotateAndZoom.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
/** /**
@@ -71,9 +71,8 @@ inherits(DragRotateAndZoom, PointerInteraction);
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.DragRotateAndZoom} * @this {ol.interaction.DragRotateAndZoom}
* @private
*/ */
DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return; return;
} }
@@ -100,16 +99,15 @@ DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) {
this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
} }
this.lastMagnitude_ = magnitude; this.lastMagnitude_ = magnitude;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.DragRotateAndZoom} * @this {ol.interaction.DragRotateAndZoom}
* @private
*/ */
DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return true; return true;
} }
@@ -123,16 +121,15 @@ DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) {
undefined, this.duration_, direction); undefined, this.duration_, direction);
this.lastScaleDelta_ = 0; this.lastScaleDelta_ = 0;
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.DragRotateAndZoom} * @this {ol.interaction.DragRotateAndZoom}
* @private
*/ */
DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (!mouseOnly(mapBrowserEvent)) { if (!mouseOnly(mapBrowserEvent)) {
return false; return false;
} }
@@ -145,5 +142,6 @@ DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
return false; return false;
} }
}; }
export default DragRotateAndZoom; export default DragRotateAndZoom;
+54 -56
View File
@@ -29,6 +29,20 @@ import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/Vector.js'; import VectorSource from '../source/Vector.js';
import Style from '../style/Style.js'; import Style from '../style/Style.js';
/**
* Draw mode. This collapses multi-part geometry types with their single-part
* cousins.
* @enum {string}
*/
const Mode = {
POINT: 'Point',
LINE_STRING: 'LineString',
POLYGON: 'Polygon',
CIRCLE: 'Circle'
};
/** /**
* @classdesc * @classdesc
* Interaction for drawing feature geometries. * Interaction for drawing feature geometries.
@@ -42,9 +56,9 @@ import Style from '../style/Style.js';
const Draw = function(options) { const Draw = function(options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: Draw.handleDownEvent_, handleDownEvent: handleDownEvent,
handleEvent: Draw.handleEvent, handleEvent: handleEvent,
handleUpEvent: Draw.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
/** /**
@@ -107,10 +121,10 @@ const Draw = function(options) {
/** /**
* Drawing mode (derived from geometry type. * Drawing mode (derived from geometry type.
* @type {ol.interaction.Draw.Mode_} * @type {ol.interaction.Mode}
* @private * @private
*/ */
this.mode_ = Draw.getMode_(this.type_); this.mode_ = getMode(this.type_);
/** /**
* Stop click, singleclick, and doubleclick events from firing during drawing. * Stop click, singleclick, and doubleclick events from firing during drawing.
@@ -129,7 +143,7 @@ const Draw = function(options) {
*/ */
this.minPoints_ = options.minPoints ? this.minPoints_ = options.minPoints ?
options.minPoints : options.minPoints :
(this.mode_ === Draw.Mode_.POLYGON ? 3 : 2); (this.mode_ === Mode.POLYGON ? 3 : 2);
/** /**
* The number of points that can be drawn before a polygon ring or line string * The number of points that can be drawn before a polygon ring or line string
@@ -166,11 +180,11 @@ const Draw = function(options) {
} else { } else {
let Constructor; let Constructor;
const mode = this.mode_; const mode = this.mode_;
if (mode === Draw.Mode_.POINT) { if (mode === Mode.POINT) {
Constructor = Point; Constructor = Point;
} else if (mode === Draw.Mode_.LINE_STRING) { } else if (mode === Mode.LINE_STRING) {
Constructor = LineString; Constructor = LineString;
} else if (mode === Draw.Mode_.POLYGON) { } else if (mode === Mode.POLYGON) {
Constructor = Polygon; Constructor = Polygon;
} }
/** /**
@@ -182,7 +196,7 @@ const Draw = function(options) {
geometryFunction = function(coordinates, opt_geometry) { geometryFunction = function(coordinates, opt_geometry) {
let geometry = opt_geometry; let geometry = opt_geometry;
if (geometry) { if (geometry) {
if (mode === Draw.Mode_.POLYGON) { if (mode === Mode.POLYGON) {
if (coordinates[0].length) { if (coordinates[0].length) {
// Add a closing coordinate to match the first // Add a closing coordinate to match the first
geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]); geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
@@ -342,12 +356,12 @@ Draw.prototype.setMap = function(map) {
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @api * @api
*/ */
Draw.handleEvent = function(event) { export function handleEvent(event) {
if (event.originalEvent.type === EventType.CONTEXTMENU) { if (event.originalEvent.type === EventType.CONTEXTMENU) {
// Avoid context menu for long taps when drawing on mobile // Avoid context menu for long taps when drawing on mobile
event.preventDefault(); event.preventDefault();
} }
this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event); this.freehand_ = this.mode_ !== Mode.POINT && this.freehandCondition_(event);
let move = event.type === MapBrowserEventType.POINTERMOVE; let move = event.type === MapBrowserEventType.POINTERMOVE;
let pass = true; let pass = true;
if (this.lastDragTime_ && event.type === MapBrowserEventType.POINTERDRAG) { if (this.lastDragTime_ && event.type === MapBrowserEventType.POINTERDRAG) {
@@ -385,16 +399,15 @@ Draw.handleEvent = function(event) {
} }
return PointerInteraction.handleEvent.call(this, event) && pass; return PointerInteraction.handleEvent.call(this, event) && pass;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {ol.MapBrowserPointerEvent} event Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @private
*/ */
Draw.handleDownEvent_ = function(event) { function handleDownEvent(event) {
this.shouldHandle_ = !this.freehand_; this.shouldHandle_ = !this.freehand_;
if (this.freehand_) { if (this.freehand_) {
@@ -414,16 +427,15 @@ Draw.handleDownEvent_ = function(event) {
} else { } else {
return false; return false;
} }
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {ol.MapBrowserPointerEvent} event Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @private
*/ */
Draw.handleUpEvent_ = function(event) { function handleUpEvent(event) {
let pass = true; let pass = true;
if (this.downTimeout_) { if (this.downTimeout_) {
@@ -433,12 +445,12 @@ Draw.handleUpEvent_ = function(event) {
this.handlePointerMove_(event); this.handlePointerMove_(event);
const circleMode = this.mode_ === Draw.Mode_.CIRCLE; const circleMode = this.mode_ === Mode.CIRCLE;
if (this.shouldHandle_) { if (this.shouldHandle_) {
if (!this.finishCoordinate_) { if (!this.finishCoordinate_) {
this.startDrawing_(event); this.startDrawing_(event);
if (this.mode_ === Draw.Mode_.POINT) { if (this.mode_ === Mode.POINT) {
this.finishDrawing(); this.finishDrawing();
} }
} else if (this.freehand_ || circleMode) { } else if (this.freehand_ || circleMode) {
@@ -459,7 +471,7 @@ Draw.handleUpEvent_ = function(event) {
event.stopPropagation(); event.stopPropagation();
} }
return pass; return pass;
}; }
/** /**
@@ -505,9 +517,9 @@ Draw.prototype.atFinish_ = function(event) {
if (this.sketchFeature_) { if (this.sketchFeature_) {
let potentiallyDone = false; let potentiallyDone = false;
let potentiallyFinishCoordinates = [this.finishCoordinate_]; let potentiallyFinishCoordinates = [this.finishCoordinate_];
if (this.mode_ === Draw.Mode_.LINE_STRING) { if (this.mode_ === Mode.LINE_STRING) {
potentiallyDone = this.sketchCoords_.length > this.minPoints_; potentiallyDone = this.sketchCoords_.length > this.minPoints_;
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
potentiallyDone = this.sketchCoords_[0].length > potentiallyDone = this.sketchCoords_[0].length >
this.minPoints_; this.minPoints_;
potentiallyFinishCoordinates = [this.sketchCoords_[0][0], potentiallyFinishCoordinates = [this.sketchCoords_[0][0],
@@ -558,9 +570,9 @@ Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
Draw.prototype.startDrawing_ = function(event) { Draw.prototype.startDrawing_ = function(event) {
const start = event.coordinate; const start = event.coordinate;
this.finishCoordinate_ = start; this.finishCoordinate_ = start;
if (this.mode_ === Draw.Mode_.POINT) { if (this.mode_ === Mode.POINT) {
this.sketchCoords_ = start.slice(); this.sketchCoords_ = start.slice();
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
this.sketchCoords_ = [[start.slice(), start.slice()]]; this.sketchCoords_ = [[start.slice(), start.slice()]];
this.sketchLineCoords_ = this.sketchCoords_[0]; this.sketchLineCoords_ = this.sketchCoords_[0];
} else { } else {
@@ -590,9 +602,9 @@ Draw.prototype.modifyDrawing_ = function(event) {
let coordinate = event.coordinate; let coordinate = event.coordinate;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let coordinates, last; let coordinates, last;
if (this.mode_ === Draw.Mode_.POINT) { if (this.mode_ === Mode.POINT) {
last = this.sketchCoords_; last = this.sketchCoords_;
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
last = coordinates[coordinates.length - 1]; last = coordinates[coordinates.length - 1];
if (this.atFinish_(event)) { if (this.atFinish_(event)) {
@@ -612,7 +624,7 @@ Draw.prototype.modifyDrawing_ = function(event) {
} }
let sketchLineGeom; let sketchLineGeom;
if (geometry instanceof Polygon && if (geometry instanceof Polygon &&
this.mode_ !== Draw.Mode_.POLYGON) { this.mode_ !== Mode.POLYGON) {
if (!this.sketchLine_) { if (!this.sketchLine_) {
this.sketchLine_ = new Feature(new LineString(null)); this.sketchLine_ = new Feature(new LineString(null));
} }
@@ -638,7 +650,7 @@ Draw.prototype.addToDrawing_ = function(event) {
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let done; let done;
let coordinates; let coordinates;
if (this.mode_ === Draw.Mode_.LINE_STRING) { if (this.mode_ === Mode.LINE_STRING) {
this.finishCoordinate_ = coordinate.slice(); this.finishCoordinate_ = coordinate.slice();
coordinates = this.sketchCoords_; coordinates = this.sketchCoords_;
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
@@ -650,7 +662,7 @@ Draw.prototype.addToDrawing_ = function(event) {
} }
coordinates.push(coordinate.slice()); coordinates.push(coordinate.slice());
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
if (this.freehand_) { if (this.freehand_) {
@@ -682,14 +694,14 @@ Draw.prototype.removeLastPoint = function() {
} }
const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
let coordinates, sketchLineGeom; let coordinates, sketchLineGeom;
if (this.mode_ === Draw.Mode_.LINE_STRING) { if (this.mode_ === Mode.LINE_STRING) {
coordinates = this.sketchCoords_; coordinates = this.sketchCoords_;
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
if (coordinates.length >= 2) { if (coordinates.length >= 2) {
this.finishCoordinate_ = coordinates[coordinates.length - 2].slice(); this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
} }
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry()); sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
@@ -718,11 +730,11 @@ Draw.prototype.finishDrawing = function() {
} }
let coordinates = this.sketchCoords_; let coordinates = this.sketchCoords_;
const geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry()); const geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
if (this.mode_ === Draw.Mode_.LINE_STRING) { if (this.mode_ === Mode.LINE_STRING) {
// remove the redundant last point // remove the redundant last point
coordinates.pop(); coordinates.pop();
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
} else if (this.mode_ === Draw.Mode_.POLYGON) { } else if (this.mode_ === Mode.POLYGON) {
// remove the redundant last point in ring // remove the redundant last point in ring
coordinates[0].pop(); coordinates[0].pop();
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
@@ -899,40 +911,26 @@ Draw.createBox = function() {
* Get the drawing mode. The mode for mult-part geometries is the same as for * Get the drawing mode. The mode for mult-part geometries is the same as for
* their single-part cousins. * their single-part cousins.
* @param {ol.geom.GeometryType} type Geometry type. * @param {ol.geom.GeometryType} type Geometry type.
* @return {ol.interaction.Draw.Mode_} Drawing mode. * @return {ol.interaction.Mode} Drawing mode.
* @private
*/ */
Draw.getMode_ = function(type) { function getMode(type) {
let mode; let mode;
if (type === GeometryType.POINT || if (type === GeometryType.POINT ||
type === GeometryType.MULTI_POINT) { type === GeometryType.MULTI_POINT) {
mode = Draw.Mode_.POINT; mode = Mode.POINT;
} else if (type === GeometryType.LINE_STRING || } else if (type === GeometryType.LINE_STRING ||
type === GeometryType.MULTI_LINE_STRING) { type === GeometryType.MULTI_LINE_STRING) {
mode = Draw.Mode_.LINE_STRING; mode = Mode.LINE_STRING;
} else if (type === GeometryType.POLYGON || } else if (type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON) { type === GeometryType.MULTI_POLYGON) {
mode = Draw.Mode_.POLYGON; mode = Mode.POLYGON;
} else if (type === GeometryType.CIRCLE) { } else if (type === GeometryType.CIRCLE) {
mode = Draw.Mode_.CIRCLE; mode = Mode.CIRCLE;
} }
return /** @type {!ol.interaction.Draw.Mode_} */ (mode); return /** @type {!ol.interaction.Mode} */ (mode);
}; }
/**
* Draw mode. This collapses multi-part geometry types with their single-part
* cousins.
* @enum {string}
* @private
*/
Draw.Mode_ = {
POINT: 'Point',
LINE_STRING: 'LineString',
POLYGON: 'Polygon',
CIRCLE: 'Circle'
};
/** /**
* @classdesc * @classdesc
* Events emitted by {@link ol.interaction.Draw} instances are instances of * Events emitted by {@link ol.interaction.Draw} instances are instances of
+29 -38
View File
@@ -82,10 +82,10 @@ const ExtentInteraction = function(opt_options) {
/* Inherit ol.interaction.Pointer */ /* Inherit ol.interaction.Pointer */
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: ExtentInteraction.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: ExtentInteraction.handleDragEvent_, handleDragEvent: handleDragEvent,
handleEvent: ExtentInteraction.handleEvent_, handleEvent: handleEvent,
handleUpEvent: ExtentInteraction.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
/** /**
@@ -98,7 +98,7 @@ const ExtentInteraction = function(opt_options) {
useSpatialIndex: false, useSpatialIndex: false,
wrapX: !!opt_options.wrapX wrapX: !!opt_options.wrapX
}), }),
style: opt_options.boxStyle ? opt_options.boxStyle : ExtentInteraction.getDefaultExtentStyleFunction_(), style: opt_options.boxStyle ? opt_options.boxStyle : getDefaultExtentStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true updateWhileInteracting: true
}); });
@@ -113,7 +113,7 @@ const ExtentInteraction = function(opt_options) {
useSpatialIndex: false, useSpatialIndex: false,
wrapX: !!opt_options.wrapX wrapX: !!opt_options.wrapX
}), }),
style: opt_options.pointerStyle ? opt_options.pointerStyle : ExtentInteraction.getDefaultPointerStyleFunction_(), style: opt_options.pointerStyle ? opt_options.pointerStyle : getDefaultPointerStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true updateWhileInteracting: true
}); });
@@ -129,9 +129,8 @@ inherits(ExtentInteraction, PointerInteraction);
* @param {ol.MapBrowserEvent} mapBrowserEvent Event. * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
* @return {boolean} Propagate event? * @return {boolean} Propagate event?
* @this {ol.interaction.Extent} * @this {ol.interaction.Extent}
* @private
*/ */
ExtentInteraction.handleEvent_ = function(mapBrowserEvent) { function handleEvent(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) { if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
return true; return true;
} }
@@ -143,15 +142,14 @@ ExtentInteraction.handleEvent_ = function(mapBrowserEvent) {
PointerInteraction.handleEvent.call(this, mapBrowserEvent); PointerInteraction.handleEvent.call(this, mapBrowserEvent);
//return false to stop propagation //return false to stop propagation
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Event handled? * @return {boolean} Event handled?
* @this {ol.interaction.Extent} * @this {ol.interaction.Extent}
* @private
*/ */
ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
const pixel = mapBrowserEvent.pixel; const pixel = mapBrowserEvent.pixel;
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
@@ -183,15 +181,15 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
//snap to point //snap to point
if (x !== null && y !== null) { if (x !== null && y !== null) {
this.pointerHandler_ = ExtentInteraction.getPointHandler_(getOpposingPoint(vertex)); this.pointerHandler_ = getPointHandler(getOpposingPoint(vertex));
//snap to edge //snap to edge
} else if (x !== null) { } else if (x !== null) {
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_( this.pointerHandler_ = getEdgeHandler(
getOpposingPoint([x, extent[1]]), getOpposingPoint([x, extent[1]]),
getOpposingPoint([x, extent[3]]) getOpposingPoint([x, extent[3]])
); );
} else if (y !== null) { } else if (y !== null) {
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_( this.pointerHandler_ = getEdgeHandler(
getOpposingPoint([extent[0], y]), getOpposingPoint([extent[0], y]),
getOpposingPoint([extent[2], y]) getOpposingPoint([extent[2], y])
); );
@@ -200,33 +198,31 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
vertex = map.getCoordinateFromPixel(pixel); vertex = map.getCoordinateFromPixel(pixel);
this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]); this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]);
this.pointerHandler_ = ExtentInteraction.getPointHandler_(vertex); this.pointerHandler_ = getPointHandler(vertex);
} }
return true; //event handled; start downup sequence return true; //event handled; start downup sequence
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Event handled? * @return {boolean} Event handled?
* @this {ol.interaction.Extent} * @this {ol.interaction.Extent}
* @private
*/ */
ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
if (this.pointerHandler_) { if (this.pointerHandler_) {
const pixelCoordinate = mapBrowserEvent.coordinate; const pixelCoordinate = mapBrowserEvent.coordinate;
this.setExtent(this.pointerHandler_(pixelCoordinate)); this.setExtent(this.pointerHandler_(pixelCoordinate));
this.createOrUpdatePointerFeature_(pixelCoordinate); this.createOrUpdatePointerFeature_(pixelCoordinate);
} }
return true; return true;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Extent} * @this {ol.interaction.Extent}
* @private
*/ */
ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
this.pointerHandler_ = null; this.pointerHandler_ = null;
//If bbox is zero area, set to null; //If bbox is zero area, set to null;
const extent = this.getExtent(); const extent = this.getExtent();
@@ -234,52 +230,48 @@ ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
this.setExtent(null); this.setExtent(null);
} }
return false; //Stop handling downup sequence return false; //Stop handling downup sequence
}; }
/** /**
* Returns the default style for the drawn bbox * Returns the default style for the drawn bbox
* *
* @return {ol.StyleFunction} Default Extent style * @return {ol.StyleFunction} Default Extent style
* @private
*/ */
ExtentInteraction.getDefaultExtentStyleFunction_ = function() { function getDefaultExtentStyleFunction() {
const style = Style.createDefaultEditing(); const style = Style.createDefaultEditing();
return function(feature, resolution) { return function(feature, resolution) {
return style[GeometryType.POLYGON]; return style[GeometryType.POLYGON];
}; };
}; }
/** /**
* Returns the default style for the pointer * Returns the default style for the pointer
* *
* @return {ol.StyleFunction} Default pointer style * @return {ol.StyleFunction} Default pointer style
* @private
*/ */
ExtentInteraction.getDefaultPointerStyleFunction_ = function() { function getDefaultPointerStyleFunction() {
const style = Style.createDefaultEditing(); const style = Style.createDefaultEditing();
return function(feature, resolution) { return function(feature, resolution) {
return style[GeometryType.POINT]; return style[GeometryType.POINT];
}; };
}; }
/** /**
* @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent * @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent
* @returns {function (ol.Coordinate): ol.Extent} event handler * @returns {function (ol.Coordinate): ol.Extent} event handler
* @private
*/ */
ExtentInteraction.getPointHandler_ = function(fixedPoint) { function getPointHandler(fixedPoint) {
return function(point) { return function(point) {
return boundingExtent([fixedPoint, point]); return boundingExtent([fixedPoint, point]);
}; };
}; }
/** /**
* @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent * @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent
* @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent * @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent
* @returns {function (ol.Coordinate): ol.Extent|null} event handler * @returns {function (ol.Coordinate): ol.Extent|null} event handler
* @private
*/ */
ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) { function getEdgeHandler(fixedP1, fixedP2) {
if (fixedP1[0] == fixedP2[0]) { if (fixedP1[0] == fixedP2[0]) {
return function(point) { return function(point) {
return boundingExtent([fixedP1, [point[0], fixedP2[1]]]); return boundingExtent([fixedP1, [point[0], fixedP2[1]]]);
@@ -291,21 +283,20 @@ ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) {
} else { } else {
return null; return null;
} }
}; }
/** /**
* @param {ol.Extent} extent extent * @param {ol.Extent} extent extent
* @returns {Array<Array<ol.Coordinate>>} extent line segments * @returns {Array<Array<ol.Coordinate>>} extent line segments
* @private
*/ */
ExtentInteraction.getSegments_ = function(extent) { function getSegments(extent) {
return [ return [
[[extent[0], extent[1]], [extent[0], extent[3]]], [[extent[0], extent[1]], [extent[0], extent[3]]],
[[extent[0], extent[3]], [extent[2], extent[3]]], [[extent[0], extent[3]], [extent[2], extent[3]]],
[[extent[2], extent[3]], [extent[2], extent[1]]], [[extent[2], extent[3]], [extent[2], extent[1]]],
[[extent[2], extent[1]], [extent[0], extent[1]]] [[extent[2], extent[1]], [extent[0], extent[1]]]
]; ];
}; }
/** /**
* @param {ol.Pixel} pixel cursor location * @param {ol.Pixel} pixel cursor location
@@ -322,7 +313,7 @@ ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
const extent = this.getExtent(); const extent = this.getExtent();
if (extent) { if (extent) {
//convert extents to line segments and find the segment closest to pixelCoordinate //convert extents to line segments and find the segment closest to pixelCoordinate
const segments = ExtentInteraction.getSegments_(extent); const segments = getSegments(extent);
segments.sort(sortByDistance); segments.sort(sortByDistance);
const closestSegment = segments[0]; const closestSegment = segments[0];
+20 -24
View File
@@ -46,10 +46,10 @@ import Style from '../style/Style.js';
const Modify = function(options) { const Modify = function(options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: Modify.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: Modify.handleDragEvent_, handleDragEvent: handleDragEvent,
handleEvent: Modify.handleEvent, handleEvent: Modify.handleEvent,
handleUpEvent: Modify.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
/** /**
@@ -592,20 +592,18 @@ Modify.prototype.createOrUpdateVertexFeature_ = function(coordinates) {
* @param {ol.ModifySegmentDataType} a The first segment data. * @param {ol.ModifySegmentDataType} a The first segment data.
* @param {ol.ModifySegmentDataType} b The second segment data. * @param {ol.ModifySegmentDataType} b The second segment data.
* @return {number} The difference in indexes. * @return {number} The difference in indexes.
* @private
*/ */
Modify.compareIndexes_ = function(a, b) { function compareIndexes(a, b) {
return a.index - b.index; return a.index - b.index;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} evt Event. * @param {ol.MapBrowserPointerEvent} evt Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.Modify} * @this {ol.interaction.Modify}
* @private
*/ */
Modify.handleDownEvent_ = function(evt) { function handleDownEvent(evt) {
if (!this.condition_(evt)) { if (!this.condition_(evt)) {
return false; return false;
} }
@@ -621,7 +619,7 @@ Modify.handleDownEvent_ = function(evt) {
const vertexExtent = boundingExtent([vertex]); const vertexExtent = boundingExtent([vertex]);
const segmentDataMatches = this.rBush_.getInExtent(vertexExtent); const segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
const componentSegments = {}; const componentSegments = {};
segmentDataMatches.sort(Modify.compareIndexes_); segmentDataMatches.sort(compareIndexes);
for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) { for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) {
const segmentDataMatch = segmentDataMatches[i]; const segmentDataMatch = segmentDataMatches[i];
const segment = segmentDataMatch.segment; const segment = segmentDataMatch.segment;
@@ -636,7 +634,7 @@ Modify.handleDownEvent_ = function(evt) {
if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE && if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
const closestVertex = Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch); const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch);
if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) { if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) {
this.dragSegments_.push([segmentDataMatch, 0]); this.dragSegments_.push([segmentDataMatch, 0]);
componentSegments[uid][0] = segmentDataMatch; componentSegments[uid][0] = segmentDataMatch;
@@ -673,15 +671,14 @@ Modify.handleDownEvent_ = function(evt) {
} }
} }
return !!this.vertexFeature_; return !!this.vertexFeature_;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} evt Event. * @param {ol.MapBrowserPointerEvent} evt Event.
* @this {ol.interaction.Modify} * @this {ol.interaction.Modify}
* @private
*/ */
Modify.handleDragEvent_ = function(evt) { function handleDragEvent(evt) {
this.ignoreNextSingleClick_ = false; this.ignoreNextSingleClick_ = false;
this.willModifyFeatures_(evt); this.willModifyFeatures_(evt);
@@ -750,16 +747,15 @@ Modify.handleDragEvent_ = function(evt) {
} }
} }
this.createOrUpdateVertexFeature_(vertex); this.createOrUpdateVertexFeature_(vertex);
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} evt Event. * @param {ol.MapBrowserPointerEvent} evt Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Modify} * @this {ol.interaction.Modify}
* @private
*/ */
Modify.handleUpEvent_ = function(evt) { function handleUpEvent(evt) {
let segmentData; let segmentData;
let geometry; let geometry;
for (let i = this.dragSegments_.length - 1; i >= 0; --i) { for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
@@ -785,7 +781,7 @@ Modify.handleUpEvent_ = function(evt) {
this.modified_ = false; this.modified_ = false;
} }
return false; return false;
}; }
/** /**
@@ -844,8 +840,8 @@ Modify.prototype.handlePointerMove_ = function(evt) {
Modify.prototype.handlePointerAtPixel_ = function(pixel, map) { Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
const pixelCoordinate = map.getCoordinateFromPixel(pixel); const pixelCoordinate = map.getCoordinateFromPixel(pixel);
const sortByDistance = function(a, b) { const sortByDistance = function(a, b) {
return Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, a) - return pointDistanceToSegmentDataSquared(pixelCoordinate, a) -
Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, b); pointDistanceToSegmentDataSquared(pixelCoordinate, b);
}; };
const box = buffer(createOrUpdateFromCoordinate(pixelCoordinate), const box = buffer(createOrUpdateFromCoordinate(pixelCoordinate),
@@ -857,7 +853,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
nodes.sort(sortByDistance); nodes.sort(sortByDistance);
const node = nodes[0]; const node = nodes[0];
const closestSegment = node.segment; const closestSegment = node.segment;
let vertex = Modify.closestOnSegmentData_(pixelCoordinate, node); let vertex = closestOnSegmentData(pixelCoordinate, node);
const vertexPixel = map.getPixelFromCoordinate(vertex); const vertexPixel = map.getPixelFromCoordinate(vertex);
let dist = coordinateDistance(pixel, vertexPixel); let dist = coordinateDistance(pixel, vertexPixel);
if (dist <= this.pixelTolerance_) { if (dist <= this.pixelTolerance_) {
@@ -915,7 +911,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
* segment we are calculating the distance to. * segment we are calculating the distance to.
* @return {number} The square of the distance between a point and a line segment. * @return {number} The square of the distance between a point and a line segment.
*/ */
Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentData) { function pointDistanceToSegmentDataSquared(pointCoordinates, segmentData) {
const geometry = segmentData.geometry; const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE) { if (geometry.getType() === GeometryType.CIRCLE) {
@@ -930,7 +926,7 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa
} }
} }
return squaredDistanceToSegment(pointCoordinates, segmentData.segment); return squaredDistanceToSegment(pointCoordinates, segmentData.segment);
}; }
/** /**
* Returns the point closest to a given line segment. * Returns the point closest to a given line segment.
@@ -941,7 +937,7 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa
* segment which should contain the closest point. * segment which should contain the closest point.
* @return {ol.Coordinate} The point closest to the specified line segment. * @return {ol.Coordinate} The point closest to the specified line segment.
*/ */
Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) { function closestOnSegmentData(pointCoordinates, segmentData) {
const geometry = segmentData.geometry; const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE && if (geometry.getType() === GeometryType.CIRCLE &&
@@ -949,7 +945,7 @@ Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) {
return geometry.getClosestPoint(pointCoordinates); return geometry.getClosestPoint(pointCoordinates);
} }
return closestOnSegment(pointCoordinates, segmentData.segment); return closestOnSegment(pointCoordinates, segmentData.segment);
}; }
/** /**
+13 -12
View File
@@ -18,6 +18,15 @@ import {clamp} from '../math.js';
const MAX_DELTA = 1; const MAX_DELTA = 1;
/**
* @enum {string}
*/
export const Mode = {
TRACKPAD: 'trackpad',
WHEEL: 'wheel'
};
/** /**
* @classdesc * @classdesc
* Allows the user to zoom the map by scrolling the mouse wheel. * Allows the user to zoom the map by scrolling the mouse wheel.
@@ -91,7 +100,7 @@ const MouseWheelZoom = function(opt_options) {
/** /**
* @private * @private
* @type {ol.interaction.MouseWheelZoom.Mode_|undefined} * @type {ol.interaction.Mode|undefined}
*/ */
this.mode_ = undefined; this.mode_ = undefined;
@@ -183,11 +192,11 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) { if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) {
this.mode_ = Math.abs(delta) < 4 ? this.mode_ = Math.abs(delta) < 4 ?
MouseWheelZoom.Mode_.TRACKPAD : Mode.TRACKPAD :
MouseWheelZoom.Mode_.WHEEL; Mode.WHEEL;
} }
if (this.mode_ === MouseWheelZoom.Mode_.TRACKPAD) { if (this.mode_ === Mode.TRACKPAD) {
const view = map.getView(); const view = map.getView();
if (this.trackpadTimeoutId_) { if (this.trackpadTimeoutId_) {
clearTimeout(this.trackpadTimeoutId_); clearTimeout(this.trackpadTimeoutId_);
@@ -296,12 +305,4 @@ MouseWheelZoom.prototype.setMouseAnchor = function(useAnchor) {
}; };
/**
* @enum {string}
* @private
*/
MouseWheelZoom.Mode_ = {
TRACKPAD: 'trackpad',
WHEEL: 'wheel'
};
export default MouseWheelZoom; export default MouseWheelZoom;
+10 -12
View File
@@ -21,9 +21,9 @@ import RotationConstraint from '../RotationConstraint.js';
const PinchRotate = function(opt_options) { const PinchRotate = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: PinchRotate.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: PinchRotate.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: PinchRotate.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options || {}; const options = opt_options || {};
@@ -72,9 +72,8 @@ inherits(PinchRotate, PointerInteraction);
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.PinchRotate} * @this {ol.interaction.PinchRotate}
* @private
*/ */
PinchRotate.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
let rotationDelta = 0.0; let rotationDelta = 0.0;
const touch0 = this.targetPointers[0]; const touch0 = this.targetPointers[0];
@@ -118,16 +117,15 @@ PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
Interaction.rotateWithoutConstraints(view, Interaction.rotateWithoutConstraints(view,
rotation + rotationDelta, this.anchor_); rotation + rotationDelta, this.anchor_);
} }
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.PinchRotate} * @this {ol.interaction.PinchRotate}
* @private
*/ */
PinchRotate.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
if (this.targetPointers.length < 2) { if (this.targetPointers.length < 2) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
@@ -141,16 +139,15 @@ PinchRotate.handleUpEvent_ = function(mapBrowserEvent) {
} else { } else {
return true; return true;
} }
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.PinchRotate} * @this {ol.interaction.PinchRotate}
* @private
*/ */
PinchRotate.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (this.targetPointers.length >= 2) { if (this.targetPointers.length >= 2) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
this.anchor_ = null; this.anchor_ = null;
@@ -164,11 +161,12 @@ PinchRotate.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
return false; return false;
} }
}; }
/** /**
* @inheritDoc * @inheritDoc
*/ */
PinchRotate.prototype.shouldStopEvent = FALSE; PinchRotate.prototype.shouldStopEvent = FALSE;
export default PinchRotate; export default PinchRotate;
+9 -12
View File
@@ -20,9 +20,9 @@ import PointerInteraction from '../interaction/Pointer.js';
const PinchZoom = function(opt_options) { const PinchZoom = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: PinchZoom.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: PinchZoom.handleDragEvent_, handleDragEvent: handleDragEvent,
handleUpEvent: PinchZoom.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -65,9 +65,8 @@ inherits(PinchZoom, PointerInteraction);
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.PinchZoom} * @this {ol.interaction.PinchZoom}
* @private
*/ */
PinchZoom.handleDragEvent_ = function(mapBrowserEvent) { function handleDragEvent(mapBrowserEvent) {
let scaleDelta = 1.0; let scaleDelta = 1.0;
const touch0 = this.targetPointers[0]; const touch0 = this.targetPointers[0];
@@ -112,16 +111,15 @@ PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
// scale, bypass the resolution constraint // scale, bypass the resolution constraint
map.render(); map.render();
Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_); Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_);
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.PinchZoom} * @this {ol.interaction.PinchZoom}
* @private
*/ */
PinchZoom.handleUpEvent_ = function(mapBrowserEvent) { function handleUpEvent(mapBrowserEvent) {
if (this.targetPointers.length < 2) { if (this.targetPointers.length < 2) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
@@ -141,16 +139,15 @@ PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
} else { } else {
return true; return true;
} }
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.PinchZoom} * @this {ol.interaction.PinchZoom}
* @private
*/ */
PinchZoom.handleDownEvent_ = function(mapBrowserEvent) { function handleDownEvent(mapBrowserEvent) {
if (this.targetPointers.length >= 2) { if (this.targetPointers.length >= 2) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
this.anchor_ = null; this.anchor_ = null;
@@ -163,7 +160,7 @@ PinchZoom.handleDownEvent_ = function(mapBrowserEvent) {
} else { } else {
return false; return false;
} }
}; }
/** /**
+17 -14
View File
@@ -15,6 +15,20 @@ import {clear} from '../obj.js';
import VectorSource from '../source/Vector.js'; import VectorSource from '../source/Vector.js';
import Style from '../style/Style.js'; import Style from '../style/Style.js';
/**
* @enum {string}
*/
const SelectEventType = {
/**
* Triggered when feature(s) has been (de)selected.
* @event ol.interaction.Select.Event#select
* @api
*/
SELECT: 'select'
};
/** /**
* @classdesc * @classdesc
* Interaction for selecting vector features. By default, selected features are * Interaction for selecting vector features. By default, selected features are
@@ -276,7 +290,7 @@ Select.handleEvent = function(mapBrowserEvent) {
} }
if (selected.length > 0 || deselected.length > 0) { if (selected.length > 0 || deselected.length > 0) {
this.dispatchEvent( this.dispatchEvent(
new Select.Event(Select.EventType_.SELECT, new Select.Event(SelectEventType.SELECT,
selected, deselected, mapBrowserEvent)); selected, deselected, mapBrowserEvent));
} }
return pointerMove(mapBrowserEvent); return pointerMove(mapBrowserEvent);
@@ -373,7 +387,7 @@ Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
* Events emitted by {@link ol.interaction.Select} instances are instances of * Events emitted by {@link ol.interaction.Select} instances are instances of
* this type. * this type.
* *
* @param {ol.interaction.Select.EventType_} type The event type. * @param {ol.interaction.SelectEventType} type The event type.
* @param {Array.<ol.Feature>} selected Selected features. * @param {Array.<ol.Feature>} selected Selected features.
* @param {Array.<ol.Feature>} deselected Deselected features. * @param {Array.<ol.Feature>} deselected Deselected features.
* @param {ol.MapBrowserEvent} mapBrowserEvent Associated * @param {ol.MapBrowserEvent} mapBrowserEvent Associated
@@ -406,19 +420,8 @@ Select.Event = function(type, selected, deselected, mapBrowserEvent) {
*/ */
this.mapBrowserEvent = mapBrowserEvent; this.mapBrowserEvent = mapBrowserEvent;
}; };
inherits(Select.Event, Event); inherits(Select.Event, Event);
/**
* @enum {string}
* @private
*/
Select.EventType_ = {
/**
* Triggered when feature(s) has been (de)selected.
* @event ol.interaction.Select.Event#select
* @api
*/
SELECT: 'select'
};
export default Select; export default Select;
+7 -8
View File
@@ -42,9 +42,9 @@ import RBush from '../structs/RBush.js';
const Snap = function(opt_options) { const Snap = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleEvent: Snap.handleEvent_, handleEvent: handleEvent,
handleDownEvent: TRUE, handleDownEvent: TRUE,
handleUpEvent: Snap.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -586,32 +586,30 @@ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
* @param {ol.MapBrowserEvent} evt A move event. * @param {ol.MapBrowserEvent} evt A move event.
* @return {boolean} Pass the event to other interactions. * @return {boolean} Pass the event to other interactions.
* @this {ol.interaction.Snap} * @this {ol.interaction.Snap}
* @private
*/ */
Snap.handleEvent_ = function(evt) { export function handleEvent(evt) {
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map); const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
if (result.snapped) { if (result.snapped) {
evt.coordinate = result.vertex.slice(0, 2); evt.coordinate = result.vertex.slice(0, 2);
evt.pixel = result.vertexPixel; evt.pixel = result.vertexPixel;
} }
return PointerInteraction.handleEvent.call(this, evt); return PointerInteraction.handleEvent.call(this, evt);
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} evt Event. * @param {ol.MapBrowserPointerEvent} evt Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Snap} * @this {ol.interaction.Snap}
* @private
*/ */
Snap.handleUpEvent_ = function(evt) { function handleUpEvent(evt) {
const featuresToUpdate = getValues(this.pendingFeatures_); const featuresToUpdate = getValues(this.pendingFeatures_);
if (featuresToUpdate.length) { if (featuresToUpdate.length) {
featuresToUpdate.forEach(this.updateFeature_.bind(this)); featuresToUpdate.forEach(this.updateFeature_.bind(this));
this.pendingFeatures_ = {}; this.pendingFeatures_ = {};
} }
return false; return false;
}; }
/** /**
@@ -627,4 +625,5 @@ Snap.sortByDistance = function(a, b) {
squaredDistanceToSegment( squaredDistanceToSegment(
this.pixelCoordinate_, b.segment); this.pixelCoordinate_, b.segment);
}; };
export default Snap; export default Snap;
+16 -18
View File
@@ -24,10 +24,10 @@ import TranslateEventType from '../interaction/TranslateEventType.js';
*/ */
const Translate = function(opt_options) { const Translate = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: Translate.handleDownEvent_, handleDownEvent: handleDownEvent,
handleDragEvent: Translate.handleDragEvent_, handleDragEvent: handleDragEvent,
handleMoveEvent: Translate.handleMoveEvent_, handleMoveEvent: handleMoveEvent,
handleUpEvent: Translate.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -92,13 +92,12 @@ inherits(Translate, PointerInteraction);
* @param {ol.MapBrowserPointerEvent} event Event. * @param {ol.MapBrowserPointerEvent} event Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private
*/ */
Translate.handleDownEvent_ = function(event) { function handleDownEvent(event) {
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map); this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
if (!this.lastCoordinate_ && this.lastFeature_) { if (!this.lastCoordinate_ && this.lastFeature_) {
this.lastCoordinate_ = event.coordinate; this.lastCoordinate_ = event.coordinate;
Translate.handleMoveEvent_.call(this, event); handleMoveEvent.call(this, event);
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
@@ -109,19 +108,18 @@ Translate.handleDownEvent_ = function(event) {
return true; return true;
} }
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {ol.MapBrowserPointerEvent} event Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private
*/ */
Translate.handleUpEvent_ = function(event) { function handleUpEvent(event) {
if (this.lastCoordinate_) { if (this.lastCoordinate_) {
this.lastCoordinate_ = null; this.lastCoordinate_ = null;
Translate.handleMoveEvent_.call(this, event); handleMoveEvent.call(this, event);
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
@@ -132,15 +130,14 @@ Translate.handleUpEvent_ = function(event) {
return true; return true;
} }
return false; return false;
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {ol.MapBrowserPointerEvent} event Event.
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private
*/ */
Translate.handleDragEvent_ = function(event) { function handleDragEvent(event) {
if (this.lastCoordinate_) { if (this.lastCoordinate_) {
const newCoordinate = event.coordinate; const newCoordinate = event.coordinate;
const deltaX = newCoordinate[0] - this.lastCoordinate_[0]; const deltaX = newCoordinate[0] - this.lastCoordinate_[0];
@@ -160,15 +157,14 @@ Translate.handleDragEvent_ = function(event) {
TranslateEventType.TRANSLATING, features, TranslateEventType.TRANSLATING, features,
newCoordinate)); newCoordinate));
} }
}; }
/** /**
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private
*/ */
Translate.handleMoveEvent_ = function(event) { function handleMoveEvent(event) {
const elem = event.map.getViewport(); const elem = event.map.getViewport();
// Change the cursor to grab/grabbing if hovering any of the features managed // Change the cursor to grab/grabbing if hovering any of the features managed
@@ -179,7 +175,7 @@ Translate.handleMoveEvent_ = function(event) {
} else { } else {
elem.classList.remove('ol-grab', 'ol-grabbing'); elem.classList.remove('ol-grab', 'ol-grabbing');
} }
}; }
/** /**
@@ -292,5 +288,7 @@ Translate.Event = function(type, features, coordinate) {
*/ */
this.coordinate = coordinate; this.coordinate = coordinate;
}; };
inherits(Translate.Event, Event); inherits(Translate.Event, Event);
export default Translate; export default Translate;
+33 -31
View File
@@ -11,6 +11,36 @@ import {equivalent} from '../proj.js';
import ReprojImage from '../reproj/Image.js'; import ReprojImage from '../reproj/Image.js';
import Source from '../source/Source.js'; import Source from '../source/Source.js';
/**
* @enum {string}
*/
const ImageSourceEventType = {
/**
* Triggered when an image starts loading.
* @event ol.source.Image.Event#imageloadstart
* @api
*/
IMAGELOADSTART: 'imageloadstart',
/**
* Triggered when an image finishes loading.
* @event ol.source.Image.Event#imageloadend
* @api
*/
IMAGELOADEND: 'imageloadend',
/**
* Triggered if image loading results in an error.
* @event ol.source.Image.Event#imageloaderror
* @api
*/
IMAGELOADERROR: 'imageloaderror'
};
/** /**
* @classdesc * @classdesc
* Abstract base class; normally only used for creating subclasses and not * Abstract base class; normally only used for creating subclasses and not
@@ -144,17 +174,17 @@ ImageSource.prototype.handleImageChange = function(event) {
switch (image.getState()) { switch (image.getState()) {
case ImageState.LOADING: case ImageState.LOADING:
this.dispatchEvent( this.dispatchEvent(
new ImageSource.Event(ImageSource.EventType_.IMAGELOADSTART, new ImageSource.Event(ImageSourceEventType.IMAGELOADSTART,
image)); image));
break; break;
case ImageState.LOADED: case ImageState.LOADED:
this.dispatchEvent( this.dispatchEvent(
new ImageSource.Event(ImageSource.EventType_.IMAGELOADEND, new ImageSource.Event(ImageSourceEventType.IMAGELOADEND,
image)); image));
break; break;
case ImageState.ERROR: case ImageState.ERROR:
this.dispatchEvent( this.dispatchEvent(
new ImageSource.Event(ImageSource.EventType_.IMAGELOADERROR, new ImageSource.Event(ImageSourceEventType.IMAGELOADERROR,
image)); image));
break; break;
default: default:
@@ -200,32 +230,4 @@ ImageSource.Event = function(type, image) {
inherits(ImageSource.Event, Event); inherits(ImageSource.Event, Event);
/**
* @enum {string}
* @private
*/
ImageSource.EventType_ = {
/**
* Triggered when an image starts loading.
* @event ol.source.Image.Event#imageloadstart
* @api
*/
IMAGELOADSTART: 'imageloadstart',
/**
* Triggered when an image finishes loading.
* @event ol.source.Image.Event#imageloadend
* @api
*/
IMAGELOADEND: 'imageloadend',
/**
* Triggered if image loading results in an error.
* @event ol.source.Image.Event#imageloaderror
* @api
*/
IMAGELOADERROR: 'imageloaderror'
};
export default ImageSource; export default ImageSource;
+3 -4
View File
@@ -114,9 +114,8 @@ inherits(ImageWMS, ImageSource);
/** /**
* @const * @const
* @type {ol.Size} * @type {ol.Size}
* @private
*/ */
ImageWMS.GETFEATUREINFO_IMAGE_SIZE_ = [101, 101]; const GETFEATUREINFO_IMAGE_SIZE = [101, 101];
/** /**
@@ -146,7 +145,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje
} }
const extent = getForViewAndSize(coordinate, resolution, 0, const extent = getForViewAndSize(coordinate, resolution, 0,
ImageWMS.GETFEATUREINFO_IMAGE_SIZE_); GETFEATUREINFO_IMAGE_SIZE);
const baseParams = { const baseParams = {
'SERVICE': 'WMS', 'SERVICE': 'WMS',
@@ -164,7 +163,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje
baseParams[this.v13_ ? 'J' : 'Y'] = y; baseParams[this.v13_ ? 'J' : 'Y'] = y;
return this.getRequestUrl_( return this.getRequestUrl_(
extent, ImageWMS.GETFEATUREINFO_IMAGE_SIZE_, extent, GETFEATUREINFO_IMAGE_SIZE,
1, sourceProjectionObj || projectionObj, baseParams); 1, sourceProjectionObj || projectionObj, baseParams);
}; };
+15 -15
View File
@@ -326,6 +326,14 @@ RasterSource.prototype.onWorkerComplete_ = function(frameState, err, output, dat
}; };
/**
* A reusable canvas context.
* @type {CanvasRenderingContext2D}
* @private
*/
let sharedContext = null;
/** /**
* Get image data from a renderer. * Get image data from a renderer.
* @param {ol.renderer.canvas.Layer} renderer Layer renderer. * @param {ol.renderer.canvas.Layer} renderer Layer renderer.
@@ -339,29 +347,21 @@ function getImageData(renderer, frameState, layerState) {
} }
const width = frameState.size[0]; const width = frameState.size[0];
const height = frameState.size[1]; const height = frameState.size[1];
if (!RasterSource.context_) { if (!sharedContext) {
RasterSource.context_ = createCanvasContext2D(width, height); sharedContext = createCanvasContext2D(width, height);
} else { } else {
const canvas = RasterSource.context_.canvas; const canvas = sharedContext.canvas;
if (canvas.width !== width || canvas.height !== height) { if (canvas.width !== width || canvas.height !== height) {
RasterSource.context_ = createCanvasContext2D(width, height); sharedContext = createCanvasContext2D(width, height);
} else { } else {
RasterSource.context_.clearRect(0, 0, width, height); sharedContext.clearRect(0, 0, width, height);
} }
} }
renderer.composeFrame(frameState, layerState, RasterSource.context_); renderer.composeFrame(frameState, layerState, sharedContext);
return RasterSource.context_.getImageData(0, 0, width, height); return sharedContext.getImageData(0, 0, width, height);
} }
/**
* A reusable canvas context.
* @type {CanvasRenderingContext2D}
* @private
*/
RasterSource.context_ = null;
/** /**
* Get a list of layer states from a list of renderers. * Get a list of layer states from a list of renderers.
* @param {Array.<ol.renderer.canvas.Layer>} renderers Layer renderers. * @param {Array.<ol.renderer.canvas.Layer>} renderers Layer renderers.
+68 -66
View File
@@ -9,6 +9,72 @@ import {toSize} from '../size.js';
import TileSource from '../source/Tile.js'; import TileSource from '../source/Tile.js';
import _ol_tilecoord_ from '../tilecoord.js'; import _ol_tilecoord_ from '../tilecoord.js';
/**
* @constructor
* @extends {ol.Tile}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.Size} tileSize Tile size.
* @param {string} text Text.
*/
const LabeledTile = function(tileCoord, tileSize, text) {
Tile.call(this, tileCoord, TileState.LOADED);
/**
* @private
* @type {ol.Size}
*/
this.tileSize_ = tileSize;
/**
* @private
* @type {string}
*/
this.text_ = text;
/**
* @private
* @type {HTMLCanvasElement}
*/
this.canvas_ = null;
};
inherits(LabeledTile, Tile);
/**
* Get the image element for this tile.
* @return {HTMLCanvasElement} Image.
*/
LabeledTile.prototype.getImage = function() {
if (this.canvas_) {
return this.canvas_;
} else {
const tileSize = this.tileSize_;
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
context.strokeStyle = 'black';
context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
context.fillStyle = 'black';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = '24px sans-serif';
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
this.canvas_ = context.canvas;
return context.canvas;
}
};
/**
* @override
*/
LabeledTile.prototype.load = function() {};
/** /**
* @classdesc * @classdesc
* A pseudo tile source, which does not fetch tiles from a server, but renders * A pseudo tile source, which does not fetch tiles from a server, but renders
@@ -42,82 +108,18 @@ inherits(TileDebug, TileSource);
TileDebug.prototype.getTile = function(z, x, y) { TileDebug.prototype.getTile = function(z, x, y) {
const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y); const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) { if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.source.TileDebug.Tile_} */ (this.tileCache.get(tileCoordKey)); return /** @type {!ol.source.LabeledTile} */ (this.tileCache.get(tileCoordKey));
} else { } else {
const tileSize = toSize(this.tileGrid.getTileSize(z)); const tileSize = toSize(this.tileGrid.getTileSize(z));
const tileCoord = [z, x, y]; const tileCoord = [z, x, y];
const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord); const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
const text = !textTileCoord ? '' : const text = !textTileCoord ? '' :
this.getTileCoordForTileUrlFunction(textTileCoord).toString(); this.getTileCoordForTileUrlFunction(textTileCoord).toString();
const tile = new TileDebug.Tile_(tileCoord, tileSize, text); const tile = new LabeledTile(tileCoord, tileSize, text);
this.tileCache.set(tileCoordKey, tile); this.tileCache.set(tileCoordKey, tile);
return tile; return tile;
} }
}; };
/**
* @constructor
* @extends {ol.Tile}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.Size} tileSize Tile size.
* @param {string} text Text.
* @private
*/
TileDebug.Tile_ = function(tileCoord, tileSize, text) {
Tile.call(this, tileCoord, TileState.LOADED);
/**
* @private
* @type {ol.Size}
*/
this.tileSize_ = tileSize;
/**
* @private
* @type {string}
*/
this.text_ = text;
/**
* @private
* @type {HTMLCanvasElement}
*/
this.canvas_ = null;
};
inherits(TileDebug.Tile_, Tile);
/**
* Get the image element for this tile.
* @return {HTMLCanvasElement} Image.
*/
TileDebug.Tile_.prototype.getImage = function() {
if (this.canvas_) {
return this.canvas_;
} else {
const tileSize = this.tileSize_;
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
context.strokeStyle = 'black';
context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
context.fillStyle = 'black';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = '24px sans-serif';
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
this.canvas_ = context.canvas;
return context.canvas;
}
};
/**
* @override
*/
TileDebug.Tile_.prototype.load = function() {};
export default TileDebug; export default TileDebug;
+235 -233
View File
@@ -16,6 +16,239 @@ import TileSource from '../source/Tile.js';
import _ol_tilecoord_ from '../tilecoord.js'; import _ol_tilecoord_ from '../tilecoord.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js'; import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @constructor
* @extends {ol.Tile}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileState} state State.
* @param {string} src Image source URI.
* @param {ol.Extent} extent Extent of the tile.
* @param {boolean} preemptive Load the tile when visible (before it's needed).
* @param {boolean} jsonp Load the tile as a script.
*/
export const CustomTile = function(tileCoord, state, src, extent, preemptive, jsonp) {
Tile.call(this, tileCoord, state);
/**
* @private
* @type {string}
*/
this.src_ = src;
/**
* @private
* @type {ol.Extent}
*/
this.extent_ = extent;
/**
* @private
* @type {boolean}
*/
this.preemptive_ = preemptive;
/**
* @private
* @type {Array.<string>}
*/
this.grid_ = null;
/**
* @private
* @type {Array.<string>}
*/
this.keys_ = null;
/**
* @private
* @type {Object.<string, Object>|undefined}
*/
this.data_ = null;
/**
* @private
* @type {boolean}
*/
this.jsonp_ = jsonp;
};
inherits(CustomTile, Tile);
/**
* Get the image element for this tile.
* @return {Image} Image.
*/
CustomTile.prototype.getImage = function() {
return null;
};
/**
* Synchronously returns data at given coordinate (if available).
* @param {ol.Coordinate} coordinate Coordinate.
* @return {*} The data.
*/
CustomTile.prototype.getData = function(coordinate) {
if (!this.grid_ || !this.keys_) {
return null;
}
const xRelative = (coordinate[0] - this.extent_[0]) /
(this.extent_[2] - this.extent_[0]);
const yRelative = (coordinate[1] - this.extent_[1]) /
(this.extent_[3] - this.extent_[1]);
const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
if (typeof row !== 'string') {
return null;
}
let code = row.charCodeAt(Math.floor(xRelative * row.length));
if (code >= 93) {
code--;
}
if (code >= 35) {
code--;
}
code -= 32;
let data = null;
if (code in this.keys_) {
const id = this.keys_[code];
if (this.data_ && id in this.data_) {
data = this.data_[id];
} else {
data = id;
}
}
return data;
};
/**
* Calls the callback (synchronously by default) with the available data
* for given coordinate (or `null` if not yet loaded).
* @param {ol.Coordinate} coordinate Coordinate.
* @param {function(this: T, *)} callback Callback.
* @param {T=} opt_this The object to use as `this` in the callback.
* @param {boolean=} opt_request If `true` the callback is always async.
* The tile data is requested if not yet loaded.
* @template T
*/
CustomTile.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
if (this.state == TileState.IDLE && opt_request === true) {
listenOnce(this, EventType.CHANGE, function(e) {
callback.call(opt_this, this.getData(coordinate));
}, this);
this.loadInternal_();
} else {
if (opt_request === true) {
setTimeout(function() {
callback.call(opt_this, this.getData(coordinate));
}.bind(this), 0);
} else {
callback.call(opt_this, this.getData(coordinate));
}
}
};
/**
* @inheritDoc
*/
CustomTile.prototype.getKey = function() {
return this.src_;
};
/**
* @private
*/
CustomTile.prototype.handleError_ = function() {
this.state = TileState.ERROR;
this.changed();
};
/**
* @param {!UTFGridJSON} json UTFGrid data.
* @private
*/
CustomTile.prototype.handleLoad_ = function(json) {
this.grid_ = json.grid;
this.keys_ = json.keys;
this.data_ = json.data;
this.state = TileState.EMPTY;
this.changed();
};
/**
* @private
*/
CustomTile.prototype.loadInternal_ = function() {
if (this.state == TileState.IDLE) {
this.state = TileState.LOADING;
if (this.jsonp_) {
requestJSONP(this.src_, this.handleLoad_.bind(this),
this.handleError_.bind(this));
} else {
const client = new XMLHttpRequest();
client.addEventListener('load', this.onXHRLoad_.bind(this));
client.addEventListener('error', this.onXHRError_.bind(this));
client.open('GET', this.src_);
client.send();
}
}
};
/**
* @private
* @param {Event} event The load event.
*/
CustomTile.prototype.onXHRLoad_ = function(event) {
const client = /** @type {XMLHttpRequest} */ (event.target);
// status will be 0 for file:// urls
if (!client.status || client.status >= 200 && client.status < 300) {
let response;
try {
response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
} catch (err) {
this.handleError_();
return;
}
this.handleLoad_(response);
} else {
this.handleError_();
}
};
/**
* @private
* @param {Event} event The error event.
*/
CustomTile.prototype.onXHRError_ = function(event) {
this.handleError_();
};
/**
* @override
*/
CustomTile.prototype.load = function() {
if (this.preemptive_) {
this.loadInternal_();
}
};
/** /**
* @classdesc * @classdesc
* Layer source for UTFGrid interaction data loaded from TileJSON format. * Layer source for UTFGrid interaction data loaded from TileJSON format.
@@ -134,7 +367,7 @@ UTFGrid.prototype.forDataAtCoordinateAndResolution = function(
if (this.tileGrid) { if (this.tileGrid) {
const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution( const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
coordinate, resolution); coordinate, resolution);
const tile = /** @type {!ol.source.TileUTFGrid.Tile_} */(this.getTile( const tile = /** @type {!ol.source.CustomTile} */(this.getTile(
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection())); tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
tile.forDataAtCoordinate(coordinate, callback, null, opt_request); tile.forDataAtCoordinate(coordinate, callback, null, opt_request);
} else { } else {
@@ -222,7 +455,7 @@ UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
const urlTileCoord = const urlTileCoord =
this.getTileCoordForTileUrlFunction(tileCoord, projection); this.getTileCoordForTileUrlFunction(tileCoord, projection);
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
const tile = new UTFGrid.Tile_( const tile = new CustomTile(
tileCoord, tileCoord,
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY, tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
tileUrl !== undefined ? tileUrl : '', tileUrl !== undefined ? tileUrl : '',
@@ -246,235 +479,4 @@ UTFGrid.prototype.useTile = function(z, x, y) {
}; };
/**
* @constructor
* @extends {ol.Tile}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileState} state State.
* @param {string} src Image source URI.
* @param {ol.Extent} extent Extent of the tile.
* @param {boolean} preemptive Load the tile when visible (before it's needed).
* @param {boolean} jsonp Load the tile as a script.
* @private
*/
UTFGrid.Tile_ = function(tileCoord, state, src, extent, preemptive, jsonp) {
Tile.call(this, tileCoord, state);
/**
* @private
* @type {string}
*/
this.src_ = src;
/**
* @private
* @type {ol.Extent}
*/
this.extent_ = extent;
/**
* @private
* @type {boolean}
*/
this.preemptive_ = preemptive;
/**
* @private
* @type {Array.<string>}
*/
this.grid_ = null;
/**
* @private
* @type {Array.<string>}
*/
this.keys_ = null;
/**
* @private
* @type {Object.<string, Object>|undefined}
*/
this.data_ = null;
/**
* @private
* @type {boolean}
*/
this.jsonp_ = jsonp;
};
inherits(UTFGrid.Tile_, Tile);
/**
* Get the image element for this tile.
* @return {Image} Image.
*/
UTFGrid.Tile_.prototype.getImage = function() {
return null;
};
/**
* Synchronously returns data at given coordinate (if available).
* @param {ol.Coordinate} coordinate Coordinate.
* @return {*} The data.
*/
UTFGrid.Tile_.prototype.getData = function(coordinate) {
if (!this.grid_ || !this.keys_) {
return null;
}
const xRelative = (coordinate[0] - this.extent_[0]) /
(this.extent_[2] - this.extent_[0]);
const yRelative = (coordinate[1] - this.extent_[1]) /
(this.extent_[3] - this.extent_[1]);
const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
if (typeof row !== 'string') {
return null;
}
let code = row.charCodeAt(Math.floor(xRelative * row.length));
if (code >= 93) {
code--;
}
if (code >= 35) {
code--;
}
code -= 32;
let data = null;
if (code in this.keys_) {
const id = this.keys_[code];
if (this.data_ && id in this.data_) {
data = this.data_[id];
} else {
data = id;
}
}
return data;
};
/**
* Calls the callback (synchronously by default) with the available data
* for given coordinate (or `null` if not yet loaded).
* @param {ol.Coordinate} coordinate Coordinate.
* @param {function(this: T, *)} callback Callback.
* @param {T=} opt_this The object to use as `this` in the callback.
* @param {boolean=} opt_request If `true` the callback is always async.
* The tile data is requested if not yet loaded.
* @template T
*/
UTFGrid.Tile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
if (this.state == TileState.IDLE && opt_request === true) {
listenOnce(this, EventType.CHANGE, function(e) {
callback.call(opt_this, this.getData(coordinate));
}, this);
this.loadInternal_();
} else {
if (opt_request === true) {
setTimeout(function() {
callback.call(opt_this, this.getData(coordinate));
}.bind(this), 0);
} else {
callback.call(opt_this, this.getData(coordinate));
}
}
};
/**
* @inheritDoc
*/
UTFGrid.Tile_.prototype.getKey = function() {
return this.src_;
};
/**
* @private
*/
UTFGrid.Tile_.prototype.handleError_ = function() {
this.state = TileState.ERROR;
this.changed();
};
/**
* @param {!UTFGridJSON} json UTFGrid data.
* @private
*/
UTFGrid.Tile_.prototype.handleLoad_ = function(json) {
this.grid_ = json.grid;
this.keys_ = json.keys;
this.data_ = json.data;
this.state = TileState.EMPTY;
this.changed();
};
/**
* @private
*/
UTFGrid.Tile_.prototype.loadInternal_ = function() {
if (this.state == TileState.IDLE) {
this.state = TileState.LOADING;
if (this.jsonp_) {
requestJSONP(this.src_, this.handleLoad_.bind(this),
this.handleError_.bind(this));
} else {
const client = new XMLHttpRequest();
client.addEventListener('load', this.onXHRLoad_.bind(this));
client.addEventListener('error', this.onXHRError_.bind(this));
client.open('GET', this.src_);
client.send();
}
}
};
/**
* @private
* @param {Event} event The load event.
*/
UTFGrid.Tile_.prototype.onXHRLoad_ = function(event) {
const client = /** @type {XMLHttpRequest} */ (event.target);
// status will be 0 for file:// urls
if (!client.status || client.status >= 200 && client.status < 300) {
let response;
try {
response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
} catch (err) {
this.handleError_();
return;
}
this.handleLoad_(response);
} else {
this.handleError_();
}
};
/**
* @private
* @param {Event} event The error event.
*/
UTFGrid.Tile_.prototype.onXHRError_ = function(event) {
this.handleError_();
};
/**
* @override
*/
UTFGrid.Tile_.prototype.load = function() {
if (this.preemptive_) {
this.loadInternal_();
}
};
export default UTFGrid; export default UTFGrid;
+70 -67
View File
@@ -13,6 +13,72 @@ import {toSize} from '../size.js';
import TileImage from '../source/TileImage.js'; import TileImage from '../source/TileImage.js';
import TileGrid from '../tilegrid/TileGrid.js'; import TileGrid from '../tilegrid/TileGrid.js';
/**
* @enum {string}
*/
const TierSizeCalculation = {
DEFAULT: 'default',
TRUNCATED: 'truncated'
};
/**
* @constructor
* @extends {ol.ImageTile}
* @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileState} state State.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
* @param {olx.TileOptions=} opt_options Tile options.
*/
export const CustomTile = function(
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
/**
* @private
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
*/
this.zoomifyImage_ = null;
/**
* @private
* @type {ol.Size}
*/
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
};
inherits(CustomTile, ImageTile);
/**
* @inheritDoc
*/
CustomTile.prototype.getImage = function() {
if (this.zoomifyImage_) {
return this.zoomifyImage_;
}
const image = ImageTile.prototype.getImage.call(this);
if (this.state == TileState.LOADED) {
const tileSize = this.tileSize_;
if (image.width == tileSize[0] && image.height == tileSize[1]) {
this.zoomifyImage_ = image;
return image;
} else {
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
context.drawImage(image, 0, 0);
this.zoomifyImage_ = context.canvas;
return context.canvas;
}
} else {
return image;
}
};
/** /**
* @classdesc * @classdesc
* Layer source for tile data in Zoomify format (both Zoomify and Internet * Layer source for tile data in Zoomify format (both Zoomify and Internet
@@ -30,7 +96,7 @@ const Zoomify = function(opt_options) {
const size = options.size; const size = options.size;
const tierSizeCalculation = options.tierSizeCalculation !== undefined ? const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
options.tierSizeCalculation : options.tierSizeCalculation :
Zoomify.TierSizeCalculation_.DEFAULT; TierSizeCalculation.DEFAULT;
const imageWidth = size[0]; const imageWidth = size[0];
const imageHeight = size[1]; const imageHeight = size[1];
@@ -40,7 +106,7 @@ const Zoomify = function(opt_options) {
let tileSizeForTierSizeCalculation = tileSize; let tileSizeForTierSizeCalculation = tileSize;
switch (tierSizeCalculation) { switch (tierSizeCalculation) {
case Zoomify.TierSizeCalculation_.DEFAULT: case TierSizeCalculation.DEFAULT:
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) { while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([ tierSizeInTiles.push([
Math.ceil(imageWidth / tileSizeForTierSizeCalculation), Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
@@ -49,7 +115,7 @@ const Zoomify = function(opt_options) {
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation; tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
} }
break; break;
case Zoomify.TierSizeCalculation_.TRUNCATED: case TierSizeCalculation.TRUNCATED:
let width = imageWidth; let width = imageWidth;
let height = imageHeight; let height = imageHeight;
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) { while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
@@ -134,7 +200,7 @@ const Zoomify = function(opt_options) {
const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate)); const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate));
const ZoomifyTileClass = Zoomify.Tile_.bind(null, tileGrid); const ZoomifyTileClass = CustomTile.bind(null, tileGrid);
TileImage.call(this, { TileImage.call(this, {
attributions: options.attributions, attributions: options.attributions,
@@ -152,68 +218,5 @@ const Zoomify = function(opt_options) {
inherits(Zoomify, TileImage); inherits(Zoomify, TileImage);
/**
* @constructor
* @extends {ol.ImageTile}
* @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileState} state State.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
* @param {olx.TileOptions=} opt_options Tile options.
* @private
*/
Zoomify.Tile_ = function(
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
/**
* @private
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
*/
this.zoomifyImage_ = null;
/**
* @private
* @type {ol.Size}
*/
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
};
inherits(Zoomify.Tile_, ImageTile);
/**
* @inheritDoc
*/
Zoomify.Tile_.prototype.getImage = function() {
if (this.zoomifyImage_) {
return this.zoomifyImage_;
}
const image = ImageTile.prototype.getImage.call(this);
if (this.state == TileState.LOADED) {
const tileSize = this.tileSize_;
if (image.width == tileSize[0] && image.height == tileSize[1]) {
this.zoomifyImage_ = image;
return image;
} else {
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
context.drawImage(image, 0, 0);
this.zoomifyImage_ = context.canvas;
return context.canvas;
}
} else {
return image;
}
};
/**
* @enum {string}
* @private
*/
Zoomify.TierSizeCalculation_ = {
DEFAULT: 'default',
TRUNCATED: 'truncated'
};
export default Zoomify; export default Zoomify;
+4 -5
View File
@@ -305,9 +305,8 @@ Style.createFunction = function(obj) {
/** /**
* @type {Array.<ol.style.Style>} * @type {Array.<ol.style.Style>}
* @private
*/ */
Style.default_ = null; let defaultStyles = null;
/** /**
@@ -321,7 +320,7 @@ Style.defaultFunction = function(feature, resolution) {
// browsers that do not support Canvas. (ol.style.Circle does // browsers that do not support Canvas. (ol.style.Circle does
// canvas.getContext('2d') at construction time, which will cause an.error // canvas.getContext('2d') at construction time, which will cause an.error
// in such browsers.) // in such browsers.)
if (!Style.default_) { if (!defaultStyles) {
const fill = new Fill({ const fill = new Fill({
color: 'rgba(255,255,255,0.4)' color: 'rgba(255,255,255,0.4)'
}); });
@@ -329,7 +328,7 @@ Style.defaultFunction = function(feature, resolution) {
color: '#3399CC', color: '#3399CC',
width: 1.25 width: 1.25
}); });
Style.default_ = [ defaultStyles = [
new Style({ new Style({
image: new CircleStyle({ image: new CircleStyle({
fill: fill, fill: fill,
@@ -341,7 +340,7 @@ Style.defaultFunction = function(feature, resolution) {
}) })
]; ];
} }
return Style.default_; return defaultStyles;
}; };
+11 -11
View File
@@ -4,6 +4,16 @@
import Fill from '../style/Fill.js'; import Fill from '../style/Fill.js';
import TextPlacement from '../style/TextPlacement.js'; import TextPlacement from '../style/TextPlacement.js';
/**
* The default fill color to use if no fill was set at construction time; a
* blackish `#333`.
*
* @const {string}
*/
const DEFAULT_FILL_COLOR = '#333';
/** /**
* @classdesc * @classdesc
* Set text style for vector features. * Set text style for vector features.
@@ -63,7 +73,7 @@ const Text = function(opt_options) {
* @type {ol.style.Fill} * @type {ol.style.Fill}
*/ */
this.fill_ = options.fill !== undefined ? options.fill : this.fill_ = options.fill !== undefined ? options.fill :
new Fill({color: Text.DEFAULT_FILL_COLOR_}); new Fill({color: DEFAULT_FILL_COLOR});
/** /**
* @private * @private
@@ -121,16 +131,6 @@ const Text = function(opt_options) {
}; };
/**
* The default fill color to use if no fill was set at construction time; a
* blackish `#333`.
*
* @const {string}
* @private
*/
Text.DEFAULT_FILL_COLOR_ = '#333';
/** /**
* Clones the style. * Clones the style.
* @return {ol.style.Text} The cloned style. * @return {ol.style.Text} The cloned style.
+2 -2
View File
@@ -155,7 +155,7 @@ const TileGrid = function(options) {
* @private * @private
* @type {ol.TileCoord} * @type {ol.TileCoord}
*/ */
TileGrid.tmpTileCoord_ = [0, 0, 0]; const tmpTileCoord = [0, 0, 0];
/** /**
@@ -325,7 +325,7 @@ TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) {
* @return {ol.TileRange} Tile range. * @return {ol.TileRange} Tile range.
*/ */
TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange) { TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange) {
const tileCoord = TileGrid.tmpTileCoord_; const tileCoord = tmpTileCoord;
this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord); this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord);
const minX = tileCoord[1]; const minX = tileCoord[1];
const minY = tileCoord[2]; const minY = tileCoord[2];
@@ -4,7 +4,7 @@ import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js'; import Event from '../../../../src/ol/events/Event.js';
import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../../../../src/ol/has.js'; import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../../../../src/ol/has.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js';
import MouseWheelZoom from '../../../../src/ol/interaction/MouseWheelZoom.js'; import MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js';
describe('ol.interaction.MouseWheelZoom', function() { describe('ol.interaction.MouseWheelZoom', function() {
@@ -65,7 +65,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
if (FIREFOX) { if (FIREFOX) {
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function(done) { it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
map.once('postrender', function() { map.once('postrender', function() {
expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD); expect(interaction.mode_).to.be(Mode.TRACKPAD);
done(); done();
}); });
const event = new MapBrowserEvent('wheel', map, { const event = new MapBrowserEvent('wheel', map, {
@@ -83,7 +83,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
if (!FIREFOX) { if (!FIREFOX) {
it('works in DOM_DELTA_PIXEL mode (trackpad)', function(done) { it('works in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
map.once('postrender', function() { map.once('postrender', function() {
expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD); expect(interaction.mode_).to.be(Mode.TRACKPAD);
done(); done();
}); });
const event = new MapBrowserEvent('wheel', map, { const event = new MapBrowserEvent('wheel', map, {
+9 -9
View File
@@ -5,7 +5,7 @@ import View from '../../../../src/ol/View.js';
import Circle from '../../../../src/ol/geom/Circle.js'; import Circle from '../../../../src/ol/geom/Circle.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import LineString from '../../../../src/ol/geom/LineString.js'; import LineString from '../../../../src/ol/geom/LineString.js';
import Snap from '../../../../src/ol/interaction/Snap.js'; import Snap, {handleEvent} from '../../../../src/ol/interaction/Snap.js';
describe('ol.interaction.Snap', function() { describe('ol.interaction.Snap', function() {
@@ -19,7 +19,7 @@ describe('ol.interaction.Snap', function() {
}); });
describe('handleEvent_', function() { describe('handleEvent', function() {
let target, map; let target, map;
const width = 360; const width = 360;
@@ -67,7 +67,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [0, 0], coordinate: [0, 0],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
// check that the coordinate is in XY and not XYZ // check that the coordinate is in XY and not XYZ
expect(event.coordinate).to.eql([0, 0]); expect(event.coordinate).to.eql([0, 0]);
}); });
@@ -86,7 +86,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([7, 0]); expect(event.coordinate).to.eql([7, 0]);
}); });
@@ -104,7 +104,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -121,7 +121,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [5, 5], coordinate: [5, 5],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
@@ -143,7 +143,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -163,7 +163,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -186,7 +186,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
+2 -2
View File
@@ -1,6 +1,6 @@
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js'; import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
import TileSource from '../../../../src/ol/source/Tile.js'; import TileSource from '../../../../src/ol/source/Tile.js';
import UTFGrid from '../../../../src/ol/source/TileUTFGrid.js'; import UTFGrid, {CustomTile} from '../../../../src/ol/source/TileUTFGrid.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
@@ -228,7 +228,7 @@ describe('ol.source.TileUTFGrid', function() {
const urlTileCoord = const urlTileCoord =
this.getTileCoordForTileUrlFunction(tileCoord, projection); this.getTileCoordForTileUrlFunction(tileCoord, projection);
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
const tile = new UTFGrid.Tile_( const tile = new CustomTile(
tileCoord, tileCoord,
tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY
tileUrl !== undefined ? tileUrl : '', tileUrl !== undefined ? tileUrl : '',
+2 -2
View File
@@ -1,7 +1,7 @@
import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js'; import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js';
import {listen} from '../../../../src/ol/events.js'; import {listen} from '../../../../src/ol/events.js';
import Projection from '../../../../src/ol/proj/Projection.js'; import Projection from '../../../../src/ol/proj/Projection.js';
import Zoomify from '../../../../src/ol/source/Zoomify.js'; import Zoomify, {CustomTile} from '../../../../src/ol/source/Zoomify.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
@@ -280,7 +280,7 @@ describe('ol.source.Zoomify', function() {
it('returns expected tileClass instances via "getTile"', function() { it('returns expected tileClass instances via "getTile"', function() {
const source = getZoomifySource(); const source = getZoomifySource();
const tile = source.getTile(0, 0, -1, 1, proj); const tile = source.getTile(0, 0, -1, 1, proj);
expect(tile).to.be.an(Zoomify.Tile_); expect(tile).to.be.a(CustomTile);
}); });
it('"tile.getImage" returns and caches an unloaded image', function() { it('"tile.getImage" returns and caches an unloaded image', function() {
+10 -10
View File
@@ -1,5 +1,5 @@
import Map from '../../../src/ol/Map.js'; import Map from '../../../src/ol/Map.js';
import View from '../../../src/ol/View.js'; import View, {createCenterConstraint, createResolutionConstraint, createRotationConstraint} from '../../../src/ol/View.js';
import ViewHint from '../../../src/ol/ViewHint.js'; import ViewHint from '../../../src/ol/ViewHint.js';
import * as _ol_extent_ from '../../../src/ol/extent.js'; import * as _ol_extent_ from '../../../src/ol/extent.js';
import Circle from '../../../src/ol/geom/Circle.js'; import Circle from '../../../src/ol/geom/Circle.js';
@@ -32,7 +32,7 @@ describe('ol.View', function() {
describe('with no options', function() { describe('with no options', function() {
it('gives a correct center constraint function', function() { it('gives a correct center constraint function', function() {
const options = {}; const options = {};
const fn = View.createCenterConstraint_(options); const fn = createCenterConstraint(options);
expect(fn([0, 0])).to.eql([0, 0]); expect(fn([0, 0])).to.eql([0, 0]);
expect(fn(undefined)).to.eql(undefined); expect(fn(undefined)).to.eql(undefined);
expect(fn([42, -100])).to.eql([42, -100]); expect(fn([42, -100])).to.eql([42, -100]);
@@ -44,7 +44,7 @@ describe('ol.View', function() {
const options = { const options = {
extent: [0, 0, 1, 1] extent: [0, 0, 1, 1]
}; };
const fn = View.createCenterConstraint_(options); const fn = createCenterConstraint(options);
expect(fn([0, 0])).to.eql([0, 0]); expect(fn([0, 0])).to.eql([0, 0]);
expect(fn([-10, 0])).to.eql([0, 0]); expect(fn([-10, 0])).to.eql([0, 0]);
expect(fn([100, 100])).to.eql([1, 1]); expect(fn([100, 100])).to.eql([1, 1]);
@@ -58,7 +58,7 @@ describe('ol.View', function() {
describe('with no options', function() { describe('with no options', function() {
it('gives a correct resolution constraint function', function() { it('gives a correct resolution constraint function', function() {
const options = {}; const options = {};
const fn = View.createResolutionConstraint_(options).constraint; const fn = createResolutionConstraint(options).constraint;
expect(fn(156543.03392804097, 0, 0)) expect(fn(156543.03392804097, 0, 0))
.to.roughlyEqual(156543.03392804097, 1e-9); .to.roughlyEqual(156543.03392804097, 1e-9);
expect(fn(78271.51696402048, 0, 0)) expect(fn(78271.51696402048, 0, 0))
@@ -74,7 +74,7 @@ describe('ol.View', function() {
maxZoom: 3, maxZoom: 3,
zoomFactor: 3 zoomFactor: 3
}; };
const info = View.createResolutionConstraint_(options); const info = createResolutionConstraint(options);
const maxResolution = info.maxResolution; const maxResolution = info.maxResolution;
expect(maxResolution).to.eql(81); expect(maxResolution).to.eql(81);
const minResolution = info.minResolution; const minResolution = info.minResolution;
@@ -94,7 +94,7 @@ describe('ol.View', function() {
const options = { const options = {
resolutions: [97, 76, 65, 54, 0.45] resolutions: [97, 76, 65, 54, 0.45]
}; };
const info = View.createResolutionConstraint_(options); const info = createResolutionConstraint(options);
const maxResolution = info.maxResolution; const maxResolution = info.maxResolution;
expect(maxResolution).to.eql(97); expect(maxResolution).to.eql(97);
const minResolution = info.minResolution; const minResolution = info.minResolution;
@@ -112,7 +112,7 @@ describe('ol.View', function() {
const defaultMaxRes = 156543.03392804097; const defaultMaxRes = 156543.03392804097;
function getConstraint(options) { function getConstraint(options) {
return View.createResolutionConstraint_(options).constraint; return createResolutionConstraint(options).constraint;
} }
it('works with only maxZoom', function() { it('works with only maxZoom', function() {
@@ -179,7 +179,7 @@ describe('ol.View', function() {
const defaultMaxRes = 156543.03392804097; const defaultMaxRes = 156543.03392804097;
function getConstraint(options) { function getConstraint(options) {
return View.createResolutionConstraint_(options).constraint; return createResolutionConstraint(options).constraint;
} }
it('works with only maxResolution', function() { it('works with only maxResolution', function() {
@@ -248,7 +248,7 @@ describe('ol.View', function() {
const defaultMaxRes = 156543.03392804097; const defaultMaxRes = 156543.03392804097;
function getConstraint(options) { function getConstraint(options) {
return View.createResolutionConstraint_(options).constraint; return createResolutionConstraint(options).constraint;
} }
it('respects maxResolution over minZoom', function() { it('respects maxResolution over minZoom', function() {
@@ -292,7 +292,7 @@ describe('ol.View', function() {
describe('create rotation constraint', function() { describe('create rotation constraint', function() {
it('gives a correct rotation constraint function', function() { it('gives a correct rotation constraint function', function() {
const options = {}; const options = {};
const fn = View.createRotationConstraint_(options); const fn = createRotationConstraint(options);
expect(fn(0.01, 0)).to.eql(0); expect(fn(0.01, 0)).to.eql(0);
expect(fn(0.15, 0)).to.eql(0.15); expect(fn(0.15, 0)).to.eql(0.15);
}); });