Merge pull request #7894 from tschaub/named-exports

More named exports, fewer static members
This commit is contained in:
Tim Schaub
2018-02-25 13:33:02 -08:00
committed by GitHub
60 changed files with 672 additions and 638 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import LineString from '../src/ol/geom/LineString.js';
import Point from '../src/ol/geom/Point.js'; import Point from '../src/ol/geom/Point.js';
import TileLayer from '../src/ol/layer/Tile.js'; import TileLayer from '../src/ol/layer/Tile.js';
import VectorLayer from '../src/ol/layer/Vector.js'; import VectorLayer from '../src/ol/layer/Vector.js';
import OSM from '../src/ol/source/OSM.js'; import OSM, {ATTRIBUTION} from '../src/ol/source/OSM.js';
import VectorSource from '../src/ol/source/Vector.js'; import VectorSource from '../src/ol/source/Vector.js';
import CircleStyle from '../src/ol/style/Circle.js'; import CircleStyle from '../src/ol/style/Circle.js';
import Fill from '../src/ol/style/Fill.js'; import Fill from '../src/ol/style/Fill.js';
@@ -86,7 +86,7 @@ const map = new Map({
source: new OSM({ source: new OSM({
attributions: [ attributions: [
'All maps © <a href="https://www.opencyclemap.org/">OpenCycleMap</a>', 'All maps © <a href="https://www.opencyclemap.org/">OpenCycleMap</a>',
OSM.ATTRIBUTION ATTRIBUTION
], ],
url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' + url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' +
'?apikey=0e6fc415256d4fbb9b5166a718591d71' '?apikey=0e6fc415256d4fbb9b5166a718591d71'
+3 -3
View File
@@ -2,14 +2,14 @@ import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.js'; import {defaults as defaultControls} from '../src/ol/control.js';
import TileLayer from '../src/ol/layer/Tile.js'; import TileLayer from '../src/ol/layer/Tile.js';
import OSM from '../src/ol/source/OSM.js'; import OSM, {ATTRIBUTION} from '../src/ol/source/OSM.js';
const openCycleMapLayer = new TileLayer({ const openCycleMapLayer = new TileLayer({
source: new OSM({ source: new OSM({
attributions: [ attributions: [
'All maps © <a href="https://www.opencyclemap.org/">OpenCycleMap</a>', 'All maps © <a href="https://www.opencyclemap.org/">OpenCycleMap</a>',
OSM.ATTRIBUTION ATTRIBUTION
], ],
url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' + url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' +
'?apikey=0e6fc415256d4fbb9b5166a718591d71' '?apikey=0e6fc415256d4fbb9b5166a718591d71'
@@ -20,7 +20,7 @@ const openSeaMapLayer = new TileLayer({
source: new OSM({ source: new OSM({
attributions: [ attributions: [
'All maps © <a href="http://www.openseamap.org/">OpenSeaMap</a>', 'All maps © <a href="http://www.openseamap.org/">OpenSeaMap</a>',
OSM.ATTRIBUTION ATTRIBUTION
], ],
opaque: false, opaque: false,
url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png' url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png'
+2 -2
View File
@@ -8,7 +8,7 @@ import {register} from '../src/ol/proj/proj4.js';
import OSM from '../src/ol/source/OSM.js'; import OSM from '../src/ol/source/OSM.js';
import TileImage from '../src/ol/source/TileImage.js'; import TileImage from '../src/ol/source/TileImage.js';
import TileWMS from '../src/ol/source/TileWMS.js'; import TileWMS from '../src/ol/source/TileWMS.js';
import WMTS from '../src/ol/source/WMTS.js'; import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js';
import XYZ from '../src/ol/source/XYZ.js'; import XYZ from '../src/ol/source/XYZ.js';
import TileGrid from '../src/ol/tilegrid/TileGrid.js'; import TileGrid from '../src/ol/tilegrid/TileGrid.js';
import proj4 from 'proj4'; import proj4 from 'proj4';
@@ -104,7 +104,7 @@ fetch(url).then(function(response) {
return response.text(); return response.text();
}).then(function(text) { }).then(function(text) {
const result = parser.read(text); const result = parser.read(text);
const options = WMTS.optionsFromCapabilities(result, { const options = optionsFromCapabilities(result, {
layer: 'OSM_Land_Mask', layer: 'OSM_Land_Mask',
matrixSet: 'EPSG3413_250m' matrixSet: 'EPSG3413_250m'
}); });
+2 -2
View File
@@ -3,7 +3,7 @@ import View from '../src/ol/View.js';
import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js'; import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js';
import {DEVICE_PIXEL_RATIO} from '../src/ol/has.js'; import {DEVICE_PIXEL_RATIO} from '../src/ol/has.js';
import TileLayer from '../src/ol/layer/Tile.js'; import TileLayer from '../src/ol/layer/Tile.js';
import WMTS from '../src/ol/source/WMTS.js'; import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js';
const capabilitiesUrl = 'https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml'; const capabilitiesUrl = 'https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml';
@@ -27,7 +27,7 @@ fetch(capabilitiesUrl).then(function(response) {
return response.text(); return response.text();
}).then(function(text) { }).then(function(text) {
const result = new WMTSCapabilities().read(text); const result = new WMTSCapabilities().read(text);
const options = WMTS.optionsFromCapabilities(result, { const options = optionsFromCapabilities(result, {
layer: layer, layer: layer,
matrixSet: 'google3857', matrixSet: 'google3857',
style: 'normal' style: 'normal'
+2 -2
View File
@@ -3,7 +3,7 @@ import View from '../src/ol/View.js';
import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js'; import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js';
import TileLayer from '../src/ol/layer/Tile.js'; import TileLayer from '../src/ol/layer/Tile.js';
import OSM from '../src/ol/source/OSM.js'; import OSM from '../src/ol/source/OSM.js';
import WMTS from '../src/ol/source/WMTS.js'; import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js';
const parser = new WMTSCapabilities(); const parser = new WMTSCapabilities();
let map; let map;
@@ -12,7 +12,7 @@ fetch('data/WMTSCapabilities.xml').then(function(response) {
return response.text(); return response.text();
}).then(function(text) { }).then(function(text) {
const result = parser.read(text); const result = parser.read(text);
const options = WMTS.optionsFromCapabilities(result, { const options = optionsFromCapabilities(result, {
layer: 'layer-7328', layer: 'layer-7328',
matrixSet: 'EPSG:3857' matrixSet: 'EPSG:3857'
}); });
+4 -4
View File
@@ -5,7 +5,7 @@ import {assert} from './asserts.js';
import {listen, unlisten, unlistenByKey} from './events.js'; import {listen, unlisten, unlistenByKey} from './events.js';
import EventType from './events/EventType.js'; import EventType from './events/EventType.js';
import {inherits} from './index.js'; import {inherits} from './index.js';
import BaseObject from './Object.js'; import BaseObject, {getChangeEventType} from './Object.js';
import Geometry from './geom/Geometry.js'; import Geometry from './geom/Geometry.js';
import Style from './style/Style.js'; import Style from './style/Style.js';
@@ -90,7 +90,7 @@ const Feature = function(opt_geometryOrProperties) {
this.geometryChangeKey_ = null; this.geometryChangeKey_ = null;
listen( listen(
this, BaseObject.getChangeEventType(this.geometryName_), this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this); this.handleGeometryChanged_, this);
if (opt_geometryOrProperties !== undefined) { if (opt_geometryOrProperties !== undefined) {
@@ -266,11 +266,11 @@ Feature.prototype.setId = function(id) {
*/ */
Feature.prototype.setGeometryName = function(name) { Feature.prototype.setGeometryName = function(name) {
unlisten( unlisten(
this, BaseObject.getChangeEventType(this.geometryName_), this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this); this.handleGeometryChanged_, this);
this.geometryName_ = name; this.geometryName_ = name;
listen( listen(
this, BaseObject.getChangeEventType(this.geometryName_), this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this); this.handleGeometryChanged_, this);
this.handleGeometryChanged_(); this.handleGeometryChanged_();
}; };
+3 -3
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from './index.js'; import {inherits} from './index.js';
import GeolocationProperty from './GeolocationProperty.js'; import GeolocationProperty from './GeolocationProperty.js';
import BaseObject from './Object.js'; import BaseObject, {getChangeEventType} from './Object.js';
import {listen} from './events.js'; import {listen} from './events.js';
import EventType from './events/EventType.js'; import EventType from './events/EventType.js';
import {circular as circularPolygon} from './geom/Polygon.js'; import {circular as circularPolygon} from './geom/Polygon.js';
@@ -79,10 +79,10 @@ const Geolocation = function(opt_options) {
this.watchId_ = undefined; this.watchId_ = undefined;
listen( listen(
this, BaseObject.getChangeEventType(GeolocationProperty.PROJECTION), this, getChangeEventType(GeolocationProperty.PROJECTION),
this.handleProjectionChanged_, this); this.handleProjectionChanged_, this);
listen( listen(
this, BaseObject.getChangeEventType(GeolocationProperty.TRACKING), this, getChangeEventType(GeolocationProperty.TRACKING),
this.handleTrackingChanged_, this); this.handleTrackingChanged_, this);
if (options.projection !== undefined) { if (options.projection !== undefined) {
+39 -36
View File
@@ -7,6 +7,40 @@ import Observable from './Observable.js';
import Event from './events/Event.js'; import Event from './events/Event.js';
import {assign} from './obj.js'; import {assign} from './obj.js';
/**
* @classdesc
* Events emitted by {@link ol.Object} instances are instances of this type.
*
* @param {string} type The event type.
* @param {string} key The property name.
* @param {*} oldValue The old value for `key`.
* @extends {ol.events.Event}
* @implements {oli.Object.Event}
* @constructor
*/
const BaseObjectEvent = function(type, key, oldValue) {
Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api
*/
this.key = key;
/**
* The old value. To get the new value use `e.target.get(e.key)` where
* `e` is the event object.
* @type {*}
* @api
*/
this.oldValue = oldValue;
};
inherits(BaseObjectEvent, Event);
/** /**
* @classdesc * @classdesc
* Abstract base class; normally only used for creating subclasses and not * Abstract base class; normally only used for creating subclasses and not
@@ -85,11 +119,11 @@ const changeEventTypeCache = {};
* @param {string} key Key name. * @param {string} key Key name.
* @return {string} Change name. * @return {string} Change name.
*/ */
BaseObject.getChangeEventType = function(key) { export function getChangeEventType(key) {
return changeEventTypeCache.hasOwnProperty(key) ? return changeEventTypeCache.hasOwnProperty(key) ?
changeEventTypeCache[key] : changeEventTypeCache[key] :
(changeEventTypeCache[key] = 'change:' + key); (changeEventTypeCache[key] = 'change:' + key);
}; }
/** /**
@@ -133,10 +167,10 @@ BaseObject.prototype.getProperties = function() {
*/ */
BaseObject.prototype.notify = function(key, oldValue) { BaseObject.prototype.notify = function(key, oldValue) {
let eventType; let eventType;
eventType = BaseObject.getChangeEventType(key); eventType = getChangeEventType(key);
this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue));
eventType = ObjectEventType.PROPERTYCHANGE; eventType = ObjectEventType.PROPERTYCHANGE;
this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue));
}; };
@@ -191,35 +225,4 @@ BaseObject.prototype.unset = function(key, opt_silent) {
}; };
/**
* @classdesc
* Events emitted by {@link ol.Object} instances are instances of this type.
*
* @param {string} type The event type.
* @param {string} key The property name.
* @param {*} oldValue The old value for `key`.
* @extends {ol.events.Event}
* @implements {oli.Object.Event}
* @constructor
*/
BaseObject.Event = function(type, key, oldValue) {
Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api
*/
this.key = key;
/**
* The old value. To get the new value use `e.target.get(e.key)` where
* `e` is the event object.
* @type {*}
* @api
*/
this.oldValue = oldValue;
};
inherits(BaseObject.Event, Event);
export default BaseObject; export default BaseObject;
+6 -6
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from './index.js'; import {inherits} from './index.js';
import MapEventType from './MapEventType.js'; import MapEventType from './MapEventType.js';
import BaseObject from './Object.js'; import BaseObject, {getChangeEventType} from './Object.js';
import OverlayPositioning from './OverlayPositioning.js'; import OverlayPositioning from './OverlayPositioning.js';
import {CLASS_SELECTABLE} from './css.js'; import {CLASS_SELECTABLE} from './css.js';
import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js'; import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js';
@@ -126,23 +126,23 @@ const Overlay = function(options) {
this.mapPostrenderListenerKey = null; this.mapPostrenderListenerKey = null;
listen( listen(
this, BaseObject.getChangeEventType(Property.ELEMENT), this, getChangeEventType(Property.ELEMENT),
this.handleElementChanged, this); this.handleElementChanged, this);
listen( listen(
this, BaseObject.getChangeEventType(Property.MAP), this, getChangeEventType(Property.MAP),
this.handleMapChanged, this); this.handleMapChanged, this);
listen( listen(
this, BaseObject.getChangeEventType(Property.OFFSET), this, getChangeEventType(Property.OFFSET),
this.handleOffsetChanged, this); this.handleOffsetChanged, this);
listen( listen(
this, BaseObject.getChangeEventType(Property.POSITION), this, getChangeEventType(Property.POSITION),
this.handlePositionChanged, this); this.handlePositionChanged, this);
listen( listen(
this, BaseObject.getChangeEventType(Property.POSITIONING), this, getChangeEventType(Property.POSITIONING),
this.handlePositioningChanged, this); this.handlePositioningChanged, this);
if (options.element !== undefined) { if (options.element !== undefined) {
+5 -5
View File
@@ -10,7 +10,7 @@ import MapBrowserEventType from './MapBrowserEventType.js';
import MapEvent from './MapEvent.js'; import MapEvent from './MapEvent.js';
import MapEventType from './MapEventType.js'; import MapEventType from './MapEventType.js';
import MapProperty from './MapProperty.js'; import MapProperty from './MapProperty.js';
import BaseObject from './Object.js'; import BaseObject, {getChangeEventType} from './Object.js';
import ObjectEventType from './ObjectEventType.js'; import ObjectEventType from './ObjectEventType.js';
import TileQueue from './TileQueue.js'; import TileQueue from './TileQueue.js';
import View from './View.js'; import View from './View.js';
@@ -346,13 +346,13 @@ const PluggableMap = function(options) {
this.skippedFeatureUids_ = {}; this.skippedFeatureUids_ = {};
listen( listen(
this, BaseObject.getChangeEventType(MapProperty.LAYERGROUP), this, getChangeEventType(MapProperty.LAYERGROUP),
this.handleLayerGroupChanged_, this); this.handleLayerGroupChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.VIEW), listen(this, getChangeEventType(MapProperty.VIEW),
this.handleViewChanged_, this); this.handleViewChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.SIZE), listen(this, getChangeEventType(MapProperty.SIZE),
this.handleSizeChanged_, this); this.handleSizeChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.TARGET), listen(this, getChangeEventType(MapProperty.TARGET),
this.handleTargetChanged_, this); this.handleTargetChanged_, this);
// setProperties will trigger the rendering of the map if the map // setProperties will trigger the rendering of the map if the map
+2 -2
View File
@@ -5,7 +5,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import {listen} from '../events.js'; import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import Control from '../control/Control.js'; import Control from '../control/Control.js';
import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js'; import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js';
@@ -48,7 +48,7 @@ const MousePosition = function(opt_options) {
}); });
listen(this, listen(this,
BaseObject.getChangeEventType(PROJECTION), getChangeEventType(PROJECTION),
this.handleProjectionChanged_, this); this.handleProjectionChanged_, this);
if (options.coordinateFormat) { if (options.coordinateFormat) {
+3 -3
View File
@@ -6,7 +6,7 @@ import Collection from '../Collection.js';
import PluggableMap from '../PluggableMap.js'; import PluggableMap from '../PluggableMap.js';
import MapEventType from '../MapEventType.js'; import MapEventType from '../MapEventType.js';
import MapProperty from '../MapProperty.js'; import MapProperty from '../MapProperty.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import ObjectEventType from '../ObjectEventType.js'; import ObjectEventType from '../ObjectEventType.js';
import Overlay from '../Overlay.js'; import Overlay from '../Overlay.js';
import OverlayPositioning from '../OverlayPositioning.js'; import OverlayPositioning from '../OverlayPositioning.js';
@@ -270,7 +270,7 @@ OverviewMap.prototype.handleMapPropertyChange_ = function(event) {
*/ */
OverviewMap.prototype.bindView_ = function(view) { OverviewMap.prototype.bindView_ = function(view) {
listen(view, listen(view,
BaseObject.getChangeEventType(ViewProperty.ROTATION), getChangeEventType(ViewProperty.ROTATION),
this.handleRotationChanged_, this); this.handleRotationChanged_, this);
}; };
@@ -282,7 +282,7 @@ OverviewMap.prototype.bindView_ = function(view) {
*/ */
OverviewMap.prototype.unbindView_ = function(view) { OverviewMap.prototype.unbindView_ = function(view) {
unlisten(view, unlisten(view,
BaseObject.getChangeEventType(ViewProperty.ROTATION), getChangeEventType(ViewProperty.ROTATION),
this.handleRotationChanged_, this); this.handleRotationChanged_, this);
}; };
+2 -2
View File
@@ -2,7 +2,7 @@
* @module ol/control/ScaleLine * @module ol/control/ScaleLine
*/ */
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import Control from '../control/Control.js'; import Control from '../control/Control.js';
import ScaleLineUnits from '../control/ScaleLineUnits.js'; import ScaleLineUnits from '../control/ScaleLineUnits.js';
@@ -98,7 +98,7 @@ const ScaleLine = function(opt_options) {
}); });
listen( listen(
this, BaseObject.getChangeEventType(UNITS), this, getChangeEventType(UNITS),
this.handleUnitsChanged_, this); this.handleUnitsChanged_, this);
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
+2 -2
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import Interaction from '../interaction/Interaction.js'; import Interaction, {zoomByDelta} from '../interaction/Interaction.js';
/** /**
* @classdesc * @classdesc
@@ -54,7 +54,7 @@ function handleEvent(mapBrowserEvent) {
const anchor = mapBrowserEvent.coordinate; const anchor = mapBrowserEvent.coordinate;
const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_; const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
const view = map.getView(); const view = map.getView();
Interaction.zoomByDelta(view, delta, anchor, this.duration_); zoomByDelta(view, delta, anchor, this.duration_);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
stopEvent = true; stopEvent = true;
} }
+3 -5
View File
@@ -6,7 +6,7 @@ import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import Interaction from '../interaction/Interaction.js'; import {rotate, rotateWithoutConstraints} from '../interaction/Interaction.js';
import PointerInteraction from '../interaction/Pointer.js'; import PointerInteraction from '../interaction/Pointer.js';
/** /**
@@ -75,8 +75,7 @@ function handleDragEvent(mapBrowserEvent) {
if (this.lastAngle_ !== undefined) { if (this.lastAngle_ !== undefined) {
const delta = theta - this.lastAngle_; const delta = theta - this.lastAngle_;
const rotation = view.getRotation(); const rotation = view.getRotation();
Interaction.rotateWithoutConstraints( rotateWithoutConstraints(view, rotation - delta);
view, rotation - delta);
} }
this.lastAngle_ = theta; this.lastAngle_ = theta;
} }
@@ -96,8 +95,7 @@ function handleUpEvent(mapBrowserEvent) {
const view = map.getView(); const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
const rotation = view.getRotation(); const rotation = view.getRotation();
Interaction.rotate(view, rotation, rotate(view, rotation, undefined, this.duration_);
undefined, this.duration_);
return false; return false;
} }
+5 -7
View File
@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js';
import Interaction from '../interaction/Interaction.js'; import {rotate, rotateWithoutConstraints, zoom, zoomWithoutConstraints} from '../interaction/Interaction.js';
import PointerInteraction from '../interaction/Pointer.js'; import PointerInteraction from '../interaction/Pointer.js';
/** /**
@@ -87,13 +87,12 @@ function handleDragEvent(mapBrowserEvent) {
const view = map.getView(); const view = map.getView();
if (view.getConstraints().rotation !== disable && this.lastAngle_ !== undefined) { if (view.getConstraints().rotation !== disable && this.lastAngle_ !== undefined) {
const angleDelta = theta - this.lastAngle_; const angleDelta = theta - this.lastAngle_;
Interaction.rotateWithoutConstraints( rotateWithoutConstraints(view, view.getRotation() - angleDelta);
view, view.getRotation() - angleDelta);
} }
this.lastAngle_ = theta; this.lastAngle_ = theta;
if (this.lastMagnitude_ !== undefined) { if (this.lastMagnitude_ !== undefined) {
const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
Interaction.zoomWithoutConstraints(view, resolution); zoomWithoutConstraints(view, resolution);
} }
if (this.lastMagnitude_ !== undefined) { if (this.lastMagnitude_ !== undefined) {
this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
@@ -116,9 +115,8 @@ function handleUpEvent(mapBrowserEvent) {
const view = map.getView(); const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
const direction = this.lastScaleDelta_ - 1; const direction = this.lastScaleDelta_ - 1;
Interaction.rotate(view, view.getRotation()); rotate(view, view.getRotation());
Interaction.zoom(view, view.getResolution(), zoom(view, view.getResolution(), undefined, this.duration_, direction);
undefined, this.duration_, direction);
this.lastScaleDelta_ = 0; this.lastScaleDelta_ = 0;
return false; return false;
} }
+2 -2
View File
@@ -6,7 +6,7 @@ import EventType from '../events/EventType.js';
import Feature from '../Feature.js'; import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js'; import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
import {listen} from '../events.js'; import {listen} from '../events.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
@@ -365,7 +365,7 @@ const Draw = function(options) {
} }
listen(this, listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE), getChangeEventType(InteractionProperty.ACTIVE),
this.updateState_, this); this.updateState_, this);
}; };
+16 -18
View File
@@ -108,7 +108,7 @@ Interaction.prototype.setMap = function(map) {
* @param {ol.Coordinate} delta Delta. * @param {ol.Coordinate} delta Delta.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
Interaction.pan = function(view, delta, opt_duration) { export function pan(view, delta, opt_duration) {
const currentCenter = view.getCenter(); const currentCenter = view.getCenter();
if (currentCenter) { if (currentCenter) {
const center = view.constrainCenter( const center = view.constrainCenter(
@@ -123,7 +123,7 @@ Interaction.pan = function(view, delta, opt_duration) {
view.setCenter(center); view.setCenter(center);
} }
} }
}; }
/** /**
@@ -132,11 +132,10 @@ Interaction.pan = function(view, delta, opt_duration) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) { export function rotate(view, rotation, opt_anchor, opt_duration) {
rotation = view.constrainRotation(rotation, 0); rotation = view.constrainRotation(rotation, 0);
Interaction.rotateWithoutConstraints( rotateWithoutConstraints(view, rotation, opt_anchor, opt_duration);
view, rotation, opt_anchor, opt_duration); }
};
/** /**
@@ -145,7 +144,7 @@ Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_duration) { export function rotateWithoutConstraints(view, rotation, opt_anchor, opt_duration) {
if (rotation !== undefined) { if (rotation !== undefined) {
const currentRotation = view.getRotation(); const currentRotation = view.getRotation();
const currentCenter = view.getCenter(); const currentCenter = view.getCenter();
@@ -160,7 +159,7 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_
view.rotate(rotation, opt_anchor); view.rotate(rotation, opt_anchor);
} }
} }
}; }
/** /**
@@ -177,11 +176,10 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_
* will select the nearest resolution. If not defined 0 is * will select the nearest resolution. If not defined 0 is
* assumed. * assumed.
*/ */
Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_direction) { export function zoom(view, resolution, opt_anchor, opt_duration, opt_direction) {
resolution = view.constrainResolution(resolution, 0, opt_direction); resolution = view.constrainResolution(resolution, 0, opt_direction);
Interaction.zoomWithoutConstraints( zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration);
view, resolution, opt_anchor, opt_duration); }
};
/** /**
@@ -190,7 +188,7 @@ Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_dire
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { export function zoomByDelta(view, delta, opt_anchor, opt_duration) {
const currentResolution = view.getResolution(); const currentResolution = view.getResolution();
let resolution = view.constrainResolution(currentResolution, delta, 0); let resolution = view.constrainResolution(currentResolution, delta, 0);
@@ -218,9 +216,8 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
]; ];
} }
Interaction.zoomWithoutConstraints( zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration);
view, resolution, opt_anchor, opt_duration); }
};
/** /**
@@ -229,7 +226,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_duration) { export function zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration) {
if (resolution) { if (resolution) {
const currentResolution = view.getResolution(); const currentResolution = view.getResolution();
const currentCenter = view.getCenter(); const currentCenter = view.getCenter();
@@ -249,5 +246,6 @@ Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_
view.setResolution(resolution); view.setResolution(resolution);
} }
} }
}; }
export default Interaction; export default Interaction;
+2 -2
View File
@@ -6,7 +6,7 @@ import {rotate as rotateCoordinate} from '../coordinate.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import KeyCode from '../events/KeyCode.js'; import KeyCode from '../events/KeyCode.js';
import {noModifierKeys, targetNotEditable} from '../events/condition.js'; import {noModifierKeys, targetNotEditable} from '../events/condition.js';
import Interaction from '../interaction/Interaction.js'; import Interaction, {pan} from '../interaction/Interaction.js';
/** /**
* @classdesc * @classdesc
@@ -100,7 +100,7 @@ function handleEvent(mapBrowserEvent) {
} }
const delta = [deltaX, deltaY]; const delta = [deltaX, deltaY];
rotateCoordinate(delta, view.getRotation()); rotateCoordinate(delta, view.getRotation());
Interaction.pan(view, delta, this.duration_); pan(view, delta, this.duration_);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
stopEvent = true; stopEvent = true;
} }
+2 -3
View File
@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {targetNotEditable} from '../events/condition.js'; import {targetNotEditable} from '../events/condition.js';
import Interaction from '../interaction/Interaction.js'; import Interaction, {zoomByDelta} from '../interaction/Interaction.js';
/** /**
* @classdesc * @classdesc
@@ -73,8 +73,7 @@ function handleEvent(mapBrowserEvent) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_; const delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_;
const view = map.getView(); const view = map.getView();
Interaction.zoomByDelta( zoomByDelta(view, delta, undefined, this.duration_);
view, delta, undefined, this.duration_);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
stopEvent = true; stopEvent = true;
} }
+77 -55
View File
@@ -16,7 +16,6 @@ import {always, primaryAction, altKeyOnly, singleClick} from '../events/conditio
import {boundingExtent, buffer, createOrUpdateFromCoordinate} from '../extent.js'; import {boundingExtent, buffer, createOrUpdateFromCoordinate} from '../extent.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import Point from '../geom/Point.js'; import Point from '../geom/Point.js';
import ModifyEventType from '../interaction/ModifyEventType.js';
import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
import VectorLayer from '../layer/Vector.js'; import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/Vector.js'; import VectorSource from '../source/Vector.js';
@@ -24,6 +23,61 @@ import VectorEventType from '../source/VectorEventType.js';
import RBush from '../structs/RBush.js'; import RBush from '../structs/RBush.js';
import {createEditingStyle} from '../style/Style.js'; import {createEditingStyle} from '../style/Style.js';
/**
* @enum {string}
*/
const ModifyEventType = {
/**
* Triggered upon feature modification start
* @event ModifyEvent#modifystart
* @api
*/
MODIFYSTART: 'modifystart',
/**
* Triggered upon feature modification end
* @event ModifyEvent#modifyend
* @api
*/
MODIFYEND: 'modifyend'
};
/**
* @classdesc
* Events emitted by {@link ol.interaction.Modify} instances are instances of
* this type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.ModifyEvent}
* @param {ModifyEventType} type Type.
* @param {ol.Collection.<ol.Feature>} features The features modified.
* @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated
* {@link ol.MapBrowserPointerEvent}.
*/
export const ModifyEvent = function(type, features, mapBrowserPointerEvent) {
Event.call(this, type);
/**
* The features being modified.
* @type {ol.Collection.<ol.Feature>}
* @api
*/
this.features = features;
/**
* Associated {@link ol.MapBrowserEvent}.
* @type {ol.MapBrowserEvent}
* @api
*/
this.mapBrowserEvent = mapBrowserPointerEvent;
};
inherits(ModifyEvent, Event);
/** /**
* @classdesc * @classdesc
* Interaction for modifying feature geometries. To modify features that have * Interaction for modifying feature geometries. To modify features that have
@@ -40,7 +94,7 @@ import {createEditingStyle} from '../style/Style.js';
* @constructor * @constructor
* @extends {ol.interaction.Pointer} * @extends {ol.interaction.Pointer}
* @param {olx.interaction.ModifyOptions} options Options. * @param {olx.interaction.ModifyOptions} options Options.
* @fires ol.interaction.Modify.Event * @fires ol.interaction.ModifyEvent
* @api * @api
*/ */
const Modify = function(options) { const Modify = function(options) {
@@ -161,7 +215,7 @@ const Modify = function(options) {
wrapX: !!options.wrapX wrapX: !!options.wrapX
}), }),
style: options.style ? options.style : style: options.style ? options.style :
Modify.getDefaultStyleFunction(), getDefaultStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true updateWhileInteracting: true
}); });
@@ -229,16 +283,18 @@ inherits(Modify, PointerInteraction);
/** /**
* @define {number} The segment index assigned to a circle's center when * The segment index assigned to a circle's center when
* breaking up a cicrle into ModifySegmentDataType segments. * breaking up a cicrle into ModifySegmentDataType segments.
* @type {number}
*/ */
Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX = 0; const CIRCLE_CENTER_INDEX = 0;
/** /**
* @define {number} The segment index assigned to a circle's circumference when * The segment index assigned to a circle's circumference when
* breaking up a circle into ModifySegmentDataType segments. * breaking up a circle into ModifySegmentDataType segments.
* @type {number}
*/ */
Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX = 1; const CIRCLE_CIRCUMFERENCE_INDEX = 1;
/** /**
@@ -266,7 +322,7 @@ Modify.prototype.addFeature_ = function(feature) {
Modify.prototype.willModifyFeatures_ = function(evt) { Modify.prototype.willModifyFeatures_ = function(evt) {
if (!this.modified_) { if (!this.modified_) {
this.modified_ = true; this.modified_ = true;
this.dispatchEvent(new Modify.Event( this.dispatchEvent(new ModifyEvent(
ModifyEventType.MODIFYSTART, this.features_, evt)); ModifyEventType.MODIFYSTART, this.features_, evt));
} }
}; };
@@ -525,9 +581,9 @@ Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
/** /**
* We convert a circle into two segments. The segment at index * We convert a circle into two segments. The segment at index
* {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX} is the * {@link CIRCLE_CENTER_INDEX} is the
* circle's center (a point). The segment at index * circle's center (a point). The segment at index
* {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX} is * {@link CIRCLE_CIRCUMFERENCE_INDEX} is
* the circumference, and is not a line segment. * the circumference, and is not a line segment.
* *
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
@@ -539,13 +595,13 @@ Modify.prototype.writeCircleGeometry_ = function(feature, geometry) {
const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({ const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
feature: feature, feature: feature,
geometry: geometry, geometry: geometry,
index: Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX, index: CIRCLE_CENTER_INDEX,
segment: [coordinates, coordinates] segment: [coordinates, coordinates]
}); });
const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({ const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
feature: feature, feature: feature,
geometry: geometry, geometry: geometry,
index: Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX, index: CIRCLE_CIRCUMFERENCE_INDEX,
segment: [coordinates, coordinates] segment: [coordinates, coordinates]
}); });
const featureSegments = [centerSegmentData, circumferenceSegmentData]; const featureSegments = [centerSegmentData, circumferenceSegmentData];
@@ -631,7 +687,7 @@ function handleDownEvent(evt) {
componentSegments[uid] = new Array(2); componentSegments[uid] = new Array(2);
} }
if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE && if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { segmentDataMatch.index === CIRCLE_CIRCUMFERENCE_INDEX) {
const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch); const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch);
if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) { if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) {
@@ -727,7 +783,7 @@ function handleDragEvent(evt) {
break; break;
case GeometryType.CIRCLE: case GeometryType.CIRCLE:
segment[0] = segment[1] = vertex; segment[0] = segment[1] = vertex;
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX) { if (segmentData.index === CIRCLE_CENTER_INDEX) {
this.changingFeature_ = true; this.changingFeature_ = true;
geometry.setCenter(vertex); geometry.setCenter(vertex);
this.changingFeature_ = false; this.changingFeature_ = false;
@@ -775,7 +831,7 @@ function handleUpEvent(evt) {
} }
} }
if (this.modified_) { if (this.modified_) {
this.dispatchEvent(new Modify.Event( this.dispatchEvent(new ModifyEvent(
ModifyEventType.MODIFYEND, this.features_, evt)); ModifyEventType.MODIFYEND, this.features_, evt));
this.modified_ = false; this.modified_ = false;
} }
@@ -856,7 +912,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
const vertexSegments = {}; const vertexSegments = {};
if (node.geometry.getType() === GeometryType.CIRCLE && if (node.geometry.getType() === GeometryType.CIRCLE &&
node.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { node.index === CIRCLE_CIRCUMFERENCE_INDEX) {
this.snappedToVertex_ = true; this.snappedToVertex_ = true;
this.createOrUpdateVertexFeature_(vertex); this.createOrUpdateVertexFeature_(vertex);
@@ -912,7 +968,7 @@ function pointDistanceToSegmentDataSquared(pointCoordinates, segmentData) {
if (geometry.getType() === GeometryType.CIRCLE) { if (geometry.getType() === GeometryType.CIRCLE) {
const circleGeometry = /** @type {ol.geom.Circle} */ (geometry); const circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { if (segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
const distanceToCenterSquared = const distanceToCenterSquared =
squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates); squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates);
const distanceToCircumference = const distanceToCircumference =
@@ -936,7 +992,7 @@ function closestOnSegmentData(pointCoordinates, segmentData) {
const geometry = segmentData.geometry; const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE && if (geometry.getType() === GeometryType.CIRCLE &&
segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
return geometry.getClosestPoint(pointCoordinates); return geometry.getClosestPoint(pointCoordinates);
} }
return closestOnSegment(pointCoordinates, segmentData.segment); return closestOnSegment(pointCoordinates, segmentData.segment);
@@ -1018,7 +1074,7 @@ Modify.prototype.removePoint = function() {
const evt = this.lastPointerEvent_; const evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt); this.willModifyFeatures_(evt);
this.removeVertex_(); this.removeVertex_();
this.dispatchEvent(new Modify.Event(ModifyEventType.MODIFYEND, this.features_, evt)); this.dispatchEvent(new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt));
this.modified_ = false; this.modified_ = false;
return true; return true;
} }
@@ -1179,46 +1235,12 @@ Modify.prototype.updateSegmentIndices_ = function(
/** /**
* @return {ol.StyleFunction} Styles. * @return {ol.StyleFunction} Styles.
*/ */
Modify.getDefaultStyleFunction = function() { function getDefaultStyleFunction() {
const style = createEditingStyle(); const style = createEditingStyle();
return function(feature, resolution) { return function(feature, resolution) {
return style[GeometryType.POINT]; return style[GeometryType.POINT];
}; };
}; }
/**
* @classdesc
* Events emitted by {@link ol.interaction.Modify} instances are instances of
* this type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.ModifyEvent}
* @param {ol.interaction.ModifyEventType} type Type.
* @param {ol.Collection.<ol.Feature>} features The features modified.
* @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated
* {@link ol.MapBrowserPointerEvent}.
*/
Modify.Event = function(type, features, mapBrowserPointerEvent) {
Event.call(this, type);
/**
* The features being modified.
* @type {ol.Collection.<ol.Feature>}
* @api
*/
this.features = features;
/**
* Associated {@link ol.MapBrowserEvent}.
* @type {ol.MapBrowserEvent}
* @api
*/
this.mapBrowserEvent = mapBrowserPointerEvent;
};
inherits(Modify.Event, Event);
export default Modify; export default Modify;
-21
View File
@@ -1,21 +0,0 @@
/**
* @module ol/interaction/ModifyEventType
*/
/**
* @enum {string}
*/
export default {
/**
* Triggered upon feature modification start
* @event ol.interaction.Modify.Event#modifystart
* @api
*/
MODIFYSTART: 'modifystart',
/**
* Triggered upon feature modification end
* @event ol.interaction.Modify.Event#modifyend
* @api
*/
MODIFYEND: 'modifyend'
};
+2 -3
View File
@@ -7,7 +7,7 @@ import {always} from '../events/condition.js';
import {easeOut} from '../easing.js'; import {easeOut} from '../easing.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../has.js'; import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../has.js';
import Interaction from '../interaction/Interaction.js'; import Interaction, {zoomByDelta} from '../interaction/Interaction.js';
import {clamp} from '../math.js'; import {clamp} from '../math.js';
@@ -280,8 +280,7 @@ MouseWheelZoom.prototype.handleWheelZoom_ = function(map) {
} }
const maxDelta = MAX_DELTA; const maxDelta = MAX_DELTA;
const delta = clamp(this.delta_, -maxDelta, maxDelta); const delta = clamp(this.delta_, -maxDelta, maxDelta);
Interaction.zoomByDelta(view, -delta, this.lastAnchor_, zoomByDelta(view, -delta, this.lastAnchor_, this.duration_);
this.duration_);
this.mode_ = undefined; this.mode_ = undefined;
this.delta_ = 0; this.delta_ = 0;
this.lastAnchor_ = null; this.lastAnchor_ = null;
+3 -5
View File
@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import Interaction from '../interaction/Interaction.js'; import {rotate, rotateWithoutConstraints} from '../interaction/Interaction.js';
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';
@@ -114,8 +114,7 @@ function handleDragEvent(mapBrowserEvent) {
if (this.rotating_) { if (this.rotating_) {
const rotation = view.getRotation(); const rotation = view.getRotation();
map.render(); map.render();
Interaction.rotateWithoutConstraints(view, rotateWithoutConstraints(view, rotation + rotationDelta, this.anchor_);
rotation + rotationDelta, this.anchor_);
} }
} }
@@ -132,8 +131,7 @@ function handleUpEvent(mapBrowserEvent) {
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
if (this.rotating_) { if (this.rotating_) {
const rotation = view.getRotation(); const rotation = view.getRotation();
Interaction.rotate( rotate(view, rotation, this.anchor_, this.duration_);
view, rotation, this.anchor_, this.duration_);
} }
return false; return false;
} else { } else {
+3 -4
View File
@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import Interaction from '../interaction/Interaction.js'; import {zoom, zoomWithoutConstraints} from '../interaction/Interaction.js';
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
/** /**
@@ -110,7 +110,7 @@ function handleDragEvent(mapBrowserEvent) {
// scale, bypass the resolution constraint // scale, bypass the resolution constraint
map.render(); map.render();
Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_); zoomWithoutConstraints(view, newResolution, this.anchor_);
} }
@@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) {
// direction not to zoom out/in if user was pinching in/out. // direction not to zoom out/in if user was pinching in/out.
// Direction is > 0 if pinching out, and < 0 if pinching in. // Direction is > 0 if pinching out, and < 0 if pinching in.
const direction = this.lastScaleDelta_ - 1; const direction = this.lastScaleDelta_ - 1;
Interaction.zoom(view, resolution, zoom(view, resolution, this.anchor_, this.duration_, direction);
this.anchor_, this.duration_, direction);
} }
return false; return false;
} else { } else {
+35 -34
View File
@@ -8,6 +8,37 @@ import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import Interaction from '../interaction/Interaction.js'; import Interaction from '../interaction/Interaction.js';
import {getValues} from '../obj.js'; import {getValues} from '../obj.js';
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.Pointer}
*/
const handleDragEvent = nullFunction;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Capture dragging.
* @this {ol.interaction.Pointer}
*/
const handleUpEvent = FALSE;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Capture dragging.
* @this {ol.interaction.Pointer}
*/
const handleDownEvent = FALSE;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.Pointer}
*/
const handleMoveEvent = nullFunction;
/** /**
* @classdesc * @classdesc
* Base class that calls user-defined functions on `down`, `move` and `up` * Base class that calls user-defined functions on `down`, `move` and `up`
@@ -36,28 +67,28 @@ const PointerInteraction = function(opt_options) {
* @private * @private
*/ */
this.handleDownEvent_ = options.handleDownEvent ? this.handleDownEvent_ = options.handleDownEvent ?
options.handleDownEvent : PointerInteraction.handleDownEvent; options.handleDownEvent : handleDownEvent;
/** /**
* @type {function(ol.MapBrowserPointerEvent)} * @type {function(ol.MapBrowserPointerEvent)}
* @private * @private
*/ */
this.handleDragEvent_ = options.handleDragEvent ? this.handleDragEvent_ = options.handleDragEvent ?
options.handleDragEvent : PointerInteraction.handleDragEvent; options.handleDragEvent : handleDragEvent;
/** /**
* @type {function(ol.MapBrowserPointerEvent)} * @type {function(ol.MapBrowserPointerEvent)}
* @private * @private
*/ */
this.handleMoveEvent_ = options.handleMoveEvent ? this.handleMoveEvent_ = options.handleMoveEvent ?
options.handleMoveEvent : PointerInteraction.handleMoveEvent; options.handleMoveEvent : handleMoveEvent;
/** /**
* @type {function(ol.MapBrowserPointerEvent):boolean} * @type {function(ol.MapBrowserPointerEvent):boolean}
* @private * @private
*/ */
this.handleUpEvent_ = options.handleUpEvent ? this.handleUpEvent_ = options.handleUpEvent ?
options.handleUpEvent : PointerInteraction.handleUpEvent; options.handleUpEvent : handleUpEvent;
/** /**
* @type {boolean} * @type {boolean}
@@ -134,36 +165,6 @@ PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent)
}; };
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.Pointer}
*/
PointerInteraction.handleDragEvent = nullFunction;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Capture dragging.
* @this {ol.interaction.Pointer}
*/
PointerInteraction.handleUpEvent = FALSE;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Capture dragging.
* @this {ol.interaction.Pointer}
*/
PointerInteraction.handleDownEvent = FALSE;
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @this {ol.interaction.Pointer}
*/
PointerInteraction.handleMoveEvent = nullFunction;
/** /**
* Handles the {@link ol.MapBrowserEvent map browser event} and may call into * Handles the {@link ol.MapBrowserEvent map browser event} and may call into
* other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are * other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are
+48 -48
View File
@@ -22,13 +22,55 @@ import {createEditingStyle} from '../style/Style.js';
const SelectEventType = { const SelectEventType = {
/** /**
* Triggered when feature(s) has been (de)selected. * Triggered when feature(s) has been (de)selected.
* @event ol.interaction.Select.Event#select * @event SelectEvent#select
* @api * @api
*/ */
SELECT: 'select' SELECT: 'select'
}; };
/**
* @classdesc
* Events emitted by {@link ol.interaction.Select} instances are instances of
* this type.
*
* @param {SelectEventType} type The event type.
* @param {Array.<ol.Feature>} selected Selected features.
* @param {Array.<ol.Feature>} deselected Deselected features.
* @param {ol.MapBrowserEvent} mapBrowserEvent Associated
* {@link ol.MapBrowserEvent}.
* @implements {oli.SelectEvent}
* @extends {ol.events.Event}
* @constructor
*/
const SelectEvent = function(type, selected, deselected, mapBrowserEvent) {
Event.call(this, type);
/**
* Selected features array.
* @type {Array.<ol.Feature>}
* @api
*/
this.selected = selected;
/**
* Deselected features array.
* @type {Array.<ol.Feature>}
* @api
*/
this.deselected = deselected;
/**
* Associated {@link ol.MapBrowserEvent}.
* @type {ol.MapBrowserEvent}
* @api
*/
this.mapBrowserEvent = mapBrowserEvent;
};
inherits(SelectEvent, Event);
/** /**
* @classdesc * @classdesc
* Interaction for selecting vector features. By default, selected features are * Interaction for selecting vector features. By default, selected features are
@@ -44,7 +86,7 @@ const SelectEventType = {
* @constructor * @constructor
* @extends {ol.interaction.Interaction} * @extends {ol.interaction.Interaction}
* @param {olx.interaction.SelectOptions=} opt_options Options. * @param {olx.interaction.SelectOptions=} opt_options Options.
* @fires ol.interaction.Select.Event * @fires SelectEvent
* @api * @api
*/ */
const Select = function(opt_options) { const Select = function(opt_options) {
@@ -104,7 +146,7 @@ const Select = function(opt_options) {
wrapX: options.wrapX wrapX: options.wrapX
}), }),
style: options.style ? options.style : style: options.style ? options.style :
Select.getDefaultStyleFunction(), getDefaultStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true updateWhileInteracting: true
}); });
@@ -289,7 +331,7 @@ function handleEvent(mapBrowserEvent) {
} }
if (selected.length > 0 || deselected.length > 0) { if (selected.length > 0 || deselected.length > 0) {
this.dispatchEvent( this.dispatchEvent(
new Select.Event(SelectEventType.SELECT, new SelectEvent(SelectEventType.SELECT,
selected, deselected, mapBrowserEvent)); selected, deselected, mapBrowserEvent));
} }
return pointerMove(mapBrowserEvent); return pointerMove(mapBrowserEvent);
@@ -333,7 +375,7 @@ Select.prototype.setMap = function(map) {
/** /**
* @return {ol.StyleFunction} Styles. * @return {ol.StyleFunction} Styles.
*/ */
Select.getDefaultStyleFunction = function() { function getDefaultStyleFunction() {
const styles = createEditingStyle(); const styles = createEditingStyle();
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]); extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]); extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]);
@@ -344,7 +386,7 @@ Select.getDefaultStyleFunction = function() {
} }
return styles[feature.getGeometry().getType()]; return styles[feature.getGeometry().getType()];
}; };
}; }
/** /**
@@ -381,46 +423,4 @@ Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
}; };
/**
* @classdesc
* Events emitted by {@link ol.interaction.Select} instances are instances of
* this type.
*
* @param {ol.interaction.SelectEventType} type The event type.
* @param {Array.<ol.Feature>} selected Selected features.
* @param {Array.<ol.Feature>} deselected Deselected features.
* @param {ol.MapBrowserEvent} mapBrowserEvent Associated
* {@link ol.MapBrowserEvent}.
* @implements {oli.SelectEvent}
* @extends {ol.events.Event}
* @constructor
*/
Select.Event = function(type, selected, deselected, mapBrowserEvent) {
Event.call(this, type);
/**
* Selected features array.
* @type {Array.<ol.Feature>}
* @api
*/
this.selected = selected;
/**
* Deselected features array.
* @type {Array.<ol.Feature>}
* @api
*/
this.deselected = deselected;
/**
* Associated {@link ol.MapBrowserEvent}.
* @type {ol.MapBrowserEvent}
* @api
*/
this.mapBrowserEvent = mapBrowserEvent;
};
inherits(Select.Event, Event);
export default Select; export default Select;
+9 -10
View File
@@ -13,7 +13,7 @@ import GeometryType from '../geom/GeometryType.js';
import {fromCircle} from '../geom/Polygon.js'; import {fromCircle} from '../geom/Polygon.js';
import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
import {getValues} from '../obj.js'; import {getValues} from '../obj.js';
import VectorSource from '../source/Vector.js'; import {VectorSourceEvent} from '../source/Vector.js';
import VectorEventType from '../source/VectorEventType.js'; import VectorEventType from '../source/VectorEventType.js';
import RBush from '../structs/RBush.js'; import RBush from '../structs/RBush.js';
@@ -120,7 +120,7 @@ const Snap = function(opt_options) {
* @type {function(ol.SnapSegmentDataType, ol.SnapSegmentDataType): number} * @type {function(ol.SnapSegmentDataType, ol.SnapSegmentDataType): number}
* @private * @private
*/ */
this.sortByDistance_ = Snap.sortByDistance.bind(this); this.sortByDistance_ = sortByDistance.bind(this);
/** /**
@@ -219,7 +219,7 @@ Snap.prototype.getFeatures_ = function() {
*/ */
Snap.prototype.handleFeatureAdd_ = function(evt) { Snap.prototype.handleFeatureAdd_ = function(evt) {
let feature; let feature;
if (evt instanceof VectorSource.Event) { if (evt instanceof VectorSourceEvent) {
feature = evt.feature; feature = evt.feature;
} else if (evt instanceof CollectionEvent) { } else if (evt instanceof CollectionEvent) {
feature = evt.element; feature = evt.element;
@@ -234,7 +234,7 @@ Snap.prototype.handleFeatureAdd_ = function(evt) {
*/ */
Snap.prototype.handleFeatureRemove_ = function(evt) { Snap.prototype.handleFeatureRemove_ = function(evt) {
let feature; let feature;
if (evt instanceof VectorSource.Event) { if (evt instanceof VectorSourceEvent) {
feature = evt.feature; feature = evt.feature;
} else if (evt instanceof CollectionEvent) { } else if (evt instanceof CollectionEvent) {
feature = evt.element; feature = evt.element;
@@ -616,11 +616,10 @@ function handleUpEvent(evt) {
* @return {number} The difference in distance. * @return {number} The difference in distance.
* @this {ol.interaction.Snap} * @this {ol.interaction.Snap}
*/ */
Snap.sortByDistance = function(a, b) { function sortByDistance(a, b) {
return squaredDistanceToSegment( const deltaA = squaredDistanceToSegment(this.pixelCoordinate_, a.segment);
this.pixelCoordinate_, a.segment) - const deltaB = squaredDistanceToSegment(this.pixelCoordinate_, b.segment);
squaredDistanceToSegment( return deltaA - deltaB;
this.pixelCoordinate_, b.segment); }
};
export default Snap; export default Snap;
+67 -41
View File
@@ -3,14 +3,74 @@
*/ */
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import Collection from '../Collection.js'; import Collection from '../Collection.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import {listen} from '../events.js'; import {listen} from '../events.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
import {TRUE} from '../functions.js'; import {TRUE} from '../functions.js';
import {includes} from '../array.js'; import {includes} from '../array.js';
import PointerInteraction from '../interaction/Pointer.js'; import PointerInteraction from '../interaction/Pointer.js';
import InteractionProperty from '../interaction/Property.js'; import InteractionProperty from '../interaction/Property.js';
import TranslateEventType from '../interaction/TranslateEventType.js';
/**
* @enum {string}
*/
const TranslateEventType = {
/**
* Triggered upon feature translation start.
* @event TranslateEvent#translatestart
* @api
*/
TRANSLATESTART: 'translatestart',
/**
* Triggered upon feature translation.
* @event TranslateEvent#translating
* @api
*/
TRANSLATING: 'translating',
/**
* Triggered upon feature translation end.
* @event TranslateEvent#translateend
* @api
*/
TRANSLATEEND: 'translateend'
};
/**
* @classdesc
* Events emitted by {@link ol.interaction.Translate} instances are instances of
* this type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.interaction.TranslateEvent}
* @param {ol.interaction.TranslateEventType} type Type.
* @param {ol.Collection.<ol.Feature>} features The features translated.
* @param {ol.Coordinate} coordinate The event coordinate.
*/
export const TranslateEvent = function(type, features, coordinate) {
Event.call(this, type);
/**
* The features being translated.
* @type {ol.Collection.<ol.Feature>}
* @api
*/
this.features = features;
/**
* The coordinate of the drag event.
* @const
* @type {ol.Coordinate}
* @api
*/
this.coordinate = coordinate;
};
inherits(TranslateEvent, Event);
/** /**
* @classdesc * @classdesc
@@ -18,7 +78,7 @@ import TranslateEventType from '../interaction/TranslateEventType.js';
* *
* @constructor * @constructor
* @extends {ol.interaction.Pointer} * @extends {ol.interaction.Pointer}
* @fires ol.interaction.Translate.Event * @fires ol.interaction.TranslateEvent
* @param {olx.interaction.TranslateOptions=} opt_options Options. * @param {olx.interaction.TranslateOptions=} opt_options Options.
* @api * @api
*/ */
@@ -80,7 +140,7 @@ const Translate = function(opt_options) {
this.lastFeature_ = null; this.lastFeature_ = null;
listen(this, listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE), getChangeEventType(InteractionProperty.ACTIVE),
this.handleActiveChanged_, this); this.handleActiveChanged_, this);
}; };
@@ -102,7 +162,7 @@ function handleDownEvent(event) {
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent( this.dispatchEvent(
new Translate.Event( new TranslateEvent(
TranslateEventType.TRANSLATESTART, features, TranslateEventType.TRANSLATESTART, features,
event.coordinate)); event.coordinate));
return true; return true;
@@ -124,7 +184,7 @@ function handleUpEvent(event) {
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent( this.dispatchEvent(
new Translate.Event( new TranslateEvent(
TranslateEventType.TRANSLATEEND, features, TranslateEventType.TRANSLATEEND, features,
event.coordinate)); event.coordinate));
return true; return true;
@@ -153,7 +213,7 @@ function handleDragEvent(event) {
this.lastCoordinate_ = newCoordinate; this.lastCoordinate_ = newCoordinate;
this.dispatchEvent( this.dispatchEvent(
new Translate.Event( new TranslateEvent(
TranslateEventType.TRANSLATING, features, TranslateEventType.TRANSLATING, features,
newCoordinate)); newCoordinate));
} }
@@ -257,38 +317,4 @@ Translate.prototype.updateState_ = function(oldMap) {
}; };
/**
* @classdesc
* Events emitted by {@link ol.interaction.Translate} instances are instances of
* this type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.interaction.TranslateEvent}
* @param {ol.interaction.TranslateEventType} type Type.
* @param {ol.Collection.<ol.Feature>} features The features translated.
* @param {ol.Coordinate} coordinate The event coordinate.
*/
Translate.Event = function(type, features, coordinate) {
Event.call(this, type);
/**
* The features being translated.
* @type {ol.Collection.<ol.Feature>}
* @api
*/
this.features = features;
/**
* The coordinate of the drag event.
* @const
* @type {ol.Coordinate}
* @api
*/
this.coordinate = coordinate;
};
inherits(Translate.Event, Event);
export default Translate; export default Translate;
-27
View File
@@ -1,27 +0,0 @@
/**
* @module ol/interaction/TranslateEventType
*/
/**
* @enum {string}
*/
export default {
/**
* Triggered upon feature translation start.
* @event ol.interaction.Translate.Event#translatestart
* @api
*/
TRANSLATESTART: 'translatestart',
/**
* Triggered upon feature translation.
* @event ol.interaction.Translate.Event#translating
* @api
*/
TRANSLATING: 'translating',
/**
* Triggered upon feature translation end.
* @event ol.interaction.Translate.Event#translateend
* @api
*/
TRANSLATEEND: 'translateend'
};
+2 -2
View File
@@ -4,7 +4,7 @@
import {getUid, inherits} from '../index.js'; import {getUid, inherits} from '../index.js';
import Collection from '../Collection.js'; import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js'; import CollectionEventType from '../CollectionEventType.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import ObjectEventType from '../ObjectEventType.js'; import ObjectEventType from '../ObjectEventType.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import {listen, unlistenByKey} from '../events.js'; import {listen, unlistenByKey} from '../events.js';
@@ -58,7 +58,7 @@ const LayerGroup = function(opt_options) {
this.listenerKeys_ = {}; this.listenerKeys_ = {};
listen(this, listen(this,
BaseObject.getChangeEventType(Property.LAYERS), getChangeEventType(Property.LAYERS),
this.handleLayersChanged_, this); this.handleLayersChanged_, this);
if (layers) { if (layers) {
+4 -4
View File
@@ -3,7 +3,7 @@
*/ */
import {listen} from '../events.js'; import {listen} from '../events.js';
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import {createCanvasContext2D} from '../dom.js'; import {createCanvasContext2D} from '../dom.js';
import VectorLayer from '../layer/Vector.js'; import VectorLayer from '../layer/Vector.js';
import {clamp} from '../math.js'; import {clamp} from '../math.js';
@@ -81,7 +81,7 @@ const Heatmap = function(opt_options) {
this.styleCache_ = null; this.styleCache_ = null;
listen(this, listen(this,
BaseObject.getChangeEventType(Property.GRADIENT), getChangeEventType(Property.GRADIENT),
this.handleGradientChanged_, this); this.handleGradientChanged_, this);
this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT); this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT);
@@ -91,10 +91,10 @@ const Heatmap = function(opt_options) {
this.setRadius(options.radius !== undefined ? options.radius : 8); this.setRadius(options.radius !== undefined ? options.radius : 8);
listen(this, listen(this,
BaseObject.getChangeEventType(Property.BLUR), getChangeEventType(Property.BLUR),
this.handleStyleChanged_, this); this.handleStyleChanged_, this);
listen(this, listen(this,
BaseObject.getChangeEventType(Property.RADIUS), getChangeEventType(Property.RADIUS),
this.handleStyleChanged_, this); this.handleStyleChanged_, this);
this.handleStyleChanged_(); this.handleStyleChanged_();
+2 -2
View File
@@ -4,7 +4,7 @@
import {listen, unlistenByKey} from '../events.js'; import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {getUid, inherits} from '../index.js'; import {getUid, inherits} from '../index.js';
import BaseObject from '../Object.js'; import {getChangeEventType} from '../Object.js';
import BaseLayer from '../layer/Base.js'; import BaseLayer from '../layer/Base.js';
import LayerProperty from '../layer/Property.js'; import LayerProperty from '../layer/Property.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
@@ -63,7 +63,7 @@ const Layer = function(options) {
} }
listen(this, listen(this,
BaseObject.getChangeEventType(LayerProperty.SOURCE), getChangeEventType(LayerProperty.SOURCE),
this.handleSourcePropertyChange_, this); this.handleSourcePropertyChange_, this);
const source = options.source ? options.source : null; const source = options.source ? options.source : null;
+3 -3
View File
@@ -7,7 +7,7 @@ import {modulo} from './math.js';
import {toEPSG4326, fromEPSG4326, PROJECTIONS as EPSG3857_PROJECTIONS} from './proj/epsg3857.js'; import {toEPSG4326, fromEPSG4326, PROJECTIONS as EPSG3857_PROJECTIONS} from './proj/epsg3857.js';
import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js'; import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js';
import Projection from './proj/Projection.js'; import Projection from './proj/Projection.js';
import Units from './proj/Units.js'; import Units, {METERS_PER_UNIT} from './proj/Units.js';
import * as projections from './proj/projections.js'; import * as projections from './proj/projections.js';
import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransformFunc} from './proj/transforms.js'; import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransformFunc} from './proj/transforms.js';
@@ -18,7 +18,7 @@ import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransfo
* @type {Object.<ol.proj.Units, number>} * @type {Object.<ol.proj.Units, number>}
* @api * @api
*/ */
export const METERS_PER_UNIT = Units.METERS_PER_UNIT; export {METERS_PER_UNIT};
/** /**
@@ -147,7 +147,7 @@ export function getPointResolution(projection, resolution, point, opt_units) {
const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8)); const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8));
pointResolution = (width + height) / 2; pointResolution = (width + height) / 2;
const metersPerUnit = opt_units ? const metersPerUnit = opt_units ?
Units.METERS_PER_UNIT[opt_units] : METERS_PER_UNIT[opt_units] :
projection.getMetersPerUnit(); projection.getMetersPerUnit();
if (metersPerUnit !== undefined) { if (metersPerUnit !== undefined) {
pointResolution /= metersPerUnit; pointResolution /= metersPerUnit;
+2 -2
View File
@@ -1,7 +1,7 @@
/** /**
* @module ol/proj/Projection * @module ol/proj/Projection
*/ */
import Units from '../proj/Units.js'; import {METERS_PER_UNIT} from '../proj/Units.js';
/** /**
* @classdesc * @classdesc
@@ -153,7 +153,7 @@ Projection.prototype.getUnits = function() {
* @api * @api
*/ */
Projection.prototype.getMetersPerUnit = function() { Projection.prototype.getMetersPerUnit = function() {
return this.metersPerUnit_ || Units.METERS_PER_UNIT[this.units_]; return this.metersPerUnit_ || METERS_PER_UNIT[this.units_];
}; };
+7 -6
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/proj/Units * @module ol/proj/Units
*/ */
/** /**
* Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or * Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or
* `'us-ft'`. * `'us-ft'`.
@@ -22,11 +23,11 @@ const Units = {
* @type {Object.<ol.proj.Units, number>} * @type {Object.<ol.proj.Units, number>}
* @api * @api
*/ */
Units.METERS_PER_UNIT = {}; export const METERS_PER_UNIT = {};
// use the radius of the Normal sphere // use the radius of the Normal sphere
Units.METERS_PER_UNIT[Units.DEGREES] = METERS_PER_UNIT[Units.DEGREES] = 2 * Math.PI * 6370997 / 360;
2 * Math.PI * 6370997 / 360; METERS_PER_UNIT[Units.FEET] = 0.3048;
Units.METERS_PER_UNIT[Units.FEET] = 0.3048; METERS_PER_UNIT[Units.METERS] = 1;
Units.METERS_PER_UNIT[Units.METERS] = 1; METERS_PER_UNIT[Units.USFEET] = 1200 / 3937;
Units.METERS_PER_UNIT[Units.USFEET] = 1200 / 3937;
export default Units; export default Units;
+2 -3
View File
@@ -83,9 +83,8 @@ inherits(BingMaps, TileImage);
* Terms Of Use. * Terms Of Use.
* @const * @const
* @type {string} * @type {string}
* @api
*/ */
BingMaps.TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' + const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html">' + 'href="https://www.microsoft.com/maps/product/terms.html">' +
'Terms of Use</a>'; 'Terms of Use</a>';
@@ -197,7 +196,7 @@ BingMaps.prototype.handleImageryMetadataResponse = function(response) {
} }
}); });
attributions.push(BingMaps.TOS_ATTRIBUTION); attributions.push(TOS_ATTRIBUTION);
return attributions; return attributions;
}); });
} }
+31 -31
View File
@@ -41,6 +41,32 @@ const ImageSourceEventType = {
}; };
/**
* @classdesc
* Events emitted by {@link ol.source.Image} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.ImageEvent}
* @param {string} type Type.
* @param {ol.Image} image The image.
*/
const ImageSourceEvent = function(type, image) {
Event.call(this, type);
/**
* The image related to the event.
* @type {ol.Image}
* @api
*/
this.image = image;
};
inherits(ImageSourceEvent, Event);
/** /**
* @classdesc * @classdesc
* Abstract base class; normally only used for creating subclasses and not * Abstract base class; normally only used for creating subclasses and not
@@ -174,17 +200,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(ImageSourceEventType.IMAGELOADSTART, new ImageSourceEvent(ImageSourceEventType.IMAGELOADSTART,
image)); image));
break; break;
case ImageState.LOADED: case ImageState.LOADED:
this.dispatchEvent( this.dispatchEvent(
new ImageSource.Event(ImageSourceEventType.IMAGELOADEND, new ImageSourceEvent(ImageSourceEventType.IMAGELOADEND,
image)); image));
break; break;
case ImageState.ERROR: case ImageState.ERROR:
this.dispatchEvent( this.dispatchEvent(
new ImageSource.Event(ImageSourceEventType.IMAGELOADERROR, new ImageSourceEvent(ImageSourceEventType.IMAGELOADERROR,
image)); image));
break; break;
default: default:
@@ -199,35 +225,9 @@ ImageSource.prototype.handleImageChange = function(event) {
* @param {ol.Image} image Image. * @param {ol.Image} image Image.
* @param {string} src Source. * @param {string} src Source.
*/ */
ImageSource.defaultImageLoadFunction = function(image, src) { export function defaultImageLoadFunction(image, src) {
image.getImage().src = src; image.getImage().src = src;
}; }
/**
* @classdesc
* Events emitted by {@link ol.source.Image} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.ImageEvent}
* @param {string} type Type.
* @param {ol.Image} image The image.
*/
ImageSource.Event = function(type, image) {
Event.call(this, type);
/**
* The image related to the event.
* @type {ol.Image}
* @api
*/
this.image = image;
};
inherits(ImageSource.Event, Event);
export default ImageSource; export default ImageSource;
+2 -2
View File
@@ -8,7 +8,7 @@ import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {containsExtent, getHeight, getWidth} from '../extent.js'; import {containsExtent, getHeight, getWidth} from '../extent.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import ImageSource from '../source/Image.js'; import ImageSource, {defaultImageLoadFunction} from '../source/Image.js';
import {appendParams} from '../uri.js'; import {appendParams} from '../uri.js';
/** /**
@@ -60,7 +60,7 @@ const ImageArcGISRest = function(opt_options) {
* @type {ol.ImageLoadFunctionType} * @type {ol.ImageLoadFunctionType}
*/ */
this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
options.imageLoadFunction : ImageSource.defaultImageLoadFunction; options.imageLoadFunction : defaultImageLoadFunction;
/** /**
+5 -5
View File
@@ -7,7 +7,7 @@ import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js'; import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import ImageSource from '../source/Image.js'; import ImageSource, {defaultImageLoadFunction} from '../source/Image.js';
import {appendParams} from '../uri.js'; import {appendParams} from '../uri.js';
/** /**
@@ -58,7 +58,7 @@ const ImageMapGuide = function(options) {
* @type {ol.ImageLoadFunctionType} * @type {ol.ImageLoadFunctionType}
*/ */
this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
options.imageLoadFunction : ImageSource.defaultImageLoadFunction; options.imageLoadFunction : defaultImageLoadFunction;
/** /**
* @private * @private
@@ -173,7 +173,7 @@ ImageMapGuide.prototype.getImageLoadFunction = function() {
* @param {number} dpi The display resolution. * @param {number} dpi The display resolution.
* @return {number} The computed map scale. * @return {number} The computed map scale.
*/ */
ImageMapGuide.getScale = function(extent, size, metersPerUnit, dpi) { function getScale(extent, size, metersPerUnit, dpi) {
const mcsW = getWidth(extent); const mcsW = getWidth(extent);
const mcsH = getHeight(extent); const mcsH = getHeight(extent);
const devW = size[0]; const devW = size[0];
@@ -184,7 +184,7 @@ ImageMapGuide.getScale = function(extent, size, metersPerUnit, dpi) {
} else { } else {
return mcsH * metersPerUnit / (devH * mpp); // height limited return mcsH * metersPerUnit / (devH * mpp); // height limited
} }
}; }
/** /**
@@ -207,7 +207,7 @@ ImageMapGuide.prototype.updateParams = function(params) {
* @return {string} The mapagent map image request URL. * @return {string} The mapagent map image request URL.
*/ */
ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, projection) { ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, projection) {
const scale = ImageMapGuide.getScale(extent, size, const scale = getScale(extent, size,
this.metersPerUnit_, this.displayDpi_); this.metersPerUnit_, this.displayDpi_);
const center = getCenter(extent); const center = getCenter(extent);
const baseParams = { const baseParams = {
+2 -2
View File
@@ -9,7 +9,7 @@ import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {intersects, getHeight, getWidth} from '../extent.js'; import {intersects, getHeight, getWidth} from '../extent.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
import ImageSource from '../source/Image.js'; import ImageSource, {defaultImageLoadFunction} from '../source/Image.js';
/** /**
* @classdesc * @classdesc
@@ -28,7 +28,7 @@ const Static = function(options) {
const /** @type {ol.ImageLoadFunctionType} */ imageLoadFunction = const /** @type {ol.ImageLoadFunctionType} */ imageLoadFunction =
options.imageLoadFunction !== undefined ? options.imageLoadFunction !== undefined ?
options.imageLoadFunction : ImageSource.defaultImageLoadFunction; options.imageLoadFunction : defaultImageLoadFunction;
ImageSource.call(this, { ImageSource.call(this, {
attributions: options.attributions, attributions: options.attributions,
+2 -2
View File
@@ -12,7 +12,7 @@ import {containsExtent, getCenter, getForViewAndSize, getHeight, getWidth} from
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection, transform} from '../proj.js'; import {get as getProjection, transform} from '../proj.js';
import {calculateSourceResolution} from '../reproj.js'; import {calculateSourceResolution} from '../reproj.js';
import ImageSource from '../source/Image.js'; import ImageSource, {defaultImageLoadFunction} from '../source/Image.js';
import WMSServerType from '../source/WMSServerType.js'; import WMSServerType from '../source/WMSServerType.js';
import {compareVersions} from '../string.js'; import {compareVersions} from '../string.js';
import {appendParams} from '../uri.js'; import {appendParams} from '../uri.js';
@@ -55,7 +55,7 @@ const ImageWMS = function(opt_options) {
* @type {ol.ImageLoadFunctionType} * @type {ol.ImageLoadFunctionType}
*/ */
this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
options.imageLoadFunction : ImageSource.defaultImageLoadFunction; options.imageLoadFunction : defaultImageLoadFunction;
/** /**
* @private * @private
+14 -12
View File
@@ -4,6 +4,19 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import XYZ from '../source/XYZ.js'; import XYZ from '../source/XYZ.js';
/**
* The attribution containing a link to the OpenStreetMap Copyright and License
* page.
* @const
* @type {string}
* @api
*/
export const ATTRIBUTION = '&copy; ' +
'<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> ' +
'contributors.';
/** /**
* @classdesc * @classdesc
* Layer source for the OpenStreetMap tile server. * Layer source for the OpenStreetMap tile server.
@@ -21,7 +34,7 @@ const OSM = function(opt_options) {
if (options.attributions !== undefined) { if (options.attributions !== undefined) {
attributions = options.attributions; attributions = options.attributions;
} else { } else {
attributions = [OSM.ATTRIBUTION]; attributions = [ATTRIBUTION];
} }
const crossOrigin = options.crossOrigin !== undefined ? const crossOrigin = options.crossOrigin !== undefined ?
@@ -46,15 +59,4 @@ const OSM = function(opt_options) {
inherits(OSM, XYZ); inherits(OSM, XYZ);
/**
* The attribution containing a link to the OpenStreetMap Copyright and License
* page.
* @const
* @type {string}
* @api
*/
OSM.ATTRIBUTION = '&copy; ' +
'<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> ' +
'contributors.';
export default OSM; export default OSM;
+43 -43
View File
@@ -42,6 +42,47 @@ const RasterEventType = {
}; };
/**
* @classdesc
* Events emitted by {@link ol.source.Raster} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.RasterEvent}
* @param {string} type Type.
* @param {olx.FrameState} frameState The frame state.
* @param {Object} data An object made available to operations.
*/
const RasterSourceEvent = function(type, frameState, data) {
Event.call(this, type);
/**
* The raster extent.
* @type {ol.Extent}
* @api
*/
this.extent = frameState.extent;
/**
* The pixel resolution (map units per pixel).
* @type {number}
* @api
*/
this.resolution = frameState.viewState.resolution / frameState.pixelRatio;
/**
* An object made available to all operations. This can be used by operations
* as a storage object (e.g. for calculating statistics).
* @type {Object}
* @api
*/
this.data = data;
};
inherits(RasterSourceEvent, Event);
/** /**
* @classdesc * @classdesc
* A source that transforms data from any number of input sources using an * A source that transforms data from any number of input sources using an
@@ -282,7 +323,7 @@ RasterSource.prototype.processSources_ = function() {
} }
const data = {}; const data = {};
this.dispatchEvent(new RasterSource.Event(RasterEventType.BEFOREOPERATIONS, frameState, data)); this.dispatchEvent(new RasterSourceEvent(RasterEventType.BEFOREOPERATIONS, frameState, data));
this.worker_.process(imageDatas, data, this.onWorkerComplete_.bind(this, frameState)); this.worker_.process(imageDatas, data, this.onWorkerComplete_.bind(this, frameState));
}; };
@@ -322,7 +363,7 @@ RasterSource.prototype.onWorkerComplete_ = function(frameState, err, output, dat
this.changed(); this.changed();
this.renderedRevision_ = this.getRevision(); this.renderedRevision_ = this.getRevision();
this.dispatchEvent(new RasterSource.Event(RasterEventType.AFTEROPERATIONS, frameState, data)); this.dispatchEvent(new RasterSourceEvent(RasterEventType.AFTEROPERATIONS, frameState, data));
}; };
@@ -427,47 +468,6 @@ function createTileRenderer(source) {
} }
/**
* @classdesc
* Events emitted by {@link ol.source.Raster} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.RasterEvent}
* @param {string} type Type.
* @param {olx.FrameState} frameState The frame state.
* @param {Object} data An object made available to operations.
*/
RasterSource.Event = function(type, frameState, data) {
Event.call(this, type);
/**
* The raster extent.
* @type {ol.Extent}
* @api
*/
this.extent = frameState.extent;
/**
* The pixel resolution (map units per pixel).
* @type {number}
* @api
*/
this.resolution = frameState.viewState.resolution / frameState.pixelRatio;
/**
* An object made available to all operations. This can be used by operations
* as a storage object (e.g. for calculating statistics).
* @type {Object}
* @api
*/
this.data = data;
};
inherits(RasterSource.Event, Event);
/** /**
* @override * @override
*/ */
+45 -41
View File
@@ -2,61 +2,26 @@
* @module ol/source/Stamen * @module ol/source/Stamen
*/ */
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import OSM from '../source/OSM.js'; import {ATTRIBUTION as OSM_ATTRIBUTION} from '../source/OSM.js';
import XYZ from '../source/XYZ.js'; import XYZ from '../source/XYZ.js';
/**
* @classdesc
* Layer source for the Stamen tile server.
*
* @constructor
* @extends {ol.source.XYZ}
* @param {olx.source.StamenOptions} options Stamen options.
* @api
*/
const Stamen = function(options) {
const i = options.layer.indexOf('-');
const provider = i == -1 ? options.layer : options.layer.slice(0, i);
const providerConfig = Stamen.ProviderConfig[provider];
const layerConfig = Stamen.LayerConfig[options.layer];
const url = options.url !== undefined ? options.url :
'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
'/{z}/{x}/{y}.' + layerConfig.extension;
XYZ.call(this, {
attributions: Stamen.ATTRIBUTIONS,
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom,
minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom,
opaque: layerConfig.opaque,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
};
inherits(Stamen, XYZ);
/** /**
* @const * @const
* @type {Array.<string>} * @type {Array.<string>}
*/ */
Stamen.ATTRIBUTIONS = [ const ATTRIBUTIONS = [
'Map tiles by <a href="https://stamen.com/">Stamen Design</a>, ' + 'Map tiles by <a href="https://stamen.com/">Stamen Design</a>, ' +
'under <a href="https://creativecommons.org/licenses/by/3.0/">CC BY' + 'under <a href="https://creativecommons.org/licenses/by/3.0/">CC BY' +
' 3.0</a>.', ' 3.0</a>.',
OSM.ATTRIBUTION OSM_ATTRIBUTION
]; ];
/** /**
* @type {Object.<string, {extension: string, opaque: boolean}>} * @type {Object.<string, {extension: string, opaque: boolean}>}
*/ */
Stamen.LayerConfig = { const LayerConfig = {
'terrain': { 'terrain': {
extension: 'jpg', extension: 'jpg',
opaque: true opaque: true
@@ -103,10 +68,11 @@ Stamen.LayerConfig = {
} }
}; };
/** /**
* @type {Object.<string, {minZoom: number, maxZoom: number}>} * @type {Object.<string, {minZoom: number, maxZoom: number}>}
*/ */
Stamen.ProviderConfig = { const ProviderConfig = {
'terrain': { 'terrain': {
minZoom: 4, minZoom: 4,
maxZoom: 18 maxZoom: 18
@@ -120,4 +86,42 @@ Stamen.ProviderConfig = {
maxZoom: 16 maxZoom: 16
} }
}; };
/**
* @classdesc
* Layer source for the Stamen tile server.
*
* @constructor
* @extends {ol.source.XYZ}
* @param {olx.source.StamenOptions} options Stamen options.
* @api
*/
const Stamen = function(options) {
const i = options.layer.indexOf('-');
const provider = i == -1 ? options.layer : options.layer.slice(0, i);
const providerConfig = ProviderConfig[provider];
const layerConfig = LayerConfig[options.layer];
const url = options.url !== undefined ? options.url :
'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
'/{z}/{x}/{y}.' + layerConfig.extension;
XYZ.call(this, {
attributions: ATTRIBUTIONS,
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom,
minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom,
opaque: layerConfig.opaque,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
};
inherits(Stamen, XYZ);
export default Stamen; export default Stamen;
+3 -2
View File
@@ -317,7 +317,7 @@ TileSource.prototype.useTile = nullFunction;
* @param {string} type Type. * @param {string} type Type.
* @param {ol.Tile} tile The tile. * @param {ol.Tile} tile The tile.
*/ */
TileSource.Event = function(type, tile) { export const TileSourceEvent = function(type, tile) {
Event.call(this, type); Event.call(this, type);
@@ -329,5 +329,6 @@ TileSource.Event = function(type, tile) {
this.tile = tile; this.tile = tile;
}; };
inherits(TileSource.Event, Event); inherits(TileSourceEvent, Event);
export default TileSource; export default TileSource;
+4 -3
View File
@@ -35,7 +35,7 @@ const TileImage = function(options) {
state: options.state, state: options.state,
tileGrid: options.tileGrid, tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction ? tileLoadFunction: options.tileLoadFunction ?
options.tileLoadFunction : TileImage.defaultTileLoadFunction, options.tileLoadFunction : defaultTileLoadFunction,
tilePixelRatio: options.tilePixelRatio, tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: options.tileUrlFunction, tileUrlFunction: options.tileUrlFunction,
url: options.url, url: options.url,
@@ -365,7 +365,8 @@ TileImage.prototype.setTileGridForProjection = function(projection, tilegrid) {
* @param {ol.ImageTile} imageTile Image tile. * @param {ol.ImageTile} imageTile Image tile.
* @param {string} src Source. * @param {string} src Source.
*/ */
TileImage.defaultTileLoadFunction = function(imageTile, src) { function defaultTileLoadFunction(imageTile, src) {
imageTile.getImage().src = src; imageTile.getImage().src = src;
}; }
export default TileImage; export default TileImage;
+2 -2
View File
@@ -4,7 +4,7 @@
import {getUid, inherits} from '../index.js'; import {getUid, inherits} from '../index.js';
import TileState from '../TileState.js'; import TileState from '../TileState.js';
import {expandUrl, createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js'; import {expandUrl, createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js';
import TileSource from '../source/Tile.js'; import TileSource, {TileSourceEvent} from '../source/Tile.js';
import TileEventType from '../source/TileEventType.js'; import TileEventType from '../source/TileEventType.js';
import {getKeyZXY} from '../tilecoord.js'; import {getKeyZXY} from '../tilecoord.js';
@@ -130,7 +130,7 @@ UrlTile.prototype.handleTileChange = function(event) {
TileEventType.TILELOADEND : undefined; TileEventType.TILELOADEND : undefined;
} }
if (type != undefined) { if (type != undefined) {
this.dispatchEvent(new TileSource.Event(type, tile)); this.dispatchEvent(new TileSourceEvent(type, tile));
} }
}; };
+32 -30
View File
@@ -21,6 +21,33 @@ import SourceState from '../source/State.js';
import VectorEventType from '../source/VectorEventType.js'; import VectorEventType from '../source/VectorEventType.js';
import RBush from '../structs/RBush.js'; import RBush from '../structs/RBush.js';
/**
* @classdesc
* Events emitted by {@link ol.source.Vector} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.Vector.Event}
* @param {string} type Type.
* @param {ol.Feature=} opt_feature Feature.
*/
export const VectorSourceEvent = function(type, opt_feature) {
Event.call(this, type);
/**
* The feature being added or removed.
* @type {ol.Feature|undefined}
* @api
*/
this.feature = opt_feature;
};
inherits(VectorSourceEvent, Event);
/** /**
* @classdesc * @classdesc
* Provides a source of features for vector layers. Vector features provided * Provides a source of features for vector layers. Vector features provided
@@ -191,7 +218,7 @@ VectorSource.prototype.addFeatureInternal = function(feature) {
} }
this.dispatchEvent( this.dispatchEvent(
new VectorSource.Event(VectorEventType.ADDFEATURE, feature)); new VectorSourceEvent(VectorEventType.ADDFEATURE, feature));
}; };
@@ -283,7 +310,7 @@ VectorSource.prototype.addFeaturesInternal = function(features) {
} }
for (let i = 0, length = newFeatures.length; i < length; i++) { for (let i = 0, length = newFeatures.length; i < length; i++) {
this.dispatchEvent(new VectorSource.Event(VectorEventType.ADDFEATURE, newFeatures[i])); this.dispatchEvent(new VectorSourceEvent(VectorEventType.ADDFEATURE, newFeatures[i]));
} }
}; };
@@ -364,7 +391,7 @@ VectorSource.prototype.clear = function(opt_fast) {
this.loadedExtentsRtree_.clear(); this.loadedExtentsRtree_.clear();
this.nullGeometryFeatures_ = {}; this.nullGeometryFeatures_ = {};
const clearEvent = new VectorSource.Event(VectorEventType.CLEAR); const clearEvent = new VectorSourceEvent(VectorEventType.CLEAR);
this.dispatchEvent(clearEvent); this.dispatchEvent(clearEvent);
this.changed(); this.changed();
}; };
@@ -709,7 +736,7 @@ VectorSource.prototype.handleFeatureChange_ = function(event) {
} }
} }
this.changed(); this.changed();
this.dispatchEvent(new VectorSource.Event( this.dispatchEvent(new VectorSourceEvent(
VectorEventType.CHANGEFEATURE, feature)); VectorEventType.CHANGEFEATURE, feature));
}; };
@@ -805,7 +832,7 @@ VectorSource.prototype.removeFeatureInternal = function(feature) {
} else { } else {
delete this.undefIdIndex_[featureKey]; delete this.undefIdIndex_[featureKey];
} }
this.dispatchEvent(new VectorSource.Event( this.dispatchEvent(new VectorSourceEvent(
VectorEventType.REMOVEFEATURE, feature)); VectorEventType.REMOVEFEATURE, feature));
}; };
@@ -840,29 +867,4 @@ VectorSource.prototype.setLoader = function(loader) {
this.loader_ = loader; this.loader_ = loader;
}; };
/**
* @classdesc
* Events emitted by {@link ol.source.Vector} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.Vector.Event}
* @param {string} type Type.
* @param {ol.Feature=} opt_feature Feature.
*/
VectorSource.Event = function(type, opt_feature) {
Event.call(this, type);
/**
* The feature being added or removed.
* @type {ol.Feature|undefined}
* @api
*/
this.feature = opt_feature;
};
inherits(VectorSource.Event, Event);
export default VectorSource; export default VectorSource;
+3 -2
View File
@@ -309,7 +309,7 @@ WMTS.prototype.updateDimensions = function(dimensions) {
* @return {?olx.source.WMTSOptions} WMTS source options object or `null` if the layer was not found. * @return {?olx.source.WMTSOptions} WMTS source options object or `null` if the layer was not found.
* @api * @api
*/ */
WMTS.optionsFromCapabilities = function(wmtsCap, config) { export function optionsFromCapabilities(wmtsCap, config) {
const layers = wmtsCap['Contents']['Layer']; const layers = wmtsCap['Contents']['Layer'];
const l = find(layers, function(elt, index, array) { const l = find(layers, function(elt, index, array) {
return elt['Identifier'] == config['layer']; return elt['Identifier'] == config['layer'];
@@ -476,5 +476,6 @@ WMTS.optionsFromCapabilities = function(wmtsCap, config) {
wrapX: wrapX, wrapX: wrapX,
crossOrigin: config['crossOrigin'] crossOrigin: config['crossOrigin']
}; };
}; }
export default WMTS; export default WMTS;
+5 -5
View File
@@ -2,7 +2,7 @@ import ImageTile from '../../../src/ol/ImageTile.js';
import TileState from '../../../src/ol/TileState.js'; import TileState from '../../../src/ol/TileState.js';
import {listen, unlistenByKey} from '../../../src/ol/events.js'; import {listen, unlistenByKey} from '../../../src/ol/events.js';
import EventType from '../../../src/ol/events/EventType.js'; import EventType from '../../../src/ol/events/EventType.js';
import ImageSource from '../../../src/ol/source/Image.js'; import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js';
describe('ol.ImageTile', function() { describe('ol.ImageTile', function() {
@@ -13,7 +13,7 @@ describe('ol.ImageTile', function() {
const tileCoord = [0, 0, 0]; const tileCoord = [0, 0, 0];
const state = TileState.IDLE; const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-0.png'; const src = 'spec/ol/data/osm-0-0-0.png';
const tileLoadFunction = ImageSource.defaultImageLoadFunction; const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
let previousState = tile.getState(); let previousState = tile.getState();
@@ -38,7 +38,7 @@ describe('ol.ImageTile', function() {
const tileCoord = [0, 0, 0]; const tileCoord = [0, 0, 0];
const state = TileState.ERROR; const state = TileState.ERROR;
const src = 'spec/ol/data/osm-0-0-0.png'; const src = 'spec/ol/data/osm-0-0-0.png';
const tileLoadFunction = ImageSource.defaultImageLoadFunction; const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
let previousState = tile.getState(); let previousState = tile.getState();
@@ -63,7 +63,7 @@ describe('ol.ImageTile', function() {
const tileCoord = [0, 0, 0]; const tileCoord = [0, 0, 0];
const state = TileState.IDLE; const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-99.png'; const src = 'spec/ol/data/osm-0-0-99.png';
const tileLoadFunction = ImageSource.defaultImageLoadFunction; const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
const key = listen(tile, EventType.CHANGE, function(event) { const key = listen(tile, EventType.CHANGE, function(event) {
@@ -89,7 +89,7 @@ describe('ol.ImageTile', function() {
const tileCoord = [0, 0, 0]; const tileCoord = [0, 0, 0];
const state = TileState.IDLE; const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-0.png'; const src = 'spec/ol/data/osm-0-0-0.png';
const tileLoadFunction = ImageSource.defaultImageLoadFunction; const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
tile.load(); tile.load();
expect(tile.getState()).to.be(TileState.LOADING); expect(tile.getState()).to.be(TileState.LOADING);
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js'; import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
import VectorSource from '../../../../src/ol/source/Vector.js'; import VectorSource from '../../../../src/ol/source/Vector.js';
@@ -62,22 +61,30 @@ describe('ol.interaction.DragRotateAndZoom', function() {
new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}), new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}),
true); true);
interaction.lastAngle_ = Math.PI; interaction.lastAngle_ = Math.PI;
const spy = sinon.spy(Interaction, 'rotateWithoutConstraints');
let view = map.getView();
let spy = sinon.spy(view, 'rotate');
interaction.handleDragEvent_(event); interaction.handleDragEvent_(event);
expect(spy.callCount).to.be(1); expect(spy.callCount).to.be(1);
expect(interaction.lastAngle_).to.be(-0.8308214428190254); expect(interaction.lastAngle_).to.be(-0.8308214428190254);
map.setView(new View({ view.rotate.restore();
view = new View({
projection: 'EPSG:4326', projection: 'EPSG:4326',
center: [0, 0], center: [0, 0],
resolution: 1, resolution: 1,
enableRotation: false enableRotation: false
})); });
map.setView(view);
event = new MapBrowserPointerEvent('pointermove', map, event = new MapBrowserPointerEvent('pointermove', map,
new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}), new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}),
true); true);
spy = sinon.spy(view, 'rotate');
interaction.handleDragEvent_(event); interaction.handleDragEvent_(event);
expect(spy.callCount).to.be(1); expect(spy.callCount).to.be(0);
Interaction.rotateWithoutConstraints.restore(); view.rotate.restore();
}); });
}); });
+13 -13
View File
@@ -1,7 +1,7 @@
import Map from '../../../../src/ol/Map.js'; import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import EventTarget from '../../../../src/ol/events/EventTarget.js'; import EventTarget from '../../../../src/ol/events/EventTarget.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js'; import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.Interaction', function() { describe('ol.interaction.Interaction', function() {
@@ -64,16 +64,16 @@ describe('ol.interaction.Interaction', function() {
resolutions: [4, 2, 1, 0.5, 0.25] resolutions: [4, 2, 1, 0.5, 0.25]
}); });
Interaction.zoomByDelta(view, 1); zoomByDelta(view, 1);
expect(view.getResolution()).to.be(0.5); expect(view.getResolution()).to.be(0.5);
Interaction.zoomByDelta(view, -1); zoomByDelta(view, -1);
expect(view.getResolution()).to.be(1); expect(view.getResolution()).to.be(1);
Interaction.zoomByDelta(view, 2); zoomByDelta(view, 2);
expect(view.getResolution()).to.be(0.25); expect(view.getResolution()).to.be(0.25);
Interaction.zoomByDelta(view, -2); zoomByDelta(view, -2);
expect(view.getResolution()).to.be(1); expect(view.getResolution()).to.be(1);
}); });
@@ -84,16 +84,16 @@ describe('ol.interaction.Interaction', function() {
resolutions: [4, 2, 1, 0.5, 0.25] resolutions: [4, 2, 1, 0.5, 0.25]
}); });
Interaction.zoomByDelta(view, 1, [10, 10]); zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([5, 5]); expect(view.getCenter()).to.eql([5, 5]);
Interaction.zoomByDelta(view, -1, [0, 0]); zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]); expect(view.getCenter()).to.eql([10, 10]);
Interaction.zoomByDelta(view, 2, [0, 0]); zoomByDelta(view, 2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]); expect(view.getCenter()).to.eql([2.5, 2.5]);
Interaction.zoomByDelta(view, -2, [0, 0]); zoomByDelta(view, -2, [0, 0]);
expect(view.getCenter()).to.eql([10, 10]); expect(view.getCenter()).to.eql([10, 10]);
}); });
@@ -105,16 +105,16 @@ describe('ol.interaction.Interaction', function() {
resolutions: [4, 2, 1, 0.5, 0.25] resolutions: [4, 2, 1, 0.5, 0.25]
}); });
Interaction.zoomByDelta(view, 1, [10, 10]); zoomByDelta(view, 1, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]); expect(view.getCenter()).to.eql([2.5, 2.5]);
Interaction.zoomByDelta(view, -1, [0, 0]); zoomByDelta(view, -1, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]); expect(view.getCenter()).to.eql([2.5, 2.5]);
Interaction.zoomByDelta(view, 2, [10, 10]); zoomByDelta(view, 2, [10, 10]);
expect(view.getCenter()).to.eql([2.5, 2.5]); expect(view.getCenter()).to.eql([2.5, 2.5]);
Interaction.zoomByDelta(view, -2, [0, 0]); zoomByDelta(view, -2, [0, 0]);
expect(view.getCenter()).to.eql([2.5, 2.5]); expect(view.getCenter()).to.eql([2.5, 2.5]);
}); });
}); });
+16 -7
View File
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js'; import Event from '../../../../src/ol/events/Event.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.KeyboardPan', function() { describe('ol.interaction.KeyboardPan', function() {
let map; let map;
@@ -24,25 +23,35 @@ describe('ol.interaction.KeyboardPan', function() {
describe('handleEvent()', function() { describe('handleEvent()', function() {
it('pans on arrow keys', function() { it('pans on arrow keys', function() {
const spy = sinon.spy(Interaction, 'pan'); const view = map.getView();
const spy = sinon.spy(view, 'animate');
const event = new MapBrowserEvent('keydown', map, { const event = new MapBrowserEvent('keydown', map, {
type: 'keydown', type: 'keydown',
target: map.getTargetElement(), target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
event.originalEvent.keyCode = 40; // DOWN event.originalEvent.keyCode = 40; // DOWN
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(0).args[0].center).to.eql([0, -128]);
view.setCenter([0, 0]);
event.originalEvent.keyCode = 38; // UP event.originalEvent.keyCode = 38; // UP
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(1).args[0].center).to.eql([0, 128]);
view.setCenter([0, 0]);
event.originalEvent.keyCode = 37; // LEFT event.originalEvent.keyCode = 37; // LEFT
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(2).args[0].center).to.eql([-128, 0]);
view.setCenter([0, 0]);
event.originalEvent.keyCode = 39; // RIGHT event.originalEvent.keyCode = 39; // RIGHT
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(0).args[1]).to.eql([0, -128]); expect(spy.getCall(3).args[0].center).to.eql([128, 0]);
expect(spy.getCall(1).args[1]).to.eql([0, 128]); view.setCenter([0, 0]);
expect(spy.getCall(2).args[1]).to.eql([-128, 0]);
expect(spy.getCall(3).args[1]).to.eql([128, 0]); view.animate.restore();
Interaction.pan.restore();
}); });
}); });
+12 -7
View File
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js'; import Event from '../../../../src/ol/events/Event.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.KeyboardZoom', function() { describe('ol.interaction.KeyboardZoom', function() {
let map; let map;
@@ -12,8 +11,8 @@ describe('ol.interaction.KeyboardZoom', function() {
target: createMapDiv(100, 100), target: createMapDiv(100, 100),
view: new View({ view: new View({
center: [0, 0], center: [0, 0],
resolutions: [1], resolutions: [4, 2, 1],
zoom: 0 zoom: 1
}) })
}); });
map.renderSync(); map.renderSync();
@@ -24,19 +23,25 @@ describe('ol.interaction.KeyboardZoom', function() {
describe('handleEvent()', function() { describe('handleEvent()', function() {
it('zooms on + and - keys', function() { it('zooms on + and - keys', function() {
const spy = sinon.spy(Interaction, 'zoomByDelta'); const view = map.getView();
const spy = sinon.spy(view, 'animate');
const event = new MapBrowserEvent('keydown', map, { const event = new MapBrowserEvent('keydown', map, {
type: 'keydown', type: 'keydown',
target: map.getTargetElement(), target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
event.originalEvent.charCode = '+'.charCodeAt(0); event.originalEvent.charCode = '+'.charCodeAt(0);
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(0).args[0].resolution).to.eql(1);
view.setResolution(2);
event.originalEvent.charCode = '-'.charCodeAt(0); event.originalEvent.charCode = '-'.charCodeAt(0);
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
expect(spy.getCall(0).args[1]).to.eql(1); expect(spy.getCall(1).args[0].resolution).to.eql(4);
expect(spy.getCall(1).args[1]).to.eql(-1); view.setResolution(2);
Interaction.zoomByDelta.restore();
view.animate.restore();
}); });
}); });
+5 -5
View File
@@ -9,7 +9,7 @@ import Circle from '../../../../src/ol/geom/Circle.js';
import LineString from '../../../../src/ol/geom/LineString.js'; import LineString from '../../../../src/ol/geom/LineString.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js'; import Polygon from '../../../../src/ol/geom/Polygon.js';
import Modify from '../../../../src/ol/interaction/Modify.js'; import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
import VectorSource from '../../../../src/ol/source/Vector.js'; import VectorSource from '../../../../src/ol/source/Vector.js';
@@ -101,7 +101,7 @@ describe('ol.interaction.Modify', function() {
* modifications. Helper function to * modifications. Helper function to
* @param {ol.Feature} feature Modified feature. * @param {ol.Feature} feature Modified feature.
* @param {ol.interaction.Modify} interaction The interaction. * @param {ol.interaction.Modify} interaction The interaction.
* @return {Array<ol.interaction.Modify.Event|string>} events * @return {Array<ModifyEvent|string>} events
*/ */
function trackEvents(feature, interaction) { function trackEvents(feature, interaction) {
const events = []; const events = [];
@@ -121,7 +121,7 @@ describe('ol.interaction.Modify', function() {
* Validates the event array to verify proper event sequence. Checks * Validates the event array to verify proper event sequence. Checks
* that first and last event are correct ModifyEvents and that feature * that first and last event are correct ModifyEvents and that feature
* modifications event are in between. * modifications event are in between.
* @param {Array<ol.interaction.Modify.Event|string>} events The events. * @param {Array<ModifyEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features. * @param {Array<ol.Feature>} features The features.
*/ */
function validateEvents(events, features) { function validateEvents(events, features) {
@@ -130,11 +130,11 @@ describe('ol.interaction.Modify', function() {
const endevent = events[events.length - 1]; const endevent = events[events.length - 1];
// first event should be modifystary // first event should be modifystary
expect(startevent).to.be.an(Modify.Event); expect(startevent).to.be.a(ModifyEvent);
expect(startevent.type).to.eql('modifystart'); expect(startevent.type).to.eql('modifystart');
// last event should be modifyend // last event should be modifyend
expect(endevent).to.be.an(Modify.Event); expect(endevent).to.be.a(ModifyEvent);
expect(endevent.type).to.eql('modifyend'); expect(endevent.type).to.eql('modifyend');
// make sure we get change events to events array // make sure we get change events to events array
+27 -17
View File
@@ -3,7 +3,6 @@ import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import View from '../../../../src/ol/View.js'; 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 MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js'; import MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js';
@@ -33,13 +32,13 @@ describe('ol.interaction.MouseWheelZoom', function() {
describe('timeout duration', function() { describe('timeout duration', function() {
let clock; let clock;
beforeEach(function() { beforeEach(function() {
sinon.spy(Interaction, 'zoomByDelta'); sinon.spy(interaction, 'handleWheelZoom_');
clock = sinon.useFakeTimers(); clock = sinon.useFakeTimers();
}); });
afterEach(function() { afterEach(function() {
clock.restore(); clock.restore();
Interaction.zoomByDelta.restore(); interaction.handleWheelZoom_.restore();
}); });
it('works with the defaut value', function(done) { it('works with the defaut value', function(done) {
@@ -48,12 +47,14 @@ describe('ol.interaction.MouseWheelZoom', function() {
target: map.getViewport(), target: map.getViewport(),
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
clock.tick(50); clock.tick(50);
// default timeout is 80 ms, not called yet // default timeout is 80 ms, not called yet
expect(Interaction.zoomByDelta.called).to.be(false); expect(interaction.handleWheelZoom_.called).to.be(false);
clock.tick(30); clock.tick(30);
expect(Interaction.zoomByDelta.called).to.be(true); expect(interaction.handleWheelZoom_.called).to.be(true);
done(); done();
}); });
@@ -98,21 +99,25 @@ describe('ol.interaction.MouseWheelZoom', function() {
}); });
} }
describe('spying on ol.interaction.Interaction.zoomByDelta', function() { describe('spying on view.animate()', function() {
let view;
beforeEach(function() { beforeEach(function() {
sinon.spy(Interaction, 'zoomByDelta'); view = map.getView();
sinon.spy(view, 'animate');
}); });
afterEach(function() { afterEach(function() {
Interaction.zoomByDelta.restore(); view.animate.restore();
}); });
it('works in DOM_DELTA_LINE mode (wheel)', function(done) { it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
map.once('postrender', function() { map.once('postrender', function() {
const call = Interaction.zoomByDelta.getCall(0); const call = view.animate.getCall(0);
expect(call.args[1]).to.be(-1); expect(call.args[0].resolution).to.be(2);
expect(call.args[2]).to.eql([0, 0]); expect(call.args[0].anchor).to.eql([0, 0]);
done(); done();
}); });
const event = new MapBrowserEvent('wheel', map, { const event = new MapBrowserEvent('wheel', map, {
type: 'wheel', type: 'wheel',
deltaMode: WheelEvent.DOM_DELTA_LINE, deltaMode: WheelEvent.DOM_DELTA_LINE,
@@ -121,17 +126,19 @@ describe('ol.interaction.MouseWheelZoom', function() {
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
event.coordinate = [0, 0]; event.coordinate = [0, 0];
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
}); });
if (SAFARI) { if (SAFARI) {
it('works on Safari (wheel)', function(done) { it('works on Safari (wheel)', function(done) {
map.once('postrender', function() { map.once('postrender', function() {
const call = Interaction.zoomByDelta.getCall(0); const call = view.animate.getCall(0);
expect(call.args[1]).to.be(-1); expect(call.args[0].resolution).to.be(2);
expect(call.args[2]).to.eql([0, 0]); expect(call.args[0].anchor).to.eql([0, 0]);
done(); done();
}); });
const event = new MapBrowserEvent('mousewheel', map, { const event = new MapBrowserEvent('mousewheel', map, {
type: 'mousewheel', type: 'mousewheel',
wheelDeltaY: -50, wheelDeltaY: -50,
@@ -139,6 +146,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
event.coordinate = [0, 0]; event.coordinate = [0, 0];
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
}); });
} }
@@ -146,11 +154,12 @@ describe('ol.interaction.MouseWheelZoom', function() {
if (!SAFARI) { if (!SAFARI) {
it('works on other browsers (wheel)', function(done) { it('works on other browsers (wheel)', function(done) {
map.once('postrender', function() { map.once('postrender', function() {
const call = Interaction.zoomByDelta.getCall(0); const call = view.animate.getCall(0);
expect(call.args[1]).to.be(-1); expect(call.args[0].resolution).to.be(2);
expect(call.args[2]).to.eql([0, 0]); expect(call.args[0].anchor).to.eql([0, 0]);
done(); done();
}); });
const event = new MapBrowserEvent('mousewheel', map, { const event = new MapBrowserEvent('mousewheel', map, {
type: 'mousewheel', type: 'mousewheel',
wheelDeltaY: -120, wheelDeltaY: -120,
@@ -158,6 +167,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
preventDefault: Event.prototype.preventDefault preventDefault: Event.prototype.preventDefault
}); });
event.coordinate = [0, 0]; event.coordinate = [0, 0];
map.handleMapBrowserEvent(event); map.handleMapBrowserEvent(event);
}); });
} }
+5 -5
View File
@@ -4,7 +4,7 @@ import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import Translate from '../../../../src/ol/interaction/Translate.js'; import Translate, {TranslateEvent} from '../../../../src/ol/interaction/Translate.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
@@ -80,7 +80,7 @@ describe('ol.interaction.Translate', function() {
* modifications. Helper function to * modifications. Helper function to
* @param {ol.Feature} feature Translated feature. * @param {ol.Feature} feature Translated feature.
* @param {ol.interaction.Translate} interaction The interaction. * @param {ol.interaction.Translate} interaction The interaction.
* @return {Array<ol.interaction.Translate.Event|string>} events * @return {Array<TranslateEvent|string>} events
*/ */
function trackEvents(feature, interaction) { function trackEvents(feature, interaction) {
const events = []; const events = [];
@@ -100,7 +100,7 @@ describe('ol.interaction.Translate', function() {
* Validates the event array to verify proper event sequence. Checks * Validates the event array to verify proper event sequence. Checks
* that first and last event are correct TranslateEvents and that feature * that first and last event are correct TranslateEvents and that feature
* modifications event are in between. * modifications event are in between.
* @param {Array<ol.interaction.Translate.Event|string>} events The events. * @param {Array<TranslateEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features. * @param {Array<ol.Feature>} features The features.
*/ */
function validateEvents(events, features) { function validateEvents(events, features) {
@@ -109,11 +109,11 @@ describe('ol.interaction.Translate', function() {
const endevent = events[events.length - 1]; const endevent = events[events.length - 1];
// first event should be translatestart // first event should be translatestart
expect(startevent).to.be.an(Translate.Event); expect(startevent).to.be.an(TranslateEvent);
expect(startevent.type).to.eql('translatestart'); expect(startevent.type).to.eql('translatestart');
// last event should be translateend // last event should be translateend
expect(endevent).to.be.an(Translate.Event); expect(endevent).to.be.an(TranslateEvent);
expect(endevent.type).to.eql('translateend'); expect(endevent.type).to.eql('translateend');
// make sure we get change events to events array // make sure we get change events to events array
+13 -13
View File
@@ -2,7 +2,7 @@ import WMTSCapabilities from '../../../../src/ol/format/WMTSCapabilities.js';
import {get as getProjection} from '../../../../src/ol/proj.js'; import {get as getProjection} from '../../../../src/ol/proj.js';
import Projection from '../../../../src/ol/proj/Projection.js'; import Projection from '../../../../src/ol/proj/Projection.js';
import WMTSTileGrid from '../../../../src/ol/tilegrid/WMTS.js'; import WMTSTileGrid from '../../../../src/ol/tilegrid/WMTS.js';
import WMTS from '../../../../src/ol/source/WMTS.js'; import WMTS, {optionsFromCapabilities} from '../../../../src/ol/source/WMTS.js';
describe('ol.source.WMTS', function() { describe('ol.source.WMTS', function() {
@@ -23,7 +23,7 @@ describe('ol.source.WMTS', function() {
}); });
it('returns null if the layer was not found in the capabilities', function() { it('returns null if the layer was not found in the capabilities', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'invalid' layer: 'invalid'
}); });
@@ -31,7 +31,7 @@ describe('ol.source.WMTS', function() {
}); });
it('passes the crossOrigin option', function() { it('passes the crossOrigin option', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
matrixSet: 'google3857', matrixSet: 'google3857',
crossOrigin: '' crossOrigin: ''
@@ -42,7 +42,7 @@ describe('ol.source.WMTS', function() {
it('can create KVP options from spec/ol/format/wmts/ogcsample.xml', it('can create KVP options from spec/ol/format/wmts/ogcsample.xml',
function() { function() {
const options = WMTS.optionsFromCapabilities( const options = optionsFromCapabilities(
capabilities, capabilities,
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
@@ -74,7 +74,7 @@ describe('ol.source.WMTS', function() {
it('can create REST options from spec/ol/format/wmts/ogcsample.xml', it('can create REST options from spec/ol/format/wmts/ogcsample.xml',
function() { function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
matrixSet: 'google3857', matrixSet: 'google3857',
requestEncoding: 'REST' requestEncoding: 'REST'
@@ -105,7 +105,7 @@ describe('ol.source.WMTS', function() {
}); });
it('can find a MatrixSet by SRS identifier', function() { it('can find a MatrixSet by SRS identifier', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
projection: 'EPSG:3857', projection: 'EPSG:3857',
requestEncoding: 'REST' requestEncoding: 'REST'
@@ -116,7 +116,7 @@ describe('ol.source.WMTS', function() {
}); });
it('can find a MatrixSet by equivalent SRS identifier', function() { it('can find a MatrixSet by equivalent SRS identifier', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
projection: 'EPSG:900913', projection: 'EPSG:900913',
requestEncoding: 'REST' requestEncoding: 'REST'
@@ -127,7 +127,7 @@ describe('ol.source.WMTS', function() {
}); });
it('can find the default MatrixSet', function() { it('can find the default MatrixSet', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
requestEncoding: 'REST' requestEncoding: 'REST'
}); });
@@ -137,7 +137,7 @@ describe('ol.source.WMTS', function() {
}); });
it('uses the projection of the default MatrixSet if the config\'s projection is not supported', function() { it('uses the projection of the default MatrixSet if the config\'s projection is not supported', function() {
const options = WMTS.optionsFromCapabilities(capabilities, { const options = optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration', layer: 'BlueMarbleNextGeneration',
projection: new Projection({ projection: new Projection({
code: 'EPSG:2056', code: 'EPSG:2056',
@@ -153,7 +153,7 @@ describe('ol.source.WMTS', function() {
const tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, ''); const tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, '');
const tmpCapabilities = parser.read(tmpXml); const tmpCapabilities = parser.read(tmpXml);
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined); expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
const options = WMTS.optionsFromCapabilities(tmpCapabilities, const options = optionsFromCapabilities(tmpCapabilities,
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
expect(options.layer).to.be.eql('BlueMarbleNextGeneration'); expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
expect(options.matrixSet).to.be.eql('google3857'); expect(options.matrixSet).to.be.eql('google3857');
@@ -166,7 +166,7 @@ describe('ol.source.WMTS', function() {
const tmpCapabilities = parser.read(tmpXml); const tmpCapabilities = parser.read(tmpXml);
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined); expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(undefined); expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(undefined);
const options = WMTS.optionsFromCapabilities(tmpCapabilities, const options = optionsFromCapabilities(tmpCapabilities,
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
expect(options.layer).to.be.eql('BlueMarbleNextGeneration'); expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
expect(options.matrixSet).to.be.eql('google3857'); expect(options.matrixSet).to.be.eql('google3857');
@@ -247,7 +247,7 @@ describe('ol.source.WMTS', function() {
it('can create KVP options from spec/ol/format/wmts/arcgis.xml', it('can create KVP options from spec/ol/format/wmts/arcgis.xml',
function() { function() {
const options = WMTS.optionsFromCapabilities( const options = optionsFromCapabilities(
capabilities, { capabilities, {
layer: 'Demographics_USA_Population_Density', layer: 'Demographics_USA_Population_Density',
requestEncoding: 'KVP', requestEncoding: 'KVP',
@@ -263,7 +263,7 @@ describe('ol.source.WMTS', function() {
it('can create REST options from spec/ol/format/wmts/arcgis.xml', it('can create REST options from spec/ol/format/wmts/arcgis.xml',
function() { function() {
const options = WMTS.optionsFromCapabilities( const options = optionsFromCapabilities(
capabilities, { capabilities, {
layer: 'Demographics_USA_Population_Density', layer: 'Demographics_USA_Population_Density',
matrixSet: 'default028mm' matrixSet: 'default028mm'
+2 -2
View File
@@ -2,7 +2,7 @@ import ImageTile from '../../../src/ol/ImageTile.js';
import Tile from '../../../src/ol/Tile.js'; import Tile from '../../../src/ol/Tile.js';
import TileQueue from '../../../src/ol/TileQueue.js'; import TileQueue from '../../../src/ol/TileQueue.js';
import TileState from '../../../src/ol/TileState.js'; import TileState from '../../../src/ol/TileState.js';
import ImageSource from '../../../src/ol/source/Image.js'; import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js';
import {DROP} from '../../../src/ol/structs/PriorityQueue.js'; import {DROP} from '../../../src/ol/structs/PriorityQueue.js';
@@ -32,7 +32,7 @@ describe('ol.TileQueue', function() {
'yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; 'yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
const tileLoadFunction = opt_tileLoadFunction ? const tileLoadFunction = opt_tileLoadFunction ?
opt_tileLoadFunction : ImageSource.defaultImageLoadFunction; opt_tileLoadFunction : defaultImageLoadFunction;
return new ImageTile(tileCoord, state, src, null, tileLoadFunction); return new ImageTile(tileCoord, state, src, null, tileLoadFunction);
} }