Lint removal

This commit is contained in:
Tim Schaub
2018-07-16 17:57:57 -06:00
parent f78d0d4cfa
commit d0ab8dce38
63 changed files with 2945 additions and 2917 deletions

View File

@@ -8,15 +8,15 @@ import {UNDEFINED} from './functions.js';
* @constructor * @constructor
*/ */
class Disposable { class Disposable {
/** /**
* Clean up. * Clean up.
*/ */
dispose() { dispose() {
if (!this.disposed_) { if (!this.disposed_) {
this.disposed_ = true; this.disposed_ = true;
this.disposeInternal(); this.disposeInternal();
} }
} }
} }
/** /**

View File

@@ -39,115 +39,115 @@ import {getHeight} from './extent.js';
* @param {module:ol/Image~LoadFunction} imageLoadFunction Image load function. * @param {module:ol/Image~LoadFunction} imageLoadFunction Image load function.
*/ */
class ImageWrapper { class ImageWrapper {
constructor(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) { constructor(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) {
ImageBase.call(this, extent, resolution, pixelRatio, ImageState.IDLE); ImageBase.call(this, extent, resolution, pixelRatio, ImageState.IDLE);
/** /**
* @private * @private
* @type {string} * @type {string}
*/ */
this.src_ = src; this.src_ = src;
/** /**
* @private * @private
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
*/ */
this.image_ = new Image(); this.image_ = new Image();
if (crossOrigin !== null) { if (crossOrigin !== null) {
this.image_.crossOrigin = crossOrigin; this.image_.crossOrigin = crossOrigin;
} }
/** /**
* @private * @private
* @type {Array.<module:ol/events~EventsKey>} * @type {Array.<module:ol/events~EventsKey>}
*/ */
this.imageListenerKeys_ = null; this.imageListenerKeys_ = null;
/** /**
* @protected * @protected
* @type {module:ol/ImageState} * @type {module:ol/ImageState}
*/ */
this.state = ImageState.IDLE; this.state = ImageState.IDLE;
/** /**
* @private * @private
* @type {module:ol/Image~LoadFunction} * @type {module:ol/Image~LoadFunction}
*/ */
this.imageLoadFunction_ = imageLoadFunction; this.imageLoadFunction_ = imageLoadFunction;
} }
/** /**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
getImage() { getImage() {
return this.image_; return this.image_;
} }
/** /**
* Tracks loading or read errors. * Tracks loading or read errors.
* *
* @private * @private
*/ */
handleImageError_() { handleImageError_() {
this.state = ImageState.ERROR; this.state = ImageState.ERROR;
this.unlistenImage_(); this.unlistenImage_();
this.changed(); this.changed();
} }
/** /**
* Tracks successful image load. * Tracks successful image load.
* *
* @private * @private
*/ */
handleImageLoad_() { handleImageLoad_() {
if (this.resolution === undefined) { if (this.resolution === undefined) {
this.resolution = getHeight(this.extent) / this.image_.height; this.resolution = getHeight(this.extent) / this.image_.height;
} }
this.state = ImageState.LOADED; this.state = ImageState.LOADED;
this.unlistenImage_(); this.unlistenImage_();
this.changed(); this.changed();
} }
/** /**
* Load the image or retry if loading previously failed. * Load the image or retry if loading previously failed.
* Loading is taken care of by the tile queue, and calling this method is * Loading is taken care of by the tile queue, and calling this method is
* only needed for preloading or for reloading in case of an error. * only needed for preloading or for reloading in case of an error.
* @override * @override
* @api * @api
*/ */
load() { load() {
if (this.state == ImageState.IDLE || this.state == ImageState.ERROR) { if (this.state == ImageState.IDLE || this.state == ImageState.ERROR) {
this.state = ImageState.LOADING; this.state = ImageState.LOADING;
this.changed(); this.changed();
this.imageListenerKeys_ = [ this.imageListenerKeys_ = [
listenOnce(this.image_, EventType.ERROR, listenOnce(this.image_, EventType.ERROR,
this.handleImageError_, this), this.handleImageError_, this),
listenOnce(this.image_, EventType.LOAD, listenOnce(this.image_, EventType.LOAD,
this.handleImageLoad_, this) this.handleImageLoad_, this)
]; ];
this.imageLoadFunction_(this, this.src_); this.imageLoadFunction_(this, this.src_);
} }
} }
/** /**
* @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image. * @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image.
*/ */
setImage(image) { setImage(image) {
this.image_ = image; this.image_ = image;
} }
/** /**
* Discards event handlers which listen for load completion or errors. * Discards event handlers which listen for load completion or errors.
* *
* @private * @private
*/ */
unlistenImage_() { unlistenImage_() {
this.imageListenerKeys_.forEach(unlistenByKey); this.imageListenerKeys_.forEach(unlistenByKey);
this.imageListenerKeys_ = null; this.imageListenerKeys_ = null;
} }
} }
inherits(ImageWrapper, ImageBase); inherits(ImageWrapper, ImageBase);

View File

@@ -15,82 +15,82 @@ import EventType from './events/EventType.js';
* @param {module:ol/ImageState} state State. * @param {module:ol/ImageState} state State.
*/ */
class ImageBase { class ImageBase {
constructor(extent, resolution, pixelRatio, state) { constructor(extent, resolution, pixelRatio, state) {
EventTarget.call(this); EventTarget.call(this);
/** /**
* @protected * @protected
* @type {module:ol/extent~Extent} * @type {module:ol/extent~Extent}
*/ */
this.extent = extent; this.extent = extent;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.pixelRatio_ = pixelRatio; this.pixelRatio_ = pixelRatio;
/** /**
* @protected * @protected
* @type {number|undefined} * @type {number|undefined}
*/ */
this.resolution = resolution; this.resolution = resolution;
/** /**
* @protected * @protected
* @type {module:ol/ImageState} * @type {module:ol/ImageState}
*/ */
this.state = state; this.state = state;
} }
/** /**
* @protected * @protected
*/ */
changed() { changed() {
this.dispatchEvent(EventType.CHANGE); this.dispatchEvent(EventType.CHANGE);
} }
/** /**
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
*/ */
getExtent() { getExtent() {
return this.extent; return this.extent;
} }
/** /**
* @abstract * @abstract
* @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image. * @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image.
*/ */
getImage() {} getImage() {}
/** /**
* @return {number} PixelRatio. * @return {number} PixelRatio.
*/ */
getPixelRatio() { getPixelRatio() {
return this.pixelRatio_; return this.pixelRatio_;
} }
/** /**
* @return {number} Resolution. * @return {number} Resolution.
*/ */
getResolution() { getResolution() {
return /** @type {number} */ (this.resolution); return /** @type {number} */ (this.resolution);
} }
/** /**
* @return {module:ol/ImageState} State. * @return {module:ol/ImageState} State.
*/ */
getState() { getState() {
return this.state; return this.state;
} }
/** /**
* Load not yet loaded URI. * Load not yet loaded URI.
* @abstract * @abstract
*/ */
load() {} load() {}
} }
inherits(ImageBase, EventTarget); inherits(ImageBase, EventTarget);

View File

@@ -27,73 +27,73 @@ import ImageState from './ImageState.js';
* support asynchronous canvas drawing. * support asynchronous canvas drawing.
*/ */
class ImageCanvas { class ImageCanvas {
constructor(extent, resolution, pixelRatio, canvas, opt_loader) { constructor(extent, resolution, pixelRatio, canvas, opt_loader) {
/** /**
* Optional canvas loader function. * Optional canvas loader function.
* @type {?module:ol/ImageCanvas~Loader} * @type {?module:ol/ImageCanvas~Loader}
* @private * @private
*/ */
this.loader_ = opt_loader !== undefined ? opt_loader : null; this.loader_ = opt_loader !== undefined ? opt_loader : null;
const state = opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED; const state = opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
ImageBase.call(this, extent, resolution, pixelRatio, state); ImageBase.call(this, extent, resolution, pixelRatio, state);
/** /**
* @private * @private
* @type {HTMLCanvasElement} * @type {HTMLCanvasElement}
*/ */
this.canvas_ = canvas; this.canvas_ = canvas;
/** /**
* @private * @private
* @type {Error} * @type {Error}
*/ */
this.error_ = null; this.error_ = null;
} }
/** /**
* Get any error associated with asynchronous rendering. * Get any error associated with asynchronous rendering.
* @return {Error} Any error that occurred during rendering. * @return {Error} Any error that occurred during rendering.
*/ */
getError() { getError() {
return this.error_; return this.error_;
} }
/** /**
* Handle async drawing complete. * Handle async drawing complete.
* @param {Error} err Any error during drawing. * @param {Error} err Any error during drawing.
* @private * @private
*/ */
handleLoad_(err) { handleLoad_(err) {
if (err) { if (err) {
this.error_ = err; this.error_ = err;
this.state = ImageState.ERROR; this.state = ImageState.ERROR;
} else { } else {
this.state = ImageState.LOADED; this.state = ImageState.LOADED;
} }
this.changed(); this.changed();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
load() { load() {
if (this.state == ImageState.IDLE) { if (this.state == ImageState.IDLE) {
this.state = ImageState.LOADING; this.state = ImageState.LOADING;
this.changed(); this.changed();
this.loader_(this.handleLoad_.bind(this)); this.loader_(this.handleLoad_.bind(this));
} }
} }
/** /**
* @return {HTMLCanvasElement} Canvas element. * @return {HTMLCanvasElement} Canvas element.
*/ */
getImage() { getImage() {
return this.canvas_; return this.canvas_;
} }
} }
inherits(ImageCanvas, ImageBase); inherits(ImageCanvas, ImageBase);

View File

@@ -15,113 +15,113 @@
* @api * @api
*/ */
class Kinetic { class Kinetic {
constructor(decay, minVelocity, delay) { constructor(decay, minVelocity, delay) {
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.decay_ = decay; this.decay_ = decay;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.minVelocity_ = minVelocity; this.minVelocity_ = minVelocity;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.delay_ = delay; this.delay_ = delay;
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.points_ = []; this.points_ = [];
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.angle_ = 0; this.angle_ = 0;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.initialVelocity_ = 0; this.initialVelocity_ = 0;
} }
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
begin() { begin() {
this.points_.length = 0; this.points_.length = 0;
this.angle_ = 0; this.angle_ = 0;
this.initialVelocity_ = 0; this.initialVelocity_ = 0;
} }
/** /**
* @param {number} x X. * @param {number} x X.
* @param {number} y Y. * @param {number} y Y.
*/ */
update(x, y) { update(x, y) {
this.points_.push(x, y, Date.now()); this.points_.push(x, y, Date.now());
} }
/** /**
* @return {boolean} Whether we should do kinetic animation. * @return {boolean} Whether we should do kinetic animation.
*/ */
end() { end() {
if (this.points_.length < 6) { if (this.points_.length < 6) {
// at least 2 points are required (i.e. there must be at least 6 elements // at least 2 points are required (i.e. there must be at least 6 elements
// in the array) // in the array)
return false; return false;
} }
const delay = Date.now() - this.delay_; const delay = Date.now() - this.delay_;
const lastIndex = this.points_.length - 3; const lastIndex = this.points_.length - 3;
if (this.points_[lastIndex + 2] < delay) { if (this.points_[lastIndex + 2] < delay) {
// the last tracked point is too old, which means that the user stopped // the last tracked point is too old, which means that the user stopped
// panning before releasing the map // panning before releasing the map
return false; return false;
} }
// get the first point which still falls into the delay time // get the first point which still falls into the delay time
let firstIndex = lastIndex - 3; let firstIndex = lastIndex - 3;
while (firstIndex > 0 && this.points_[firstIndex + 2] > delay) { while (firstIndex > 0 && this.points_[firstIndex + 2] > delay) {
firstIndex -= 3; firstIndex -= 3;
} }
const duration = this.points_[lastIndex + 2] - this.points_[firstIndex + 2]; const duration = this.points_[lastIndex + 2] - this.points_[firstIndex + 2];
// we don't want a duration of 0 (divide by zero) // we don't want a duration of 0 (divide by zero)
// we also make sure the user panned for a duration of at least one frame // we also make sure the user panned for a duration of at least one frame
// (1/60s) to compute sane displacement values // (1/60s) to compute sane displacement values
if (duration < 1000 / 60) { if (duration < 1000 / 60) {
return false; return false;
} }
const dx = this.points_[lastIndex] - this.points_[firstIndex]; const dx = this.points_[lastIndex] - this.points_[firstIndex];
const dy = this.points_[lastIndex + 1] - this.points_[firstIndex + 1]; const dy = this.points_[lastIndex + 1] - this.points_[firstIndex + 1];
this.angle_ = Math.atan2(dy, dx); this.angle_ = Math.atan2(dy, dx);
this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / duration; this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / duration;
return this.initialVelocity_ > this.minVelocity_; return this.initialVelocity_ > this.minVelocity_;
} }
/** /**
* @return {number} Total distance travelled (pixels). * @return {number} Total distance travelled (pixels).
*/ */
getDistance() { getDistance() {
return (this.minVelocity_ - this.initialVelocity_) / this.decay_; return (this.minVelocity_ - this.initialVelocity_) / this.decay_;
} }
/** /**
* @return {number} Angle of the kinetic panning animation (radians). * @return {number} Angle of the kinetic panning animation (radians).
*/ */
getAngle() { getAngle() {
return this.angle_; return this.angle_;
} }
} }
export default Kinetic; export default Kinetic;

View File

@@ -18,64 +18,64 @@ import MapEvent from './MapEvent.js';
* @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state. * @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state.
*/ */
class MapBrowserEvent { class MapBrowserEvent {
constructor(type, map, browserEvent, opt_dragging, opt_frameState) { constructor(type, map, browserEvent, opt_dragging, opt_frameState) {
MapEvent.call(this, type, map, opt_frameState); MapEvent.call(this, type, map, opt_frameState);
/** /**
* The original browser event. * The original browser event.
* @const * @const
* @type {Event} * @type {Event}
* @api * @api
*/ */
this.originalEvent = browserEvent; this.originalEvent = browserEvent;
/** /**
* The map pixel relative to the viewport corresponding to the original browser event. * The map pixel relative to the viewport corresponding to the original browser event.
* @type {module:ol~Pixel} * @type {module:ol~Pixel}
* @api * @api
*/ */
this.pixel = map.getEventPixel(browserEvent); this.pixel = map.getEventPixel(browserEvent);
/** /**
* The coordinate in view projection corresponding to the original browser event. * The coordinate in view projection corresponding to the original browser event.
* @type {module:ol/coordinate~Coordinate} * @type {module:ol/coordinate~Coordinate}
* @api * @api
*/ */
this.coordinate = map.getCoordinateFromPixel(this.pixel); this.coordinate = map.getCoordinateFromPixel(this.pixel);
/** /**
* Indicates if the map is currently being dragged. Only set for * Indicates if the map is currently being dragged. Only set for
* `POINTERDRAG` and `POINTERMOVE` events. Default is `false`. * `POINTERDRAG` and `POINTERMOVE` events. Default is `false`.
* *
* @type {boolean} * @type {boolean}
* @api * @api
*/ */
this.dragging = opt_dragging !== undefined ? opt_dragging : false; this.dragging = opt_dragging !== undefined ? opt_dragging : false;
} }
/** /**
* Prevents the default browser action. * Prevents the default browser action.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault * @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
* @override * @override
* @api * @api
*/ */
preventDefault() { preventDefault() {
MapEvent.prototype.preventDefault.call(this); MapEvent.prototype.preventDefault.call(this);
this.originalEvent.preventDefault(); this.originalEvent.preventDefault();
} }
/** /**
* Prevents further propagation of the current event. * Prevents further propagation of the current event.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation * @see https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation
* @override * @override
* @api * @api
*/ */
stopPropagation() { stopPropagation() {
MapEvent.prototype.stopPropagation.call(this); MapEvent.prototype.stopPropagation.call(this);
this.originalEvent.stopPropagation(); this.originalEvent.stopPropagation();
} }
} }
inherits(MapBrowserEvent, MapEvent); inherits(MapBrowserEvent, MapEvent);

View File

@@ -13,114 +13,114 @@
* @struct * @struct
*/ */
class TileRange { class TileRange {
constructor(minX, maxX, minY, maxY) { constructor(minX, maxX, minY, maxY) {
/** /**
* @type {number} * @type {number}
*/ */
this.minX = minX; this.minX = minX;
/** /**
* @type {number} * @type {number}
*/ */
this.maxX = maxX; this.maxX = maxX;
/** /**
* @type {number} * @type {number}
*/ */
this.minY = minY; this.minY = minY;
/** /**
* @type {number} * @type {number}
*/ */
this.maxY = maxY; this.maxY = maxY;
} }
/** /**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @return {boolean} Contains tile coordinate. * @return {boolean} Contains tile coordinate.
*/ */
contains(tileCoord) { contains(tileCoord) {
return this.containsXY(tileCoord[1], tileCoord[2]); return this.containsXY(tileCoord[1], tileCoord[2]);
} }
/** /**
* @param {module:ol/TileRange} tileRange Tile range. * @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Contains. * @return {boolean} Contains.
*/ */
containsTileRange(tileRange) { containsTileRange(tileRange) {
return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX && return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
this.minY <= tileRange.minY && tileRange.maxY <= this.maxY; this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
} }
/** /**
* @param {number} x Tile coordinate x. * @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y. * @param {number} y Tile coordinate y.
* @return {boolean} Contains coordinate. * @return {boolean} Contains coordinate.
*/ */
containsXY(x, y) { containsXY(x, y) {
return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY; return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY;
} }
/** /**
* @param {module:ol/TileRange} tileRange Tile range. * @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Equals. * @return {boolean} Equals.
*/ */
equals(tileRange) { equals(tileRange) {
return this.minX == tileRange.minX && this.minY == tileRange.minY && return this.minX == tileRange.minX && this.minY == tileRange.minY &&
this.maxX == tileRange.maxX && this.maxY == tileRange.maxY; this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
} }
/** /**
* @param {module:ol/TileRange} tileRange Tile range. * @param {module:ol/TileRange} tileRange Tile range.
*/ */
extend(tileRange) { extend(tileRange) {
if (tileRange.minX < this.minX) { if (tileRange.minX < this.minX) {
this.minX = tileRange.minX; this.minX = tileRange.minX;
} }
if (tileRange.maxX > this.maxX) { if (tileRange.maxX > this.maxX) {
this.maxX = tileRange.maxX; this.maxX = tileRange.maxX;
} }
if (tileRange.minY < this.minY) { if (tileRange.minY < this.minY) {
this.minY = tileRange.minY; this.minY = tileRange.minY;
} }
if (tileRange.maxY > this.maxY) { if (tileRange.maxY > this.maxY) {
this.maxY = tileRange.maxY; this.maxY = tileRange.maxY;
} }
} }
/** /**
* @return {number} Height. * @return {number} Height.
*/ */
getHeight() { getHeight() {
return this.maxY - this.minY + 1; return this.maxY - this.minY + 1;
} }
/** /**
* @return {module:ol/size~Size} Size. * @return {module:ol/size~Size} Size.
*/ */
getSize() { getSize() {
return [this.getWidth(), this.getHeight()]; return [this.getWidth(), this.getHeight()];
} }
/** /**
* @return {number} Width. * @return {number} Width.
*/ */
getWidth() { getWidth() {
return this.maxX - this.minX + 1; return this.maxX - this.minX + 1;
} }
/** /**
* @param {module:ol/TileRange} tileRange Tile range. * @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Intersects. * @return {boolean} Intersects.
*/ */
intersects(tileRange) { intersects(tileRange) {
return this.minX <= tileRange.maxX && return this.minX <= tileRange.maxX &&
this.maxX >= tileRange.minX && this.maxX >= tileRange.minX &&
this.minY <= tileRange.maxY && this.minY <= tileRange.maxY &&
this.maxY >= tileRange.minY; this.maxY >= tileRange.minY;
} }
} }

View File

@@ -5,6 +5,13 @@ import {getUid, inherits} from './util.js';
import Tile from './Tile.js'; import Tile from './Tile.js';
import TileState from './TileState.js'; import TileState from './TileState.js';
/**
* @const
* @type {module:ol/extent~Extent}
*/
const DEFAULT_EXTENT = [0, 0, 4096, 4096];
/** /**
* @typedef {function(new: module:ol/VectorTile, module:ol/tilecoord~TileCoord, * @typedef {function(new: module:ol/VectorTile, module:ol/tilecoord~TileCoord,
* module:ol/TileState, string, ?string, module:ol/Tile~LoadFunction)} TileClass * module:ol/TileState, string, ?string, module:ol/Tile~LoadFunction)} TileClass
@@ -22,162 +29,162 @@ import TileState from './TileState.js';
* @param {module:ol/Tile~Options=} opt_options Tile options. * @param {module:ol/Tile~Options=} opt_options Tile options.
*/ */
class VectorTile { class VectorTile {
constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) { constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) {
Tile.call(this, tileCoord, state, opt_options); Tile.call(this, tileCoord, state, opt_options);
/** /**
* @type {number} * @type {number}
*/ */
this.consumers = 0; this.consumers = 0;
/** /**
* @private * @private
* @type {module:ol/extent~Extent} * @type {module:ol/extent~Extent}
*/ */
this.extent_ = null; this.extent_ = null;
/** /**
* @private * @private
* @type {module:ol/format/Feature} * @type {module:ol/format/Feature}
*/ */
this.format_ = format; this.format_ = format;
/** /**
* @private * @private
* @type {Array.<module:ol/Feature>} * @type {Array.<module:ol/Feature>}
*/ */
this.features_ = null; this.features_ = null;
/** /**
* @private * @private
* @type {module:ol/featureloader~FeatureLoader} * @type {module:ol/featureloader~FeatureLoader}
*/ */
this.loader_; this.loader_;
/** /**
* Data projection * Data projection
* @private * @private
* @type {module:ol/proj/Projection} * @type {module:ol/proj/Projection}
*/ */
this.projection_ = null; this.projection_ = null;
/** /**
* @private * @private
* @type {Object.<string, module:ol/render/ReplayGroup>} * @type {Object.<string, module:ol/render/ReplayGroup>}
*/ */
this.replayGroups_ = {}; this.replayGroups_ = {};
/** /**
* @private * @private
* @type {module:ol/Tile~LoadFunction} * @type {module:ol/Tile~LoadFunction}
*/ */
this.tileLoadFunction_ = tileLoadFunction; this.tileLoadFunction_ = tileLoadFunction;
/** /**
* @private * @private
* @type {string} * @type {string}
*/ */
this.url_ = src; this.url_ = src;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
disposeInternal() { disposeInternal() {
this.features_ = null; this.features_ = null;
this.replayGroups_ = {}; this.replayGroups_ = {};
this.state = TileState.ABORT; this.state = TileState.ABORT;
this.changed(); this.changed();
Tile.prototype.disposeInternal.call(this); Tile.prototype.disposeInternal.call(this);
} }
/** /**
* Gets the extent of the vector tile. * Gets the extent of the vector tile.
* @return {module:ol/extent~Extent} The extent. * @return {module:ol/extent~Extent} The extent.
* @api * @api
*/ */
getExtent() { getExtent() {
return this.extent_ || DEFAULT_EXTENT; return this.extent_ || DEFAULT_EXTENT;
} }
/** /**
* Get the feature format assigned for reading this tile's features. * Get the feature format assigned for reading this tile's features.
* @return {module:ol/format/Feature} Feature format. * @return {module:ol/format/Feature} Feature format.
* @api * @api
*/ */
getFormat() { getFormat() {
return this.format_; return this.format_;
} }
/** /**
* Get the features for this tile. Geometries will be in the projection returned * Get the features for this tile. Geometries will be in the projection returned
* by {@link module:ol/VectorTile~VectorTile#getProjection}. * by {@link module:ol/VectorTile~VectorTile#getProjection}.
* @return {Array.<module:ol/Feature|module:ol/render/Feature>} Features. * @return {Array.<module:ol/Feature|module:ol/render/Feature>} Features.
* @api * @api
*/ */
getFeatures() { getFeatures() {
return this.features_; return this.features_;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getKey() { getKey() {
return this.url_; return this.url_;
} }
/** /**
* Get the feature projection of features returned by * Get the feature projection of features returned by
* {@link module:ol/VectorTile~VectorTile#getFeatures}. * {@link module:ol/VectorTile~VectorTile#getFeatures}.
* @return {module:ol/proj/Projection} Feature projection. * @return {module:ol/proj/Projection} Feature projection.
* @api * @api
*/ */
getProjection() { getProjection() {
return this.projection_; return this.projection_;
} }
/** /**
* @param {module:ol/layer/Layer} layer Layer. * @param {module:ol/layer/Layer} layer Layer.
* @param {string} key Key. * @param {string} key Key.
* @return {module:ol/render/ReplayGroup} Replay group. * @return {module:ol/render/ReplayGroup} Replay group.
*/ */
getReplayGroup(layer, key) { getReplayGroup(layer, key) {
return this.replayGroups_[getUid(layer) + ',' + key]; return this.replayGroups_[getUid(layer) + ',' + key];
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
load() { load() {
if (this.state == TileState.IDLE) { if (this.state == TileState.IDLE) {
this.setState(TileState.LOADING); this.setState(TileState.LOADING);
this.tileLoadFunction_(this, this.url_); this.tileLoadFunction_(this, this.url_);
this.loader_(null, NaN, null); this.loader_(null, NaN, null);
} }
} }
/** /**
* Handler for successful tile load. * Handler for successful tile load.
* @param {Array.<module:ol/Feature>} features The loaded features. * @param {Array.<module:ol/Feature>} features The loaded features.
* @param {module:ol/proj/Projection} dataProjection Data projection. * @param {module:ol/proj/Projection} dataProjection Data projection.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
*/ */
onLoad(features, dataProjection, extent) { onLoad(features, dataProjection, extent) {
this.setProjection(dataProjection); this.setProjection(dataProjection);
this.setFeatures(features); this.setFeatures(features);
this.setExtent(extent); this.setExtent(extent);
} }
/** /**
* Handler for tile load errors. * Handler for tile load errors.
*/ */
onError() { onError() {
this.setState(TileState.ERROR); this.setState(TileState.ERROR);
} }
/** /**
* Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s * Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s
* `tileLoadFunction`. Sets the extent of the vector tile. This is only required * `tileLoadFunction`. Sets the extent of the vector tile. This is only required
* for tiles in projections with `tile-pixels` as units. The extent should be * for tiles in projections with `tile-pixels` as units. The extent should be
@@ -189,58 +196,51 @@ class VectorTile {
* @param {module:ol/extent~Extent} extent The extent. * @param {module:ol/extent~Extent} extent The extent.
* @api * @api
*/ */
setExtent(extent) { setExtent(extent) {
this.extent_ = extent; this.extent_ = extent;
} }
/** /**
* Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s `tileLoadFunction`. * Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s `tileLoadFunction`.
* Sets the features for the tile. * Sets the features for the tile.
* @param {Array.<module:ol/Feature>} features Features. * @param {Array.<module:ol/Feature>} features Features.
* @api * @api
*/ */
setFeatures(features) { setFeatures(features) {
this.features_ = features; this.features_ = features;
this.setState(TileState.LOADED); this.setState(TileState.LOADED);
} }
/** /**
* Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s `tileLoadFunction`. * Function for use in an {@link module:ol/source/VectorTile~VectorTile}'s `tileLoadFunction`.
* Sets the projection of the features that were added with * Sets the projection of the features that were added with
* {@link module:ol/VectorTile~VectorTile#setFeatures}. * {@link module:ol/VectorTile~VectorTile#setFeatures}.
* @param {module:ol/proj/Projection} projection Feature projection. * @param {module:ol/proj/Projection} projection Feature projection.
* @api * @api
*/ */
setProjection(projection) { setProjection(projection) {
this.projection_ = projection; this.projection_ = projection;
} }
/** /**
* @param {module:ol/layer/Layer} layer Layer. * @param {module:ol/layer/Layer} layer Layer.
* @param {string} key Key. * @param {string} key Key.
* @param {module:ol/render/ReplayGroup} replayGroup Replay group. * @param {module:ol/render/ReplayGroup} replayGroup Replay group.
*/ */
setReplayGroup(layer, key, replayGroup) { setReplayGroup(layer, key, replayGroup) {
this.replayGroups_[getUid(layer) + ',' + key] = replayGroup; this.replayGroups_[getUid(layer) + ',' + key] = replayGroup;
} }
/** /**
* Set the feature loader for reading this tile's features. * Set the feature loader for reading this tile's features.
* @param {module:ol/featureloader~FeatureLoader} loader Feature loader. * @param {module:ol/featureloader~FeatureLoader} loader Feature loader.
* @api * @api
*/ */
setLoader(loader) { setLoader(loader) {
this.loader_ = loader; this.loader_ = loader;
} }
} }
inherits(VectorTile, Tile); inherits(VectorTile, Tile);
/**
* @const
* @type {module:ol/extent~Extent}
*/
const DEFAULT_EXTENT = [0, 0, 4096, 4096];
export default VectorTile; export default VectorTile;

View File

@@ -50,91 +50,91 @@ import {listen, unlistenByKey} from '../events.js';
* @api * @api
*/ */
class Control { class Control {
constructor(options) { constructor(options) {
BaseObject.call(this); BaseObject.call(this);
/** /**
* @protected * @protected
* @type {Element} * @type {Element}
*/ */
this.element = options.element ? options.element : null; this.element = options.element ? options.element : null;
/** /**
* @private * @private
* @type {Element} * @type {Element}
*/ */
this.target_ = null; this.target_ = null;
/** /**
* @private * @private
* @type {module:ol/PluggableMap} * @type {module:ol/PluggableMap}
*/ */
this.map_ = null; this.map_ = null;
/** /**
* @protected * @protected
* @type {!Array.<module:ol/events~EventsKey>} * @type {!Array.<module:ol/events~EventsKey>}
*/ */
this.listenerKeys = []; this.listenerKeys = [];
/** /**
* @type {function(module:ol/MapEvent)} * @type {function(module:ol/MapEvent)}
*/ */
this.render = options.render ? options.render : UNDEFINED; this.render = options.render ? options.render : UNDEFINED;
if (options.target) { if (options.target) {
this.setTarget(options.target); this.setTarget(options.target);
} }
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
disposeInternal() { disposeInternal() {
removeNode(this.element); removeNode(this.element);
BaseObject.prototype.disposeInternal.call(this); BaseObject.prototype.disposeInternal.call(this);
} }
/** /**
* Get the map associated with this control. * Get the map associated with this control.
* @return {module:ol/PluggableMap} Map. * @return {module:ol/PluggableMap} Map.
* @api * @api
*/ */
getMap() { getMap() {
return this.map_; return this.map_;
} }
/** /**
* Remove the control from its current map and attach it to the new map. * Remove the control from its current map and attach it to the new map.
* Subclasses may set up event handlers to get notified about changes to * Subclasses may set up event handlers to get notified about changes to
* the map here. * the map here.
* @param {module:ol/PluggableMap} map Map. * @param {module:ol/PluggableMap} map Map.
* @api * @api
*/ */
setMap(map) { setMap(map) {
if (this.map_) { if (this.map_) {
removeNode(this.element); removeNode(this.element);
} }
for (let i = 0, ii = this.listenerKeys.length; i < ii; ++i) { for (let i = 0, ii = this.listenerKeys.length; i < ii; ++i) {
unlistenByKey(this.listenerKeys[i]); unlistenByKey(this.listenerKeys[i]);
} }
this.listenerKeys.length = 0; this.listenerKeys.length = 0;
this.map_ = map; this.map_ = map;
if (this.map_) { if (this.map_) {
const target = this.target_ ? const target = this.target_ ?
this.target_ : map.getOverlayContainerStopEvent(); this.target_ : map.getOverlayContainerStopEvent();
target.appendChild(this.element); target.appendChild(this.element);
if (this.render !== UNDEFINED) { if (this.render !== UNDEFINED) {
this.listenerKeys.push(listen(map, this.listenerKeys.push(listen(map,
MapEventType.POSTRENDER, this.render, this)); MapEventType.POSTRENDER, this.render, this));
} }
map.render(); map.render();
} }
} }
/** /**
* This function is used to set a target element for the control. It has no * This function is used to set a target element for the control. It has no
* effect if it is called after the control has been added to the map (i.e. * effect if it is called after the control has been added to the map (i.e.
* after `setMap` is called on the control). If no `target` is set in the * after `setMap` is called on the control). If no `target` is set in the
@@ -143,11 +143,11 @@ class Control {
* @param {Element|string} target Target. * @param {Element|string} target Target.
* @api * @api
*/ */
setTarget(target) { setTarget(target) {
this.target_ = typeof target === 'string' ? this.target_ = typeof target === 'string' ?
document.getElementById(target) : document.getElementById(target) :
target; target;
} }
} }
inherits(Control, BaseObject); inherits(Control, BaseObject);

View File

@@ -32,57 +32,57 @@ import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
* @api * @api
*/ */
class ZoomToExtent { class ZoomToExtent {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
/** /**
* @type {module:ol/extent~Extent} * @type {module:ol/extent~Extent}
* @protected * @protected
*/ */
this.extent = options.extent ? options.extent : null; this.extent = options.extent ? options.extent : null;
const className = options.className !== undefined ? options.className : 'ol-zoom-extent'; const className = options.className !== undefined ? options.className : 'ol-zoom-extent';
const label = options.label !== undefined ? options.label : 'E'; const label = options.label !== undefined ? options.label : 'E';
const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Fit to extent'; const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Fit to extent';
const button = document.createElement('button'); const button = document.createElement('button');
button.setAttribute('type', 'button'); button.setAttribute('type', 'button');
button.title = tipLabel; button.title = tipLabel;
button.appendChild( button.appendChild(
typeof label === 'string' ? document.createTextNode(label) : label typeof label === 'string' ? document.createTextNode(label) : label
); );
listen(button, EventType.CLICK, this.handleClick_, this); listen(button, EventType.CLICK, this.handleClick_, this);
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL; const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
const element = document.createElement('div'); const element = document.createElement('div');
element.className = cssClasses; element.className = cssClasses;
element.appendChild(button); element.appendChild(button);
Control.call(this, { Control.call(this, {
element: element, element: element,
target: options.target target: options.target
}); });
} }
/** /**
* @param {MouseEvent} event The event to handle * @param {MouseEvent} event The event to handle
* @private * @private
*/ */
handleClick_(event) { handleClick_(event) {
event.preventDefault(); event.preventDefault();
this.handleZoomToExtent(); this.handleZoomToExtent();
} }
/** /**
* @protected * @protected
*/ */
handleZoomToExtent() { handleZoomToExtent() {
const map = this.getMap(); const map = this.getMap();
const view = map.getView(); const view = map.getView();
const extent = !this.extent ? view.getProjection().getExtent() : this.extent; const extent = !this.extent ? view.getProjection().getExtent() : this.extent;
view.fit(extent); view.fit(extent);
} }
} }
inherits(ZoomToExtent, Control); inherits(ZoomToExtent, Control);

View File

@@ -61,42 +61,42 @@ import {get as getProjection, equivalent as equivalentProjection, transformExten
* @api * @api
*/ */
class FeatureFormat { class FeatureFormat {
constructor() { constructor() {
/** /**
* @protected * @protected
* @type {module:ol/proj/Projection} * @type {module:ol/proj/Projection}
*/ */
this.dataProjection = null; this.dataProjection = null;
/** /**
* @protected * @protected
* @type {module:ol/proj/Projection} * @type {module:ol/proj/Projection}
*/ */
this.defaultFeatureProjection = null; this.defaultFeatureProjection = null;
} }
/** /**
* Adds the data projection to the read options. * Adds the data projection to the read options.
* @param {Document|Node|Object|string} source Source. * @param {Document|Node|Object|string} source Source.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
* @return {module:ol/format/Feature~ReadOptions|undefined} Options. * @return {module:ol/format/Feature~ReadOptions|undefined} Options.
* @protected * @protected
*/ */
getReadOptions(source, opt_options) { getReadOptions(source, opt_options) {
let options; let options;
if (opt_options) { if (opt_options) {
options = { options = {
dataProjection: opt_options.dataProjection ? dataProjection: opt_options.dataProjection ?
opt_options.dataProjection : this.readProjection(source), opt_options.dataProjection : this.readProjection(source),
featureProjection: opt_options.featureProjection featureProjection: opt_options.featureProjection
}; };
} }
return this.adaptOptions(options); return this.adaptOptions(options);
} }
/** /**
* Sets the `dataProjection` on the options, if no `dataProjection` * Sets the `dataProjection` on the options, if no `dataProjection`
* is set. * is set.
* @param {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined} options * @param {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined} options
@@ -105,28 +105,28 @@ class FeatureFormat {
* @return {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined} * @return {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined}
* Updated options. * Updated options.
*/ */
adaptOptions(options) { adaptOptions(options) {
return assign({ return assign({
dataProjection: this.dataProjection, dataProjection: this.dataProjection,
featureProjection: this.defaultFeatureProjection featureProjection: this.defaultFeatureProjection
}, options); }, options);
} }
/** /**
* Get the extent from the source of the last {@link readFeatures} call. * Get the extent from the source of the last {@link readFeatures} call.
* @return {module:ol/extent~Extent} Tile extent. * @return {module:ol/extent~Extent} Tile extent.
*/ */
getLastExtent() { getLastExtent() {
return null; return null;
} }
/** /**
* @abstract * @abstract
* @return {module:ol/format/FormatType} Format. * @return {module:ol/format/FormatType} Format.
*/ */
getType() {} getType() {}
/** /**
* Read a single feature from a source. * Read a single feature from a source.
* *
* @abstract * @abstract
@@ -134,9 +134,9 @@ class FeatureFormat {
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {module:ol/Feature} Feature. * @return {module:ol/Feature} Feature.
*/ */
readFeature(source, opt_options) {} readFeature(source, opt_options) {}
/** /**
* Read all features from a source. * Read all features from a source.
* *
* @abstract * @abstract
@@ -144,9 +144,9 @@ class FeatureFormat {
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {Array.<module:ol/Feature>} Features. * @return {Array.<module:ol/Feature>} Features.
*/ */
readFeatures(source, opt_options) {} readFeatures(source, opt_options) {}
/** /**
* Read a single geometry from a source. * Read a single geometry from a source.
* *
* @abstract * @abstract
@@ -154,18 +154,18 @@ class FeatureFormat {
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {module:ol/geom/Geometry} Geometry. * @return {module:ol/geom/Geometry} Geometry.
*/ */
readGeometry(source, opt_options) {} readGeometry(source, opt_options) {}
/** /**
* Read the projection from a source. * Read the projection from a source.
* *
* @abstract * @abstract
* @param {Document|Node|Object|string} source Source. * @param {Document|Node|Object|string} source Source.
* @return {module:ol/proj/Projection} Projection. * @return {module:ol/proj/Projection} Projection.
*/ */
readProjection(source) {} readProjection(source) {}
/** /**
* Encode a feature in this format. * Encode a feature in this format.
* *
* @abstract * @abstract
@@ -173,9 +173,9 @@ class FeatureFormat {
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {string} Result. * @return {string} Result.
*/ */
writeFeature(feature, opt_options) {} writeFeature(feature, opt_options) {}
/** /**
* Encode an array of features in this format. * Encode an array of features in this format.
* *
* @abstract * @abstract
@@ -183,9 +183,9 @@ class FeatureFormat {
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {string} Result. * @return {string} Result.
*/ */
writeFeatures(features, opt_options) {} writeFeatures(features, opt_options) {}
/** /**
* Write a single geometry in this format. * Write a single geometry in this format.
* *
* @abstract * @abstract
@@ -193,7 +193,7 @@ class FeatureFormat {
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {string} Result. * @return {string} Result.
*/ */
writeGeometry(geometry, opt_options) {} writeGeometry(geometry, opt_options) {}
} }
export default FeatureFormat; export default FeatureFormat;

View File

@@ -20,6 +20,18 @@ import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
const schemaLocation = GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd'; const schemaLocation = GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @const
* @type {Object.<string, string>}
*/
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/** /**
* @classdesc * @classdesc
* Feature format for reading and writing data in the GML format, * Feature format for reading and writing data in the GML format,
@@ -576,18 +588,6 @@ class GML2 {
inherits(GML2, GMLBase); inherits(GML2, GMLBase);
/**
* @const
* @type {Object.<string, string>}
*/
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -30,6 +30,18 @@ const schemaLocation = GMLNS +
'1.0.0/gmlsf.xsd'; '1.0.0/gmlsf.xsd';
/**
* @const
* @type {Object.<string, string>}
*/
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/** /**
* @classdesc * @classdesc
* Feature format for reading and writing data in the GML format * Feature format for reading and writing data in the GML format
@@ -1088,18 +1100,6 @@ GML3.prototype.SEGMENTS_PARSERS_ = {
}; };
/**
* @const
* @type {Object.<string, string>}
*/
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/** /**
* Encode an array of features in GML 3.1.1 Simple Features. * Encode an array of features in GML 3.1.1 Simple Features.
* *

View File

@@ -29,6 +29,20 @@ import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseN
export const GMLNS = 'http://www.opengis.net/gml'; export const GMLNS = 'http://www.opengis.net/gml';
/**
* A regular expression that matches if a string only contains whitespace
* characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
* space (0xa0) is explicitly included as IE doesn't include it in its
* definition of `\s`.
*
* Information from `goog.string.isEmptyOrWhitespace`: https://github.com/google/closure-library/blob/e877b1e/closure/goog/string/string.js#L156-L160
*
* @const
* @type {RegExp}
*/
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {Object.<string, string>|string} [featureNS] Feature * @property {Object.<string, string>|string} [featureNS] Feature
@@ -458,20 +472,6 @@ class GMLBase {
inherits(GMLBase, XMLFeature); inherits(GMLBase, XMLFeature);
/**
* A regular expression that matches if a string only contains whitespace
* characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
* space (0xa0) is explicitly included as IE doesn't include it in its
* definition of `\s`.
*
* Information from `goog.string.isEmptyOrWhitespace`: https://github.com/google/closure-library/blob/e877b1e/closure/goog/string/string.js#L156-L160
*
* @const
* @type {RegExp}
*/
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -18,6 +18,71 @@ import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender
XML_SCHEMA_INSTANCE_URI} from '../xml.js'; XML_SCHEMA_INSTANCE_URI} from '../xml.js';
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.topografix.com/GPX/1/0',
'http://www.topografix.com/GPX/1/1'
];
/**
* @const
* @type {string}
*/
const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd';
/**
* @const
* @type {Object.<string, function(Node, Array.<*>): (module:ol/Feature|undefined)>}
*/
const FEATURE_READER = {
'rte': readRte,
'trk': readTrk,
'wpt': readWpt
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const GPX_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeArrayPusher(readRte),
'trk': makeArrayPusher(readTrk),
'wpt': makeArrayPusher(readWpt)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'text': makeObjectPropertySetter(readString, 'linkText'),
'type': makeObjectPropertySetter(readString, 'linkType')
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const GPX_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeChildAppender(writeRte),
'trk': makeChildAppender(writeTrk),
'wpt': makeChildAppender(writeWpt)
});
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {function(module:ol/Feature, Node)} [readExtensions] Callback function * @property {function(module:ol/Feature, Node)} [readExtensions] Callback function
@@ -150,59 +215,6 @@ class GPX {
inherits(GPX, XMLFeature); inherits(GPX, XMLFeature);
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.topografix.com/GPX/1/0',
'http://www.topografix.com/GPX/1/1'
];
/**
* @const
* @type {string}
*/
const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd';
/**
* @const
* @type {Object.<string, function(Node, Array.<*>): (module:ol/Feature|undefined)>}
*/
const FEATURE_READER = {
'rte': readRte,
'trk': readTrk,
'wpt': readWpt
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const GPX_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeArrayPusher(readRte),
'trk': makeArrayPusher(readTrk),
'wpt': makeArrayPusher(readWpt)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'text': makeObjectPropertySetter(readString, 'linkText'),
'type': makeObjectPropertySetter(readString, 'linkType')
});
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
@@ -466,18 +478,6 @@ function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
} }
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const GPX_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeChildAppender(writeRte),
'trk': makeChildAppender(writeTrk),
'wpt': makeChildAppender(writeWpt)
});
/** /**
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {module:ol/format/GPX~LayoutOptions} layoutOptions Layout options. * @param {module:ol/format/GPX~LayoutOptions} layoutOptions Layout options.

View File

@@ -19,6 +19,36 @@ const IGCZ = {
NONE: 'none' NONE: 'none'
}; };
/**
* @const
* @type {RegExp}
*/
const B_RECORD_RE =
/^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
/**
* @const
* @type {RegExp}
*/
const H_RECORD_RE = /^H.([A-Z]{3}).*?:(.*)/;
/**
* @const
* @type {RegExp}
*/
const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
/**
* A regular expression matching the newline characters `\r\n`, `\r` and `\n`.
*
* @const
* @type {RegExp}
*/
const NEWLINE_RE = /\r\n|\r|\n/;
/** /**
* @typedef {Object} Options * @typedef {Object} Options
@@ -170,37 +200,6 @@ class IGC {
inherits(IGC, TextFeature); inherits(IGC, TextFeature);
/**
* @const
* @type {RegExp}
*/
const B_RECORD_RE =
/^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
/**
* @const
* @type {RegExp}
*/
const H_RECORD_RE = /^H.([A-Z]{3}).*?:(.*)/;
/**
* @const
* @type {RegExp}
*/
const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
/**
* A regular expression matching the newline characters `\r\n`, `\r` and `\n`.
*
* @const
* @type {RegExp}
*/
const NEWLINE_RE = /\r\n|\r|\n/;
/** /**
* Read the feature from the IGC source. * Read the feature from the IGC source.
* *

View File

@@ -16,127 +16,127 @@ import FormatType from '../format/FormatType.js';
* @extends {module:ol/format/Feature} * @extends {module:ol/format/Feature}
*/ */
class JSONFeature { class JSONFeature {
constructor() { constructor() {
FeatureFormat.call(this); FeatureFormat.call(this);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getType() { getType() {
return FormatType.JSON; return FormatType.JSON;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
readFeature(source, opt_options) { readFeature(source, opt_options) {
return this.readFeatureFromObject( return this.readFeatureFromObject(
getObject(source), this.getReadOptions(source, opt_options)); getObject(source), this.getReadOptions(source, opt_options));
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
readFeatures(source, opt_options) { readFeatures(source, opt_options) {
return this.readFeaturesFromObject( return this.readFeaturesFromObject(
getObject(source), this.getReadOptions(source, opt_options)); getObject(source), this.getReadOptions(source, opt_options));
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {module:ol/Feature} Feature. * @return {module:ol/Feature} Feature.
*/ */
readFeatureFromObject(object, opt_options) {} readFeatureFromObject(object, opt_options) {}
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {Array.<module:ol/Feature>} Features. * @return {Array.<module:ol/Feature>} Features.
*/ */
readFeaturesFromObject(object, opt_options) {} readFeaturesFromObject(object, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
readGeometry(source, opt_options) { readGeometry(source, opt_options) {
return this.readGeometryFromObject( return this.readGeometryFromObject(
getObject(source), this.getReadOptions(source, opt_options)); getObject(source), this.getReadOptions(source, opt_options));
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {module:ol/geom/Geometry} Geometry. * @return {module:ol/geom/Geometry} Geometry.
*/ */
readGeometryFromObject(object, opt_options) {} readGeometryFromObject(object, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
readProjection(source) { readProjection(source) {
return this.readProjectionFromObject(getObject(source)); return this.readProjectionFromObject(getObject(source));
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @protected * @protected
* @return {module:ol/proj/Projection} Projection. * @return {module:ol/proj/Projection} Projection.
*/ */
readProjectionFromObject(object) {} readProjectionFromObject(object) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, opt_options) {
return JSON.stringify(this.writeFeatureObject(feature, opt_options)); return JSON.stringify(this.writeFeatureObject(feature, opt_options));
} }
/** /**
* @abstract * @abstract
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeFeatureObject(feature, opt_options) {} writeFeatureObject(feature, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, opt_options) {
return JSON.stringify(this.writeFeaturesObject(features, opt_options)); return JSON.stringify(this.writeFeaturesObject(features, opt_options));
} }
/** /**
* @abstract * @abstract
* @param {Array.<module:ol/Feature>} features Features. * @param {Array.<module:ol/Feature>} features Features.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeFeaturesObject(features, opt_options) {} writeFeaturesObject(features, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, opt_options) {
return JSON.stringify(this.writeGeometryObject(geometry, opt_options)); return JSON.stringify(this.writeGeometryObject(geometry, opt_options));
} }
/** /**
* @abstract * @abstract
* @param {module:ol/geom/Geometry} geometry Geometry. * @param {module:ol/geom/Geometry} geometry Geometry.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeGeometryObject(geometry, opt_options) {} writeGeometryObject(geometry, opt_options) {}
} }
inherits(JSONFeature, FeatureFormat); inherits(JSONFeature, FeatureFormat);

View File

@@ -48,6 +48,143 @@ import {createElementNS, getAllTextContent, isDocument, isNode, makeArrayExtende
* @property {Array.<number>} whens * @property {Array.<number>} whens
*/ */
/**
* @const
* @type {Array.<string>}
*/
const GX_NAMESPACE_URIS = [
'http://www.google.com/kml/ext/2.2'
];
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://earth.google.com/kml/2.0',
'http://earth.google.com/kml/2.1',
'http://earth.google.com/kml/2.2',
'http://www.opengis.net/kml/2.2'
];
/**
* @const
* @type {string}
*/
const SCHEMA_LOCATION = 'http://www.opengis.net/kml/2.2 ' +
'https://developers.google.com/kml/schema/kml22gx.xsd';
/**
* @type {Object.<string, module:ol/style/IconAnchorUnits>}
*/
const ICON_ANCHOR_UNITS_MAP = {
'fraction': IconAnchorUnits.FRACTION,
'pixels': IconAnchorUnits.PIXELS,
'insetPixels': IconAnchorUnits.PIXELS
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PLACEMARK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ExtendedData': extendedDataParser,
'Region': regionParser,
'MultiGeometry': makeObjectPropertySetter(
readMultiGeometry, 'geometry'),
'LineString': makeObjectPropertySetter(
readLineString, 'geometry'),
'LinearRing': makeObjectPropertySetter(
readLinearRing, 'geometry'),
'Point': makeObjectPropertySetter(
readPoint, 'geometry'),
'Polygon': makeObjectPropertySetter(
readPolygon, 'geometry'),
'Style': makeObjectPropertySetter(readStyle),
'StyleMap': placemarkStyleMapParser,
'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(readString),
'styleUrl': makeObjectPropertySetter(readURI),
'visibility': makeObjectPropertySetter(readBoolean)
}, makeStructureNS(
GX_NAMESPACE_URIS, {
'MultiTrack': makeObjectPropertySetter(
readGxMultiTrack, 'geometry'),
'Track': makeObjectPropertySetter(
readGxTrack, 'geometry')
}
));
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const NETWORK_LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ExtendedData': extendedDataParser,
'Region': regionParser,
'Link': linkParser,
'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(readString),
'visibility': makeObjectPropertySetter(readBoolean)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'href': makeObjectPropertySetter(readURI)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const REGION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'LatLonAltBox': latLonAltBoxParser,
'Lod': lodParser
});
/**
* @const
* @type {Object.<string, Array.<string>>}
*/
const KML_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'Document', 'Placemark'
]);
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const KML_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'Document': makeChildAppender(writeDocument),
'Placemark': makeChildAppender(writePlacemark)
});
/** /**
* @type {module:ol/color~Color} * @type {module:ol/color~Color}
*/ */
@@ -713,46 +850,6 @@ class KML {
inherits(KML, XMLFeature); inherits(KML, XMLFeature);
/**
* @const
* @type {Array.<string>}
*/
const GX_NAMESPACE_URIS = [
'http://www.google.com/kml/ext/2.2'
];
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://earth.google.com/kml/2.0',
'http://earth.google.com/kml/2.1',
'http://earth.google.com/kml/2.2',
'http://www.opengis.net/kml/2.2'
];
/**
* @const
* @type {string}
*/
const SCHEMA_LOCATION = 'http://www.opengis.net/kml/2.2 ' +
'https://developers.google.com/kml/schema/kml22gx.xsd';
/**
* @type {Object.<string, module:ol/style/IconAnchorUnits>}
*/
const ICON_ANCHOR_UNITS_MAP = {
'fraction': IconAnchorUnits.FRACTION,
'pixels': IconAnchorUnits.PIXELS,
'insetPixels': IconAnchorUnits.PIXELS
};
/** /**
* @param {module:ol/style/Style|undefined} foundStyle Style. * @param {module:ol/style/Style|undefined} foundStyle Style.
* @param {string} name Name. * @param {string} name Name.
@@ -1723,17 +1820,6 @@ function extendedDataParser(node, objectStack) {
parseNode(EXTENDED_DATA_PARSERS, node, objectStack); parseNode(EXTENDED_DATA_PARSERS, node, objectStack);
} }
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const REGION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'LatLonAltBox': latLonAltBoxParser,
'Lod': lodParser
});
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack. * @param {Array.<*>} objectStack Object stack.
@@ -1955,34 +2041,6 @@ function outerBoundaryIsParser(node, objectStack) {
} }
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const NETWORK_LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ExtendedData': extendedDataParser,
'Region': regionParser,
'Link': linkParser,
'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(readString),
'visibility': makeObjectPropertySetter(readBoolean)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'href': makeObjectPropertySetter(readURI)
});
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack. * @param {Array.<*>} objectStack Object stack.
@@ -2006,43 +2064,6 @@ function whenParser(node, objectStack) {
} }
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PLACEMARK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ExtendedData': extendedDataParser,
'Region': regionParser,
'MultiGeometry': makeObjectPropertySetter(
readMultiGeometry, 'geometry'),
'LineString': makeObjectPropertySetter(
readLineString, 'geometry'),
'LinearRing': makeObjectPropertySetter(
readLinearRing, 'geometry'),
'Point': makeObjectPropertySetter(
readPoint, 'geometry'),
'Polygon': makeObjectPropertySetter(
readPolygon, 'geometry'),
'Style': makeObjectPropertySetter(readStyle),
'StyleMap': placemarkStyleMapParser,
'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(readString),
'styleUrl': makeObjectPropertySetter(readURI),
'visibility': makeObjectPropertySetter(readBoolean)
}, makeStructureNS(
GX_NAMESPACE_URIS, {
'MultiTrack': makeObjectPropertySetter(
readGxMultiTrack, 'geometry'),
'Track': makeObjectPropertySetter(
readGxTrack, 'geometry')
}
));
/** /**
* Read the first feature from a KML source. MultiGeometries are converted into * Read the first feature from a KML source. MultiGeometries are converted into
* GeometryCollections if they are a mix of geometry types, and into MultiPoint/ * GeometryCollections if they are a mix of geometry types, and into MultiPoint/
@@ -2941,27 +2962,6 @@ function writeVec2(node, vec2) {
} }
/**
* @const
* @type {Object.<string, Array.<string>>}
*/
const KML_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'Document', 'Placemark'
]);
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const KML_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'Document': makeChildAppender(writeDocument),
'Placemark': makeChildAppender(writePlacemark)
});
/** /**
* Encode an array of features in the KML format. GeometryCollections, MultiPoints, * Encode an array of features in the KML format. GeometryCollections, MultiPoints,
* MultiLineStrings, and MultiPolygons are output as MultiGeometries. * MultiLineStrings, and MultiPolygons are output as MultiGeometries.

View File

@@ -15,6 +15,36 @@ import {isEmpty} from '../obj.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
import {pushParseAndPop, makeStructureNS} from '../xml.js'; import {pushParseAndPop, makeStructureNS} from '../xml.js';
/**
* @const
* @type {Array.<null>}
*/
const NAMESPACE_URIS = [null];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const WAY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'nd': readNd,
'tag': readTag
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'node': readNode,
'way': readWay
});
/** /**
* @classdesc * @classdesc
* Feature format for reading data in the * Feature format for reading data in the
@@ -96,35 +126,6 @@ class OSMXML {
inherits(OSMXML, XMLFeature); inherits(OSMXML, XMLFeature);
/**
* @const
* @type {Array.<null>}
*/
const NAMESPACE_URIS = [null];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const WAY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'nd': readNd,
'tag': readTag
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'node': readNode,
'way': readWay
});
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -7,6 +7,26 @@ import XML from '../format/XML.js';
import {readString} from '../format/xsd.js'; import {readString} from '../format/xsd.js';
import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js'; import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js';
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
});
/** /**
* @constructor * @constructor
* @extends {module:ol/format/XML} * @extends {module:ol/format/XML}
@@ -41,25 +61,6 @@ class OWS {
inherits(OWS, XML); inherits(OWS, XML);
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
});
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -16,128 +16,128 @@ import FormatType from '../format/FormatType.js';
* @extends {module:ol/format/Feature} * @extends {module:ol/format/Feature}
*/ */
class TextFeature { class TextFeature {
constructor() { constructor() {
FeatureFormat.call(this); FeatureFormat.call(this);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getType() { getType() {
return FormatType.TEXT; return FormatType.TEXT;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
readFeature(source, opt_options) { readFeature(source, opt_options) {
return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options)); return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {module:ol/Feature} Feature. * @return {module:ol/Feature} Feature.
*/ */
readFeatureFromText(text, opt_options) {} readFeatureFromText(text, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
readFeatures(source, opt_options) { readFeatures(source, opt_options) {
return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options)); return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {Array.<module:ol/Feature>} Features. * @return {Array.<module:ol/Feature>} Features.
*/ */
readFeaturesFromText(text, opt_options) {} readFeaturesFromText(text, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
readGeometry(source, opt_options) { readGeometry(source, opt_options) {
return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options)); return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @protected * @protected
* @return {module:ol/geom/Geometry} Geometry. * @return {module:ol/geom/Geometry} Geometry.
*/ */
readGeometryFromText(text, opt_options) {} readGeometryFromText(text, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
readProjection(source) { readProjection(source) {
return this.readProjectionFromText(getText(source)); return this.readProjectionFromText(getText(source));
} }
/** /**
* @param {string} text Text. * @param {string} text Text.
* @protected * @protected
* @return {module:ol/proj/Projection} Projection. * @return {module:ol/proj/Projection} Projection.
*/ */
readProjectionFromText(text) { readProjectionFromText(text) {
return this.dataProjection; return this.dataProjection;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, opt_options) {
return this.writeFeatureText(feature, this.adaptOptions(opt_options)); return this.writeFeatureText(feature, this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {module:ol/Feature} feature Features. * @param {module:ol/Feature} feature Features.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeatureText(feature, opt_options) {} writeFeatureText(feature, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, opt_options) {
return this.writeFeaturesText(features, this.adaptOptions(opt_options)); return this.writeFeaturesText(features, this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {Array.<module:ol/Feature>} features Features. * @param {Array.<module:ol/Feature>} features Features.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeaturesText(features, opt_options) {} writeFeaturesText(features, opt_options) {}
/** /**
* @inheritDoc * @inheritDoc
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, opt_options) {
return this.writeGeometryText(geometry, this.adaptOptions(opt_options)); return this.writeGeometryText(geometry, this.adaptOptions(opt_options));
} }
/** /**
* @abstract * @abstract
* @param {module:ol/geom/Geometry} geometry Geometry. * @param {module:ol/geom/Geometry} geometry Geometry.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeGeometryText(geometry, opt_options) {} writeGeometryText(geometry, opt_options) {}
} }
inherits(TextFeature, FeatureFormat); inherits(TextFeature, FeatureFormat);

View File

@@ -17,6 +17,69 @@ import {createElementNS, isDocument, isNode, makeArrayPusher, makeChildAppender,
pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js'; pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const FEATURE_COLLECTION_PARSERS = {
'http://www.opengis.net/gml': {
'boundedBy': makeObjectPropertySetter(
GMLBase.prototype.readGeometryElement, 'bounds')
}
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const TRANSACTION_SUMMARY_PARSERS = {
'http://www.opengis.net/wfs': {
'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
}
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const TRANSACTION_RESPONSE_PARSERS = {
'http://www.opengis.net/wfs': {
'TransactionSummary': makeObjectPropertySetter(
readTransactionSummary, 'transactionSummary'),
'InsertResults': makeObjectPropertySetter(
readInsertResults, 'insertIds')
}
};
/**
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const QUERY_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'PropertyName': makeChildAppender(writeStringTextNode)
}
};
/**
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const TRANSACTION_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'Insert': makeChildAppender(writeFeature),
'Update': makeChildAppender(writeUpdate),
'Delete': makeChildAppender(writeDelete),
'Property': makeChildAppender(writeProperty),
'Native': makeChildAppender(writeNative)
}
};
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {Object.<string, string>|string} [featureNS] The namespace URI used for features. * @property {Object.<string, string>|string} [featureNS] The namespace URI used for features.
@@ -487,31 +550,6 @@ inherits(WFS, XMLFeature);
WFS.prototype.readFeatures; WFS.prototype.readFeatures;
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const FEATURE_COLLECTION_PARSERS = {
'http://www.opengis.net/gml': {
'boundedBy': makeObjectPropertySetter(
GMLBase.prototype.readGeometryElement, 'bounds')
}
};
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const TRANSACTION_SUMMARY_PARSERS = {
'http://www.opengis.net/wfs': {
'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
}
};
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack. * @param {Array.<*>} objectStack Object stack.
@@ -567,30 +605,6 @@ function readInsertResults(node, objectStack) {
} }
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const TRANSACTION_RESPONSE_PARSERS = {
'http://www.opengis.net/wfs': {
'TransactionSummary': makeObjectPropertySetter(
readTransactionSummary, 'transactionSummary'),
'InsertResults': makeObjectPropertySetter(
readInsertResults, 'insertIds')
}
};
/**
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const QUERY_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'PropertyName': makeChildAppender(writeStringTextNode)
}
};
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.
@@ -663,20 +677,6 @@ function writeDelete(node, feature, objectStack) {
} }
/**
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
*/
const TRANSACTION_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'Insert': makeChildAppender(writeFeature),
'Update': makeChildAppender(writeUpdate),
'Delete': makeChildAppender(writeDelete),
'Property': makeChildAppender(writeProperty),
'Native': makeChildAppender(writeNative)
}
};
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.

View File

@@ -17,6 +17,19 @@ import Polygon from '../geom/Polygon.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
/**
* @enum {function (new:module:ol/geom/Geometry, Array, module:ol/geom/GeometryLayout)}
*/
const GeometryConstructor = {
'POINT': Point,
'LINESTRING': LineString,
'POLYGON': Polygon,
'MULTIPOINT': MultiPoint,
'MULTILINESTRING': MultiLineString,
'MULTIPOLYGON': MultiPolygon
};
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {boolean} [splitCollection=false] Whether to split GeometryCollections into * @property {boolean} [splitCollection=false] Whether to split GeometryCollections into
@@ -521,12 +534,42 @@ class Parser {
const geometries = this.parseGeometryCollectionText_(); const geometries = this.parseGeometryCollectionText_();
return new GeometryCollection(geometries); return new GeometryCollection(geometries);
} else { } else {
const parser = GeometryParser[geomType];
const ctor = GeometryConstructor[geomType]; const ctor = GeometryConstructor[geomType];
if (!parser || !ctor) { if (!ctor) {
throw new Error('Invalid geometry type: ' + geomType); throw new Error('Invalid geometry type: ' + geomType);
} }
let coordinates = parser.call(this);
let coordinates;
switch (geomType) {
case GeometryType.POINT: {
coordinates = this.parsePointText_();
break;
}
case GeometryType.LINESTRING: {
coordinates = this.parseLineStringText_();
break;
}
case GeometryType.POLYGON: {
coordinates = Parser.prototype.parsePolygonText_();
break;
}
case GeometryType.MULTIPOINT: {
coordinates = Parser.prototype.parseMultiPointText_();
break;
}
case GeometryType.MULTILINESTRING: {
coordinates = Parser.prototype.parseMultiLineStringText_();
break;
}
case GeometryType.MULTIPOLYGON: {
coordinates = Parser.prototype.parseMultiPolygonText_();
break;
}
default: {
throw new Error('Invalid geometry type: ' + geomType);
}
}
if (!coordinates) { if (!coordinates) {
if (ctor === GeometryConstructor[GeometryType.POINT]) { if (ctor === GeometryConstructor[GeometryType.POINT]) {
coordinates = [NaN, NaN]; coordinates = [NaN, NaN];
@@ -541,6 +584,7 @@ class Parser {
} }
} }
/** /**
* @classdesc * @classdesc
* Geometry format for reading and writing data in the `WellKnownText` (WKT) * Geometry format for reading and writing data in the `WellKnownText` (WKT)
@@ -855,32 +899,6 @@ WKT.prototype.readFeatures;
WKT.prototype.readGeometry; WKT.prototype.readGeometry;
/**
* @enum {function (new:module:ol/geom/Geometry, Array, module:ol/geom/GeometryLayout)}
*/
const GeometryConstructor = {
'POINT': Point,
'LINESTRING': LineString,
'POLYGON': Polygon,
'MULTIPOINT': MultiPoint,
'MULTILINESTRING': MultiLineString,
'MULTIPOLYGON': MultiPolygon
};
/**
* @enum {(function(): Array)}
*/
const GeometryParser = {
'POINT': Parser.prototype.parsePointText_,
'LINESTRING': Parser.prototype.parseLineStringText_,
'POLYGON': Parser.prototype.parsePolygonText_,
'MULTIPOINT': Parser.prototype.parseMultiPointText_,
'MULTILINESTRING': Parser.prototype.parseMultiLineStringText_,
'MULTIPOLYGON': Parser.prototype.parseMultiPolygonText_
};
/** /**
* Encode a feature as a WKT string. * Encode a feature as a WKT string.
* *

View File

@@ -9,6 +9,39 @@ import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter,
makeStructureNS, pushParseAndPop} from '../xml.js'; makeStructureNS, pushParseAndPop} from '../xml.js';
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wms'
];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Service': makeObjectPropertySetter(readService),
'Capability': makeObjectPropertySetter(readCapability)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const CAPABILITY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Request': makeObjectPropertySetter(readRequest),
'Exception': makeObjectPropertySetter(readException),
'Layer': makeObjectPropertySetter(readCapabilityLayer)
});
/** /**
* @classdesc * @classdesc
* Format for reading WMS capabilities data * Format for reading WMS capabilities data
@@ -55,39 +88,6 @@ class WMSCapabilities {
inherits(WMSCapabilities, XML); inherits(WMSCapabilities, XML);
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wms'
];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Service': makeObjectPropertySetter(readService),
'Capability': makeObjectPropertySetter(readCapability)
});
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const CAPABILITY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Request': makeObjectPropertySetter(readRequest),
'Exception': makeObjectPropertySetter(readException),
'Layer': makeObjectPropertySetter(readCapabilityLayer)
});
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -15,6 +15,20 @@ import {makeArrayPusher, makeStructureNS, pushParseAndPop} from '../xml.js';
*/ */
/**
* @const
* @type {string}
*/
const featureIdentifier = '_feature';
/**
* @const
* @type {string}
*/
const layerIdentifier = '_layer';
/** /**
* @classdesc * @classdesc
* Format for reading WMSGetFeatureInfo format. It uses * Format for reading WMSGetFeatureInfo format. It uses
@@ -159,20 +173,6 @@ class WMSGetFeatureInfo {
inherits(WMSGetFeatureInfo, XMLFeature); inherits(WMSGetFeatureInfo, XMLFeature);
/**
* @const
* @type {string}
*/
const featureIdentifier = '_feature';
/**
* @const
* @type {string}
*/
const layerIdentifier = '_layer';
/** /**
* Read all features from a WMSGetFeatureInfo response. * Read all features from a WMSGetFeatureInfo response.
* *

View File

@@ -10,6 +10,37 @@ import {readString, readNonNegativeInteger, readDecimal} from '../format/xsd.js'
import {pushParseAndPop, makeStructureNS, import {pushParseAndPop, makeStructureNS,
makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js'; makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js';
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wmts/1.0'
];
/**
* @const
* @type {Array.<null|string>}
*/
const OWS_NAMESPACE_URIS = [
null,
'http://www.opengis.net/ows/1.1'
];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Contents': makeObjectPropertySetter(readContents)
});
/** /**
* @classdesc * @classdesc
* Format for reading WMTS capabilities data. * Format for reading WMTS capabilities data.
@@ -59,36 +90,6 @@ class WMTSCapabilities {
inherits(WMTSCapabilities, XML); inherits(WMTSCapabilities, XML);
/**
* @const
* @type {Array.<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wmts/1.0'
];
/**
* @const
* @type {Array.<null|string>}
*/
const OWS_NAMESPACE_URIS = [
null,
'http://www.opengis.net/ows/1.1'
];
/**
* @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
*/
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Contents': makeObjectPropertySetter(readContents)
});
/** /**
* @const * @const
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>} * @type {Object.<string, Object.<string, module:ol/xml~Parser>>}

View File

@@ -12,36 +12,36 @@ import {isDocument, isNode, parse} from '../xml.js';
* @struct * @struct
*/ */
class XML { class XML {
/** /**
* @param {Document|Node|string} source Source. * @param {Document|Node|string} source Source.
* @return {Object} The parsed result. * @return {Object} The parsed result.
*/ */
read(source) { read(source) {
if (isDocument(source)) { if (isDocument(source)) {
return this.readFromDocument(/** @type {Document} */ (source)); return this.readFromDocument(/** @type {Document} */ (source));
} else if (isNode(source)) { } else if (isNode(source)) {
return this.readFromNode(/** @type {Node} */ (source)); return this.readFromNode(/** @type {Node} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readFromDocument(doc); return this.readFromDocument(doc);
} else { } else {
return null; return null;
} }
} }
/** /**
* @abstract * @abstract
* @param {Document} doc Document. * @param {Document} doc Document.
* @return {Object} Object * @return {Object} Object
*/ */
readFromDocument(doc) {} readFromDocument(doc) {}
/** /**
* @abstract * @abstract
* @param {Node} node Node. * @param {Node} node Node.
* @return {Object} Object * @return {Object} Object
*/ */
readFromNode(node) {} readFromNode(node) {}
} }
export default XML; export default XML;

View File

@@ -14,22 +14,22 @@
* @struct * @struct
*/ */
class Filter { class Filter {
constructor(tagName) { constructor(tagName) {
/** /**
* @private * @private
* @type {!string} * @type {!string}
*/ */
this.tagName_ = tagName; this.tagName_ = tagName;
} }
/** /**
* The XML tag name for a filter. * The XML tag name for a filter.
* @returns {!string} Name. * @returns {!string} Name.
*/ */
getTagName() { getTagName() {
return this.tagName_; return this.tagName_;
} }
} }
export default Filter; export default Filter;

View File

@@ -11,6 +11,12 @@ import Units from '../proj/Units.js';
import {create as createTransform, compose as composeTransform} from '../transform.js'; import {create as createTransform, compose as composeTransform} from '../transform.js';
/**
* @type {module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* @classdesc * @classdesc
* Abstract base class; normally only used for creating subclasses and not * Abstract base class; normally only used for creating subclasses and not
@@ -26,50 +32,50 @@ import {create as createTransform, compose as composeTransform} from '../transfo
* @api * @api
*/ */
class Geometry { class Geometry {
constructor() { constructor() {
BaseObject.call(this); BaseObject.call(this);
/** /**
* @private * @private
* @type {module:ol/extent~Extent} * @type {module:ol/extent~Extent}
*/ */
this.extent_ = createEmpty(); this.extent_ = createEmpty();
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.extentRevision_ = -1; this.extentRevision_ = -1;
/** /**
* @protected * @protected
* @type {Object.<string, module:ol/geom/Geometry>} * @type {Object.<string, module:ol/geom/Geometry>}
*/ */
this.simplifiedGeometryCache = {}; this.simplifiedGeometryCache = {};
/** /**
* @protected * @protected
* @type {number} * @type {number}
*/ */
this.simplifiedGeometryMaxMinSquaredTolerance = 0; this.simplifiedGeometryMaxMinSquaredTolerance = 0;
/** /**
* @protected * @protected
* @type {number} * @type {number}
*/ */
this.simplifiedGeometryRevision = 0; this.simplifiedGeometryRevision = 0;
} }
/** /**
* Make a complete copy of the geometry. * Make a complete copy of the geometry.
* @abstract * @abstract
* @return {!module:ol/geom/Geometry} Clone. * @return {!module:ol/geom/Geometry} Clone.
*/ */
clone() {} clone() {}
/** /**
* @abstract * @abstract
* @param {number} x X. * @param {number} x X.
* @param {number} y Y. * @param {number} y Y.
@@ -77,9 +83,9 @@ class Geometry {
* @param {number} minSquaredDistance Minimum squared distance. * @param {number} minSquaredDistance Minimum squared distance.
* @return {number} Minimum squared distance. * @return {number} Minimum squared distance.
*/ */
closestPointXY(x, y, closestPoint, minSquaredDistance) {} closestPointXY(x, y, closestPoint, minSquaredDistance) {}
/** /**
* Return the closest point of the geometry to the passed point as * Return the closest point of the geometry to the passed point as
* {@link module:ol/coordinate~Coordinate coordinate}. * {@link module:ol/coordinate~Coordinate coordinate}.
* @param {module:ol/coordinate~Coordinate} point Point. * @param {module:ol/coordinate~Coordinate} point Point.
@@ -87,46 +93,46 @@ class Geometry {
* @return {module:ol/coordinate~Coordinate} Closest point. * @return {module:ol/coordinate~Coordinate} Closest point.
* @api * @api
*/ */
getClosestPoint(point, opt_closestPoint) { getClosestPoint(point, opt_closestPoint) {
const closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN]; const closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN];
this.closestPointXY(point[0], point[1], closestPoint, Infinity); this.closestPointXY(point[0], point[1], closestPoint, Infinity);
return closestPoint; return closestPoint;
} }
/** /**
* Returns true if this geometry includes the specified coordinate. If the * Returns true if this geometry includes the specified coordinate. If the
* coordinate is on the boundary of the geometry, returns false. * coordinate is on the boundary of the geometry, returns false.
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate. * @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
* @return {boolean} Contains coordinate. * @return {boolean} Contains coordinate.
* @api * @api
*/ */
intersectsCoordinate(coordinate) { intersectsCoordinate(coordinate) {
return this.containsXY(coordinate[0], coordinate[1]); return this.containsXY(coordinate[0], coordinate[1]);
} }
/** /**
* @abstract * @abstract
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @protected * @protected
* @return {module:ol/extent~Extent} extent Extent. * @return {module:ol/extent~Extent} extent Extent.
*/ */
computeExtent(extent) {} computeExtent(extent) {}
/** /**
* Get the extent of the geometry. * Get the extent of the geometry.
* @param {module:ol/extent~Extent=} opt_extent Extent. * @param {module:ol/extent~Extent=} opt_extent Extent.
* @return {module:ol/extent~Extent} extent Extent. * @return {module:ol/extent~Extent} extent Extent.
* @api * @api
*/ */
getExtent(opt_extent) { getExtent(opt_extent) {
if (this.extentRevision_ != this.getRevision()) { if (this.extentRevision_ != this.getRevision()) {
this.extent_ = this.computeExtent(this.extent_); this.extent_ = this.computeExtent(this.extent_);
this.extentRevision_ = this.getRevision(); this.extentRevision_ = this.getRevision();
} }
return returnOrUpdate(this.extent_, opt_extent); return returnOrUpdate(this.extent_, opt_extent);
} }
/** /**
* Rotate the geometry around a given coordinate. This modifies the geometry * Rotate the geometry around a given coordinate. This modifies the geometry
* coordinates in place. * coordinates in place.
* @abstract * @abstract
@@ -134,9 +140,9 @@ class Geometry {
* @param {module:ol/coordinate~Coordinate} anchor The rotation center. * @param {module:ol/coordinate~Coordinate} anchor The rotation center.
* @api * @api
*/ */
rotate(angle, anchor) {} rotate(angle, anchor) {}
/** /**
* Scale the geometry (with an optional origin). This modifies the geometry * Scale the geometry (with an optional origin). This modifies the geometry
* coordinates in place. * coordinates in place.
* @abstract * @abstract
@@ -147,9 +153,9 @@ class Geometry {
* of the geometry extent). * of the geometry extent).
* @api * @api
*/ */
scale(sx, opt_sy, opt_anchor) {} scale(sx, opt_sy, opt_anchor) {}
/** /**
* Create a simplified version of this geometry. For linestrings, this uses * Create a simplified version of this geometry. For linestrings, this uses
* the the {@link * the the {@link
* https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm * https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
@@ -161,11 +167,11 @@ class Geometry {
* geometry. * geometry.
* @api * @api
*/ */
simplify(tolerance) { simplify(tolerance) {
return this.getSimplifiedGeometry(tolerance * tolerance); return this.getSimplifiedGeometry(tolerance * tolerance);
} }
/** /**
* Create a simplified version of this geometry using the Douglas Peucker * Create a simplified version of this geometry using the Douglas Peucker
* algorithm. * algorithm.
* @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm * @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
@@ -173,16 +179,16 @@ class Geometry {
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {module:ol/geom/Geometry} Simplified geometry. * @return {module:ol/geom/Geometry} Simplified geometry.
*/ */
getSimplifiedGeometry(squaredTolerance) {} getSimplifiedGeometry(squaredTolerance) {}
/** /**
* Get the type of this geometry. * Get the type of this geometry.
* @abstract * @abstract
* @return {module:ol/geom/GeometryType} Geometry type. * @return {module:ol/geom/GeometryType} Geometry type.
*/ */
getType() {} getType() {}
/** /**
* Apply a transform function to each coordinate of the geometry. * Apply a transform function to each coordinate of the geometry.
* The geometry is modified in place. * The geometry is modified in place.
* If you do not want the geometry modified in place, first `clone()` it and * If you do not want the geometry modified in place, first `clone()` it and
@@ -190,26 +196,26 @@ class Geometry {
* @abstract * @abstract
* @param {module:ol/proj~TransformFunction} transformFn Transform. * @param {module:ol/proj~TransformFunction} transformFn Transform.
*/ */
applyTransform(transformFn) {} applyTransform(transformFn) {}
/** /**
* Test if the geometry and the passed extent intersect. * Test if the geometry and the passed extent intersect.
* @abstract * @abstract
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @return {boolean} `true` if the geometry and the extent intersect. * @return {boolean} `true` if the geometry and the extent intersect.
*/ */
intersectsExtent(extent) {} intersectsExtent(extent) {}
/** /**
* Translate the geometry. This modifies the geometry coordinates in place. If * Translate the geometry. This modifies the geometry coordinates in place. If
* instead you want a new geometry, first `clone()` this geometry. * instead you want a new geometry, first `clone()` this geometry.
* @abstract * @abstract
* @param {number} deltaX Delta X. * @param {number} deltaX Delta X.
* @param {number} deltaY Delta Y. * @param {number} deltaY Delta Y.
*/ */
translate(deltaX, deltaY) {} translate(deltaX, deltaY) {}
/** /**
* Transform each coordinate of the geometry from one coordinate reference * Transform each coordinate of the geometry from one coordinate reference
* system to another. The geometry is modified in place. * system to another. The geometry is modified in place.
* For example, a line will be transformed to a line and a circle to a circle. * For example, a line will be transformed to a line and a circle to a circle.
@@ -224,36 +230,30 @@ class Geometry {
* modified in place. * modified in place.
* @api * @api
*/ */
transform(source, destination) { transform(source, destination) {
source = getProjection(source); source = getProjection(source);
const transformFn = source.getUnits() == Units.TILE_PIXELS ? const transformFn = source.getUnits() == Units.TILE_PIXELS ?
function(inCoordinates, outCoordinates, stride) { function(inCoordinates, outCoordinates, stride) {
const pixelExtent = source.getExtent(); const pixelExtent = source.getExtent();
const projectedExtent = source.getWorldExtent(); const projectedExtent = source.getWorldExtent();
const scale = getHeight(projectedExtent) / getHeight(pixelExtent); const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
composeTransform(tmpTransform, composeTransform(tmpTransform,
projectedExtent[0], projectedExtent[3], projectedExtent[0], projectedExtent[3],
scale, -scale, 0, scale, -scale, 0,
0, 0); 0, 0);
transform2D(inCoordinates, 0, inCoordinates.length, stride, transform2D(inCoordinates, 0, inCoordinates.length, stride,
tmpTransform, outCoordinates); tmpTransform, outCoordinates);
return getTransform(source, destination)(inCoordinates, outCoordinates, stride); return getTransform(source, destination)(inCoordinates, outCoordinates, stride);
} : } :
getTransform(source, destination); getTransform(source, destination);
this.applyTransform(transformFn); this.applyTransform(transformFn);
return this; return this;
} }
} }
inherits(Geometry, BaseObject); inherits(Geometry, BaseObject);
/**
* @type {module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* @param {number} x X. * @param {number} x X.
* @param {number} y Y. * @param {number} y Y.

View File

@@ -24,6 +24,21 @@ import RBush from '../structs/RBush.js';
import {createEditingStyle} from '../style/Style.js'; import {createEditingStyle} from '../style/Style.js';
/**
* The segment index assigned to a circle's center when
* breaking up a circle into ModifySegmentDataType segments.
* @type {number}
*/
const CIRCLE_CENTER_INDEX = 0;
/**
* The segment index assigned to a circle's circumference when
* breaking up a circle into ModifySegmentDataType segments.
* @type {number}
*/
const CIRCLE_CIRCUMFERENCE_INDEX = 1;
/** /**
* @enum {string} * @enum {string}
*/ */
@@ -958,21 +973,6 @@ class Modify {
inherits(Modify, PointerInteraction); inherits(Modify, PointerInteraction);
/**
* The segment index assigned to a circle's center when
* breaking up a circle into ModifySegmentDataType segments.
* @type {number}
*/
const CIRCLE_CENTER_INDEX = 0;
/**
* The segment index assigned to a circle's circumference when
* breaking up a circle into ModifySegmentDataType segments.
* @type {number}
*/
const CIRCLE_CIRCUMFERENCE_INDEX = 1;
/** /**
* @param {module:ol/interaction/Modify~SegmentData} a The first segment data. * @param {module:ol/interaction/Modify~SegmentData} a The first segment data.
* @param {module:ol/interaction/Modify~SegmentData} b The second segment data. * @param {module:ol/interaction/Modify~SegmentData} b The second segment data.

View File

@@ -38,215 +38,215 @@ import {assign} from '../obj.js';
* @api * @api
*/ */
class BaseLayer { class BaseLayer {
constructor(options) { constructor(options) {
BaseObject.call(this); BaseObject.call(this);
/** /**
* @type {Object.<string, *>} * @type {Object.<string, *>}
*/ */
const properties = assign({}, options); const properties = assign({}, options);
properties[LayerProperty.OPACITY] = properties[LayerProperty.OPACITY] =
options.opacity !== undefined ? options.opacity : 1; options.opacity !== undefined ? options.opacity : 1;
properties[LayerProperty.VISIBLE] = properties[LayerProperty.VISIBLE] =
options.visible !== undefined ? options.visible : true; options.visible !== undefined ? options.visible : true;
properties[LayerProperty.Z_INDEX] = properties[LayerProperty.Z_INDEX] =
options.zIndex !== undefined ? options.zIndex : 0; options.zIndex !== undefined ? options.zIndex : 0;
properties[LayerProperty.MAX_RESOLUTION] = properties[LayerProperty.MAX_RESOLUTION] =
options.maxResolution !== undefined ? options.maxResolution : Infinity; options.maxResolution !== undefined ? options.maxResolution : Infinity;
properties[LayerProperty.MIN_RESOLUTION] = properties[LayerProperty.MIN_RESOLUTION] =
options.minResolution !== undefined ? options.minResolution : 0; options.minResolution !== undefined ? options.minResolution : 0;
this.setProperties(properties); this.setProperties(properties);
/** /**
* @type {module:ol/layer/Layer~State} * @type {module:ol/layer/Layer~State}
* @private * @private
*/ */
this.state_ = /** @type {module:ol/layer/Layer~State} */ ({ this.state_ = /** @type {module:ol/layer/Layer~State} */ ({
layer: /** @type {module:ol/layer/Layer} */ (this), layer: /** @type {module:ol/layer/Layer} */ (this),
managed: true managed: true
}); });
/** /**
* The layer type. * The layer type.
* @type {module:ol/LayerType} * @type {module:ol/LayerType}
* @protected; * @protected;
*/ */
this.type; this.type;
} }
/** /**
* Get the layer type (used when creating a layer renderer). * Get the layer type (used when creating a layer renderer).
* @return {module:ol/LayerType} The layer type. * @return {module:ol/LayerType} The layer type.
*/ */
getType() { getType() {
return this.type; return this.type;
} }
/** /**
* @return {module:ol/layer/Layer~State} Layer state. * @return {module:ol/layer/Layer~State} Layer state.
*/ */
getLayerState() { getLayerState() {
this.state_.opacity = clamp(this.getOpacity(), 0, 1); this.state_.opacity = clamp(this.getOpacity(), 0, 1);
this.state_.sourceState = this.getSourceState(); this.state_.sourceState = this.getSourceState();
this.state_.visible = this.getVisible(); this.state_.visible = this.getVisible();
this.state_.extent = this.getExtent(); this.state_.extent = this.getExtent();
this.state_.zIndex = this.getZIndex(); this.state_.zIndex = this.getZIndex();
this.state_.maxResolution = this.getMaxResolution(); this.state_.maxResolution = this.getMaxResolution();
this.state_.minResolution = Math.max(this.getMinResolution(), 0); this.state_.minResolution = Math.max(this.getMinResolution(), 0);
return this.state_; return this.state_;
} }
/** /**
* @abstract * @abstract
* @param {Array.<module:ol/layer/Layer>=} opt_array Array of layers (to be * @param {Array.<module:ol/layer/Layer>=} opt_array Array of layers (to be
* modified in place). * modified in place).
* @return {Array.<module:ol/layer/Layer>} Array of layers. * @return {Array.<module:ol/layer/Layer>} Array of layers.
*/ */
getLayersArray(opt_array) {} getLayersArray(opt_array) {}
/** /**
* @abstract * @abstract
* @param {Array.<module:ol/layer/Layer~State>=} opt_states Optional list of layer * @param {Array.<module:ol/layer/Layer~State>=} opt_states Optional list of layer
* states (to be modified in place). * states (to be modified in place).
* @return {Array.<module:ol/layer/Layer~State>} List of layer states. * @return {Array.<module:ol/layer/Layer~State>} List of layer states.
*/ */
getLayerStatesArray(opt_states) {} getLayerStatesArray(opt_states) {}
/** /**
* Return the {@link module:ol/extent~Extent extent} of the layer or `undefined` if it * Return the {@link module:ol/extent~Extent extent} of the layer or `undefined` if it
* will be visible regardless of extent. * will be visible regardless of extent.
* @return {module:ol/extent~Extent|undefined} The layer extent. * @return {module:ol/extent~Extent|undefined} The layer extent.
* @observable * @observable
* @api * @api
*/ */
getExtent() { getExtent() {
return ( return (
/** @type {module:ol/extent~Extent|undefined} */ (this.get(LayerProperty.EXTENT)) /** @type {module:ol/extent~Extent|undefined} */ (this.get(LayerProperty.EXTENT))
); );
} }
/** /**
* Return the maximum resolution of the layer. * Return the maximum resolution of the layer.
* @return {number} The maximum resolution of the layer. * @return {number} The maximum resolution of the layer.
* @observable * @observable
* @api * @api
*/ */
getMaxResolution() { getMaxResolution() {
return /** @type {number} */ (this.get(LayerProperty.MAX_RESOLUTION)); return /** @type {number} */ (this.get(LayerProperty.MAX_RESOLUTION));
} }
/** /**
* Return the minimum resolution of the layer. * Return the minimum resolution of the layer.
* @return {number} The minimum resolution of the layer. * @return {number} The minimum resolution of the layer.
* @observable * @observable
* @api * @api
*/ */
getMinResolution() { getMinResolution() {
return /** @type {number} */ (this.get(LayerProperty.MIN_RESOLUTION)); return /** @type {number} */ (this.get(LayerProperty.MIN_RESOLUTION));
} }
/** /**
* Return the opacity of the layer (between 0 and 1). * Return the opacity of the layer (between 0 and 1).
* @return {number} The opacity of the layer. * @return {number} The opacity of the layer.
* @observable * @observable
* @api * @api
*/ */
getOpacity() { getOpacity() {
return /** @type {number} */ (this.get(LayerProperty.OPACITY)); return /** @type {number} */ (this.get(LayerProperty.OPACITY));
} }
/** /**
* @abstract * @abstract
* @return {module:ol/source/State} Source state. * @return {module:ol/source/State} Source state.
*/ */
getSourceState() {} getSourceState() {}
/** /**
* Return the visibility of the layer (`true` or `false`). * Return the visibility of the layer (`true` or `false`).
* @return {boolean} The visibility of the layer. * @return {boolean} The visibility of the layer.
* @observable * @observable
* @api * @api
*/ */
getVisible() { getVisible() {
return /** @type {boolean} */ (this.get(LayerProperty.VISIBLE)); return /** @type {boolean} */ (this.get(LayerProperty.VISIBLE));
} }
/** /**
* Return the Z-index of the layer, which is used to order layers before * Return the Z-index of the layer, which is used to order layers before
* rendering. The default Z-index is 0. * rendering. The default Z-index is 0.
* @return {number} The Z-index of the layer. * @return {number} The Z-index of the layer.
* @observable * @observable
* @api * @api
*/ */
getZIndex() { getZIndex() {
return /** @type {number} */ (this.get(LayerProperty.Z_INDEX)); return /** @type {number} */ (this.get(LayerProperty.Z_INDEX));
} }
/** /**
* Set the extent at which the layer is visible. If `undefined`, the layer * Set the extent at which the layer is visible. If `undefined`, the layer
* will be visible at all extents. * will be visible at all extents.
* @param {module:ol/extent~Extent|undefined} extent The extent of the layer. * @param {module:ol/extent~Extent|undefined} extent The extent of the layer.
* @observable * @observable
* @api * @api
*/ */
setExtent(extent) { setExtent(extent) {
this.set(LayerProperty.EXTENT, extent); this.set(LayerProperty.EXTENT, extent);
} }
/** /**
* Set the maximum resolution at which the layer is visible. * Set the maximum resolution at which the layer is visible.
* @param {number} maxResolution The maximum resolution of the layer. * @param {number} maxResolution The maximum resolution of the layer.
* @observable * @observable
* @api * @api
*/ */
setMaxResolution(maxResolution) { setMaxResolution(maxResolution) {
this.set(LayerProperty.MAX_RESOLUTION, maxResolution); this.set(LayerProperty.MAX_RESOLUTION, maxResolution);
} }
/** /**
* Set the minimum resolution at which the layer is visible. * Set the minimum resolution at which the layer is visible.
* @param {number} minResolution The minimum resolution of the layer. * @param {number} minResolution The minimum resolution of the layer.
* @observable * @observable
* @api * @api
*/ */
setMinResolution(minResolution) { setMinResolution(minResolution) {
this.set(LayerProperty.MIN_RESOLUTION, minResolution); this.set(LayerProperty.MIN_RESOLUTION, minResolution);
} }
/** /**
* Set the opacity of the layer, allowed values range from 0 to 1. * Set the opacity of the layer, allowed values range from 0 to 1.
* @param {number} opacity The opacity of the layer. * @param {number} opacity The opacity of the layer.
* @observable * @observable
* @api * @api
*/ */
setOpacity(opacity) { setOpacity(opacity) {
this.set(LayerProperty.OPACITY, opacity); this.set(LayerProperty.OPACITY, opacity);
} }
/** /**
* Set the visibility of the layer (`true` or `false`). * Set the visibility of the layer (`true` or `false`).
* @param {boolean} visible The visibility of the layer. * @param {boolean} visible The visibility of the layer.
* @observable * @observable
* @api * @api
*/ */
setVisible(visible) { setVisible(visible) {
this.set(LayerProperty.VISIBLE, visible); this.set(LayerProperty.VISIBLE, visible);
} }
/** /**
* Set Z-index of the layer, which is used to order layers before rendering. * Set Z-index of the layer, which is used to order layers before rendering.
* The default Z-index is 0. * The default Z-index is 0.
* @param {number} zindex The z-index of the layer. * @param {number} zindex The z-index of the layer.
* @observable * @observable
* @api * @api
*/ */
setZIndex(zindex) { setZIndex(zindex) {
this.set(LayerProperty.Z_INDEX, zindex); this.set(LayerProperty.Z_INDEX, zindex);
} }
} }
inherits(BaseLayer, BaseObject); inherits(BaseLayer, BaseObject);

View File

@@ -289,9 +289,8 @@ inherits(Heatmap, VectorLayer);
/** /**
* @param {Array.<string>} colors A list of colored. * @param {Array.<string>} colors A list of colored.
* @return {Uint8ClampedArray} An array. * @return {Uint8ClampedArray} An array.
* @private
*/ */
const createGradient = function(colors) { function createGradient(colors) {
const width = 1; const width = 1;
const height = 256; const height = 256;
const context = createCanvasContext2D(width, height); const context = createCanvasContext2D(width, height);
@@ -306,7 +305,7 @@ const createGradient = function(colors) {
context.fillRect(0, 0, width, height); context.fillRect(0, 0, width, height);
return context.getImageData(0, 0, width, height).data; return context.getImageData(0, 0, width, height).data;
}; }
export default Heatmap; export default Heatmap;

View File

@@ -46,67 +46,67 @@ import {assign} from '../obj.js';
* @api * @api
*/ */
class TileLayer { class TileLayer {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options); const baseOptions = assign({}, options);
delete baseOptions.preload; delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError; delete baseOptions.useInterimTilesOnError;
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions)); Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
this.setPreload(options.preload !== undefined ? options.preload : 0); this.setPreload(options.preload !== undefined ? options.preload : 0);
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ? this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
options.useInterimTilesOnError : true); options.useInterimTilesOnError : true);
/** /**
* The layer type. * The layer type.
* @protected * @protected
* @type {module:ol/LayerType} * @type {module:ol/LayerType}
*/ */
this.type = LayerType.TILE; this.type = LayerType.TILE;
} }
/** /**
* Return the level as number to which we will preload tiles up to. * Return the level as number to which we will preload tiles up to.
* @return {number} The level to preload tiles up to. * @return {number} The level to preload tiles up to.
* @observable * @observable
* @api * @api
*/ */
getPreload() { getPreload() {
return /** @type {number} */ (this.get(TileProperty.PRELOAD)); return /** @type {number} */ (this.get(TileProperty.PRELOAD));
} }
/** /**
* Set the level as number to which we will preload tiles up to. * Set the level as number to which we will preload tiles up to.
* @param {number} preload The level to preload tiles up to. * @param {number} preload The level to preload tiles up to.
* @observable * @observable
* @api * @api
*/ */
setPreload(preload) { setPreload(preload) {
this.set(TileProperty.PRELOAD, preload); this.set(TileProperty.PRELOAD, preload);
} }
/** /**
* Whether we use interim tiles on error. * Whether we use interim tiles on error.
* @return {boolean} Use interim tiles on error. * @return {boolean} Use interim tiles on error.
* @observable * @observable
* @api * @api
*/ */
getUseInterimTilesOnError() { getUseInterimTilesOnError() {
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR)); return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
} }
/** /**
* Set whether we use interim tiles on error. * Set whether we use interim tiles on error.
* @param {boolean} useInterimTilesOnError Use interim tiles on error. * @param {boolean} useInterimTilesOnError Use interim tiles on error.
* @observable * @observable
* @api * @api
*/ */
setUseInterimTilesOnError(useInterimTilesOnError) { setUseInterimTilesOnError(useInterimTilesOnError) {
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError); this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
} }
} }
inherits(TileLayer, Layer); inherits(TileLayer, Layer);

View File

@@ -92,152 +92,152 @@ const Property = {
* @api * @api
*/ */
class VectorLayer { class VectorLayer {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options ? const options = opt_options ?
opt_options : /** @type {module:ol/layer/Vector~Options} */ ({}); opt_options : /** @type {module:ol/layer/Vector~Options} */ ({});
const baseOptions = assign({}, options); const baseOptions = assign({}, options);
delete baseOptions.style; delete baseOptions.style;
delete baseOptions.renderBuffer; delete baseOptions.renderBuffer;
delete baseOptions.updateWhileAnimating; delete baseOptions.updateWhileAnimating;
delete baseOptions.updateWhileInteracting; delete baseOptions.updateWhileInteracting;
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions)); Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
/** /**
* @private * @private
* @type {boolean} * @type {boolean}
*/ */
this.declutter_ = options.declutter !== undefined ? options.declutter : false; this.declutter_ = options.declutter !== undefined ? options.declutter : false;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
this.renderBuffer_ = options.renderBuffer !== undefined ? this.renderBuffer_ = options.renderBuffer !== undefined ?
options.renderBuffer : 100; options.renderBuffer : 100;
/** /**
* User provided style. * User provided style.
* @type {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction} * @type {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
* @private * @private
*/ */
this.style_ = null; this.style_ = null;
/** /**
* Style function for use within the library. * Style function for use within the library.
* @type {module:ol/style/Style~StyleFunction|undefined} * @type {module:ol/style/Style~StyleFunction|undefined}
* @private * @private
*/ */
this.styleFunction_ = undefined; this.styleFunction_ = undefined;
this.setStyle(options.style); this.setStyle(options.style);
/** /**
* @type {boolean} * @type {boolean}
* @private * @private
*/ */
this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ? this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ?
options.updateWhileAnimating : false; options.updateWhileAnimating : false;
/** /**
* @type {boolean} * @type {boolean}
* @private * @private
*/ */
this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ? this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ?
options.updateWhileInteracting : false; options.updateWhileInteracting : false;
/** /**
* @private * @private
* @type {module:ol/layer/VectorTileRenderType|string} * @type {module:ol/layer/VectorTileRenderType|string}
*/ */
this.renderMode_ = options.renderMode || VectorRenderType.VECTOR; this.renderMode_ = options.renderMode || VectorRenderType.VECTOR;
/** /**
* The layer type. * The layer type.
* @protected * @protected
* @type {module:ol/LayerType} * @type {module:ol/LayerType}
*/ */
this.type = LayerType.VECTOR; this.type = LayerType.VECTOR;
} }
/** /**
* @return {boolean} Declutter. * @return {boolean} Declutter.
*/ */
getDeclutter() { getDeclutter() {
return this.declutter_; return this.declutter_;
} }
/** /**
* @param {boolean} declutter Declutter. * @param {boolean} declutter Declutter.
*/ */
setDeclutter(declutter) { setDeclutter(declutter) {
this.declutter_ = declutter; this.declutter_ = declutter;
} }
/** /**
* @return {number|undefined} Render buffer. * @return {number|undefined} Render buffer.
*/ */
getRenderBuffer() { getRenderBuffer() {
return this.renderBuffer_; return this.renderBuffer_;
} }
/** /**
* @return {function(module:ol/Feature, module:ol/Feature): number|null|undefined} Render * @return {function(module:ol/Feature, module:ol/Feature): number|null|undefined} Render
* order. * order.
*/ */
getRenderOrder() { getRenderOrder() {
return ( return (
/** @type {module:ol/render~OrderFunction|null|undefined} */ (this.get(Property.RENDER_ORDER)) /** @type {module:ol/render~OrderFunction|null|undefined} */ (this.get(Property.RENDER_ORDER))
); );
} }
/** /**
* Get the style for features. This returns whatever was passed to the `style` * Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method. * option at construction or to the `setStyle` method.
* @return {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction} * @return {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
* Layer style. * Layer style.
* @api * @api
*/ */
getStyle() { getStyle() {
return this.style_; return this.style_;
} }
/** /**
* Get the style function. * Get the style function.
* @return {module:ol/style/Style~StyleFunction|undefined} Layer style function. * @return {module:ol/style/Style~StyleFunction|undefined} Layer style function.
* @api * @api
*/ */
getStyleFunction() { getStyleFunction() {
return this.styleFunction_; return this.styleFunction_;
} }
/** /**
* @return {boolean} Whether the rendered layer should be updated while * @return {boolean} Whether the rendered layer should be updated while
* animating. * animating.
*/ */
getUpdateWhileAnimating() { getUpdateWhileAnimating() {
return this.updateWhileAnimating_; return this.updateWhileAnimating_;
} }
/** /**
* @return {boolean} Whether the rendered layer should be updated while * @return {boolean} Whether the rendered layer should be updated while
* interacting. * interacting.
*/ */
getUpdateWhileInteracting() { getUpdateWhileInteracting() {
return this.updateWhileInteracting_; return this.updateWhileInteracting_;
} }
/** /**
* @param {module:ol/render~OrderFunction|null|undefined} renderOrder * @param {module:ol/render~OrderFunction|null|undefined} renderOrder
* Render order. * Render order.
*/ */
setRenderOrder(renderOrder) { setRenderOrder(renderOrder) {
this.set(Property.RENDER_ORDER, renderOrder); this.set(Property.RENDER_ORDER, renderOrder);
} }
/** /**
* Set the style for features. This can be a single style object, an array * Set the style for features. This can be a single style object, an array
* of styles, or a function that takes a feature and resolution and returns * of styles, or a function that takes a feature and resolution and returns
* an array of styles. If it is `undefined` the default style is used. If * an array of styles. If it is `undefined` the default style is used. If
@@ -248,19 +248,19 @@ class VectorLayer {
* style Layer style. * style Layer style.
* @api * @api
*/ */
setStyle(style) { setStyle(style) {
this.style_ = style !== undefined ? style : createDefaultStyle; this.style_ = style !== undefined ? style : createDefaultStyle;
this.styleFunction_ = style === null ? this.styleFunction_ = style === null ?
undefined : toStyleFunction(this.style_); undefined : toStyleFunction(this.style_);
this.changed(); this.changed();
} }
/** /**
* @return {module:ol/layer/VectorRenderType|string} The render mode. * @return {module:ol/layer/VectorRenderType|string} The render mode.
*/ */
getRenderMode() { getRenderMode() {
return this.renderMode_; return this.renderMode_;
} }
} }
inherits(VectorLayer, Layer); inherits(VectorLayer, Layer);

View File

@@ -100,78 +100,78 @@ export const RenderType = {
* @api * @api
*/ */
class VectorTileLayer { class VectorTileLayer {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
let renderMode = options.renderMode || VectorTileRenderType.HYBRID; let renderMode = options.renderMode || VectorTileRenderType.HYBRID;
assert(renderMode == undefined || assert(renderMode == undefined ||
renderMode == VectorTileRenderType.IMAGE || renderMode == VectorTileRenderType.IMAGE ||
renderMode == VectorTileRenderType.HYBRID || renderMode == VectorTileRenderType.HYBRID ||
renderMode == VectorTileRenderType.VECTOR, renderMode == VectorTileRenderType.VECTOR,
28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'` 28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`
if (options.declutter && renderMode == VectorTileRenderType.IMAGE) { if (options.declutter && renderMode == VectorTileRenderType.IMAGE) {
renderMode = VectorTileRenderType.HYBRID; renderMode = VectorTileRenderType.HYBRID;
} }
options.renderMode = renderMode; options.renderMode = renderMode;
const baseOptions = assign({}, options); const baseOptions = assign({}, options);
delete baseOptions.preload; delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError; delete baseOptions.useInterimTilesOnError;
VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions)); VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions));
this.setPreload(options.preload ? options.preload : 0); this.setPreload(options.preload ? options.preload : 0);
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ? this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
options.useInterimTilesOnError : true); options.useInterimTilesOnError : true);
/** /**
* The layer type. * The layer type.
* @protected * @protected
* @type {module:ol/LayerType} * @type {module:ol/LayerType}
*/ */
this.type = LayerType.VECTOR_TILE; this.type = LayerType.VECTOR_TILE;
} }
/** /**
* Return the level as number to which we will preload tiles up to. * Return the level as number to which we will preload tiles up to.
* @return {number} The level to preload tiles up to. * @return {number} The level to preload tiles up to.
* @observable * @observable
* @api * @api
*/ */
getPreload() { getPreload() {
return /** @type {number} */ (this.get(TileProperty.PRELOAD)); return /** @type {number} */ (this.get(TileProperty.PRELOAD));
} }
/** /**
* Whether we use interim tiles on error. * Whether we use interim tiles on error.
* @return {boolean} Use interim tiles on error. * @return {boolean} Use interim tiles on error.
* @observable * @observable
* @api * @api
*/ */
getUseInterimTilesOnError() { getUseInterimTilesOnError() {
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR)); return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
} }
/** /**
* Set the level as number to which we will preload tiles up to. * Set the level as number to which we will preload tiles up to.
* @param {number} preload The level to preload tiles up to. * @param {number} preload The level to preload tiles up to.
* @observable * @observable
* @api * @api
*/ */
setPreload(preload) { setPreload(preload) {
this.set(TileProperty.PRELOAD, preload); this.set(TileProperty.PRELOAD, preload);
} }
/** /**
* Set whether we use interim tiles on error. * Set whether we use interim tiles on error.
* @param {boolean} useInterimTilesOnError Use interim tiles on error. * @param {boolean} useInterimTilesOnError Use interim tiles on error.
* @observable * @observable
* @api * @api
*/ */
setUseInterimTilesOnError(useInterimTilesOnError) { setUseInterimTilesOnError(useInterimTilesOnError) {
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError); this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
} }
} }
inherits(VectorTileLayer, VectorLayer); inherits(VectorTileLayer, VectorLayer);

View File

@@ -7,36 +7,36 @@
* @constructor * @constructor
*/ */
class EventSource { class EventSource {
constructor(dispatcher, mapping) { constructor(dispatcher, mapping) {
/** /**
* @type {module:ol/pointer/PointerEventHandler} * @type {module:ol/pointer/PointerEventHandler}
*/ */
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
/** /**
* @private * @private
* @const * @const
* @type {!Object.<string, function(Event)>} * @type {!Object.<string, function(Event)>}
*/ */
this.mapping_ = mapping; this.mapping_ = mapping;
} }
/** /**
* List of events supported by this source. * List of events supported by this source.
* @return {Array.<string>} Event names * @return {Array.<string>} Event names
*/ */
getEvents() { getEvents() {
return Object.keys(this.mapping_); return Object.keys(this.mapping_);
} }
/** /**
* Returns the handler that should handle a given event type. * Returns the handler that should handle a given event type.
* @param {string} eventType The event type. * @param {string} eventType The event type.
* @return {function(Event)} Handler * @return {function(Event)} Handler
*/ */
getHandlerForEvent(eventType) { getHandlerForEvent(eventType) {
return this.mapping_[eventType]; return this.mapping_[eventType];
} }
} }
export default EventSource; export default EventSource;

View File

@@ -34,6 +34,27 @@
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
/**
* @type {number}
*/
export const POINTER_ID = 1;
/**
* @type {string}
*/
export const POINTER_TYPE = 'mouse';
/**
* Radius around touchend that swallows mouse events.
*
* @type {number}
*/
const DEDUP_DIST = 25;
/** /**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor * @constructor
@@ -195,26 +216,6 @@ class MouseSource {
inherits(MouseSource, EventSource); inherits(MouseSource, EventSource);
/**
* @type {number}
*/
export const POINTER_ID = 1;
/**
* @type {string}
*/
export const POINTER_TYPE = 'mouse';
/**
* Radius around touchend that swallows mouse events.
*
* @type {number}
*/
const DEDUP_DIST = 25;
/** /**
* Creates a copy of the original event that will be used * Creates a copy of the original event that will be used
* for the fake pointer event. * for the fake pointer event.

View File

@@ -34,143 +34,6 @@
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
/**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor
* @extends {module:ol/pointer/EventSource}
*/
class MsSource {
constructor(dispatcher) {
const mapping = {
'MSPointerDown': this.msPointerDown,
'MSPointerMove': this.msPointerMove,
'MSPointerUp': this.msPointerUp,
'MSPointerOut': this.msPointerOut,
'MSPointerOver': this.msPointerOver,
'MSPointerCancel': this.msPointerCancel,
'MSGotPointerCapture': this.msGotPointerCapture,
'MSLostPointerCapture': this.msLostPointerCapture
};
EventSource.call(this, dispatcher, mapping);
/**
* @const
* @type {!Object.<string, MSPointerEvent|Object>}
*/
this.pointerMap = dispatcher.pointerMap;
}
/**
* Creates a copy of the original event that will be used
* for the fake pointer event.
*
* @private
* @param {MSPointerEvent} inEvent The in event.
* @return {Object} The copied event.
*/
prepareEvent_(inEvent) {
let e = inEvent;
if (typeof inEvent.pointerType === 'number') {
e = this.dispatcher.cloneEvent(inEvent, inEvent);
e.pointerType = POINTER_TYPES[inEvent.pointerType];
}
return e;
}
/**
* Remove this pointer from the list of active pointers.
* @param {number} pointerId Pointer identifier.
*/
cleanup(pointerId) {
delete this.pointerMap[pointerId.toString()];
}
/**
* Handler for `msPointerDown`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerDown(inEvent) {
this.pointerMap[inEvent.pointerId.toString()] = inEvent;
const e = this.prepareEvent_(inEvent);
this.dispatcher.down(e, inEvent);
}
/**
* Handler for `msPointerMove`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerMove(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.move(e, inEvent);
}
/**
* Handler for `msPointerUp`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerUp(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.up(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msPointerOut`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOut(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.leaveOut(e, inEvent);
}
/**
* Handler for `msPointerOver`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOver(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.enterOver(e, inEvent);
}
/**
* Handler for `msPointerCancel`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerCancel(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.cancel(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msLostPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msLostPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('lostpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
/**
* Handler for `msGotPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msGotPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('gotpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
}
inherits(MsSource, EventSource);
/** /**
* @const * @const
@@ -185,4 +48,142 @@ const POINTER_TYPES = [
]; ];
/**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor
* @extends {module:ol/pointer/EventSource}
*/
class MsSource {
constructor(dispatcher) {
const mapping = {
'MSPointerDown': this.msPointerDown,
'MSPointerMove': this.msPointerMove,
'MSPointerUp': this.msPointerUp,
'MSPointerOut': this.msPointerOut,
'MSPointerOver': this.msPointerOver,
'MSPointerCancel': this.msPointerCancel,
'MSGotPointerCapture': this.msGotPointerCapture,
'MSLostPointerCapture': this.msLostPointerCapture
};
EventSource.call(this, dispatcher, mapping);
/**
* @const
* @type {!Object.<string, MSPointerEvent|Object>}
*/
this.pointerMap = dispatcher.pointerMap;
}
/**
* Creates a copy of the original event that will be used
* for the fake pointer event.
*
* @private
* @param {MSPointerEvent} inEvent The in event.
* @return {Object} The copied event.
*/
prepareEvent_(inEvent) {
let e = inEvent;
if (typeof inEvent.pointerType === 'number') {
e = this.dispatcher.cloneEvent(inEvent, inEvent);
e.pointerType = POINTER_TYPES[inEvent.pointerType];
}
return e;
}
/**
* Remove this pointer from the list of active pointers.
* @param {number} pointerId Pointer identifier.
*/
cleanup(pointerId) {
delete this.pointerMap[pointerId.toString()];
}
/**
* Handler for `msPointerDown`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerDown(inEvent) {
this.pointerMap[inEvent.pointerId.toString()] = inEvent;
const e = this.prepareEvent_(inEvent);
this.dispatcher.down(e, inEvent);
}
/**
* Handler for `msPointerMove`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerMove(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.move(e, inEvent);
}
/**
* Handler for `msPointerUp`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerUp(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.up(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msPointerOut`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOut(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.leaveOut(e, inEvent);
}
/**
* Handler for `msPointerOver`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOver(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.enterOver(e, inEvent);
}
/**
* Handler for `msPointerCancel`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerCancel(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.cancel(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msLostPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msLostPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('lostpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
/**
* Handler for `msGotPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msGotPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('gotpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
}
inherits(MsSource, EventSource);
export default MsSource; export default MsSource;

View File

@@ -40,91 +40,91 @@ import EventSource from '../pointer/EventSource.js';
* @extends {module:ol/pointer/EventSource} * @extends {module:ol/pointer/EventSource}
*/ */
class NativeSource { class NativeSource {
constructor(dispatcher) { constructor(dispatcher) {
const mapping = { const mapping = {
'pointerdown': this.pointerDown, 'pointerdown': this.pointerDown,
'pointermove': this.pointerMove, 'pointermove': this.pointerMove,
'pointerup': this.pointerUp, 'pointerup': this.pointerUp,
'pointerout': this.pointerOut, 'pointerout': this.pointerOut,
'pointerover': this.pointerOver, 'pointerover': this.pointerOver,
'pointercancel': this.pointerCancel, 'pointercancel': this.pointerCancel,
'gotpointercapture': this.gotPointerCapture, 'gotpointercapture': this.gotPointerCapture,
'lostpointercapture': this.lostPointerCapture 'lostpointercapture': this.lostPointerCapture
}; };
EventSource.call(this, dispatcher, mapping); EventSource.call(this, dispatcher, mapping);
} }
/** /**
* Handler for `pointerdown`. * Handler for `pointerdown`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerDown(inEvent) { pointerDown(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointermove`. * Handler for `pointermove`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerMove(inEvent) { pointerMove(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerup`. * Handler for `pointerup`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerUp(inEvent) { pointerUp(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerout`. * Handler for `pointerout`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerOut(inEvent) { pointerOut(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerover`. * Handler for `pointerover`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerOver(inEvent) { pointerOver(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointercancel`. * Handler for `pointercancel`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerCancel(inEvent) { pointerCancel(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `lostpointercapture`. * Handler for `lostpointercapture`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
lostPointerCapture(inEvent) { lostPointerCapture(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `gotpointercapture`. * Handler for `gotpointercapture`.
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
gotPointerCapture(inEvent) { gotPointerCapture(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
} }
inherits(NativeSource, EventSource); inherits(NativeSource, EventSource);

View File

@@ -34,6 +34,14 @@
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
/**
* Is the `buttons` property supported?
* @type {boolean}
*/
let HAS_BUTTONS = false;
/** /**
* A class for pointer events. * A class for pointer events.
* *
@@ -48,221 +56,214 @@ import Event from '../events/Event.js';
* initial event properties. * initial event properties.
*/ */
class PointerEvent { class PointerEvent {
constructor(type, originalEvent, opt_eventDict) { constructor(type, originalEvent, opt_eventDict) {
Event.call(this, type); Event.call(this, type);
/** /**
* @const * @const
* @type {Event} * @type {Event}
*/ */
this.originalEvent = originalEvent; this.originalEvent = originalEvent;
const eventDict = opt_eventDict ? opt_eventDict : {}; const eventDict = opt_eventDict ? opt_eventDict : {};
/** /**
* @type {number} * @type {number}
*/ */
this.buttons = this.getButtons_(eventDict); this.buttons = this.getButtons_(eventDict);
/** /**
* @type {number} * @type {number}
*/ */
this.pressure = this.getPressure_(eventDict, this.buttons); this.pressure = this.getPressure_(eventDict, this.buttons);
// MouseEvent related properties // MouseEvent related properties
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.bubbles = 'bubbles' in eventDict ? eventDict['bubbles'] : false; this.bubbles = 'bubbles' in eventDict ? eventDict['bubbles'] : false;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.cancelable = 'cancelable' in eventDict ? eventDict['cancelable'] : false; this.cancelable = 'cancelable' in eventDict ? eventDict['cancelable'] : false;
/** /**
* @type {Object} * @type {Object}
*/ */
this.view = 'view' in eventDict ? eventDict['view'] : null; this.view = 'view' in eventDict ? eventDict['view'] : null;
/** /**
* @type {number} * @type {number}
*/ */
this.detail = 'detail' in eventDict ? eventDict['detail'] : null; this.detail = 'detail' in eventDict ? eventDict['detail'] : null;
/** /**
* @type {number} * @type {number}
*/ */
this.screenX = 'screenX' in eventDict ? eventDict['screenX'] : 0; this.screenX = 'screenX' in eventDict ? eventDict['screenX'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.screenY = 'screenY' in eventDict ? eventDict['screenY'] : 0; this.screenY = 'screenY' in eventDict ? eventDict['screenY'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.clientX = 'clientX' in eventDict ? eventDict['clientX'] : 0; this.clientX = 'clientX' in eventDict ? eventDict['clientX'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.clientY = 'clientY' in eventDict ? eventDict['clientY'] : 0; this.clientY = 'clientY' in eventDict ? eventDict['clientY'] : 0;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.ctrlKey = 'ctrlKey' in eventDict ? eventDict['ctrlKey'] : false; this.ctrlKey = 'ctrlKey' in eventDict ? eventDict['ctrlKey'] : false;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.altKey = 'altKey' in eventDict ? eventDict['altKey'] : false; this.altKey = 'altKey' in eventDict ? eventDict['altKey'] : false;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.shiftKey = 'shiftKey' in eventDict ? eventDict['shiftKey'] : false; this.shiftKey = 'shiftKey' in eventDict ? eventDict['shiftKey'] : false;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.metaKey = 'metaKey' in eventDict ? eventDict['metaKey'] : false; this.metaKey = 'metaKey' in eventDict ? eventDict['metaKey'] : false;
/** /**
* @type {number} * @type {number}
*/ */
this.button = 'button' in eventDict ? eventDict['button'] : 0; this.button = 'button' in eventDict ? eventDict['button'] : 0;
/** /**
* @type {Node} * @type {Node}
*/ */
this.relatedTarget = 'relatedTarget' in eventDict ? this.relatedTarget = 'relatedTarget' in eventDict ?
eventDict['relatedTarget'] : null; eventDict['relatedTarget'] : null;
// PointerEvent related properties // PointerEvent related properties
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
this.pointerId = 'pointerId' in eventDict ? eventDict['pointerId'] : 0; this.pointerId = 'pointerId' in eventDict ? eventDict['pointerId'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.width = 'width' in eventDict ? eventDict['width'] : 0; this.width = 'width' in eventDict ? eventDict['width'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.height = 'height' in eventDict ? eventDict['height'] : 0; this.height = 'height' in eventDict ? eventDict['height'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.tiltX = 'tiltX' in eventDict ? eventDict['tiltX'] : 0; this.tiltX = 'tiltX' in eventDict ? eventDict['tiltX'] : 0;
/** /**
* @type {number} * @type {number}
*/ */
this.tiltY = 'tiltY' in eventDict ? eventDict['tiltY'] : 0; this.tiltY = 'tiltY' in eventDict ? eventDict['tiltY'] : 0;
/** /**
* @type {string} * @type {string}
*/ */
this.pointerType = 'pointerType' in eventDict ? eventDict['pointerType'] : ''; this.pointerType = 'pointerType' in eventDict ? eventDict['pointerType'] : '';
/** /**
* @type {number} * @type {number}
*/ */
this.hwTimestamp = 'hwTimestamp' in eventDict ? eventDict['hwTimestamp'] : 0; this.hwTimestamp = 'hwTimestamp' in eventDict ? eventDict['hwTimestamp'] : 0;
/** /**
* @type {boolean} * @type {boolean}
*/ */
this.isPrimary = 'isPrimary' in eventDict ? eventDict['isPrimary'] : false; this.isPrimary = 'isPrimary' in eventDict ? eventDict['isPrimary'] : false;
// keep the semantics of preventDefault // keep the semantics of preventDefault
if (originalEvent.preventDefault) { if (originalEvent.preventDefault) {
this.preventDefault = function() { this.preventDefault = function() {
originalEvent.preventDefault(); originalEvent.preventDefault();
}; };
} }
} }
/** /**
* @private * @private
* @param {Object.<string, ?>} eventDict The event dictionary. * @param {Object.<string, ?>} eventDict The event dictionary.
* @return {number} Button indicator. * @return {number} Button indicator.
*/ */
getButtons_(eventDict) { getButtons_(eventDict) {
// According to the w3c spec, // According to the w3c spec,
// http://www.w3.org/TR/DOM-Level-3-Events/#events-MouseEvent-button // http://www.w3.org/TR/DOM-Level-3-Events/#events-MouseEvent-button
// MouseEvent.button == 0 can mean either no mouse button depressed, or the // MouseEvent.button == 0 can mean either no mouse button depressed, or the
// left mouse button depressed. // left mouse button depressed.
// //
// As of now, the only way to distinguish between the two states of // As of now, the only way to distinguish between the two states of
// MouseEvent.button is by using the deprecated MouseEvent.which property, as // MouseEvent.button is by using the deprecated MouseEvent.which property, as
// this maps mouse buttons to positive integers > 0, and uses 0 to mean that // this maps mouse buttons to positive integers > 0, and uses 0 to mean that
// no mouse button is held. // no mouse button is held.
// //
// MouseEvent.which is derived from MouseEvent.button at MouseEvent creation, // MouseEvent.which is derived from MouseEvent.button at MouseEvent creation,
// but initMouseEvent does not expose an argument with which to set // but initMouseEvent does not expose an argument with which to set
// MouseEvent.which. Calling initMouseEvent with a buttonArg of 0 will set // MouseEvent.which. Calling initMouseEvent with a buttonArg of 0 will set
// MouseEvent.button == 0 and MouseEvent.which == 1, breaking the expectations // MouseEvent.button == 0 and MouseEvent.which == 1, breaking the expectations
// of app developers. // of app developers.
// //
// The only way to propagate the correct state of MouseEvent.which and // The only way to propagate the correct state of MouseEvent.which and
// MouseEvent.button to a new MouseEvent.button == 0 and MouseEvent.which == 0 // MouseEvent.button to a new MouseEvent.button == 0 and MouseEvent.which == 0
// is to call initMouseEvent with a buttonArg value of -1. // is to call initMouseEvent with a buttonArg value of -1.
// //
// This is fixed with DOM Level 4's use of buttons // This is fixed with DOM Level 4's use of buttons
let buttons; let buttons;
if (eventDict.buttons || HAS_BUTTONS) { if (eventDict.buttons || HAS_BUTTONS) {
buttons = eventDict.buttons; buttons = eventDict.buttons;
} else { } else {
switch (eventDict.which) { switch (eventDict.which) {
case 1: buttons = 1; break; case 1: buttons = 1; break;
case 2: buttons = 4; break; case 2: buttons = 4; break;
case 3: buttons = 2; break; case 3: buttons = 2; break;
default: buttons = 0; default: buttons = 0;
} }
} }
return buttons; return buttons;
} }
/** /**
* @private * @private
* @param {Object.<string, ?>} eventDict The event dictionary. * @param {Object.<string, ?>} eventDict The event dictionary.
* @param {number} buttons Button indicator. * @param {number} buttons Button indicator.
* @return {number} The pressure. * @return {number} The pressure.
*/ */
getPressure_(eventDict, buttons) { getPressure_(eventDict, buttons) {
// Spec requires that pointers without pressure specified use 0.5 for down // Spec requires that pointers without pressure specified use 0.5 for down
// state and 0 for up state. // state and 0 for up state.
let pressure = 0; let pressure = 0;
if (eventDict.pressure) { if (eventDict.pressure) {
pressure = eventDict.pressure; pressure = eventDict.pressure;
} else { } else {
pressure = buttons ? 0.5 : 0; pressure = buttons ? 0.5 : 0;
} }
return pressure; return pressure;
} }
} }
inherits(PointerEvent, Event); inherits(PointerEvent, Event);
/**
* Is the `buttons` property supported?
* @type {boolean}
*/
let HAS_BUTTONS = false;
/** /**
* Checks if the `buttons` property is supported. * Checks if the `buttons` property is supported.
*/ */
@@ -274,4 +275,5 @@ let HAS_BUTTONS = false;
// pass // pass
} }
})(); })();
export default PointerEvent; export default PointerEvent;

View File

@@ -42,6 +42,47 @@ import NativeSource from '../pointer/NativeSource.js';
import PointerEvent from '../pointer/PointerEvent.js'; import PointerEvent from '../pointer/PointerEvent.js';
import TouchSource from '../pointer/TouchSource.js'; import TouchSource from '../pointer/TouchSource.js';
/**
* Properties to copy when cloning an event, with default values.
* @type {Array.<Array>}
*/
const CLONE_PROPS = [
// MouseEvent
['bubbles', false],
['cancelable', false],
['view', null],
['detail', null],
['screenX', 0],
['screenY', 0],
['clientX', 0],
['clientY', 0],
['ctrlKey', false],
['altKey', false],
['shiftKey', false],
['metaKey', false],
['button', 0],
['relatedTarget', null],
// DOM Level 3
['buttons', 0],
// PointerEvent
['pointerId', 0],
['width', 0],
['height', 0],
['pressure', 0],
['tiltX', 0],
['tiltY', 0],
['pointerType', ''],
['hwTimestamp', 0],
['isPrimary', false],
// event instance
['type', ''],
['target', null],
['currentTarget', null],
['which', 0]
];
/** /**
* @constructor * @constructor
* @extends {module:ol/events/EventTarget} * @extends {module:ol/events/EventTarget}
@@ -377,44 +418,4 @@ class PointerEventHandler {
inherits(PointerEventHandler, EventTarget); inherits(PointerEventHandler, EventTarget);
/**
* Properties to copy when cloning an event, with default values.
* @type {Array.<Array>}
*/
const CLONE_PROPS = [
// MouseEvent
['bubbles', false],
['cancelable', false],
['view', null],
['detail', null],
['screenX', 0],
['screenY', 0],
['clientX', 0],
['clientY', 0],
['ctrlKey', false],
['altKey', false],
['shiftKey', false],
['metaKey', false],
['button', 0],
['relatedTarget', null],
// DOM Level 3
['buttons', 0],
// PointerEvent
['pointerId', 0],
['width', 0],
['height', 0],
['pressure', 0],
['tiltX', 0],
['tiltY', 0],
['pointerType', ''],
['hwTimestamp', 0],
['isPrimary', false],
// event instance
['type', ''],
['target', null],
['currentTarget', null],
['which', 0]
];
export default PointerEventHandler; export default PointerEventHandler;

View File

@@ -37,6 +37,18 @@ import EventSource from '../pointer/EventSource.js';
import {POINTER_ID} from '../pointer/MouseSource.js'; import {POINTER_ID} from '../pointer/MouseSource.js';
/**
* @type {number}
*/
const CLICK_COUNT_TIMEOUT = 200;
/**
* @type {string}
*/
const POINTER_TYPE = 'touch';
/** /**
* @constructor * @constructor
* @param {module:ol/pointer/PointerEventHandler} dispatcher The event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher The event handler.
@@ -411,15 +423,4 @@ class TouchSource {
inherits(TouchSource, EventSource); inherits(TouchSource, EventSource);
/**
* @type {number}
*/
const CLICK_COUNT_TIMEOUT = 200;
/**
* @type {string}
*/
const POINTER_TYPE = 'touch';
export default TouchSource; export default TouchSource;

View File

@@ -13,117 +13,117 @@ import Polygon from '../geom/Polygon.js';
* @param {string} className CSS class name. * @param {string} className CSS class name.
*/ */
class RenderBox { class RenderBox {
constructor(className) { constructor(className) {
/** /**
* @type {module:ol/geom/Polygon} * @type {module:ol/geom/Polygon}
* @private * @private
*/ */
this.geometry_ = null; this.geometry_ = null;
/** /**
* @type {HTMLDivElement} * @type {HTMLDivElement}
* @private * @private
*/ */
this.element_ = /** @type {HTMLDivElement} */ (document.createElement('div')); this.element_ = /** @type {HTMLDivElement} */ (document.createElement('div'));
this.element_.style.position = 'absolute'; this.element_.style.position = 'absolute';
this.element_.className = 'ol-box ' + className; this.element_.className = 'ol-box ' + className;
/** /**
* @private * @private
* @type {module:ol/PluggableMap} * @type {module:ol/PluggableMap}
*/ */
this.map_ = null; this.map_ = null;
/** /**
* @private * @private
* @type {module:ol~Pixel} * @type {module:ol~Pixel}
*/ */
this.startPixel_ = null; this.startPixel_ = null;
/** /**
* @private * @private
* @type {module:ol~Pixel} * @type {module:ol~Pixel}
*/ */
this.endPixel_ = null; this.endPixel_ = null;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
disposeInternal() { disposeInternal() {
this.setMap(null); this.setMap(null);
} }
/** /**
* @private * @private
*/ */
render_() { render_() {
const startPixel = this.startPixel_; const startPixel = this.startPixel_;
const endPixel = this.endPixel_; const endPixel = this.endPixel_;
const px = 'px'; const px = 'px';
const style = this.element_.style; const style = this.element_.style;
style.left = Math.min(startPixel[0], endPixel[0]) + px; style.left = Math.min(startPixel[0], endPixel[0]) + px;
style.top = Math.min(startPixel[1], endPixel[1]) + px; style.top = Math.min(startPixel[1], endPixel[1]) + px;
style.width = Math.abs(endPixel[0] - startPixel[0]) + px; style.width = Math.abs(endPixel[0] - startPixel[0]) + px;
style.height = Math.abs(endPixel[1] - startPixel[1]) + px; style.height = Math.abs(endPixel[1] - startPixel[1]) + px;
} }
/** /**
* @param {module:ol/PluggableMap} map Map. * @param {module:ol/PluggableMap} map Map.
*/ */
setMap(map) { setMap(map) {
if (this.map_) { if (this.map_) {
this.map_.getOverlayContainer().removeChild(this.element_); this.map_.getOverlayContainer().removeChild(this.element_);
const style = this.element_.style; const style = this.element_.style;
style.left = style.top = style.width = style.height = 'inherit'; style.left = style.top = style.width = style.height = 'inherit';
} }
this.map_ = map; this.map_ = map;
if (this.map_) { if (this.map_) {
this.map_.getOverlayContainer().appendChild(this.element_); this.map_.getOverlayContainer().appendChild(this.element_);
} }
} }
/** /**
* @param {module:ol~Pixel} startPixel Start pixel. * @param {module:ol~Pixel} startPixel Start pixel.
* @param {module:ol~Pixel} endPixel End pixel. * @param {module:ol~Pixel} endPixel End pixel.
*/ */
setPixels(startPixel, endPixel) { setPixels(startPixel, endPixel) {
this.startPixel_ = startPixel; this.startPixel_ = startPixel;
this.endPixel_ = endPixel; this.endPixel_ = endPixel;
this.createOrUpdateGeometry(); this.createOrUpdateGeometry();
this.render_(); this.render_();
} }
/** /**
* Creates or updates the cached geometry. * Creates or updates the cached geometry.
*/ */
createOrUpdateGeometry() { createOrUpdateGeometry() {
const startPixel = this.startPixel_; const startPixel = this.startPixel_;
const endPixel = this.endPixel_; const endPixel = this.endPixel_;
const pixels = [ const pixels = [
startPixel, startPixel,
[startPixel[0], endPixel[1]], [startPixel[0], endPixel[1]],
endPixel, endPixel,
[endPixel[0], startPixel[1]] [endPixel[0], startPixel[1]]
]; ];
const coordinates = pixels.map(this.map_.getCoordinateFromPixel, this.map_); const coordinates = pixels.map(this.map_.getCoordinateFromPixel, this.map_);
// close the polygon // close the polygon
coordinates[4] = coordinates[0].slice(); coordinates[4] = coordinates[0].slice();
if (!this.geometry_) { if (!this.geometry_) {
this.geometry_ = new Polygon([coordinates]); this.geometry_ = new Polygon([coordinates]);
} else { } else {
this.geometry_.setCoordinates([coordinates]); this.geometry_.setCoordinates([coordinates]);
} }
} }
/** /**
* @return {module:ol/geom/Polygon} Geometry. * @return {module:ol/geom/Polygon} Geometry.
*/ */
getGeometry() { getGeometry() {
return this.geometry_; return this.geometry_;
} }
} }
inherits(RenderBox, Disposable); inherits(RenderBox, Disposable);

View File

@@ -12,6 +12,13 @@ import {get as getProjection} from '../proj.js';
import {transform2D} from '../geom/flat/transform.js'; import {transform2D} from '../geom/flat/transform.js';
import {create as createTransform, compose as composeTransform} from '../transform.js'; import {create as createTransform, compose as composeTransform} from '../transform.js';
/**
* @type {module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* Lightweight, read-only, {@link module:ol/Feature~Feature} and {@link module:ol/geom/Geometry~Geometry} like * Lightweight, read-only, {@link module:ol/Feature~Feature} and {@link module:ol/geom/Geometry~Geometry} like
* structure, optimized for vector tile rendering and styling. Geometry access * structure, optimized for vector tile rendering and styling. Geometry access
@@ -26,219 +33,213 @@ import {create as createTransform, compose as composeTransform} from '../transfo
* @param {number|string|undefined} id Feature id. * @param {number|string|undefined} id Feature id.
*/ */
class RenderFeature { class RenderFeature {
constructor(type, flatCoordinates, ends, properties, id) { constructor(type, flatCoordinates, ends, properties, id) {
/** /**
* @private * @private
* @type {module:ol/extent~Extent|undefined} * @type {module:ol/extent~Extent|undefined}
*/ */
this.extent_; this.extent_;
/** /**
* @private * @private
* @type {number|string|undefined} * @type {number|string|undefined}
*/ */
this.id_ = id; this.id_ = id;
/** /**
* @private * @private
* @type {module:ol/geom/GeometryType} * @type {module:ol/geom/GeometryType}
*/ */
this.type_ = type; this.type_ = type;
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.flatCoordinates_ = flatCoordinates; this.flatCoordinates_ = flatCoordinates;
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.flatInteriorPoints_ = null; this.flatInteriorPoints_ = null;
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.flatMidpoints_ = null; this.flatMidpoints_ = null;
/** /**
* @private * @private
* @type {Array.<number>|Array.<Array.<number>>} * @type {Array.<number>|Array.<Array.<number>>}
*/ */
this.ends_ = ends; this.ends_ = ends;
/** /**
* @private * @private
* @type {Object.<string, *>} * @type {Object.<string, *>}
*/ */
this.properties_ = properties; this.properties_ = properties;
} }
/** /**
* Get a feature property by its key. * Get a feature property by its key.
* @param {string} key Key * @param {string} key Key
* @return {*} Value for the requested key. * @return {*} Value for the requested key.
* @api * @api
*/ */
get(key) { get(key) {
return this.properties_[key]; return this.properties_[key];
} }
/** /**
* Get the extent of this feature's geometry. * Get the extent of this feature's geometry.
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
* @api * @api
*/ */
getExtent() { getExtent() {
if (!this.extent_) { if (!this.extent_) {
this.extent_ = this.type_ === GeometryType.POINT ? this.extent_ = this.type_ === GeometryType.POINT ?
createOrUpdateFromCoordinate(this.flatCoordinates_) : createOrUpdateFromCoordinate(this.flatCoordinates_) :
createOrUpdateFromFlatCoordinates( createOrUpdateFromFlatCoordinates(
this.flatCoordinates_, 0, this.flatCoordinates_.length, 2); this.flatCoordinates_, 0, this.flatCoordinates_.length, 2);
} }
return this.extent_; return this.extent_;
} }
/** /**
* @return {Array.<number>} Flat interior points. * @return {Array.<number>} Flat interior points.
*/ */
getFlatInteriorPoint() { getFlatInteriorPoint() {
if (!this.flatInteriorPoints_) { if (!this.flatInteriorPoints_) {
const flatCenter = getCenter(this.getExtent()); const flatCenter = getCenter(this.getExtent());
this.flatInteriorPoints_ = getInteriorPointOfArray( this.flatInteriorPoints_ = getInteriorPointOfArray(
this.flatCoordinates_, 0, this.ends_, 2, flatCenter, 0); this.flatCoordinates_, 0, this.ends_, 2, flatCenter, 0);
} }
return this.flatInteriorPoints_; return this.flatInteriorPoints_;
} }
/** /**
* @return {Array.<number>} Flat interior points. * @return {Array.<number>} Flat interior points.
*/ */
getFlatInteriorPoints() { getFlatInteriorPoints() {
if (!this.flatInteriorPoints_) { if (!this.flatInteriorPoints_) {
const flatCenters = linearRingssCenter( const flatCenters = linearRingssCenter(
this.flatCoordinates_, 0, this.ends_, 2); this.flatCoordinates_, 0, this.ends_, 2);
this.flatInteriorPoints_ = getInteriorPointsOfMultiArray( this.flatInteriorPoints_ = getInteriorPointsOfMultiArray(
this.flatCoordinates_, 0, this.ends_, 2, flatCenters); this.flatCoordinates_, 0, this.ends_, 2, flatCenters);
} }
return this.flatInteriorPoints_; return this.flatInteriorPoints_;
} }
/** /**
* @return {Array.<number>} Flat midpoint. * @return {Array.<number>} Flat midpoint.
*/ */
getFlatMidpoint() { getFlatMidpoint() {
if (!this.flatMidpoints_) { if (!this.flatMidpoints_) {
this.flatMidpoints_ = interpolatePoint( this.flatMidpoints_ = interpolatePoint(
this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5); this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5);
} }
return this.flatMidpoints_; return this.flatMidpoints_;
} }
/** /**
* @return {Array.<number>} Flat midpoints. * @return {Array.<number>} Flat midpoints.
*/ */
getFlatMidpoints() { getFlatMidpoints() {
if (!this.flatMidpoints_) { if (!this.flatMidpoints_) {
this.flatMidpoints_ = []; this.flatMidpoints_ = [];
const flatCoordinates = this.flatCoordinates_; const flatCoordinates = this.flatCoordinates_;
let offset = 0; let offset = 0;
const ends = this.ends_; const ends = this.ends_;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const midpoint = interpolatePoint( const midpoint = interpolatePoint(
flatCoordinates, offset, end, 2, 0.5); flatCoordinates, offset, end, 2, 0.5);
extend(this.flatMidpoints_, midpoint); extend(this.flatMidpoints_, midpoint);
offset = end; offset = end;
} }
} }
return this.flatMidpoints_; return this.flatMidpoints_;
} }
/** /**
* Get the feature identifier. This is a stable identifier for the feature and * Get the feature identifier. This is a stable identifier for the feature and
* is set when reading data from a remote source. * is set when reading data from a remote source.
* @return {number|string|undefined} Id. * @return {number|string|undefined} Id.
* @api * @api
*/ */
getId() { getId() {
return this.id_; return this.id_;
} }
/** /**
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
getOrientedFlatCoordinates() { getOrientedFlatCoordinates() {
return this.flatCoordinates_; return this.flatCoordinates_;
} }
/** /**
* For API compatibility with {@link module:ol/Feature~Feature}, this method is useful when * For API compatibility with {@link module:ol/Feature~Feature}, this method is useful when
* determining the geometry type in style function (see {@link #getType}). * determining the geometry type in style function (see {@link #getType}).
* @return {module:ol/render/Feature} Feature. * @return {module:ol/render/Feature} Feature.
* @api * @api
*/ */
getGeometry() { getGeometry() {
return this; return this;
} }
/** /**
* Get the feature properties. * Get the feature properties.
* @return {Object.<string, *>} Feature properties. * @return {Object.<string, *>} Feature properties.
* @api * @api
*/ */
getProperties() { getProperties() {
return this.properties_; return this.properties_;
} }
/** /**
* @return {number} Stride. * @return {number} Stride.
*/ */
getStride() { getStride() {
return 2; return 2;
} }
/** /**
* Get the type of this feature's geometry. * Get the type of this feature's geometry.
* @return {module:ol/geom/GeometryType} Geometry type. * @return {module:ol/geom/GeometryType} Geometry type.
* @api * @api
*/ */
getType() { getType() {
return this.type_; return this.type_;
} }
/** /**
* Transform geometry coordinates from tile pixel space to projected. * Transform geometry coordinates from tile pixel space to projected.
* The SRS of the source and destination are expected to be the same. * The SRS of the source and destination are expected to be the same.
* *
* @param {module:ol/proj~ProjectionLike} source The current projection * @param {module:ol/proj~ProjectionLike} source The current projection
* @param {module:ol/proj~ProjectionLike} destination The desired projection. * @param {module:ol/proj~ProjectionLike} destination The desired projection.
*/ */
transform(source, destination) { transform(source, destination) {
source = getProjection(source); source = getProjection(source);
const pixelExtent = source.getExtent(); const pixelExtent = source.getExtent();
const projectedExtent = source.getWorldExtent(); const projectedExtent = source.getWorldExtent();
const scale = getHeight(projectedExtent) / getHeight(pixelExtent); const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
composeTransform(tmpTransform, composeTransform(tmpTransform,
projectedExtent[0], projectedExtent[3], projectedExtent[0], projectedExtent[3],
scale, -scale, 0, scale, -scale, 0,
0, 0); 0, 0);
transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2,
tmpTransform, this.flatCoordinates_); tmpTransform, this.flatCoordinates_);
} }
} }
/**
* @type {module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* @return {Array.<number>|Array.<Array.<number>>} Ends or endss. * @return {Array.<number>|Array.<Array.<number>>} Ends or endss.
*/ */

View File

@@ -7,19 +7,19 @@
* @abstract * @abstract
*/ */
class ReplayGroup { class ReplayGroup {
/** /**
* @abstract * @abstract
* @param {number|undefined} zIndex Z index. * @param {number|undefined} zIndex Z index.
* @param {module:ol/render/ReplayType} replayType Replay type. * @param {module:ol/render/ReplayType} replayType Replay type.
* @return {module:ol/render/VectorContext} Replay. * @return {module:ol/render/VectorContext} Replay.
*/ */
getReplay(zIndex, replayType) {} getReplay(zIndex, replayType) {}
/** /**
* @abstract * @abstract
* @return {boolean} Is empty. * @return {boolean} Is empty.
*/ */
isEmpty() {} isEmpty() {}
} }
export default ReplayGroup; export default ReplayGroup;

View File

@@ -10,107 +10,107 @@
* @api * @api
*/ */
class VectorContext { class VectorContext {
/** /**
* Render a geometry with a custom renderer. * Render a geometry with a custom renderer.
* *
* @param {module:ol/geom/SimpleGeometry} geometry Geometry. * @param {module:ol/geom/SimpleGeometry} geometry Geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
* @param {Function} renderer Renderer. * @param {Function} renderer Renderer.
*/ */
drawCustom(geometry, feature, renderer) {} drawCustom(geometry, feature, renderer) {}
/** /**
* Render a geometry. * Render a geometry.
* *
* @param {module:ol/geom/Geometry} geometry The geometry to render. * @param {module:ol/geom/Geometry} geometry The geometry to render.
*/ */
drawGeometry(geometry) {} drawGeometry(geometry) {}
/** /**
* Set the rendering style. * Set the rendering style.
* *
* @param {module:ol/style/Style} style The rendering style. * @param {module:ol/style/Style} style The rendering style.
*/ */
setStyle(style) {} setStyle(style) {}
/** /**
* @param {module:ol/geom/Circle} circleGeometry Circle geometry. * @param {module:ol/geom/Circle} circleGeometry Circle geometry.
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.
*/ */
drawCircle(circleGeometry, feature) {} drawCircle(circleGeometry, feature) {}
/** /**
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.
* @param {module:ol/style/Style} style Style. * @param {module:ol/style/Style} style Style.
*/ */
drawFeature(feature, style) {} drawFeature(feature, style) {}
/** /**
* @param {module:ol/geom/GeometryCollection} geometryCollectionGeometry Geometry * @param {module:ol/geom/GeometryCollection} geometryCollectionGeometry Geometry
* collection. * collection.
* @param {module:ol/Feature} feature Feature. * @param {module:ol/Feature} feature Feature.
*/ */
drawGeometryCollection(geometryCollectionGeometry, feature) {} drawGeometryCollection(geometryCollectionGeometry, feature) {}
/** /**
* @param {module:ol/geom/LineString|module:ol/render/Feature} lineStringGeometry Line string geometry. * @param {module:ol/geom/LineString|module:ol/render/Feature} lineStringGeometry Line string geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawLineString(lineStringGeometry, feature) {} drawLineString(lineStringGeometry, feature) {}
/** /**
* @param {module:ol/geom/MultiLineString|module:ol/render/Feature} multiLineStringGeometry MultiLineString geometry. * @param {module:ol/geom/MultiLineString|module:ol/render/Feature} multiLineStringGeometry MultiLineString geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawMultiLineString(multiLineStringGeometry, feature) {} drawMultiLineString(multiLineStringGeometry, feature) {}
/** /**
* @param {module:ol/geom/MultiPoint|module:ol/render/Feature} multiPointGeometry MultiPoint geometry. * @param {module:ol/geom/MultiPoint|module:ol/render/Feature} multiPointGeometry MultiPoint geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawMultiPoint(multiPointGeometry, feature) {} drawMultiPoint(multiPointGeometry, feature) {}
/** /**
* @param {module:ol/geom/MultiPolygon} multiPolygonGeometry MultiPolygon geometry. * @param {module:ol/geom/MultiPolygon} multiPolygonGeometry MultiPolygon geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawMultiPolygon(multiPolygonGeometry, feature) {} drawMultiPolygon(multiPolygonGeometry, feature) {}
/** /**
* @param {module:ol/geom/Point|module:ol/render/Feature} pointGeometry Point geometry. * @param {module:ol/geom/Point|module:ol/render/Feature} pointGeometry Point geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawPoint(pointGeometry, feature) {} drawPoint(pointGeometry, feature) {}
/** /**
* @param {module:ol/geom/Polygon|module:ol/render/Feature} polygonGeometry Polygon geometry. * @param {module:ol/geom/Polygon|module:ol/render/Feature} polygonGeometry Polygon geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawPolygon(polygonGeometry, feature) {} drawPolygon(polygonGeometry, feature) {}
/** /**
* @param {module:ol/geom/Geometry|module:ol/render/Feature} geometry Geometry. * @param {module:ol/geom/Geometry|module:ol/render/Feature} geometry Geometry.
* @param {module:ol/Feature|module:ol/render/Feature} feature Feature. * @param {module:ol/Feature|module:ol/render/Feature} feature Feature.
*/ */
drawText(geometry, feature) {} drawText(geometry, feature) {}
/** /**
* @param {module:ol/style/Fill} fillStyle Fill style. * @param {module:ol/style/Fill} fillStyle Fill style.
* @param {module:ol/style/Stroke} strokeStyle Stroke style. * @param {module:ol/style/Stroke} strokeStyle Stroke style.
*/ */
setFillStrokeStyle(fillStyle, strokeStyle) {} setFillStrokeStyle(fillStyle, strokeStyle) {}
/** /**
* @param {module:ol/style/Image} imageStyle Image style. * @param {module:ol/style/Image} imageStyle Image style.
* @param {module:ol/render/canvas~DeclutterGroup=} opt_declutterGroup Declutter. * @param {module:ol/render/canvas~DeclutterGroup=} opt_declutterGroup Declutter.
*/ */
setImageStyle(imageStyle, opt_declutterGroup) {} setImageStyle(imageStyle, opt_declutterGroup) {}
/** /**
* @param {module:ol/style/Text} textStyle Text style. * @param {module:ol/style/Text} textStyle Text style.
* @param {module:ol/render/canvas~DeclutterGroup=} opt_declutterGroup Declutter. * @param {module:ol/render/canvas~DeclutterGroup=} opt_declutterGroup Declutter.
*/ */
setTextStyle(textStyle, opt_declutterGroup) {} setTextStyle(textStyle, opt_declutterGroup) {}
} }
export default VectorContext; export default VectorContext;

View File

@@ -17,97 +17,97 @@ import CanvasReplay from '../canvas/Replay.js';
* @struct * @struct
*/ */
class CanvasImageReplay { class CanvasImageReplay {
constructor(tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) { constructor(tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
CanvasReplay.call(this, CanvasReplay.call(this,
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree); tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
/** /**
* @private * @private
* @type {module:ol/render/canvas~DeclutterGroup} * @type {module:ol/render/canvas~DeclutterGroup}
*/ */
this.declutterGroup_ = null; this.declutterGroup_ = null;
/** /**
* @private * @private
* @type {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} * @type {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement}
*/ */
this.hitDetectionImage_ = null; this.hitDetectionImage_ = null;
/** /**
* @private * @private
* @type {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} * @type {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement}
*/ */
this.image_ = null; this.image_ = null;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.anchorX_ = undefined; this.anchorX_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.anchorY_ = undefined; this.anchorY_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.height_ = undefined; this.height_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.opacity_ = undefined; this.opacity_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.originX_ = undefined; this.originX_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.originY_ = undefined; this.originY_ = undefined;
/** /**
* @private * @private
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.rotateWithView_ = undefined; this.rotateWithView_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.rotation_ = undefined; this.rotation_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.scale_ = undefined; this.scale_ = undefined;
/** /**
* @private * @private
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.snapToPixel_ = undefined; this.snapToPixel_ = undefined;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.width_ = undefined; this.width_ = undefined;
} }
/** /**
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
@@ -115,114 +115,114 @@ class CanvasImageReplay {
* @private * @private
* @return {number} My end. * @return {number} My end.
*/ */
drawCoordinates_(flatCoordinates, offset, end, stride) { drawCoordinates_(flatCoordinates, offset, end, stride) {
return this.appendFlatCoordinates(flatCoordinates, offset, end, stride, false, false); return this.appendFlatCoordinates(flatCoordinates, offset, end, stride, false, false);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
drawPoint(pointGeometry, feature) { drawPoint(pointGeometry, feature) {
if (!this.image_) { if (!this.image_) {
return; return;
} }
this.beginGeometry(pointGeometry, feature); this.beginGeometry(pointGeometry, feature);
const flatCoordinates = pointGeometry.getFlatCoordinates(); const flatCoordinates = pointGeometry.getFlatCoordinates();
const stride = pointGeometry.getStride(); const stride = pointGeometry.getStride();
const myBegin = this.coordinates.length; const myBegin = this.coordinates.length;
const myEnd = this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride); const myEnd = this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
this.instructions.push([ this.instructions.push([
CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.image_, CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.image_,
// Remaining arguments to DRAW_IMAGE are in alphabetical order // Remaining arguments to DRAW_IMAGE are in alphabetical order
this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_, this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
this.originX_, this.originY_, this.rotateWithView_, this.rotation_, this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_ this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_
]); ]);
this.hitDetectionInstructions.push([ this.hitDetectionInstructions.push([
CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.hitDetectionImage_, CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.hitDetectionImage_,
// Remaining arguments to DRAW_IMAGE are in alphabetical order // Remaining arguments to DRAW_IMAGE are in alphabetical order
this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_, this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
this.originX_, this.originY_, this.rotateWithView_, this.rotation_, this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
this.scale_, this.snapToPixel_, this.width_ this.scale_, this.snapToPixel_, this.width_
]); ]);
this.endGeometry(pointGeometry, feature); this.endGeometry(pointGeometry, feature);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
drawMultiPoint(multiPointGeometry, feature) { drawMultiPoint(multiPointGeometry, feature) {
if (!this.image_) { if (!this.image_) {
return; return;
} }
this.beginGeometry(multiPointGeometry, feature); this.beginGeometry(multiPointGeometry, feature);
const flatCoordinates = multiPointGeometry.getFlatCoordinates(); const flatCoordinates = multiPointGeometry.getFlatCoordinates();
const stride = multiPointGeometry.getStride(); const stride = multiPointGeometry.getStride();
const myBegin = this.coordinates.length; const myBegin = this.coordinates.length;
const myEnd = this.drawCoordinates_( const myEnd = this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
this.instructions.push([ this.instructions.push([
CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.image_, CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.image_,
// Remaining arguments to DRAW_IMAGE are in alphabetical order // Remaining arguments to DRAW_IMAGE are in alphabetical order
this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_, this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
this.originX_, this.originY_, this.rotateWithView_, this.rotation_, this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_ this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_
]); ]);
this.hitDetectionInstructions.push([ this.hitDetectionInstructions.push([
CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.hitDetectionImage_, CanvasInstruction.DRAW_IMAGE, myBegin, myEnd, this.hitDetectionImage_,
// Remaining arguments to DRAW_IMAGE are in alphabetical order // Remaining arguments to DRAW_IMAGE are in alphabetical order
this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_, this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
this.originX_, this.originY_, this.rotateWithView_, this.rotation_, this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
this.scale_, this.snapToPixel_, this.width_ this.scale_, this.snapToPixel_, this.width_
]); ]);
this.endGeometry(multiPointGeometry, feature); this.endGeometry(multiPointGeometry, feature);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
finish() { finish() {
this.reverseHitDetectionInstructions(); this.reverseHitDetectionInstructions();
// FIXME this doesn't really protect us against further calls to draw*Geometry // FIXME this doesn't really protect us against further calls to draw*Geometry
this.anchorX_ = undefined; this.anchorX_ = undefined;
this.anchorY_ = undefined; this.anchorY_ = undefined;
this.hitDetectionImage_ = null; this.hitDetectionImage_ = null;
this.image_ = null; this.image_ = null;
this.height_ = undefined; this.height_ = undefined;
this.scale_ = undefined; this.scale_ = undefined;
this.opacity_ = undefined; this.opacity_ = undefined;
this.originX_ = undefined; this.originX_ = undefined;
this.originY_ = undefined; this.originY_ = undefined;
this.rotateWithView_ = undefined; this.rotateWithView_ = undefined;
this.rotation_ = undefined; this.rotation_ = undefined;
this.snapToPixel_ = undefined; this.snapToPixel_ = undefined;
this.width_ = undefined; this.width_ = undefined;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
setImageStyle(imageStyle, declutterGroup) { setImageStyle(imageStyle, declutterGroup) {
const anchor = imageStyle.getAnchor(); const anchor = imageStyle.getAnchor();
const size = imageStyle.getSize(); const size = imageStyle.getSize();
const hitDetectionImage = imageStyle.getHitDetectionImage(1); const hitDetectionImage = imageStyle.getHitDetectionImage(1);
const image = imageStyle.getImage(1); const image = imageStyle.getImage(1);
const origin = imageStyle.getOrigin(); const origin = imageStyle.getOrigin();
this.anchorX_ = anchor[0]; this.anchorX_ = anchor[0];
this.anchorY_ = anchor[1]; this.anchorY_ = anchor[1];
this.declutterGroup_ = /** @type {module:ol/render/canvas~DeclutterGroup} */ (declutterGroup); this.declutterGroup_ = /** @type {module:ol/render/canvas~DeclutterGroup} */ (declutterGroup);
this.hitDetectionImage_ = hitDetectionImage; this.hitDetectionImage_ = hitDetectionImage;
this.image_ = image; this.image_ = image;
this.height_ = size[1]; this.height_ = size[1];
this.opacity_ = imageStyle.getOpacity(); this.opacity_ = imageStyle.getOpacity();
this.originX_ = origin[0]; this.originX_ = origin[0];
this.originY_ = origin[1]; this.originY_ = origin[1];
this.rotateWithView_ = imageStyle.getRotateWithView(); this.rotateWithView_ = imageStyle.getRotateWithView();
this.rotation_ = imageStyle.getRotation(); this.rotation_ = imageStyle.getRotation();
this.scale_ = imageStyle.getScale(); this.scale_ = imageStyle.getScale();
this.snapToPixel_ = imageStyle.getSnapToPixel(); this.snapToPixel_ = imageStyle.getSnapToPixel();
this.width_ = size[0]; this.width_ = size[0];
} }
} }
inherits(CanvasImageReplay, CanvasReplay); inherits(CanvasImageReplay, CanvasReplay);

View File

@@ -28,6 +28,19 @@ import {
setFromArray as transformSetFromArray setFromArray as transformSetFromArray
} from '../../transform.js'; } from '../../transform.js';
/**
* @type {module:ol/extent~Extent}
*/
const tmpExtent = createEmpty();
/**
* @type {!module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* @constructor * @constructor
* @extends {module:ol/render/VectorContext} * @extends {module:ol/render/VectorContext}
@@ -1072,18 +1085,6 @@ class CanvasReplay {
inherits(CanvasReplay, VectorContext); inherits(CanvasReplay, VectorContext);
/**
* @type {module:ol/extent~Extent}
*/
const tmpExtent = createEmpty();
/**
* @type {!module:ol/transform~Transform}
*/
const tmpTransform = createTransform();
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */

View File

@@ -24,23 +24,23 @@ import {ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, TRIANGLES,
* @struct * @struct
*/ */
class WebGLReplay { class WebGLReplay {
constructor(tolerance, maxExtent) { constructor(tolerance, maxExtent) {
VectorContext.call(this); VectorContext.call(this);
/** /**
* @protected * @protected
* @type {number} * @type {number}
*/ */
this.tolerance = tolerance; this.tolerance = tolerance;
/** /**
* @protected * @protected
* @const * @const
* @type {module:ol/extent~Extent} * @type {module:ol/extent~Extent}
*/ */
this.maxExtent = maxExtent; this.maxExtent = maxExtent;
/** /**
* The origin of the coordinate system for the point coordinates sent to * The origin of the coordinate system for the point coordinates sent to
* the GPU. To eliminate jitter caused by precision problems in the GPU * the GPU. To eliminate jitter caused by precision problems in the GPU
* we use the "Rendering Relative to Eye" technique described in the "3D * we use the "Rendering Relative to Eye" technique described in the "3D
@@ -48,93 +48,93 @@ class WebGLReplay {
* @protected * @protected
* @type {module:ol/coordinate~Coordinate} * @type {module:ol/coordinate~Coordinate}
*/ */
this.origin = getCenter(maxExtent); this.origin = getCenter(maxExtent);
/** /**
* @private * @private
* @type {module:ol/transform~Transform} * @type {module:ol/transform~Transform}
*/ */
this.projectionMatrix_ = createTransform(); this.projectionMatrix_ = createTransform();
/** /**
* @private * @private
* @type {module:ol/transform~Transform} * @type {module:ol/transform~Transform}
*/ */
this.offsetRotateMatrix_ = createTransform(); this.offsetRotateMatrix_ = createTransform();
/** /**
* @private * @private
* @type {module:ol/transform~Transform} * @type {module:ol/transform~Transform}
*/ */
this.offsetScaleMatrix_ = createTransform(); this.offsetScaleMatrix_ = createTransform();
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.tmpMat4_ = create(); this.tmpMat4_ = create();
/** /**
* @protected * @protected
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.indices = []; this.indices = [];
/** /**
* @protected * @protected
* @type {?module:ol/webgl/Buffer} * @type {?module:ol/webgl/Buffer}
*/ */
this.indicesBuffer = null; this.indicesBuffer = null;
/** /**
* Start index per feature (the index). * Start index per feature (the index).
* @protected * @protected
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.startIndices = []; this.startIndices = [];
/** /**
* Start index per feature (the feature). * Start index per feature (the feature).
* @protected * @protected
* @type {Array.<module:ol/Feature|module:ol/render/Feature>} * @type {Array.<module:ol/Feature|module:ol/render/Feature>}
*/ */
this.startIndicesFeature = []; this.startIndicesFeature = [];
/** /**
* @protected * @protected
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.vertices = []; this.vertices = [];
/** /**
* @protected * @protected
* @type {?module:ol/webgl/Buffer} * @type {?module:ol/webgl/Buffer}
*/ */
this.verticesBuffer = null; this.verticesBuffer = null;
/** /**
* Optional parameter for PolygonReplay instances. * Optional parameter for PolygonReplay instances.
* @protected * @protected
* @type {module:ol/render/webgl/LineStringReplay|undefined} * @type {module:ol/render/webgl/LineStringReplay|undefined}
*/ */
this.lineStringReplay = undefined; this.lineStringReplay = undefined;
} }
/** /**
* @abstract * @abstract
* @param {module:ol/webgl/Context} context WebGL context. * @param {module:ol/webgl/Context} context WebGL context.
* @return {function()} Delete resources function. * @return {function()} Delete resources function.
*/ */
getDeleteResourcesFunction(context) {} getDeleteResourcesFunction(context) {}
/** /**
* @abstract * @abstract
* @param {module:ol/webgl/Context} context Context. * @param {module:ol/webgl/Context} context Context.
*/ */
finish(context) {} finish(context) {}
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -146,9 +146,9 @@ class WebGLReplay {
module:ol/render/webgl/polygonreplay/defaultshader/Locations| module:ol/render/webgl/polygonreplay/defaultshader/Locations|
module:ol/render/webgl/texturereplay/defaultshader/Locations} Locations. module:ol/render/webgl/texturereplay/defaultshader/Locations} Locations.
*/ */
setUpProgram(gl, context, size, pixelRatio) {} setUpProgram(gl, context, size, pixelRatio) {}
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -157,9 +157,9 @@ class WebGLReplay {
module:ol/render/webgl/polygonreplay/defaultshader/Locations| module:ol/render/webgl/polygonreplay/defaultshader/Locations|
module:ol/render/webgl/texturereplay/defaultshader/Locations} locations Locations. module:ol/render/webgl/texturereplay/defaultshader/Locations} locations Locations.
*/ */
shutDownProgram(gl, locations) {} shutDownProgram(gl, locations) {}
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -167,9 +167,9 @@ class WebGLReplay {
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features to skip. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features to skip.
* @param {boolean} hitDetection Hit detection mode. * @param {boolean} hitDetection Hit detection mode.
*/ */
drawReplay(gl, context, skippedFeaturesHash, hitDetection) {} drawReplay(gl, context, skippedFeaturesHash, hitDetection) {}
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -180,9 +180,9 @@ class WebGLReplay {
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
drawHitDetectionReplayOneByOne(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {} drawHitDetectionReplayOneByOne(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {}
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {module:ol/webgl/Context} context Context. * @param {module:ol/webgl/Context} context Context.
@@ -194,19 +194,19 @@ class WebGLReplay {
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
drawHitDetectionReplay(gl, context, skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) { drawHitDetectionReplay(gl, context, skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) {
if (!oneByOne) { if (!oneByOne) {
// draw all hit-detection features in "once" (by texture group) // draw all hit-detection features in "once" (by texture group)
return this.drawHitDetectionReplayAll(gl, context, return this.drawHitDetectionReplayAll(gl, context,
skippedFeaturesHash, featureCallback); skippedFeaturesHash, featureCallback);
} else { } else {
// draw hit-detection features one by one // draw hit-detection features one by one
return this.drawHitDetectionReplayOneByOne(gl, context, return this.drawHitDetectionReplayOneByOne(gl, context,
skippedFeaturesHash, featureCallback, opt_hitExtent); skippedFeaturesHash, featureCallback, opt_hitExtent);
} }
} }
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {module:ol/webgl/Context} context Context. * @param {module:ol/webgl/Context} context Context.
@@ -215,19 +215,19 @@ class WebGLReplay {
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
drawHitDetectionReplayAll(gl, context, skippedFeaturesHash, featureCallback) { drawHitDetectionReplayAll(gl, context, skippedFeaturesHash, featureCallback) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
this.drawReplay(gl, context, skippedFeaturesHash, true); this.drawReplay(gl, context, skippedFeaturesHash, true);
const result = featureCallback(null); const result = featureCallback(null);
if (result) { if (result) {
return result; return result;
} else { } else {
return undefined; return undefined;
} }
} }
/** /**
* @param {module:ol/webgl/Context} context Context. * @param {module:ol/webgl/Context} context Context.
* @param {module:ol/coordinate~Coordinate} center Center. * @param {module:ol/coordinate~Coordinate} center Center.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
@@ -243,120 +243,120 @@ class WebGLReplay {
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
replay( replay(
context, context,
center, center,
resolution, resolution,
rotation, rotation,
size, size,
pixelRatio, pixelRatio,
opacity, opacity,
skippedFeaturesHash, skippedFeaturesHash,
featureCallback, featureCallback,
oneByOne, oneByOne,
opt_hitExtent opt_hitExtent
) { ) {
const gl = context.getGL(); const gl = context.getGL();
let tmpStencil, tmpStencilFunc, tmpStencilMaskVal, tmpStencilRef, tmpStencilMask, let tmpStencil, tmpStencilFunc, tmpStencilMaskVal, tmpStencilRef, tmpStencilMask,
tmpStencilOpFail, tmpStencilOpPass, tmpStencilOpZFail; tmpStencilOpFail, tmpStencilOpPass, tmpStencilOpZFail;
if (this.lineStringReplay) { if (this.lineStringReplay) {
tmpStencil = gl.isEnabled(gl.STENCIL_TEST); tmpStencil = gl.isEnabled(gl.STENCIL_TEST);
tmpStencilFunc = gl.getParameter(gl.STENCIL_FUNC); tmpStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
tmpStencilMaskVal = gl.getParameter(gl.STENCIL_VALUE_MASK); tmpStencilMaskVal = gl.getParameter(gl.STENCIL_VALUE_MASK);
tmpStencilRef = gl.getParameter(gl.STENCIL_REF); tmpStencilRef = gl.getParameter(gl.STENCIL_REF);
tmpStencilMask = gl.getParameter(gl.STENCIL_WRITEMASK); tmpStencilMask = gl.getParameter(gl.STENCIL_WRITEMASK);
tmpStencilOpFail = gl.getParameter(gl.STENCIL_FAIL); tmpStencilOpFail = gl.getParameter(gl.STENCIL_FAIL);
tmpStencilOpPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS); tmpStencilOpPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
tmpStencilOpZFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL); tmpStencilOpZFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
gl.enable(gl.STENCIL_TEST); gl.enable(gl.STENCIL_TEST);
gl.clear(gl.STENCIL_BUFFER_BIT); gl.clear(gl.STENCIL_BUFFER_BIT);
gl.stencilMask(255); gl.stencilMask(255);
gl.stencilFunc(gl.ALWAYS, 1, 255); gl.stencilFunc(gl.ALWAYS, 1, 255);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE); gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
this.lineStringReplay.replay(context, this.lineStringReplay.replay(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash, opacity, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent); featureCallback, oneByOne, opt_hitExtent);
gl.stencilMask(0); gl.stencilMask(0);
gl.stencilFunc(gl.NOTEQUAL, 1, 255); gl.stencilFunc(gl.NOTEQUAL, 1, 255);
} }
context.bindBuffer(ARRAY_BUFFER, this.verticesBuffer); context.bindBuffer(ARRAY_BUFFER, this.verticesBuffer);
context.bindBuffer(ELEMENT_ARRAY_BUFFER, this.indicesBuffer); context.bindBuffer(ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
const locations = this.setUpProgram(gl, context, size, pixelRatio); const locations = this.setUpProgram(gl, context, size, pixelRatio);
// set the "uniform" values // set the "uniform" values
const projectionMatrix = resetTransform(this.projectionMatrix_); const projectionMatrix = resetTransform(this.projectionMatrix_);
scaleTransform(projectionMatrix, 2 / (resolution * size[0]), 2 / (resolution * size[1])); scaleTransform(projectionMatrix, 2 / (resolution * size[0]), 2 / (resolution * size[1]));
rotateTransform(projectionMatrix, -rotation); rotateTransform(projectionMatrix, -rotation);
translateTransform(projectionMatrix, -(center[0] - this.origin[0]), -(center[1] - this.origin[1])); translateTransform(projectionMatrix, -(center[0] - this.origin[0]), -(center[1] - this.origin[1]));
const offsetScaleMatrix = resetTransform(this.offsetScaleMatrix_); const offsetScaleMatrix = resetTransform(this.offsetScaleMatrix_);
scaleTransform(offsetScaleMatrix, 2 / size[0], 2 / size[1]); scaleTransform(offsetScaleMatrix, 2 / size[0], 2 / size[1]);
const offsetRotateMatrix = resetTransform(this.offsetRotateMatrix_); const offsetRotateMatrix = resetTransform(this.offsetRotateMatrix_);
if (rotation !== 0) { if (rotation !== 0) {
rotateTransform(offsetRotateMatrix, -rotation); rotateTransform(offsetRotateMatrix, -rotation);
} }
gl.uniformMatrix4fv(locations.u_projectionMatrix, false, gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
fromTransform(this.tmpMat4_, projectionMatrix)); fromTransform(this.tmpMat4_, projectionMatrix));
gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false, gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false,
fromTransform(this.tmpMat4_, offsetScaleMatrix)); fromTransform(this.tmpMat4_, offsetScaleMatrix));
gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false, gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false,
fromTransform(this.tmpMat4_, offsetRotateMatrix)); fromTransform(this.tmpMat4_, offsetRotateMatrix));
gl.uniform1f(locations.u_opacity, opacity); gl.uniform1f(locations.u_opacity, opacity);
// draw! // draw!
let result; let result;
if (featureCallback === undefined) { if (featureCallback === undefined) {
this.drawReplay(gl, context, skippedFeaturesHash, false); this.drawReplay(gl, context, skippedFeaturesHash, false);
} else { } else {
// draw feature by feature for the hit-detection // draw feature by feature for the hit-detection
result = this.drawHitDetectionReplay(gl, context, skippedFeaturesHash, result = this.drawHitDetectionReplay(gl, context, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent); featureCallback, oneByOne, opt_hitExtent);
} }
// disable the vertex attrib arrays // disable the vertex attrib arrays
this.shutDownProgram(gl, locations); this.shutDownProgram(gl, locations);
if (this.lineStringReplay) { if (this.lineStringReplay) {
if (!tmpStencil) { if (!tmpStencil) {
gl.disable(gl.STENCIL_TEST); gl.disable(gl.STENCIL_TEST);
} }
gl.clear(gl.STENCIL_BUFFER_BIT); gl.clear(gl.STENCIL_BUFFER_BIT);
gl.stencilFunc(/** @type {number} */ (tmpStencilFunc), gl.stencilFunc(/** @type {number} */ (tmpStencilFunc),
/** @type {number} */ (tmpStencilRef), /** @type {number} */ (tmpStencilMaskVal)); /** @type {number} */ (tmpStencilRef), /** @type {number} */ (tmpStencilMaskVal));
gl.stencilMask(/** @type {number} */ (tmpStencilMask)); gl.stencilMask(/** @type {number} */ (tmpStencilMask));
gl.stencilOp(/** @type {number} */ (tmpStencilOpFail), gl.stencilOp(/** @type {number} */ (tmpStencilOpFail),
/** @type {number} */ (tmpStencilOpZFail), /** @type {number} */ (tmpStencilOpPass)); /** @type {number} */ (tmpStencilOpZFail), /** @type {number} */ (tmpStencilOpPass));
} }
return result; return result;
} }
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {module:ol/webgl/Context} context Context. * @param {module:ol/webgl/Context} context Context.
* @param {number} start Start index. * @param {number} start Start index.
* @param {number} end End index. * @param {number} end End index.
*/ */
drawElements(gl, context, start, end) { drawElements(gl, context, start, end) {
const elementType = context.hasOESElementIndexUint ? const elementType = context.hasOESElementIndexUint ?
UNSIGNED_INT : UNSIGNED_SHORT; UNSIGNED_INT : UNSIGNED_SHORT;
const elementSize = context.hasOESElementIndexUint ? 4 : 2; const elementSize = context.hasOESElementIndexUint ? 4 : 2;
const numItems = end - start; const numItems = end - start;
const offsetInBytes = start * elementSize; const offsetInBytes = start * elementSize;
gl.drawElements(TRIANGLES, numItems, elementType, offsetInBytes); gl.drawElements(TRIANGLES, numItems, elementType, offsetInBytes);
} }
} }
inherits(WebGLReplay, VectorContext); inherits(WebGLReplay, VectorContext);

View File

@@ -11,6 +11,18 @@ import TileImage from '../source/TileImage.js';
import {createOrUpdate, quadKey} from '../tilecoord.js'; import {createOrUpdate, quadKey} from '../tilecoord.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js'; import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs
* Terms Of Use.
* @const
* @type {string}
*/
const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html">' +
'Terms of Use</a>';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {number} [cacheSize=2048] Cache size. * @property {number} [cacheSize=2048] Cache size.
@@ -213,16 +225,4 @@ class BingMaps {
inherits(BingMaps, TileImage); inherits(BingMaps, TileImage);
/**
* The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs
* Terms Of Use.
* @const
* @type {string}
*/
const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html">' +
'Terms of Use</a>';
export default BingMaps; export default BingMaps;

View File

@@ -52,73 +52,73 @@ import ImageSource from '../source/Image.js';
* @api * @api
*/ */
class ImageCanvasSource { class ImageCanvasSource {
constructor(options) { constructor(options) {
ImageSource.call(this, { ImageSource.call(this, {
attributions: options.attributions, attributions: options.attributions,
projection: options.projection, projection: options.projection,
resolutions: options.resolutions, resolutions: options.resolutions,
state: options.state state: options.state
}); });
/** /**
* @private * @private
* @type {module:ol/source/ImageCanvas~FunctionType} * @type {module:ol/source/ImageCanvas~FunctionType}
*/ */
this.canvasFunction_ = options.canvasFunction; this.canvasFunction_ = options.canvasFunction;
/** /**
* @private * @private
* @type {module:ol/ImageCanvas} * @type {module:ol/ImageCanvas}
*/ */
this.canvas_ = null; this.canvas_ = null;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.renderedRevision_ = 0; this.renderedRevision_ = 0;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.ratio_ = options.ratio !== undefined ? this.ratio_ = options.ratio !== undefined ?
options.ratio : 1.5; options.ratio : 1.5;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getImageInternal(extent, resolution, pixelRatio, projection) { getImageInternal(extent, resolution, pixelRatio, projection) {
resolution = this.findNearestResolution(resolution); resolution = this.findNearestResolution(resolution);
let canvas = this.canvas_; let canvas = this.canvas_;
if (canvas && if (canvas &&
this.renderedRevision_ == this.getRevision() && this.renderedRevision_ == this.getRevision() &&
canvas.getResolution() == resolution && canvas.getResolution() == resolution &&
canvas.getPixelRatio() == pixelRatio && canvas.getPixelRatio() == pixelRatio &&
containsExtent(canvas.getExtent(), extent)) { containsExtent(canvas.getExtent(), extent)) {
return canvas; return canvas;
} }
extent = extent.slice(); extent = extent.slice();
scaleFromCenter(extent, this.ratio_); scaleFromCenter(extent, this.ratio_);
const width = getWidth(extent) / resolution; const width = getWidth(extent) / resolution;
const height = getHeight(extent) / resolution; const height = getHeight(extent) / resolution;
const size = [width * pixelRatio, height * pixelRatio]; const size = [width * pixelRatio, height * pixelRatio];
const canvasElement = this.canvasFunction_( const canvasElement = this.canvasFunction_(
extent, resolution, pixelRatio, size, projection); extent, resolution, pixelRatio, size, projection);
if (canvasElement) { if (canvasElement) {
canvas = new ImageCanvas(extent, resolution, pixelRatio, canvasElement); canvas = new ImageCanvas(extent, resolution, pixelRatio, canvasElement);
} }
this.canvas_ = canvas; this.canvas_ = canvas;
this.renderedRevision_ = this.getRevision(); this.renderedRevision_ = this.getRevision();
return canvas; return canvas;
} }
} }
inherits(ImageCanvasSource, ImageSource); inherits(ImageCanvasSource, ImageSource);

View File

@@ -17,6 +17,14 @@ import WMSServerType from '../source/WMSServerType.js';
import {compareVersions} from '../string.js'; import {compareVersions} from '../string.js';
import {appendParams} from '../uri.js'; import {appendParams} from '../uri.js';
/**
* @const
* @type {module:ol/size~Size}
*/
const GETFEATUREINFO_IMAGE_SIZE = [101, 101];
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {module:ol/source/Source~AttributionLike} [attributions] Attributions. * @property {module:ol/source/Source~AttributionLike} [attributions] Attributions.
@@ -380,11 +388,4 @@ class ImageWMS {
inherits(ImageWMS, ImageSource); inherits(ImageWMS, ImageSource);
/**
* @const
* @type {module:ol/size~Size}
*/
const GETFEATUREINFO_IMAGE_SIZE = [101, 101];
export default ImageWMS; export default ImageWMS;

View File

@@ -52,129 +52,129 @@ import SourceState from '../source/State.js';
* @api * @api
*/ */
class Source { class Source {
constructor(options) { constructor(options) {
BaseObject.call(this); BaseObject.call(this);
/** /**
* @private * @private
* @type {module:ol/proj/Projection} * @type {module:ol/proj/Projection}
*/ */
this.projection_ = getProjection(options.projection); this.projection_ = getProjection(options.projection);
/** /**
* @private * @private
* @type {?module:ol/source/Source~Attribution} * @type {?module:ol/source/Source~Attribution}
*/ */
this.attributions_ = this.adaptAttributions_(options.attributions); this.attributions_ = this.adaptAttributions_(options.attributions);
/** /**
* @private * @private
* @type {module:ol/source/State} * @type {module:ol/source/State}
*/ */
this.state_ = options.state !== undefined ? this.state_ = options.state !== undefined ?
options.state : SourceState.READY; options.state : SourceState.READY;
/** /**
* @private * @private
* @type {boolean} * @type {boolean}
*/ */
this.wrapX_ = options.wrapX !== undefined ? options.wrapX : false; this.wrapX_ = options.wrapX !== undefined ? options.wrapX : false;
} }
/** /**
* Turns the attributions option into an attributions function. * Turns the attributions option into an attributions function.
* @param {module:ol/source/Source~AttributionLike|undefined} attributionLike The attribution option. * @param {module:ol/source/Source~AttributionLike|undefined} attributionLike The attribution option.
* @return {?module:ol/source/Source~Attribution} An attribution function (or null). * @return {?module:ol/source/Source~Attribution} An attribution function (or null).
*/ */
adaptAttributions_(attributionLike) { adaptAttributions_(attributionLike) {
if (!attributionLike) { if (!attributionLike) {
return null; return null;
} }
if (Array.isArray(attributionLike)) { if (Array.isArray(attributionLike)) {
return function(frameState) { return function(frameState) {
return attributionLike; return attributionLike;
}; };
} }
if (typeof attributionLike === 'function') { if (typeof attributionLike === 'function') {
return attributionLike; return attributionLike;
} }
return function(frameState) { return function(frameState) {
return [attributionLike]; return [attributionLike];
}; };
} }
/** /**
* Get the attribution function for the source. * Get the attribution function for the source.
* @return {?module:ol/source/Source~Attribution} Attribution function. * @return {?module:ol/source/Source~Attribution} Attribution function.
*/ */
getAttributions() { getAttributions() {
return this.attributions_; return this.attributions_;
} }
/** /**
* Get the projection of the source. * Get the projection of the source.
* @return {module:ol/proj/Projection} Projection. * @return {module:ol/proj/Projection} Projection.
* @api * @api
*/ */
getProjection() { getProjection() {
return this.projection_; return this.projection_;
} }
/** /**
* @abstract * @abstract
* @return {Array.<number>|undefined} Resolutions. * @return {Array.<number>|undefined} Resolutions.
*/ */
getResolutions() {} getResolutions() {}
/** /**
* Get the state of the source, see {@link module:ol/source/State~State} for possible states. * Get the state of the source, see {@link module:ol/source/State~State} for possible states.
* @return {module:ol/source/State} State. * @return {module:ol/source/State} State.
* @api * @api
*/ */
getState() { getState() {
return this.state_; return this.state_;
} }
/** /**
* @return {boolean|undefined} Wrap X. * @return {boolean|undefined} Wrap X.
*/ */
getWrapX() { getWrapX() {
return this.wrapX_; return this.wrapX_;
} }
/** /**
* Refreshes the source and finally dispatches a 'change' event. * Refreshes the source and finally dispatches a 'change' event.
* @api * @api
*/ */
refresh() { refresh() {
this.changed(); this.changed();
} }
/** /**
* Set the attributions of the source. * Set the attributions of the source.
* @param {module:ol/source/Source~AttributionLike|undefined} attributions Attributions. * @param {module:ol/source/Source~AttributionLike|undefined} attributions Attributions.
* Can be passed as `string`, `Array<string>`, `{@link module:ol/source/Source~Attribution}`, * Can be passed as `string`, `Array<string>`, `{@link module:ol/source/Source~Attribution}`,
* or `undefined`. * or `undefined`.
* @api * @api
*/ */
setAttributions(attributions) { setAttributions(attributions) {
this.attributions_ = this.adaptAttributions_(attributions); this.attributions_ = this.adaptAttributions_(attributions);
this.changed(); this.changed();
} }
/** /**
* Set the state of the source. * Set the state of the source.
* @param {module:ol/source/State} state State. * @param {module:ol/source/State} state State.
* @protected * @protected
*/ */
setState(state) { setState(state) {
this.state_ = state; this.state_ = state;
this.changed(); this.changed();
} }
} }
inherits(Source, BaseObject); inherits(Source, BaseObject);

View File

@@ -18,59 +18,59 @@ import {getKeyZXY} from '../tilecoord.js';
* @param {string} text Text. * @param {string} text Text.
*/ */
class LabeledTile { class LabeledTile {
constructor(tileCoord, tileSize, text) { constructor(tileCoord, tileSize, text) {
Tile.call(this, tileCoord, TileState.LOADED); Tile.call(this, tileCoord, TileState.LOADED);
/** /**
* @private * @private
* @type {module:ol/size~Size} * @type {module:ol/size~Size}
*/ */
this.tileSize_ = tileSize; this.tileSize_ = tileSize;
/** /**
* @private * @private
* @type {string} * @type {string}
*/ */
this.text_ = text; this.text_ = text;
/** /**
* @private * @private
* @type {HTMLCanvasElement} * @type {HTMLCanvasElement}
*/ */
this.canvas_ = null; this.canvas_ = null;
} }
/** /**
* Get the image element for this tile. * Get the image element for this tile.
* @return {HTMLCanvasElement} Image. * @return {HTMLCanvasElement} Image.
*/ */
getImage() { getImage() {
if (this.canvas_) { if (this.canvas_) {
return this.canvas_; return this.canvas_;
} else { } else {
const tileSize = this.tileSize_; const tileSize = this.tileSize_;
const context = createCanvasContext2D(tileSize[0], tileSize[1]); const context = createCanvasContext2D(tileSize[0], tileSize[1]);
context.strokeStyle = 'black'; context.strokeStyle = 'black';
context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5); context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
context.fillStyle = 'black'; context.fillStyle = 'black';
context.textAlign = 'center'; context.textAlign = 'center';
context.textBaseline = 'middle'; context.textBaseline = 'middle';
context.font = '24px sans-serif'; context.font = '24px sans-serif';
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2); context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
this.canvas_ = context.canvas; this.canvas_ = context.canvas;
return context.canvas; return context.canvas;
} }
} }
/** /**
* @override * @override
*/ */
load() {} load() {}
} }
inherits(LabeledTile, Tile); inherits(LabeledTile, Tile);
@@ -98,35 +98,35 @@ inherits(LabeledTile, Tile);
* @api * @api
*/ */
class TileDebug { class TileDebug {
constructor(options) { constructor(options) {
TileSource.call(this, { TileSource.call(this, {
opaque: false, opaque: false,
projection: options.projection, projection: options.projection,
tileGrid: options.tileGrid, tileGrid: options.tileGrid,
wrapX: options.wrapX !== undefined ? options.wrapX : true wrapX: options.wrapX !== undefined ? options.wrapX : true
}); });
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getTile(z, x, y) { getTile(z, x, y) {
const tileCoordKey = getKeyZXY(z, x, y); const tileCoordKey = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) { if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!module:ol/source/TileDebug~LabeledTile} */ (this.tileCache.get(tileCoordKey)); return /** @type {!module:ol/source/TileDebug~LabeledTile} */ (this.tileCache.get(tileCoordKey));
} else { } else {
const tileSize = toSize(this.tileGrid.getTileSize(z)); const tileSize = toSize(this.tileGrid.getTileSize(z));
const tileCoord = [z, x, y]; const tileCoord = [z, x, y];
const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord); const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
const text = !textTileCoord ? '' : const text = !textTileCoord ? '' :
this.getTileCoordForTileUrlFunction(textTileCoord).toString(); this.getTileCoordForTileUrlFunction(textTileCoord).toString();
const tile = new LabeledTile(tileCoord, tileSize, text); const tile = new LabeledTile(tileCoord, tileSize, text);
this.tileCache.set(tileCoordKey, tile); this.tileCache.set(tileCoordKey, tile);
return tile; return tile;
} }
} }
} }
inherits(TileDebug, TileSource); inherits(TileDebug, TileSource);

View File

@@ -30,50 +30,50 @@ import RegularShape from '../style/RegularShape.js';
* @api * @api
*/ */
class CircleStyle { class CircleStyle {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
RegularShape.call(this, { RegularShape.call(this, {
points: Infinity, points: Infinity,
fill: options.fill, fill: options.fill,
radius: options.radius, radius: options.radius,
snapToPixel: options.snapToPixel, snapToPixel: options.snapToPixel,
stroke: options.stroke, stroke: options.stroke,
atlasManager: options.atlasManager atlasManager: options.atlasManager
}); });
} }
/** /**
* Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too. * Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too.
* @return {module:ol/style/Circle} The cloned style. * @return {module:ol/style/Circle} The cloned style.
* @override * @override
* @api * @api
*/ */
clone() { clone() {
const style = new CircleStyle({ const style = new CircleStyle({
fill: this.getFill() ? this.getFill().clone() : undefined, fill: this.getFill() ? this.getFill().clone() : undefined,
stroke: this.getStroke() ? this.getStroke().clone() : undefined, stroke: this.getStroke() ? this.getStroke().clone() : undefined,
radius: this.getRadius(), radius: this.getRadius(),
snapToPixel: this.getSnapToPixel(), snapToPixel: this.getSnapToPixel(),
atlasManager: this.atlasManager_ atlasManager: this.atlasManager_
}); });
style.setOpacity(this.getOpacity()); style.setOpacity(this.getOpacity());
style.setScale(this.getScale()); style.setScale(this.getScale());
return style; return style;
} }
/** /**
* Set the circle radius. * Set the circle radius.
* *
* @param {number} radius Circle radius. * @param {number} radius Circle radius.
* @api * @api
*/ */
setRadius(radius) { setRadius(radius) {
this.radius_ = radius; this.radius_ = radius;
this.render_(this.atlasManager_); this.render_(this.atlasManager_);
} }
} }
inherits(CircleStyle, RegularShape); inherits(CircleStyle, RegularShape);

View File

@@ -8,85 +8,85 @@ import {asString} from '../color.js';
* @constructor * @constructor
*/ */
class IconImageCache { class IconImageCache {
constructor() { constructor() {
/** /**
* @type {!Object.<string, module:ol/style/IconImage>} * @type {!Object.<string, module:ol/style/IconImage>}
* @private * @private
*/ */
this.cache_ = {}; this.cache_ = {};
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
this.cacheSize_ = 0; this.cacheSize_ = 0;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
this.maxCacheSize_ = 32; this.maxCacheSize_ = 32;
} }
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
clear() { clear() {
this.cache_ = {}; this.cache_ = {};
this.cacheSize_ = 0; this.cacheSize_ = 0;
} }
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
expire() { expire() {
if (this.cacheSize_ > this.maxCacheSize_) { if (this.cacheSize_ > this.maxCacheSize_) {
let i = 0; let i = 0;
for (const key in this.cache_) { for (const key in this.cache_) {
const iconImage = this.cache_[key]; const iconImage = this.cache_[key];
if ((i++ & 3) === 0 && !iconImage.hasListener()) { if ((i++ & 3) === 0 && !iconImage.hasListener()) {
delete this.cache_[key]; delete this.cache_[key];
--this.cacheSize_; --this.cacheSize_;
} }
} }
} }
} }
/** /**
* @param {string} src Src. * @param {string} src Src.
* @param {?string} crossOrigin Cross origin. * @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color. * @param {module:ol/color~Color} color Color.
* @return {module:ol/style/IconImage} Icon image. * @return {module:ol/style/IconImage} Icon image.
*/ */
get(src, crossOrigin, color) { get(src, crossOrigin, color) {
const key = getKey(src, crossOrigin, color); const key = getKey(src, crossOrigin, color);
return key in this.cache_ ? this.cache_[key] : null; return key in this.cache_ ? this.cache_[key] : null;
} }
/** /**
* @param {string} src Src. * @param {string} src Src.
* @param {?string} crossOrigin Cross origin. * @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color. * @param {module:ol/color~Color} color Color.
* @param {module:ol/style/IconImage} iconImage Icon image. * @param {module:ol/style/IconImage} iconImage Icon image.
*/ */
set(src, crossOrigin, color, iconImage) { set(src, crossOrigin, color, iconImage) {
const key = getKey(src, crossOrigin, color); const key = getKey(src, crossOrigin, color);
this.cache_[key] = iconImage; this.cache_[key] = iconImage;
++this.cacheSize_; ++this.cacheSize_;
} }
/** /**
* Set the cache size of the icon cache. Default is `32`. Change this value when * Set the cache size of the icon cache. Default is `32`. Change this value when
* your map uses more than 32 different icon images and you are not caching icon * your map uses more than 32 different icon images and you are not caching icon
* styles on the application level. * styles on the application level.
* @param {number} maxCacheSize Cache max size. * @param {number} maxCacheSize Cache max size.
* @api * @api
*/ */
setSize(maxCacheSize) { setSize(maxCacheSize) {
this.maxCacheSize_ = maxCacheSize; this.maxCacheSize_ = maxCacheSize;
this.expire(); this.expire();
} }
} }

View File

@@ -25,212 +25,212 @@
* @api * @api
*/ */
class ImageStyle { class ImageStyle {
constructor(options) { constructor(options) {
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.opacity_ = options.opacity; this.opacity_ = options.opacity;
/** /**
* @private * @private
* @type {boolean} * @type {boolean}
*/ */
this.rotateWithView_ = options.rotateWithView; this.rotateWithView_ = options.rotateWithView;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.rotation_ = options.rotation; this.rotation_ = options.rotation;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.scale_ = options.scale; this.scale_ = options.scale;
/** /**
* @private * @private
* @type {boolean} * @type {boolean}
*/ */
this.snapToPixel_ = options.snapToPixel; this.snapToPixel_ = options.snapToPixel;
} }
/** /**
* Get the symbolizer opacity. * Get the symbolizer opacity.
* @return {number} Opacity. * @return {number} Opacity.
* @api * @api
*/ */
getOpacity() { getOpacity() {
return this.opacity_; return this.opacity_;
} }
/** /**
* Determine whether the symbolizer rotates with the map. * Determine whether the symbolizer rotates with the map.
* @return {boolean} Rotate with map. * @return {boolean} Rotate with map.
* @api * @api
*/ */
getRotateWithView() { getRotateWithView() {
return this.rotateWithView_; return this.rotateWithView_;
} }
/** /**
* Get the symoblizer rotation. * Get the symoblizer rotation.
* @return {number} Rotation. * @return {number} Rotation.
* @api * @api
*/ */
getRotation() { getRotation() {
return this.rotation_; return this.rotation_;
} }
/** /**
* Get the symbolizer scale. * Get the symbolizer scale.
* @return {number} Scale. * @return {number} Scale.
* @api * @api
*/ */
getScale() { getScale() {
return this.scale_; return this.scale_;
} }
/** /**
* Determine whether the symbolizer should be snapped to a pixel. * Determine whether the symbolizer should be snapped to a pixel.
* @return {boolean} The symbolizer should snap to a pixel. * @return {boolean} The symbolizer should snap to a pixel.
* @api * @api
*/ */
getSnapToPixel() { getSnapToPixel() {
return this.snapToPixel_; return this.snapToPixel_;
} }
/** /**
* Get the anchor point in pixels. The anchor determines the center point for the * Get the anchor point in pixels. The anchor determines the center point for the
* symbolizer. * symbolizer.
* @abstract * @abstract
* @return {Array.<number>} Anchor. * @return {Array.<number>} Anchor.
*/ */
getAnchor() {} getAnchor() {}
/** /**
* Get the image element for the symbolizer. * Get the image element for the symbolizer.
* @abstract * @abstract
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element. * @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element.
*/ */
getImage(pixelRatio) {} getImage(pixelRatio) {}
/** /**
* @abstract * @abstract
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element. * @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element.
*/ */
getHitDetectionImage(pixelRatio) {} getHitDetectionImage(pixelRatio) {}
/** /**
* @abstract * @abstract
* @return {module:ol/ImageState} Image state. * @return {module:ol/ImageState} Image state.
*/ */
getImageState() {} getImageState() {}
/** /**
* @abstract * @abstract
* @return {module:ol/size~Size} Image size. * @return {module:ol/size~Size} Image size.
*/ */
getImageSize() {} getImageSize() {}
/** /**
* @abstract * @abstract
* @return {module:ol/size~Size} Size of the hit-detection image. * @return {module:ol/size~Size} Size of the hit-detection image.
*/ */
getHitDetectionImageSize() {} getHitDetectionImageSize() {}
/** /**
* Get the origin of the symbolizer. * Get the origin of the symbolizer.
* @abstract * @abstract
* @return {Array.<number>} Origin. * @return {Array.<number>} Origin.
*/ */
getOrigin() {} getOrigin() {}
/** /**
* Get the size of the symbolizer (in pixels). * Get the size of the symbolizer (in pixels).
* @abstract * @abstract
* @return {module:ol/size~Size} Size. * @return {module:ol/size~Size} Size.
*/ */
getSize() {} getSize() {}
/** /**
* Set the opacity. * Set the opacity.
* *
* @param {number} opacity Opacity. * @param {number} opacity Opacity.
* @api * @api
*/ */
setOpacity(opacity) { setOpacity(opacity) {
this.opacity_ = opacity; this.opacity_ = opacity;
} }
/** /**
* Set whether to rotate the style with the view. * Set whether to rotate the style with the view.
* *
* @param {boolean} rotateWithView Rotate with map. * @param {boolean} rotateWithView Rotate with map.
* @api * @api
*/ */
setRotateWithView(rotateWithView) { setRotateWithView(rotateWithView) {
this.rotateWithView_ = rotateWithView; this.rotateWithView_ = rotateWithView;
} }
/** /**
* Set the rotation. * Set the rotation.
* *
* @param {number} rotation Rotation. * @param {number} rotation Rotation.
* @api * @api
*/ */
setRotation(rotation) { setRotation(rotation) {
this.rotation_ = rotation; this.rotation_ = rotation;
} }
/** /**
* Set the scale. * Set the scale.
* *
* @param {number} scale Scale. * @param {number} scale Scale.
* @api * @api
*/ */
setScale(scale) { setScale(scale) {
this.scale_ = scale; this.scale_ = scale;
} }
/** /**
* Set whether to snap the image to the closest pixel. * Set whether to snap the image to the closest pixel.
* *
* @param {boolean} snapToPixel Snap to pixel? * @param {boolean} snapToPixel Snap to pixel?
* @api * @api
*/ */
setSnapToPixel(snapToPixel) { setSnapToPixel(snapToPixel) {
this.snapToPixel_ = snapToPixel; this.snapToPixel_ = snapToPixel;
} }
/** /**
* @abstract * @abstract
* @param {function(this: T, module:ol/events/Event)} listener Listener function. * @param {function(this: T, module:ol/events/Event)} listener Listener function.
* @param {T} thisArg Value to use as `this` when executing `listener`. * @param {T} thisArg Value to use as `this` when executing `listener`.
* @return {module:ol/events~EventsKey|undefined} Listener key. * @return {module:ol/events~EventsKey|undefined} Listener key.
* @template T * @template T
*/ */
listenImageChange(listener, thisArg) {} listenImageChange(listener, thisArg) {}
/** /**
* Load not yet loaded URI. * Load not yet loaded URI.
* @abstract * @abstract
*/ */
load() {} load() {}
/** /**
* @abstract * @abstract
* @param {function(this: T, module:ol/events/Event)} listener Listener function. * @param {function(this: T, module:ol/events/Event)} listener Listener function.
* @param {T} thisArg Value to use as `this` when executing `listener`. * @param {T} thisArg Value to use as `this` when executing `listener`.
* @template T * @template T
*/ */
unlistenImageChange(listener, thisArg) {} unlistenImageChange(listener, thisArg) {}
} }
export default ImageStyle; export default ImageStyle;

View File

@@ -54,452 +54,452 @@ const DEFAULT_FILL_COLOR = '#333';
* @api * @api
*/ */
class Text { class Text {
constructor(opt_options) { constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
/** /**
* @private * @private
* @type {string|undefined} * @type {string|undefined}
*/ */
this.font_ = options.font; this.font_ = options.font;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.rotation_ = options.rotation; this.rotation_ = options.rotation;
/** /**
* @private * @private
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.rotateWithView_ = options.rotateWithView; this.rotateWithView_ = options.rotateWithView;
/** /**
* @private * @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.scale_ = options.scale; this.scale_ = options.scale;
/** /**
* @private * @private
* @type {string|undefined} * @type {string|undefined}
*/ */
this.text_ = options.text; this.text_ = options.text;
/** /**
* @private * @private
* @type {string|undefined} * @type {string|undefined}
*/ */
this.textAlign_ = options.textAlign; this.textAlign_ = options.textAlign;
/** /**
* @private * @private
* @type {string|undefined} * @type {string|undefined}
*/ */
this.textBaseline_ = options.textBaseline; this.textBaseline_ = options.textBaseline;
/** /**
* @private * @private
* @type {module:ol/style/Fill} * @type {module:ol/style/Fill}
*/ */
this.fill_ = options.fill !== undefined ? options.fill : this.fill_ = options.fill !== undefined ? options.fill :
new Fill({color: DEFAULT_FILL_COLOR}); new Fill({color: DEFAULT_FILL_COLOR});
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.maxAngle_ = options.maxAngle !== undefined ? options.maxAngle : Math.PI / 4; this.maxAngle_ = options.maxAngle !== undefined ? options.maxAngle : Math.PI / 4;
/** /**
* @private * @private
* @type {module:ol/style/TextPlacement|string} * @type {module:ol/style/TextPlacement|string}
*/ */
this.placement_ = options.placement !== undefined ? options.placement : TextPlacement.POINT; this.placement_ = options.placement !== undefined ? options.placement : TextPlacement.POINT;
/** /**
* @private * @private
* @type {boolean} * @type {boolean}
*/ */
this.overflow_ = !!options.overflow; this.overflow_ = !!options.overflow;
/** /**
* @private * @private
* @type {module:ol/style/Stroke} * @type {module:ol/style/Stroke}
*/ */
this.stroke_ = options.stroke !== undefined ? options.stroke : null; this.stroke_ = options.stroke !== undefined ? options.stroke : null;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.offsetX_ = options.offsetX !== undefined ? options.offsetX : 0; this.offsetX_ = options.offsetX !== undefined ? options.offsetX : 0;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.offsetY_ = options.offsetY !== undefined ? options.offsetY : 0; this.offsetY_ = options.offsetY !== undefined ? options.offsetY : 0;
/** /**
* @private * @private
* @type {module:ol/style/Fill} * @type {module:ol/style/Fill}
*/ */
this.backgroundFill_ = options.backgroundFill ? options.backgroundFill : null; this.backgroundFill_ = options.backgroundFill ? options.backgroundFill : null;
/** /**
* @private * @private
* @type {module:ol/style/Stroke} * @type {module:ol/style/Stroke}
*/ */
this.backgroundStroke_ = options.backgroundStroke ? options.backgroundStroke : null; this.backgroundStroke_ = options.backgroundStroke ? options.backgroundStroke : null;
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.padding_ = options.padding === undefined ? null : options.padding; this.padding_ = options.padding === undefined ? null : options.padding;
} }
/** /**
* Clones the style. * Clones the style.
* @return {module:ol/style/Text} The cloned style. * @return {module:ol/style/Text} The cloned style.
* @api * @api
*/ */
clone() { clone() {
return new Text({ return new Text({
font: this.getFont(), font: this.getFont(),
placement: this.getPlacement(), placement: this.getPlacement(),
maxAngle: this.getMaxAngle(), maxAngle: this.getMaxAngle(),
overflow: this.getOverflow(), overflow: this.getOverflow(),
rotation: this.getRotation(), rotation: this.getRotation(),
rotateWithView: this.getRotateWithView(), rotateWithView: this.getRotateWithView(),
scale: this.getScale(), scale: this.getScale(),
text: this.getText(), text: this.getText(),
textAlign: this.getTextAlign(), textAlign: this.getTextAlign(),
textBaseline: this.getTextBaseline(), textBaseline: this.getTextBaseline(),
fill: this.getFill() ? this.getFill().clone() : undefined, fill: this.getFill() ? this.getFill().clone() : undefined,
stroke: this.getStroke() ? this.getStroke().clone() : undefined, stroke: this.getStroke() ? this.getStroke().clone() : undefined,
offsetX: this.getOffsetX(), offsetX: this.getOffsetX(),
offsetY: this.getOffsetY(), offsetY: this.getOffsetY(),
backgroundFill: this.getBackgroundFill() ? this.getBackgroundFill().clone() : undefined, backgroundFill: this.getBackgroundFill() ? this.getBackgroundFill().clone() : undefined,
backgroundStroke: this.getBackgroundStroke() ? this.getBackgroundStroke().clone() : undefined backgroundStroke: this.getBackgroundStroke() ? this.getBackgroundStroke().clone() : undefined
}); });
} }
/** /**
* Get the `overflow` configuration. * Get the `overflow` configuration.
* @return {boolean} Let text overflow the length of the path they follow. * @return {boolean} Let text overflow the length of the path they follow.
* @api * @api
*/ */
getOverflow() { getOverflow() {
return this.overflow_; return this.overflow_;
} }
/** /**
* Get the font name. * Get the font name.
* @return {string|undefined} Font. * @return {string|undefined} Font.
* @api * @api
*/ */
getFont() { getFont() {
return this.font_; return this.font_;
} }
/** /**
* Get the maximum angle between adjacent characters. * Get the maximum angle between adjacent characters.
* @return {number} Angle in radians. * @return {number} Angle in radians.
* @api * @api
*/ */
getMaxAngle() { getMaxAngle() {
return this.maxAngle_; return this.maxAngle_;
} }
/** /**
* Get the label placement. * Get the label placement.
* @return {module:ol/style/TextPlacement|string} Text placement. * @return {module:ol/style/TextPlacement|string} Text placement.
* @api * @api
*/ */
getPlacement() { getPlacement() {
return this.placement_; return this.placement_;
} }
/** /**
* Get the x-offset for the text. * Get the x-offset for the text.
* @return {number} Horizontal text offset. * @return {number} Horizontal text offset.
* @api * @api
*/ */
getOffsetX() { getOffsetX() {
return this.offsetX_; return this.offsetX_;
} }
/** /**
* Get the y-offset for the text. * Get the y-offset for the text.
* @return {number} Vertical text offset. * @return {number} Vertical text offset.
* @api * @api
*/ */
getOffsetY() { getOffsetY() {
return this.offsetY_; return this.offsetY_;
} }
/** /**
* Get the fill style for the text. * Get the fill style for the text.
* @return {module:ol/style/Fill} Fill style. * @return {module:ol/style/Fill} Fill style.
* @api * @api
*/ */
getFill() { getFill() {
return this.fill_; return this.fill_;
} }
/** /**
* Determine whether the text rotates with the map. * Determine whether the text rotates with the map.
* @return {boolean|undefined} Rotate with map. * @return {boolean|undefined} Rotate with map.
* @api * @api
*/ */
getRotateWithView() { getRotateWithView() {
return this.rotateWithView_; return this.rotateWithView_;
} }
/** /**
* Get the text rotation. * Get the text rotation.
* @return {number|undefined} Rotation. * @return {number|undefined} Rotation.
* @api * @api
*/ */
getRotation() { getRotation() {
return this.rotation_; return this.rotation_;
} }
/** /**
* Get the text scale. * Get the text scale.
* @return {number|undefined} Scale. * @return {number|undefined} Scale.
* @api * @api
*/ */
getScale() { getScale() {
return this.scale_; return this.scale_;
} }
/** /**
* Get the stroke style for the text. * Get the stroke style for the text.
* @return {module:ol/style/Stroke} Stroke style. * @return {module:ol/style/Stroke} Stroke style.
* @api * @api
*/ */
getStroke() { getStroke() {
return this.stroke_; return this.stroke_;
} }
/** /**
* Get the text to be rendered. * Get the text to be rendered.
* @return {string|undefined} Text. * @return {string|undefined} Text.
* @api * @api
*/ */
getText() { getText() {
return this.text_; return this.text_;
} }
/** /**
* Get the text alignment. * Get the text alignment.
* @return {string|undefined} Text align. * @return {string|undefined} Text align.
* @api * @api
*/ */
getTextAlign() { getTextAlign() {
return this.textAlign_; return this.textAlign_;
} }
/** /**
* Get the text baseline. * Get the text baseline.
* @return {string|undefined} Text baseline. * @return {string|undefined} Text baseline.
* @api * @api
*/ */
getTextBaseline() { getTextBaseline() {
return this.textBaseline_; return this.textBaseline_;
} }
/** /**
* Get the background fill style for the text. * Get the background fill style for the text.
* @return {module:ol/style/Fill} Fill style. * @return {module:ol/style/Fill} Fill style.
* @api * @api
*/ */
getBackgroundFill() { getBackgroundFill() {
return this.backgroundFill_; return this.backgroundFill_;
} }
/** /**
* Get the background stroke style for the text. * Get the background stroke style for the text.
* @return {module:ol/style/Stroke} Stroke style. * @return {module:ol/style/Stroke} Stroke style.
* @api * @api
*/ */
getBackgroundStroke() { getBackgroundStroke() {
return this.backgroundStroke_; return this.backgroundStroke_;
} }
/** /**
* Get the padding for the text. * Get the padding for the text.
* @return {Array.<number>} Padding. * @return {Array.<number>} Padding.
* @api * @api
*/ */
getPadding() { getPadding() {
return this.padding_; return this.padding_;
} }
/** /**
* Set the `overflow` property. * Set the `overflow` property.
* *
* @param {boolean} overflow Let text overflow the path that it follows. * @param {boolean} overflow Let text overflow the path that it follows.
* @api * @api
*/ */
setOverflow(overflow) { setOverflow(overflow) {
this.overflow_ = overflow; this.overflow_ = overflow;
} }
/** /**
* Set the font. * Set the font.
* *
* @param {string|undefined} font Font. * @param {string|undefined} font Font.
* @api * @api
*/ */
setFont(font) { setFont(font) {
this.font_ = font; this.font_ = font;
} }
/** /**
* Set the maximum angle between adjacent characters. * Set the maximum angle between adjacent characters.
* *
* @param {number} maxAngle Angle in radians. * @param {number} maxAngle Angle in radians.
* @api * @api
*/ */
setMaxAngle(maxAngle) { setMaxAngle(maxAngle) {
this.maxAngle_ = maxAngle; this.maxAngle_ = maxAngle;
} }
/** /**
* Set the x offset. * Set the x offset.
* *
* @param {number} offsetX Horizontal text offset. * @param {number} offsetX Horizontal text offset.
* @api * @api
*/ */
setOffsetX(offsetX) { setOffsetX(offsetX) {
this.offsetX_ = offsetX; this.offsetX_ = offsetX;
} }
/** /**
* Set the y offset. * Set the y offset.
* *
* @param {number} offsetY Vertical text offset. * @param {number} offsetY Vertical text offset.
* @api * @api
*/ */
setOffsetY(offsetY) { setOffsetY(offsetY) {
this.offsetY_ = offsetY; this.offsetY_ = offsetY;
} }
/** /**
* Set the text placement. * Set the text placement.
* *
* @param {module:ol/style/TextPlacement|string} placement Placement. * @param {module:ol/style/TextPlacement|string} placement Placement.
* @api * @api
*/ */
setPlacement(placement) { setPlacement(placement) {
this.placement_ = placement; this.placement_ = placement;
} }
/** /**
* Set the fill. * Set the fill.
* *
* @param {module:ol/style/Fill} fill Fill style. * @param {module:ol/style/Fill} fill Fill style.
* @api * @api
*/ */
setFill(fill) { setFill(fill) {
this.fill_ = fill; this.fill_ = fill;
} }
/** /**
* Set the rotation. * Set the rotation.
* *
* @param {number|undefined} rotation Rotation. * @param {number|undefined} rotation Rotation.
* @api * @api
*/ */
setRotation(rotation) { setRotation(rotation) {
this.rotation_ = rotation; this.rotation_ = rotation;
} }
/** /**
* Set the scale. * Set the scale.
* *
* @param {number|undefined} scale Scale. * @param {number|undefined} scale Scale.
* @api * @api
*/ */
setScale(scale) { setScale(scale) {
this.scale_ = scale; this.scale_ = scale;
} }
/** /**
* Set the stroke. * Set the stroke.
* *
* @param {module:ol/style/Stroke} stroke Stroke style. * @param {module:ol/style/Stroke} stroke Stroke style.
* @api * @api
*/ */
setStroke(stroke) { setStroke(stroke) {
this.stroke_ = stroke; this.stroke_ = stroke;
} }
/** /**
* Set the text. * Set the text.
* *
* @param {string|undefined} text Text. * @param {string|undefined} text Text.
* @api * @api
*/ */
setText(text) { setText(text) {
this.text_ = text; this.text_ = text;
} }
/** /**
* Set the text alignment. * Set the text alignment.
* *
* @param {string|undefined} textAlign Text align. * @param {string|undefined} textAlign Text align.
* @api * @api
*/ */
setTextAlign(textAlign) { setTextAlign(textAlign) {
this.textAlign_ = textAlign; this.textAlign_ = textAlign;
} }
/** /**
* Set the text baseline. * Set the text baseline.
* *
* @param {string|undefined} textBaseline Text baseline. * @param {string|undefined} textBaseline Text baseline.
* @api * @api
*/ */
setTextBaseline(textBaseline) { setTextBaseline(textBaseline) {
this.textBaseline_ = textBaseline; this.textBaseline_ = textBaseline;
} }
/** /**
* Set the background fill. * Set the background fill.
* *
* @param {module:ol/style/Fill} fill Fill style. * @param {module:ol/style/Fill} fill Fill style.
* @api * @api
*/ */
setBackgroundFill(fill) { setBackgroundFill(fill) {
this.backgroundFill_ = fill; this.backgroundFill_ = fill;
} }
/** /**
* Set the background stroke. * Set the background stroke.
* *
* @param {module:ol/style/Stroke} stroke Stroke style. * @param {module:ol/style/Stroke} stroke Stroke style.
* @api * @api
*/ */
setBackgroundStroke(stroke) { setBackgroundStroke(stroke) {
this.backgroundStroke_ = stroke; this.backgroundStroke_ = stroke;
} }
/** /**
* Set the padding (`[top, right, bottom, left]`). * Set the padding (`[top, right, bottom, left]`).
* *
* @param {!Array.<number>} padding Padding. * @param {!Array.<number>} padding Padding.
* @api * @api
*/ */
setPadding(padding) { setPadding(padding) {
this.padding_ = padding; this.padding_ = padding;
} }
} }
export default Text; export default Text;

View File

@@ -11,6 +11,13 @@ import {toSize} from '../size.js';
import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js'; import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js';
/**
* @private
* @type {module:ol/tilecoord~TileCoord}
*/
const tmpTileCoord = [0, 0, 0];
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {module:ol/extent~Extent} [extent] Extent for the tile grid. No tiles outside this * @property {module:ol/extent~Extent} [extent] Extent for the tile grid. No tiles outside this
@@ -544,11 +551,4 @@ class TileGrid {
} }
/**
* @private
* @type {module:ol/tilecoord~TileCoord}
*/
const tmpTileCoord = [0, 0, 0];
export default TileGrid; export default TileGrid;

View File

@@ -19,35 +19,35 @@ const BufferUsage = {
* @struct * @struct
*/ */
class WebGLBuffer { class WebGLBuffer {
constructor(opt_arr, opt_usage) { constructor(opt_arr, opt_usage) {
/** /**
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
this.arr_ = opt_arr !== undefined ? opt_arr : []; this.arr_ = opt_arr !== undefined ? opt_arr : [];
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.usage_ = opt_usage !== undefined ? opt_usage : BufferUsage.STATIC_DRAW; this.usage_ = opt_usage !== undefined ? opt_usage : BufferUsage.STATIC_DRAW;
} }
/** /**
* @return {Array.<number>} Array. * @return {Array.<number>} Array.
*/ */
getArray() { getArray() {
return this.arr_; return this.arr_;
} }
/** /**
* @return {number} Usage. * @return {number} Usage.
*/ */
getUsage() { getUsage() {
return this.usage_; return this.usage_;
} }
} }
export default WebGLBuffer; export default WebGLBuffer;

View File

@@ -12,16 +12,16 @@ import WebGLShader from '../webgl/Shader.js';
* @struct * @struct
*/ */
class WebGLFragment { class WebGLFragment {
constructor(source) { constructor(source) {
WebGLShader.call(this, source); WebGLShader.call(this, source);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getType() { getType() {
return FRAGMENT_SHADER; return FRAGMENT_SHADER;
} }
} }
inherits(WebGLFragment, WebGLShader); inherits(WebGLFragment, WebGLShader);

View File

@@ -10,28 +10,28 @@ import {FALSE} from '../functions.js';
* @struct * @struct
*/ */
class WebGLShader { class WebGLShader {
constructor(source) { constructor(source) {
/** /**
* @private * @private
* @type {string} * @type {string}
*/ */
this.source_ = source; this.source_ = source;
} }
/** /**
* @abstract * @abstract
* @return {number} Type. * @return {number} Type.
*/ */
getType() {} getType() {}
/** /**
* @return {string} Source. * @return {string} Source.
*/ */
getSource() { getSource() {
return this.source_; return this.source_;
} }
} }

View File

@@ -12,16 +12,16 @@ import WebGLShader from '../webgl/Shader.js';
* @struct * @struct
*/ */
class WebGLVertex { class WebGLVertex {
constructor(source) { constructor(source) {
WebGLShader.call(this, source); WebGLShader.call(this, source);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
getType() { getType() {
return VERTEX_SHADER; return VERTEX_SHADER;
} }
} }
inherits(WebGLVertex, WebGLShader); inherits(WebGLVertex, WebGLShader);