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