Manual class transform

This commit is contained in:
Tim Schaub
2018-07-16 17:09:50 -06:00
parent 7b4a73f3b9
commit f78d0d4cfa
96 changed files with 8112 additions and 7964 deletions
+5 -2
View File
@@ -11,8 +11,9 @@ import {VERSION, inherits} from './util.js';
* @extends {Error} * @extends {Error}
* @param {number} code Error code. * @param {number} code Error code.
*/ */
const AssertionError = function(code) { class AssertionError {
constructor(code) {
const path = VERSION.split('-')[0]; const path = VERSION.split('-')[0];
/** /**
@@ -33,7 +34,9 @@ const AssertionError = function(code) {
this.name = 'AssertionError'; this.name = 'AssertionError';
}; }
}
inherits(AssertionError, Error); inherits(AssertionError, Error);
+5 -2
View File
@@ -27,8 +27,9 @@ const Property = {
* @param {module:ol/CollectionEventType} type Type. * @param {module:ol/CollectionEventType} type Type.
* @param {*=} opt_element Element. * @param {*=} opt_element Element.
*/ */
export const CollectionEvent = function(type, opt_element) { export class CollectionEvent {
constructor(type, opt_element) {
Event.call(this, type); Event.call(this, type);
/** /**
@@ -38,7 +39,9 @@ export const CollectionEvent = function(type, opt_element) {
*/ */
this.element = opt_element; this.element = opt_element;
}; }
}
inherits(CollectionEvent, Event); inherits(CollectionEvent, Event);
+7 -3
View File
@@ -14,8 +14,9 @@ import MapBrowserEvent from './MapBrowserEvent.js';
* @param {boolean=} opt_dragging Is the map currently being dragged? * @param {boolean=} opt_dragging Is the map currently being dragged?
* @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state. * @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state.
*/ */
const MapBrowserPointerEvent = function(type, map, pointerEvent, opt_dragging, class MapBrowserPointerEvent {
opt_frameState) {
constructor(type, map, pointerEvent, opt_dragging, opt_frameState) {
MapBrowserEvent.call(this, type, map, pointerEvent.originalEvent, opt_dragging, MapBrowserEvent.call(this, type, map, pointerEvent.originalEvent, opt_dragging,
opt_frameState); opt_frameState);
@@ -26,7 +27,10 @@ const MapBrowserPointerEvent = function(type, map, pointerEvent, opt_dragging,
*/ */
this.pointerEvent = pointerEvent; this.pointerEvent = pointerEvent;
}; }
}
inherits(MapBrowserPointerEvent, MapBrowserEvent); inherits(MapBrowserPointerEvent, MapBrowserEvent);
export default MapBrowserPointerEvent; export default MapBrowserPointerEvent;
+7 -2
View File
@@ -15,7 +15,9 @@ import Event from './events/Event.js';
* @param {module:ol/PluggableMap} map Map. * @param {module:ol/PluggableMap} map Map.
* @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state. * @param {?module:ol/PluggableMap~FrameState=} opt_frameState Frame state.
*/ */
const MapEvent = function(type, map, opt_frameState) { class MapEvent {
constructor(type, map, opt_frameState) {
Event.call(this, type); Event.call(this, type);
@@ -33,7 +35,10 @@ const MapEvent = function(type, map, opt_frameState) {
*/ */
this.frameState = opt_frameState !== undefined ? opt_frameState : null; this.frameState = opt_frameState !== undefined ? opt_frameState : null;
}; }
}
inherits(MapEvent, Event); inherits(MapEvent, Event);
export default MapEvent; export default MapEvent;
+7 -2
View File
@@ -19,7 +19,9 @@ import {assign} from './obj.js';
* @extends {module:ol/events/Event} * @extends {module:ol/events/Event}
* @constructor * @constructor
*/ */
const ObjectEvent = function(type, key, oldValue) { class ObjectEvent {
constructor(type, key, oldValue) {
Event.call(this, type); Event.call(this, type);
/** /**
@@ -37,7 +39,10 @@ const ObjectEvent = function(type, key, oldValue) {
*/ */
this.oldValue = oldValue; this.oldValue = oldValue;
}; }
}
inherits(ObjectEvent, Event); inherits(ObjectEvent, Event);
+40 -39
View File
@@ -51,7 +51,8 @@ import EventType from './events/EventType.js';
* @param {module:ol/TileState} state State. * @param {module:ol/TileState} state State.
* @param {module:ol/Tile~Options=} opt_options Tile options. * @param {module:ol/Tile~Options=} opt_options Tile options.
*/ */
const Tile = function(tileCoord, state, opt_options) { class Tile {
constructor(tileCoord, state, opt_options) {
EventTarget.call(this); EventTarget.call(this);
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -96,33 +97,29 @@ const Tile = function(tileCoord, state, opt_options) {
*/ */
this.transitionStarts_ = {}; this.transitionStarts_ = {};
}; }
inherits(Tile, EventTarget); /**
/**
* @protected * @protected
*/ */
Tile.prototype.changed = function() { changed() {
this.dispatchEvent(EventType.CHANGE); this.dispatchEvent(EventType.CHANGE);
}; }
/**
/**
* @return {string} Key. * @return {string} Key.
*/ */
Tile.prototype.getKey = function() { getKey() {
return this.key + '/' + this.tileCoord; return this.key + '/' + this.tileCoord;
}; }
/** /**
* Get the interim tile most suitable for rendering using the chain of interim * Get the interim tile most suitable for rendering using the chain of interim
* tiles. This corresponds to the most recent tile that has been loaded, if no * tiles. This corresponds to the most recent tile that has been loaded, if no
* such tile exists, the original tile is returned. * such tile exists, the original tile is returned.
* @return {!module:ol/Tile} Best tile for rendering. * @return {!module:ol/Tile} Best tile for rendering.
*/ */
Tile.prototype.getInterimTile = function() { getInterimTile() {
if (!this.interimTile) { if (!this.interimTile) {
//empty chain //empty chain
return this; return this;
@@ -142,13 +139,13 @@ Tile.prototype.getInterimTile = function() {
// we can not find a better tile // we can not find a better tile
return this; return this;
}; }
/** /**
* Goes through the chain of interim tiles and discards sections of the chain * Goes through the chain of interim tiles and discards sections of the chain
* that are no longer relevant. * that are no longer relevant.
*/ */
Tile.prototype.refreshInterimChain = function() { refreshInterimChain() {
if (!this.interimTile) { if (!this.interimTile) {
return; return;
} }
@@ -176,49 +173,48 @@ Tile.prototype.refreshInterimChain = function() {
} }
tile = prev.interimTile; tile = prev.interimTile;
} while (tile); } while (tile);
}; }
/** /**
* Get the tile coordinate for this tile. * Get the tile coordinate for this tile.
* @return {module:ol/tilecoord~TileCoord} The tile coordinate. * @return {module:ol/tilecoord~TileCoord} The tile coordinate.
* @api * @api
*/ */
Tile.prototype.getTileCoord = function() { getTileCoord() {
return this.tileCoord; return this.tileCoord;
}; }
/**
/**
* @return {module:ol/TileState} State. * @return {module:ol/TileState} State.
*/ */
Tile.prototype.getState = function() { getState() {
return this.state; return this.state;
}; }
/** /**
* @param {module:ol/TileState} state State. * @param {module:ol/TileState} state State.
*/ */
Tile.prototype.setState = function(state) { setState(state) {
this.state = state; this.state = state;
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.
* @abstract * @abstract
* @api * @api
*/ */
Tile.prototype.load = function() {}; load() {}
/** /**
* Get the alpha value for rendering. * Get the alpha value for rendering.
* @param {number} id An id for the renderer. * @param {number} id An id for the renderer.
* @param {number} time The render frame time. * @param {number} time The render frame time.
* @return {number} A number between 0 and 1. * @return {number} A number between 0 and 1.
*/ */
Tile.prototype.getAlpha = function(id, time) { getAlpha(id, time) {
if (!this.transition_) { if (!this.transition_) {
return 1; return 1;
} }
@@ -236,29 +232,34 @@ Tile.prototype.getAlpha = function(id, time) {
return 1; return 1;
} }
return easeIn(delta / this.transition_); return easeIn(delta / this.transition_);
}; }
/** /**
* Determine if a tile is in an alpha transition. A tile is considered in * Determine if a tile is in an alpha transition. A tile is considered in
* transition if tile.getAlpha() has not yet been called or has been called * transition if tile.getAlpha() has not yet been called or has been called
* and returned 1. * and returned 1.
* @param {number} id An id for the renderer. * @param {number} id An id for the renderer.
* @return {boolean} The tile is in transition. * @return {boolean} The tile is in transition.
*/ */
Tile.prototype.inTransition = function(id) { inTransition(id) {
if (!this.transition_) { if (!this.transition_) {
return false; return false;
} }
return this.transitionStarts_[id] !== -1; return this.transitionStarts_[id] !== -1;
}; }
/** /**
* Mark a transition as complete. * Mark a transition as complete.
* @param {number} id An id for the renderer. * @param {number} id An id for the renderer.
*/ */
Tile.prototype.endTransition = function(id) { endTransition(id) {
if (this.transition_) { if (this.transition_) {
this.transitionStarts_[id] = -1; this.transitionStarts_[id] = -1;
} }
}; }
}
inherits(Tile, EventTarget);
export default Tile; export default Tile;
+14 -12
View File
@@ -11,19 +11,17 @@ import {fromKey, getKey} from './tilecoord.js';
* @param {number=} opt_highWaterMark High water mark. * @param {number=} opt_highWaterMark High water mark.
* @struct * @struct
*/ */
const TileCache = function(opt_highWaterMark) { class TileCache {
constructor(opt_highWaterMark) {
LRUCache.call(this, opt_highWaterMark); LRUCache.call(this, opt_highWaterMark);
}; }
inherits(TileCache, LRUCache); /**
/**
* @param {!Object.<string, module:ol/TileRange>} usedTiles Used tiles. * @param {!Object.<string, module:ol/TileRange>} usedTiles Used tiles.
*/ */
TileCache.prototype.expireCache = function(usedTiles) { expireCache(usedTiles) {
while (this.canExpireCache()) { while (this.canExpireCache()) {
const tile = this.peekLast(); const tile = this.peekLast();
const zKey = tile.tileCoord[0].toString(); const zKey = tile.tileCoord[0].toString();
@@ -33,13 +31,12 @@ TileCache.prototype.expireCache = function(usedTiles) {
this.pop().dispose(); this.pop().dispose();
} }
} }
}; }
/**
/**
* Prune all tiles from the cache that don't have the same z as the newest tile. * Prune all tiles from the cache that don't have the same z as the newest tile.
*/ */
TileCache.prototype.pruneExceptNewestZ = function() { pruneExceptNewestZ() {
if (this.getCount() === 0) { if (this.getCount() === 0) {
return; return;
} }
@@ -52,5 +49,10 @@ TileCache.prototype.pruneExceptNewestZ = function() {
tile.dispose(); tile.dispose();
} }
}, this); }, this);
}; }
}
inherits(TileCache, LRUCache);
export default TileCache; export default TileCache;
+20 -20
View File
@@ -22,7 +22,8 @@ import PriorityQueue from './structs/PriorityQueue.js';
* Function called on each tile change event. * Function called on each tile change event.
* @struct * @struct
*/ */
const TileQueue = function(tilePriorityFunction, tileChangeCallback) { class TileQueue {
constructor(tilePriorityFunction, tileChangeCallback) {
PriorityQueue.call( PriorityQueue.call(
this, this,
@@ -59,37 +60,32 @@ const TileQueue = function(tilePriorityFunction, tileChangeCallback) {
*/ */
this.tilesLoadingKeys_ = {}; this.tilesLoadingKeys_ = {};
}; }
inherits(TileQueue, PriorityQueue); /**
/**
* @inheritDoc * @inheritDoc
*/ */
TileQueue.prototype.enqueue = function(element) { enqueue(element) {
const added = PriorityQueue.prototype.enqueue.call(this, element); const added = PriorityQueue.prototype.enqueue.call(this, element);
if (added) { if (added) {
const tile = element[0]; const tile = element[0];
listen(tile, EventType.CHANGE, this.handleTileChange, this); listen(tile, EventType.CHANGE, this.handleTileChange, this);
} }
return added; return added;
}; }
/**
/**
* @return {number} Number of tiles loading. * @return {number} Number of tiles loading.
*/ */
TileQueue.prototype.getTilesLoading = function() { getTilesLoading() {
return this.tilesLoading_; return this.tilesLoading_;
}; }
/**
/**
* @param {module:ol/events/Event} event Event. * @param {module:ol/events/Event} event Event.
* @protected * @protected
*/ */
TileQueue.prototype.handleTileChange = function(event) { handleTileChange(event) {
const tile = /** @type {module:ol/Tile} */ (event.target); const tile = /** @type {module:ol/Tile} */ (event.target);
const state = tile.getState(); const state = tile.getState();
if (state === TileState.LOADED || state === TileState.ERROR || if (state === TileState.LOADED || state === TileState.ERROR ||
@@ -102,14 +98,13 @@ TileQueue.prototype.handleTileChange = function(event) {
} }
this.tileChangeCallback_(); this.tileChangeCallback_();
} }
}; }
/**
/**
* @param {number} maxTotalLoading Maximum number tiles to load simultaneously. * @param {number} maxTotalLoading Maximum number tiles to load simultaneously.
* @param {number} maxNewLoads Maximum number of new tiles to load. * @param {number} maxNewLoads Maximum number of new tiles to load.
*/ */
TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { loadMoreTiles(maxTotalLoading, maxNewLoads) {
let newLoads = 0; let newLoads = 0;
let abortedTiles = false; let abortedTiles = false;
let state, tile, tileKey; let state, tile, tileKey;
@@ -132,5 +127,10 @@ TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) {
// a small, saturated tile cache. // a small, saturated tile cache.
this.tileChangeCallback_(); this.tileChangeCallback_();
} }
}; }
}
inherits(TileQueue, PriorityQueue);
export default TileQueue; export default TileQueue;
+89 -94
View File
@@ -12,7 +12,8 @@
* @param {number} maxY Maximum Y. * @param {number} maxY Maximum Y.
* @struct * @struct
*/ */
const TileRange = function(minX, maxX, minY, maxY) { class TileRange {
constructor(minX, maxX, minY, maxY) {
/** /**
* @type {number} * @type {number}
@@ -34,7 +35,93 @@ const TileRange = function(minX, maxX, minY, maxY) {
*/ */
this.maxY = maxY; this.maxY = maxY;
}; }
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @return {boolean} Contains tile coordinate.
*/
contains(tileCoord) {
return this.containsXY(tileCoord[1], tileCoord[2]);
}
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Contains.
*/
containsTileRange(tileRange) {
return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
}
/**
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @return {boolean} Contains coordinate.
*/
containsXY(x, y) {
return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY;
}
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Equals.
*/
equals(tileRange) {
return this.minX == tileRange.minX && this.minY == tileRange.minY &&
this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
}
/**
* @param {module:ol/TileRange} tileRange Tile range.
*/
extend(tileRange) {
if (tileRange.minX < this.minX) {
this.minX = tileRange.minX;
}
if (tileRange.maxX > this.maxX) {
this.maxX = tileRange.maxX;
}
if (tileRange.minY < this.minY) {
this.minY = tileRange.minY;
}
if (tileRange.maxY > this.maxY) {
this.maxY = tileRange.maxY;
}
}
/**
* @return {number} Height.
*/
getHeight() {
return this.maxY - this.minY + 1;
}
/**
* @return {module:ol/size~Size} Size.
*/
getSize() {
return [this.getWidth(), this.getHeight()];
}
/**
* @return {number} Width.
*/
getWidth() {
return this.maxX - this.minX + 1;
}
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Intersects.
*/
intersects(tileRange) {
return this.minX <= tileRange.maxX &&
this.maxX >= tileRange.minX &&
this.minY <= tileRange.maxY &&
this.maxY >= tileRange.minY;
}
}
/** /**
@@ -58,96 +145,4 @@ export function createOrUpdate(minX, maxX, minY, maxY, tileRange) {
} }
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @return {boolean} Contains tile coordinate.
*/
TileRange.prototype.contains = function(tileCoord) {
return this.containsXY(tileCoord[1], tileCoord[2]);
};
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Contains.
*/
TileRange.prototype.containsTileRange = function(tileRange) {
return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
};
/**
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @return {boolean} Contains coordinate.
*/
TileRange.prototype.containsXY = function(x, y) {
return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY;
};
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Equals.
*/
TileRange.prototype.equals = function(tileRange) {
return this.minX == tileRange.minX && this.minY == tileRange.minY &&
this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
};
/**
* @param {module:ol/TileRange} tileRange Tile range.
*/
TileRange.prototype.extend = function(tileRange) {
if (tileRange.minX < this.minX) {
this.minX = tileRange.minX;
}
if (tileRange.maxX > this.maxX) {
this.maxX = tileRange.maxX;
}
if (tileRange.minY < this.minY) {
this.minY = tileRange.minY;
}
if (tileRange.maxY > this.maxY) {
this.maxY = tileRange.maxY;
}
};
/**
* @return {number} Height.
*/
TileRange.prototype.getHeight = function() {
return this.maxY - this.minY + 1;
};
/**
* @return {module:ol/size~Size} Size.
*/
TileRange.prototype.getSize = function() {
return [this.getWidth(), this.getHeight()];
};
/**
* @return {number} Width.
*/
TileRange.prototype.getWidth = function() {
return this.maxX - this.minX + 1;
};
/**
* @param {module:ol/TileRange} tileRange Tile range.
* @return {boolean} Intersects.
*/
TileRange.prototype.intersects = function(tileRange) {
return this.minX <= tileRange.maxX &&
this.maxX >= tileRange.minX &&
this.minY <= tileRange.maxY &&
this.maxY >= tileRange.minY;
};
export default TileRange; export default TileRange;
+47 -38
View File
@@ -43,9 +43,24 @@ import {UNDEFINED} from './functions.js';
* Function to call when a source tile's state changes. * Function to call when a source tile's state changes.
* @param {number} zoom Integer zoom to render the tile for. * @param {number} zoom Integer zoom to render the tile for.
*/ */
const VectorImageTile = function(tileCoord, state, sourceRevision, format, class VectorImageTile {
tileLoadFunction, urlTileCoord, tileUrlFunction, sourceTileGrid, tileGrid, constructor(
sourceTiles, pixelRatio, projection, tileClass, handleTileChange, zoom) { tileCoord,
state,
sourceRevision,
format,
tileLoadFunction,
urlTileCoord,
tileUrlFunction,
sourceTileGrid,
tileGrid,
sourceTiles,
pixelRatio,
projection,
tileClass,
handleTileChange,
zoom
) {
Tile.call(this, tileCoord, state, {transition: 0}); Tile.call(this, tileCoord, state, {transition: 0});
@@ -157,15 +172,12 @@ const VectorImageTile = function(tileCoord, state, sourceRevision, format,
} }
} }
}; }
inherits(VectorImageTile, Tile); /**
/**
* @inheritDoc * @inheritDoc
*/ */
VectorImageTile.prototype.disposeInternal = function() { disposeInternal() {
this.state = TileState.ABORT; this.state = TileState.ABORT;
this.changed(); this.changed();
if (this.interimTile) { if (this.interimTile) {
@@ -188,38 +200,35 @@ VectorImageTile.prototype.disposeInternal = function() {
this.sourceTileListenerKeys_.forEach(unlistenByKey); this.sourceTileListenerKeys_.forEach(unlistenByKey);
this.sourceTileListenerKeys_.length = 0; this.sourceTileListenerKeys_.length = 0;
Tile.prototype.disposeInternal.call(this); Tile.prototype.disposeInternal.call(this);
}; }
/**
/**
* @param {module:ol/layer/Layer} layer Layer. * @param {module:ol/layer/Layer} layer Layer.
* @return {CanvasRenderingContext2D} The rendering context. * @return {CanvasRenderingContext2D} The rendering context.
*/ */
VectorImageTile.prototype.getContext = function(layer) { getContext(layer) {
const key = getUid(layer).toString(); const key = getUid(layer).toString();
if (!(key in this.context_)) { if (!(key in this.context_)) {
this.context_[key] = createCanvasContext2D(); this.context_[key] = createCanvasContext2D();
} }
return this.context_[key]; return this.context_[key];
}; }
/**
/**
* Get the Canvas for this tile. * Get the Canvas for this tile.
* @param {module:ol/layer/Layer} layer Layer. * @param {module:ol/layer/Layer} layer Layer.
* @return {HTMLCanvasElement} Canvas. * @return {HTMLCanvasElement} Canvas.
*/ */
VectorImageTile.prototype.getImage = function(layer) { getImage(layer) {
return this.getReplayState(layer).renderedTileRevision == -1 ? return this.getReplayState(layer).renderedTileRevision == -1 ?
null : this.getContext(layer).canvas; null : this.getContext(layer).canvas;
}; }
/**
/**
* @param {module:ol/layer/Layer} layer Layer. * @param {module:ol/layer/Layer} layer Layer.
* @return {module:ol/VectorImageTile~ReplayState} The replay state. * @return {module:ol/VectorImageTile~ReplayState} The replay state.
*/ */
VectorImageTile.prototype.getReplayState = function(layer) { getReplayState(layer) {
const key = getUid(layer).toString(); const key = getUid(layer).toString();
if (!(key in this.replayState_)) { if (!(key in this.replayState_)) {
this.replayState_[key] = { this.replayState_[key] = {
@@ -230,30 +239,27 @@ VectorImageTile.prototype.getReplayState = function(layer) {
}; };
} }
return this.replayState_[key]; return this.replayState_[key];
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
VectorImageTile.prototype.getKey = function() { getKey() {
return this.tileKeys.join('/') + '-' + this.sourceRevision_; return this.tileKeys.join('/') + '-' + this.sourceRevision_;
}; }
/**
/**
* @param {string} tileKey Key (tileCoord) of the source tile. * @param {string} tileKey Key (tileCoord) of the source tile.
* @return {module:ol/VectorTile} Source tile. * @return {module:ol/VectorTile} Source tile.
*/ */
VectorImageTile.prototype.getTile = function(tileKey) { getTile(tileKey) {
return this.sourceTiles_[tileKey]; return this.sourceTiles_[tileKey];
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
VectorImageTile.prototype.load = function() { load() {
// Source tiles with LOADED state - we just count them because once they are // Source tiles with LOADED state - we just count them because once they are
// loaded, we're no longer listening to state changes. // loaded, we're no longer listening to state changes.
let leftToLoad = 0; let leftToLoad = 0;
@@ -296,13 +302,12 @@ VectorImageTile.prototype.load = function() {
if (leftToLoad - Object.keys(errorSourceTiles).length == 0) { if (leftToLoad - Object.keys(errorSourceTiles).length == 0) {
setTimeout(this.finishLoading_.bind(this), 0); setTimeout(this.finishLoading_.bind(this), 0);
} }
}; }
/**
/**
* @private * @private
*/ */
VectorImageTile.prototype.finishLoading_ = function() { finishLoading_() {
let loaded = this.tileKeys.length; let loaded = this.tileKeys.length;
let empty = 0; let empty = 0;
for (let i = loaded - 1; i >= 0; --i) { for (let i = loaded - 1; i >= 0; --i) {
@@ -321,7 +326,11 @@ VectorImageTile.prototype.finishLoading_ = function() {
} else { } else {
this.setState(empty == this.tileKeys.length ? TileState.EMPTY : TileState.ERROR); this.setState(empty == this.tileKeys.length ? TileState.EMPTY : TileState.ERROR);
} }
}; }
}
inherits(VectorImageTile, Tile);
export default VectorImageTile; export default VectorImageTile;
+58 -70
View File
@@ -21,7 +21,8 @@ import TileState from './TileState.js';
* @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function. * @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function.
* @param {module:ol/Tile~Options=} opt_options Tile options. * @param {module:ol/Tile~Options=} opt_options Tile options.
*/ */
const VectorTile = function(tileCoord, state, src, format, tileLoadFunction, opt_options) { class VectorTile {
constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) {
Tile.call(this, tileCoord, state, opt_options); Tile.call(this, tileCoord, state, opt_options);
@@ -79,123 +80,104 @@ const VectorTile = function(tileCoord, state, src, format, tileLoadFunction, opt
*/ */
this.url_ = src; this.url_ = src;
}; }
inherits(VectorTile, Tile); /**
/**
* @const
* @type {module:ol/extent~Extent}
*/
const DEFAULT_EXTENT = [0, 0, 4096, 4096];
/**
* @inheritDoc * @inheritDoc
*/ */
VectorTile.prototype.disposeInternal = function() { 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
*/ */
VectorTile.prototype.getExtent = function() { 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
*/ */
VectorTile.prototype.getFormat = function() { 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
*/ */
VectorTile.prototype.getFeatures = function() { getFeatures() {
return this.features_; return this.features_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
VectorTile.prototype.getKey = function() { 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
*/ */
VectorTile.prototype.getProjection = function() { 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.
*/ */
VectorTile.prototype.getReplayGroup = function(layer, key) { getReplayGroup(layer, key) {
return this.replayGroups_[getUid(layer) + ',' + key]; return this.replayGroups_[getUid(layer) + ',' + key];
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
VectorTile.prototype.load = function() { 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.
*/ */
VectorTile.prototype.onLoad = function(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.
*/ */
VectorTile.prototype.onError = function() { 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
@@ -207,52 +189,58 @@ VectorTile.prototype.onError = function() {
* @param {module:ol/extent~Extent} extent The extent. * @param {module:ol/extent~Extent} extent The extent.
* @api * @api
*/ */
VectorTile.prototype.setExtent = function(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
*/ */
VectorTile.prototype.setFeatures = function(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
*/ */
VectorTile.prototype.setProjection = function(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.
*/ */
VectorTile.prototype.setReplayGroup = function(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
*/ */
VectorTile.prototype.setLoader = function(loader) { setLoader(loader) {
this.loader_ = loader; this.loader_ = loader;
}; }
}
inherits(VectorTile, Tile);
/**
* @const
* @type {module:ol/extent~Extent}
*/
const DEFAULT_EXTENT = [0, 0, 4096, 4096];
export default VectorTile; export default VectorTile;
+135 -173
View File
@@ -229,7 +229,8 @@ const DEFAULT_MIN_ZOOM = 0;
* @param {module:ol/View~ViewOptions=} opt_options View options. * @param {module:ol/View~ViewOptions=} opt_options View options.
* @api * @api
*/ */
const View = function(opt_options) { class View {
constructor(opt_options) {
BaseObject.call(this); BaseObject.call(this);
const options = assign({}, opt_options); const options = assign({}, opt_options);
@@ -262,16 +263,13 @@ const View = function(opt_options) {
this.projection_ = createProjection(options.projection, 'EPSG:3857'); this.projection_ = createProjection(options.projection, 'EPSG:3857');
this.applyOptions_(options); this.applyOptions_(options);
}; }
inherits(View, BaseObject); /**
/**
* Set up the view with the given options. * Set up the view with the given options.
* @param {module:ol/View~ViewOptions} options View options. * @param {module:ol/View~ViewOptions} options View options.
*/ */
View.prototype.applyOptions_ = function(options) { applyOptions_(options) {
/** /**
* @type {Object.<string, *>} * @type {Object.<string, *>}
@@ -347,9 +345,9 @@ View.prototype.applyOptions_ = function(options) {
*/ */
this.options_ = options; this.options_ = options;
}; }
/** /**
* Get an updated version of the view options used to construct the view. The * Get an updated version of the view options used to construct the view. The
* current resolution (or zoom), center, and rotation are applied to any stored * current resolution (or zoom), center, and rotation are applied to any stored
* options. The provided options can be used to apply new min/max zoom or * options. The provided options can be used to apply new min/max zoom or
@@ -357,7 +355,7 @@ View.prototype.applyOptions_ = function(options) {
* @param {module:ol/View~ViewOptions} newOptions New options to be applied. * @param {module:ol/View~ViewOptions} newOptions New options to be applied.
* @return {module:ol/View~ViewOptions} New options updated with the current view state. * @return {module:ol/View~ViewOptions} New options updated with the current view state.
*/ */
View.prototype.getUpdatedOptions_ = function(newOptions) { getUpdatedOptions_(newOptions) {
const options = assign({}, this.options_); const options = assign({}, this.options_);
// preserve resolution (or zoom) // preserve resolution (or zoom)
@@ -374,10 +372,9 @@ View.prototype.getUpdatedOptions_ = function(newOptions) {
options.rotation = this.getRotation(); options.rotation = this.getRotation();
return assign({}, options, newOptions); return assign({}, options, newOptions);
}; }
/**
/**
* Animate the view. The view's center, zoom (or resolution), and rotation * Animate the view. The view's center, zoom (or resolution), and rotation
* can be animated for smooth transitions between view states. For example, * can be animated for smooth transitions between view states. For example,
* to animate the view to a new zoom level: * to animate the view to a new zoom level:
@@ -410,7 +407,7 @@ View.prototype.getUpdatedOptions_ = function(newOptions) {
* the animation completed without being cancelled. * the animation completed without being cancelled.
* @api * @api
*/ */
View.prototype.animate = function(var_args) { animate(var_args) {
let animationCount = arguments.length; let animationCount = arguments.length;
let callback; let callback;
if (animationCount > 1 && typeof arguments[animationCount - 1] === 'function') { if (animationCount > 1 && typeof arguments[animationCount - 1] === 'function') {
@@ -490,34 +487,31 @@ View.prototype.animate = function(var_args) {
this.animations_.push(series); this.animations_.push(series);
this.setHint(ViewHint.ANIMATING, 1); this.setHint(ViewHint.ANIMATING, 1);
this.updateAnimations_(); this.updateAnimations_();
}; }
/**
/**
* Determine if the view is being animated. * Determine if the view is being animated.
* @return {boolean} The view is being animated. * @return {boolean} The view is being animated.
* @api * @api
*/ */
View.prototype.getAnimating = function() { getAnimating() {
return this.hints_[ViewHint.ANIMATING] > 0; return this.hints_[ViewHint.ANIMATING] > 0;
}; }
/**
/**
* Determine if the user is interacting with the view, such as panning or zooming. * Determine if the user is interacting with the view, such as panning or zooming.
* @return {boolean} The view is being interacted with. * @return {boolean} The view is being interacted with.
* @api * @api
*/ */
View.prototype.getInteracting = function() { getInteracting() {
return this.hints_[ViewHint.INTERACTING] > 0; return this.hints_[ViewHint.INTERACTING] > 0;
}; }
/**
/**
* Cancel any ongoing animations. * Cancel any ongoing animations.
* @api * @api
*/ */
View.prototype.cancelAnimations = function() { cancelAnimations() {
this.setHint(ViewHint.ANIMATING, -this.hints_[ViewHint.ANIMATING]); this.setHint(ViewHint.ANIMATING, -this.hints_[ViewHint.ANIMATING]);
for (let i = 0, ii = this.animations_.length; i < ii; ++i) { for (let i = 0, ii = this.animations_.length; i < ii; ++i) {
const series = this.animations_[i]; const series = this.animations_[i];
@@ -526,12 +520,12 @@ View.prototype.cancelAnimations = function() {
} }
} }
this.animations_.length = 0; this.animations_.length = 0;
}; }
/** /**
* Update all animations. * Update all animations.
*/ */
View.prototype.updateAnimations_ = function() { updateAnimations_() {
if (this.updateAnimationKey_ !== undefined) { if (this.updateAnimationKey_ !== undefined) {
cancelAnimationFrame(this.updateAnimationKey_); cancelAnimationFrame(this.updateAnimationKey_);
this.updateAnimationKey_ = undefined; this.updateAnimationKey_ = undefined;
@@ -608,14 +602,14 @@ View.prototype.updateAnimations_ = function() {
if (more && this.updateAnimationKey_ === undefined) { if (more && this.updateAnimationKey_ === undefined) {
this.updateAnimationKey_ = requestAnimationFrame(this.updateAnimations_); this.updateAnimationKey_ = requestAnimationFrame(this.updateAnimations_);
} }
}; }
/** /**
* @param {number} rotation Target rotation. * @param {number} rotation Target rotation.
* @param {module:ol/coordinate~Coordinate} anchor Rotation anchor. * @param {module:ol/coordinate~Coordinate} anchor Rotation anchor.
* @return {module:ol/coordinate~Coordinate|undefined} Center for rotation and anchor. * @return {module:ol/coordinate~Coordinate|undefined} Center for rotation and anchor.
*/ */
View.prototype.calculateCenterRotate = function(rotation, anchor) { calculateCenterRotate(rotation, anchor) {
let center; let center;
const currentCenter = this.getCenter(); const currentCenter = this.getCenter();
if (currentCenter !== undefined) { if (currentCenter !== undefined) {
@@ -624,15 +618,14 @@ View.prototype.calculateCenterRotate = function(rotation, anchor) {
addCoordinate(center, anchor); addCoordinate(center, anchor);
} }
return center; return center;
}; }
/**
/**
* @param {number} resolution Target resolution. * @param {number} resolution Target resolution.
* @param {module:ol/coordinate~Coordinate} anchor Zoom anchor. * @param {module:ol/coordinate~Coordinate} anchor Zoom anchor.
* @return {module:ol/coordinate~Coordinate|undefined} Center for resolution and anchor. * @return {module:ol/coordinate~Coordinate|undefined} Center for resolution and anchor.
*/ */
View.prototype.calculateCenterZoom = function(resolution, anchor) { calculateCenterZoom(resolution, anchor) {
let center; let center;
const currentCenter = this.getCenter(); const currentCenter = this.getCenter();
const currentResolution = this.getResolution(); const currentResolution = this.getResolution();
@@ -642,14 +635,13 @@ View.prototype.calculateCenterZoom = function(resolution, anchor) {
center = [x, y]; center = [x, y];
} }
return center; return center;
}; }
/**
/**
* @private * @private
* @return {module:ol/size~Size} Viewport size or `[100, 100]` when no viewport is found. * @return {module:ol/size~Size} Viewport size or `[100, 100]` when no viewport is found.
*/ */
View.prototype.getSizeFromViewport_ = function() { getSizeFromViewport_() {
const size = [100, 100]; const size = [100, 100];
const selector = '.ol-viewport[data-view="' + getUid(this) + '"]'; const selector = '.ol-viewport[data-view="' + getUid(this) + '"]';
const element = document.querySelector(selector); const element = document.querySelector(selector);
@@ -659,21 +651,19 @@ View.prototype.getSizeFromViewport_ = function() {
size[1] = parseInt(metrics.height, 10); size[1] = parseInt(metrics.height, 10);
} }
return size; return size;
}; }
/**
/**
* Get the constrained center of this view. * Get the constrained center of this view.
* @param {module:ol/coordinate~Coordinate|undefined} center Center. * @param {module:ol/coordinate~Coordinate|undefined} center Center.
* @return {module:ol/coordinate~Coordinate|undefined} Constrained center. * @return {module:ol/coordinate~Coordinate|undefined} Constrained center.
* @api * @api
*/ */
View.prototype.constrainCenter = function(center) { constrainCenter(center) {
return this.constraints_.center(center); return this.constraints_.center(center);
}; }
/**
/**
* Get the constrained resolution of this view. * Get the constrained resolution of this view.
* @param {number|undefined} resolution Resolution. * @param {number|undefined} resolution Resolution.
* @param {number=} opt_delta Delta. Default is `0`. * @param {number=} opt_delta Delta. Default is `0`.
@@ -681,52 +671,48 @@ View.prototype.constrainCenter = function(center) {
* @return {number|undefined} Constrained resolution. * @return {number|undefined} Constrained resolution.
* @api * @api
*/ */
View.prototype.constrainResolution = function(resolution, opt_delta, opt_direction) { constrainResolution(resolution, opt_delta, opt_direction) {
const delta = opt_delta || 0; const delta = opt_delta || 0;
const direction = opt_direction || 0; const direction = opt_direction || 0;
return this.constraints_.resolution(resolution, delta, direction); return this.constraints_.resolution(resolution, delta, direction);
}; }
/**
/**
* Get the constrained rotation of this view. * Get the constrained rotation of this view.
* @param {number|undefined} rotation Rotation. * @param {number|undefined} rotation Rotation.
* @param {number=} opt_delta Delta. Default is `0`. * @param {number=} opt_delta Delta. Default is `0`.
* @return {number|undefined} Constrained rotation. * @return {number|undefined} Constrained rotation.
* @api * @api
*/ */
View.prototype.constrainRotation = function(rotation, opt_delta) { constrainRotation(rotation, opt_delta) {
const delta = opt_delta || 0; const delta = opt_delta || 0;
return this.constraints_.rotation(rotation, delta); return this.constraints_.rotation(rotation, delta);
}; }
/**
/**
* Get the view center. * Get the view center.
* @return {module:ol/coordinate~Coordinate|undefined} The center of the view. * @return {module:ol/coordinate~Coordinate|undefined} The center of the view.
* @observable * @observable
* @api * @api
*/ */
View.prototype.getCenter = function() { getCenter() {
return ( return (
/** @type {module:ol/coordinate~Coordinate|undefined} */ (this.get(ViewProperty.CENTER)) /** @type {module:ol/coordinate~Coordinate|undefined} */ (this.get(ViewProperty.CENTER))
); );
}; }
/**
/**
* @return {module:ol/View~Constraints} Constraints. * @return {module:ol/View~Constraints} Constraints.
*/ */
View.prototype.getConstraints = function() { getConstraints() {
return this.constraints_; return this.constraints_;
}; }
/**
/**
* @param {Array.<number>=} opt_hints Destination array. * @param {Array.<number>=} opt_hints Destination array.
* @return {Array.<number>} Hint. * @return {Array.<number>} Hint.
*/ */
View.prototype.getHints = function(opt_hints) { getHints(opt_hints) {
if (opt_hints !== undefined) { if (opt_hints !== undefined) {
opt_hints[0] = this.hints_[0]; opt_hints[0] = this.hints_[0];
opt_hints[1] = this.hints_[1]; opt_hints[1] = this.hints_[1];
@@ -734,10 +720,9 @@ View.prototype.getHints = function(opt_hints) {
} else { } else {
return this.hints_.slice(); return this.hints_.slice();
} }
}; }
/**
/**
* Calculate the extent for the current view state and the passed size. * Calculate the extent for the current view state and the passed size.
* The size is the pixel dimensions of the box into which the calculated extent * The size is the pixel dimensions of the box into which the calculated extent
* should fit. In most cases you want to get the extent of the entire map, * should fit. In most cases you want to get the extent of the entire map,
@@ -747,7 +732,7 @@ View.prototype.getHints = function(opt_hints) {
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
* @api * @api
*/ */
View.prototype.calculateExtent = function(opt_size) { calculateExtent(opt_size) {
const size = opt_size || this.getSizeFromViewport_(); const size = opt_size || this.getSizeFromViewport_();
const center = /** @type {!module:ol/coordinate~Coordinate} */ (this.getCenter()); const center = /** @type {!module:ol/coordinate~Coordinate} */ (this.getCenter());
assert(center, 1); // The view center is not defined assert(center, 1); // The view center is not defined
@@ -757,102 +742,92 @@ View.prototype.calculateExtent = function(opt_size) {
assert(rotation !== undefined, 3); // The view rotation is not defined assert(rotation !== undefined, 3); // The view rotation is not defined
return getForViewAndSize(center, resolution, rotation, size); return getForViewAndSize(center, resolution, rotation, size);
}; }
/**
/**
* Get the maximum resolution of the view. * Get the maximum resolution of the view.
* @return {number} The maximum resolution of the view. * @return {number} The maximum resolution of the view.
* @api * @api
*/ */
View.prototype.getMaxResolution = function() { getMaxResolution() {
return this.maxResolution_; return this.maxResolution_;
}; }
/**
/**
* Get the minimum resolution of the view. * Get the minimum resolution of the view.
* @return {number} The minimum resolution of the view. * @return {number} The minimum resolution of the view.
* @api * @api
*/ */
View.prototype.getMinResolution = function() { getMinResolution() {
return this.minResolution_; return this.minResolution_;
}; }
/**
/**
* Get the maximum zoom level for the view. * Get the maximum zoom level for the view.
* @return {number} The maximum zoom level. * @return {number} The maximum zoom level.
* @api * @api
*/ */
View.prototype.getMaxZoom = function() { getMaxZoom() {
return /** @type {number} */ (this.getZoomForResolution(this.minResolution_)); return /** @type {number} */ (this.getZoomForResolution(this.minResolution_));
}; }
/**
/**
* Set a new maximum zoom level for the view. * Set a new maximum zoom level for the view.
* @param {number} zoom The maximum zoom level. * @param {number} zoom The maximum zoom level.
* @api * @api
*/ */
View.prototype.setMaxZoom = function(zoom) { setMaxZoom(zoom) {
this.applyOptions_(this.getUpdatedOptions_({maxZoom: zoom})); this.applyOptions_(this.getUpdatedOptions_({maxZoom: zoom}));
}; }
/**
/**
* Get the minimum zoom level for the view. * Get the minimum zoom level for the view.
* @return {number} The minimum zoom level. * @return {number} The minimum zoom level.
* @api * @api
*/ */
View.prototype.getMinZoom = function() { getMinZoom() {
return /** @type {number} */ (this.getZoomForResolution(this.maxResolution_)); return /** @type {number} */ (this.getZoomForResolution(this.maxResolution_));
}; }
/**
/**
* Set a new minimum zoom level for the view. * Set a new minimum zoom level for the view.
* @param {number} zoom The minimum zoom level. * @param {number} zoom The minimum zoom level.
* @api * @api
*/ */
View.prototype.setMinZoom = function(zoom) { setMinZoom(zoom) {
this.applyOptions_(this.getUpdatedOptions_({minZoom: zoom})); this.applyOptions_(this.getUpdatedOptions_({minZoom: zoom}));
}; }
/**
/**
* Get the view projection. * Get the view projection.
* @return {module:ol/proj/Projection} The projection of the view. * @return {module:ol/proj/Projection} The projection of the view.
* @api * @api
*/ */
View.prototype.getProjection = function() { getProjection() {
return this.projection_; return this.projection_;
}; }
/**
/**
* Get the view resolution. * Get the view resolution.
* @return {number|undefined} The resolution of the view. * @return {number|undefined} The resolution of the view.
* @observable * @observable
* @api * @api
*/ */
View.prototype.getResolution = function() { getResolution() {
return /** @type {number|undefined} */ (this.get(ViewProperty.RESOLUTION)); return /** @type {number|undefined} */ (this.get(ViewProperty.RESOLUTION));
}; }
/**
/**
* Get the resolutions for the view. This returns the array of resolutions * Get the resolutions for the view. This returns the array of resolutions
* passed to the constructor of the View, or undefined if none were given. * passed to the constructor of the View, or undefined if none were given.
* @return {Array.<number>|undefined} The resolutions of the view. * @return {Array.<number>|undefined} The resolutions of the view.
* @api * @api
*/ */
View.prototype.getResolutions = function() { getResolutions() {
return this.resolutions_; return this.resolutions_;
}; }
/**
/**
* Get the resolution for a provided extent (in map units) and size (in pixels). * Get the resolution for a provided extent (in map units) and size (in pixels).
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @param {module:ol/size~Size=} opt_size Box pixel size. * @param {module:ol/size~Size=} opt_size Box pixel size.
@@ -860,21 +835,20 @@ View.prototype.getResolutions = function() {
* the given size. * the given size.
* @api * @api
*/ */
View.prototype.getResolutionForExtent = function(extent, opt_size) { getResolutionForExtent(extent, opt_size) {
const size = opt_size || this.getSizeFromViewport_(); const size = opt_size || this.getSizeFromViewport_();
const xResolution = getWidth(extent) / size[0]; const xResolution = getWidth(extent) / size[0];
const yResolution = getHeight(extent) / size[1]; const yResolution = getHeight(extent) / size[1];
return Math.max(xResolution, yResolution); return Math.max(xResolution, yResolution);
}; }
/**
/**
* Return a function that returns a value between 0 and 1 for a * Return a function that returns a value between 0 and 1 for a
* resolution. Exponential scaling is assumed. * resolution. Exponential scaling is assumed.
* @param {number=} opt_power Power. * @param {number=} opt_power Power.
* @return {function(number): number} Resolution for value function. * @return {function(number): number} Resolution for value function.
*/ */
View.prototype.getResolutionForValueFunction = function(opt_power) { getResolutionForValueFunction(opt_power) {
const power = opt_power || 2; const power = opt_power || 2;
const maxResolution = this.maxResolution_; const maxResolution = this.maxResolution_;
const minResolution = this.minResolution_; const minResolution = this.minResolution_;
@@ -888,27 +862,25 @@ View.prototype.getResolutionForValueFunction = function(opt_power) {
const resolution = maxResolution / Math.pow(power, value * max); const resolution = maxResolution / Math.pow(power, value * max);
return resolution; return resolution;
}); });
}; }
/**
/**
* Get the view rotation. * Get the view rotation.
* @return {number} The rotation of the view in radians. * @return {number} The rotation of the view in radians.
* @observable * @observable
* @api * @api
*/ */
View.prototype.getRotation = function() { getRotation() {
return /** @type {number} */ (this.get(ViewProperty.ROTATION)); return /** @type {number} */ (this.get(ViewProperty.ROTATION));
}; }
/**
/**
* Return a function that returns a resolution for a value between * Return a function that returns a resolution for a value between
* 0 and 1. Exponential scaling is assumed. * 0 and 1. Exponential scaling is assumed.
* @param {number=} opt_power Power. * @param {number=} opt_power Power.
* @return {function(number): number} Value for resolution function. * @return {function(number): number} Value for resolution function.
*/ */
View.prototype.getValueForResolutionFunction = function(opt_power) { getValueForResolutionFunction(opt_power) {
const power = opt_power || 2; const power = opt_power || 2;
const maxResolution = this.maxResolution_; const maxResolution = this.maxResolution_;
const minResolution = this.minResolution_; const minResolution = this.minResolution_;
@@ -922,13 +894,12 @@ View.prototype.getValueForResolutionFunction = function(opt_power) {
const value = (Math.log(maxResolution / resolution) / Math.log(power)) / max; const value = (Math.log(maxResolution / resolution) / Math.log(power)) / max;
return value; return value;
}); });
}; }
/**
/**
* @return {module:ol/View~State} View state. * @return {module:ol/View~State} View state.
*/ */
View.prototype.getState = function() { getState() {
const center = /** @type {module:ol/coordinate~Coordinate} */ (this.getCenter()); const center = /** @type {module:ol/coordinate~Coordinate} */ (this.getCenter());
const projection = this.getProjection(); const projection = this.getProjection();
const resolution = /** @type {number} */ (this.getResolution()); const resolution = /** @type {number} */ (this.getResolution());
@@ -942,33 +913,31 @@ View.prototype.getState = function() {
zoom: this.getZoom() zoom: this.getZoom()
}) })
); );
}; }
/**
/**
* Get the current zoom level. If you configured your view with a resolutions * Get the current zoom level. If you configured your view with a resolutions
* array (this is rare), this method may return non-integer zoom levels (so * array (this is rare), this method may return non-integer zoom levels (so
* the zoom level is not safe to use as an index into a resolutions array). * the zoom level is not safe to use as an index into a resolutions array).
* @return {number|undefined} Zoom. * @return {number|undefined} Zoom.
* @api * @api
*/ */
View.prototype.getZoom = function() { getZoom() {
let zoom; let zoom;
const resolution = this.getResolution(); const resolution = this.getResolution();
if (resolution !== undefined) { if (resolution !== undefined) {
zoom = this.getZoomForResolution(resolution); zoom = this.getZoomForResolution(resolution);
} }
return zoom; return zoom;
}; }
/**
/**
* Get the zoom level for a resolution. * Get the zoom level for a resolution.
* @param {number} resolution The resolution. * @param {number} resolution The resolution.
* @return {number|undefined} The zoom level for the provided resolution. * @return {number|undefined} The zoom level for the provided resolution.
* @api * @api
*/ */
View.prototype.getZoomForResolution = function(resolution) { getZoomForResolution(resolution) {
let offset = this.minZoom_ || 0; let offset = this.minZoom_ || 0;
let max, zoomFactor; let max, zoomFactor;
if (this.resolutions_) { if (this.resolutions_) {
@@ -985,22 +954,20 @@ View.prototype.getZoomForResolution = function(resolution) {
zoomFactor = this.zoomFactor_; zoomFactor = this.zoomFactor_;
} }
return offset + Math.log(max / resolution) / Math.log(zoomFactor); return offset + Math.log(max / resolution) / Math.log(zoomFactor);
}; }
/**
/**
* Get the resolution for a zoom level. * Get the resolution for a zoom level.
* @param {number} zoom Zoom level. * @param {number} zoom Zoom level.
* @return {number} The view resolution for the provided zoom level. * @return {number} The view resolution for the provided zoom level.
* @api * @api
*/ */
View.prototype.getResolutionForZoom = function(zoom) { getResolutionForZoom(zoom) {
return /** @type {number} */ (this.constrainResolution( return /** @type {number} */ (this.constrainResolution(
this.maxResolution_, zoom - this.minZoom_, 0)); this.maxResolution_, zoom - this.minZoom_, 0));
}; }
/**
/**
* Fit the given geometry or extent based on the given map size and border. * Fit the given geometry or extent based on the given map size and border.
* The size is pixel dimensions of the box to fit the extent into. * The size is pixel dimensions of the box to fit the extent into.
* In most cases you will want to use the map size, that is `map.getSize()`. * In most cases you will want to use the map size, that is `map.getSize()`.
@@ -1010,7 +977,7 @@ View.prototype.getResolutionForZoom = function(zoom) {
* @param {module:ol/View~FitOptions=} opt_options Options. * @param {module:ol/View~FitOptions=} opt_options Options.
* @api * @api
*/ */
View.prototype.fit = function(geometryOrExtent, opt_options) { fit(geometryOrExtent, opt_options) {
const options = opt_options || {}; const options = opt_options || {};
let size = options.size; let size = options.size;
if (!size) { if (!size) {
@@ -1103,17 +1070,16 @@ View.prototype.fit = function(geometryOrExtent, opt_options) {
this.setCenter(center); this.setCenter(center);
setTimeout(callback.bind(undefined, true), 0); setTimeout(callback.bind(undefined, true), 0);
} }
}; }
/**
/**
* Center on coordinate and view position. * Center on coordinate and view position.
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate. * @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
* @param {module:ol/size~Size} size Box pixel size. * @param {module:ol/size~Size} size Box pixel size.
* @param {module:ol~Pixel} position Position on the view to center on. * @param {module:ol~Pixel} position Position on the view to center on.
* @api * @api
*/ */
View.prototype.centerOn = function(coordinate, size, position) { centerOn(coordinate, size, position) {
// calculate rotated position // calculate rotated position
const rotation = this.getRotation(); const rotation = this.getRotation();
const cosAngle = Math.cos(-rotation); const cosAngle = Math.cos(-rotation);
@@ -1130,94 +1096,90 @@ View.prototype.centerOn = function(coordinate, size, position) {
const centerY = rotY * cosAngle + rotX * sinAngle; const centerY = rotY * cosAngle + rotX * sinAngle;
this.setCenter([centerX, centerY]); this.setCenter([centerX, centerY]);
}; }
/**
/**
* @return {boolean} Is defined. * @return {boolean} Is defined.
*/ */
View.prototype.isDef = function() { isDef() {
return !!this.getCenter() && this.getResolution() !== undefined; return !!this.getCenter() && this.getResolution() !== undefined;
}; }
/**
/**
* Rotate the view around a given coordinate. * Rotate the view around a given coordinate.
* @param {number} rotation New rotation value for the view. * @param {number} rotation New rotation value for the view.
* @param {module:ol/coordinate~Coordinate=} opt_anchor The rotation center. * @param {module:ol/coordinate~Coordinate=} opt_anchor The rotation center.
* @api * @api
*/ */
View.prototype.rotate = function(rotation, opt_anchor) { rotate(rotation, opt_anchor) {
if (opt_anchor !== undefined) { if (opt_anchor !== undefined) {
const center = this.calculateCenterRotate(rotation, opt_anchor); const center = this.calculateCenterRotate(rotation, opt_anchor);
this.setCenter(center); this.setCenter(center);
} }
this.setRotation(rotation); this.setRotation(rotation);
}; }
/**
/**
* Set the center of the current view. * Set the center of the current view.
* @param {module:ol/coordinate~Coordinate|undefined} center The center of the view. * @param {module:ol/coordinate~Coordinate|undefined} center The center of the view.
* @observable * @observable
* @api * @api
*/ */
View.prototype.setCenter = function(center) { setCenter(center) {
this.set(ViewProperty.CENTER, center); this.set(ViewProperty.CENTER, center);
if (this.getAnimating()) { if (this.getAnimating()) {
this.cancelAnimations(); this.cancelAnimations();
} }
}; }
/**
/**
* @param {module:ol/ViewHint} hint Hint. * @param {module:ol/ViewHint} hint Hint.
* @param {number} delta Delta. * @param {number} delta Delta.
* @return {number} New value. * @return {number} New value.
*/ */
View.prototype.setHint = function(hint, delta) { setHint(hint, delta) {
this.hints_[hint] += delta; this.hints_[hint] += delta;
this.changed(); this.changed();
return this.hints_[hint]; return this.hints_[hint];
}; }
/**
/**
* Set the resolution for this view. * Set the resolution for this view.
* @param {number|undefined} resolution The resolution of the view. * @param {number|undefined} resolution The resolution of the view.
* @observable * @observable
* @api * @api
*/ */
View.prototype.setResolution = function(resolution) { setResolution(resolution) {
this.set(ViewProperty.RESOLUTION, resolution); this.set(ViewProperty.RESOLUTION, resolution);
if (this.getAnimating()) { if (this.getAnimating()) {
this.cancelAnimations(); this.cancelAnimations();
} }
}; }
/**
/**
* Set the rotation for this view. * Set the rotation for this view.
* @param {number} rotation The rotation of the view in radians. * @param {number} rotation The rotation of the view in radians.
* @observable * @observable
* @api * @api
*/ */
View.prototype.setRotation = function(rotation) { setRotation(rotation) {
this.set(ViewProperty.ROTATION, rotation); this.set(ViewProperty.ROTATION, rotation);
if (this.getAnimating()) { if (this.getAnimating()) {
this.cancelAnimations(); this.cancelAnimations();
} }
}; }
/**
/**
* Zoom to a specific zoom level. * Zoom to a specific zoom level.
* @param {number} zoom Zoom level. * @param {number} zoom Zoom level.
* @api * @api
*/ */
View.prototype.setZoom = function(zoom) { setZoom(zoom) {
this.setResolution(this.getResolutionForZoom(zoom)); this.setResolution(this.getResolutionForZoom(zoom));
}; }
}
inherits(View, BaseObject);
/** /**
+9 -7
View File
@@ -66,7 +66,8 @@ import WebGLVectorLayerRenderer from './renderer/webgl/VectorLayer.js';
* @fires module:ol/render/Event~RenderEvent#precompose * @fires module:ol/render/Event~RenderEvent#precompose
* @api * @api
*/ */
const WebGLMap = function(options) { class WebGLMap {
constructor(options) {
options = assign({}, options); options = assign({}, options);
if (!options.controls) { if (!options.controls) {
options.controls = defaultControls(); options.controls = defaultControls();
@@ -76,12 +77,9 @@ const WebGLMap = function(options) {
} }
PluggableMap.call(this, options); PluggableMap.call(this, options);
}; }
inherits(WebGLMap, PluggableMap); createRenderer() {
WebGLMap.prototype.createRenderer = function() {
const renderer = new WebGLMapRenderer(this); const renderer = new WebGLMapRenderer(this);
renderer.registerLayerRenderers([ renderer.registerLayerRenderers([
WebGLImageLayerRenderer, WebGLImageLayerRenderer,
@@ -89,6 +87,10 @@ WebGLMap.prototype.createRenderer = function() {
WebGLVectorLayerRenderer WebGLVectorLayerRenderer
]); ]);
return renderer; return renderer;
}; }
}
inherits(WebGLMap, PluggableMap);
export default WebGLMap; export default WebGLMap;
+18 -13
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/events/Event * @module ol/events/Event
*/ */
/** /**
* @classdesc * @classdesc
* Stripped down implementation of the W3C DOM Level 2 Event interface. * Stripped down implementation of the W3C DOM Level 2 Event interface.
@@ -14,7 +15,9 @@
* @constructor * @constructor
* @param {string} type Type. * @param {string} type Type.
*/ */
const Event = function(type) { class Event {
constructor(type) {
/** /**
* @type {boolean} * @type {boolean}
@@ -34,25 +37,27 @@ const Event = function(type) {
* @api * @api
*/ */
this.target = null; this.target = null;
}
};
/**
* Stop event propagation.
* @function
* @api
*/
Event.prototype.preventDefault =
/** /**
* Stop event propagation. * Stop event propagation.
* @function * @function
* @api * @api
*/ */
Event.prototype.stopPropagation = function() { preventDefault() {
this.propagationStopped = true; this.propagationStopped = true;
}; }
/**
* Stop event propagation.
* @function
* @api
*/
stopPropagation() {
this.propagationStopped = true;
}
}
/** /**
+6 -2
View File
@@ -13,10 +13,14 @@ import LogicalNary from '../filter/LogicalNary.js';
* @param {...module:ol/format/filter/Filter} conditions Conditions. * @param {...module:ol/format/filter/Filter} conditions Conditions.
* @extends {module:ol/format/filter/LogicalNary} * @extends {module:ol/format/filter/LogicalNary}
*/ */
const And = function(conditions) { class And {
constructor(conditions) {
const params = ['And'].concat(Array.prototype.slice.call(arguments)); const params = ['And'].concat(Array.prototype.slice.call(arguments));
LogicalNary.apply(this, params); LogicalNary.apply(this, params);
}; }
}
inherits(And, LogicalNary); inherits(And, LogicalNary);
+6 -2
View File
@@ -17,7 +17,9 @@ import Filter from '../filter/Filter.js';
* @extends {module:ol/format/filter/Filter} * @extends {module:ol/format/filter/Filter}
* @api * @api
*/ */
const Bbox = function(geometryName, extent, opt_srsName) { class Bbox {
constructor(geometryName, extent, opt_srsName) {
Filter.call(this, 'BBOX'); Filter.call(this, 'BBOX');
@@ -35,7 +37,9 @@ const Bbox = function(geometryName, extent, opt_srsName) {
* @type {string|undefined} * @type {string|undefined}
*/ */
this.srsName = opt_srsName; this.srsName = opt_srsName;
}; }
}
inherits(Bbox, Filter); inherits(Bbox, Filter);
+6 -2
View File
@@ -15,7 +15,9 @@ import Filter from '../filter/Filter.js';
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @extends {module:ol/format/filter/Filter} * @extends {module:ol/format/filter/Filter}
*/ */
const Comparison = function(tagName, propertyName) { class Comparison {
constructor(tagName, propertyName) {
Filter.call(this, tagName); Filter.call(this, tagName);
@@ -23,7 +25,9 @@ const Comparison = function(tagName, propertyName) {
* @type {!string} * @type {!string}
*/ */
this.propertyName = propertyName; this.propertyName = propertyName;
}; }
}
inherits(Comparison, Filter); inherits(Comparison, Filter);
+7 -2
View File
@@ -17,7 +17,9 @@ import Comparison from '../filter/Comparison.js';
* @param {boolean=} opt_matchCase Case-sensitive? * @param {boolean=} opt_matchCase Case-sensitive?
* @extends {module:ol/format/filter/Comparison} * @extends {module:ol/format/filter/Comparison}
*/ */
const ComparisonBinary = function(tagName, propertyName, expression, opt_matchCase) { class ComparisonBinary {
constructor(tagName, propertyName, expression, opt_matchCase) {
Comparison.call(this, tagName, propertyName); Comparison.call(this, tagName, propertyName);
@@ -30,7 +32,10 @@ const ComparisonBinary = function(tagName, propertyName, expression, opt_matchCa
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.matchCase = opt_matchCase; this.matchCase = opt_matchCase;
}; }
}
inherits(ComparisonBinary, Comparison); inherits(ComparisonBinary, Comparison);
export default ComparisonBinary; export default ComparisonBinary;
+7 -2
View File
@@ -17,11 +17,16 @@ import Spatial from '../filter/Spatial.js';
* @extends {module:ol/format/filter/Spatial} * @extends {module:ol/format/filter/Spatial}
* @api * @api
*/ */
const Contains = function(geometryName, geometry, opt_srsName) { class Contains {
constructor(geometryName, geometry, opt_srsName) {
Spatial.call(this, 'Contains', geometryName, geometry, opt_srsName); Spatial.call(this, 'Contains', geometryName, geometry, opt_srsName);
}; }
}
inherits(Contains, Spatial); inherits(Contains, Spatial);
export default Contains; export default Contains;
+7 -2
View File
@@ -15,7 +15,9 @@ import Comparison from '../filter/Comparison.js';
* @extends {module:ol/format/filter/Comparison} * @extends {module:ol/format/filter/Comparison}
* @api * @api
*/ */
const During = function(propertyName, begin, end) { class During {
constructor(propertyName, begin, end) {
Comparison.call(this, 'During', propertyName); Comparison.call(this, 'During', propertyName);
/** /**
@@ -27,7 +29,10 @@ const During = function(propertyName, begin, end) {
* @type {!string} * @type {!string}
*/ */
this.end = end; this.end = end;
}; }
}
inherits(During, Comparison); inherits(During, Comparison);
export default During; export default During;
+7 -2
View File
@@ -15,9 +15,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const EqualTo = function(propertyName, expression, opt_matchCase) { class EqualTo {
constructor(propertyName, expression, opt_matchCase) {
ComparisonBinary.call(this, 'PropertyIsEqualTo', propertyName, expression, opt_matchCase); ComparisonBinary.call(this, 'PropertyIsEqualTo', propertyName, expression, opt_matchCase);
}; }
}
inherits(EqualTo, ComparisonBinary); inherits(EqualTo, ComparisonBinary);
export default EqualTo; export default EqualTo;
+7 -2
View File
@@ -14,9 +14,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const GreaterThan = function(propertyName, expression) { class GreaterThan {
constructor(propertyName, expression) {
ComparisonBinary.call(this, 'PropertyIsGreaterThan', propertyName, expression); ComparisonBinary.call(this, 'PropertyIsGreaterThan', propertyName, expression);
}; }
}
inherits(GreaterThan, ComparisonBinary); inherits(GreaterThan, ComparisonBinary);
export default GreaterThan; export default GreaterThan;
+7 -2
View File
@@ -14,9 +14,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const GreaterThanOrEqualTo = function(propertyName, expression) { class GreaterThanOrEqualTo {
constructor(propertyName, expression) {
ComparisonBinary.call(this, 'PropertyIsGreaterThanOrEqualTo', propertyName, expression); ComparisonBinary.call(this, 'PropertyIsGreaterThanOrEqualTo', propertyName, expression);
}; }
}
inherits(GreaterThanOrEqualTo, ComparisonBinary); inherits(GreaterThanOrEqualTo, ComparisonBinary);
export default GreaterThanOrEqualTo; export default GreaterThanOrEqualTo;
+6 -2
View File
@@ -17,11 +17,15 @@ import Spatial from '../filter/Spatial.js';
* @extends {module:ol/format/filter/Spatial} * @extends {module:ol/format/filter/Spatial}
* @api * @api
*/ */
const Intersects = function(geometryName, geometry, opt_srsName) { class Intersects {
constructor(geometryName, geometry, opt_srsName) {
Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName); Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName);
}
}; }
inherits(Intersects, Spatial); inherits(Intersects, Spatial);
export default Intersects; export default Intersects;
+7 -2
View File
@@ -15,7 +15,9 @@ import Comparison from '../filter/Comparison.js';
* @extends {module:ol/format/filter/Comparison} * @extends {module:ol/format/filter/Comparison}
* @api * @api
*/ */
const IsBetween = function(propertyName, lowerBoundary, upperBoundary) { class IsBetween {
constructor(propertyName, lowerBoundary, upperBoundary) {
Comparison.call(this, 'PropertyIsBetween', propertyName); Comparison.call(this, 'PropertyIsBetween', propertyName);
/** /**
@@ -27,7 +29,10 @@ const IsBetween = function(propertyName, lowerBoundary, upperBoundary) {
* @type {!number} * @type {!number}
*/ */
this.upperBoundary = upperBoundary; this.upperBoundary = upperBoundary;
};
}
}
inherits(IsBetween, Comparison); inherits(IsBetween, Comparison);
export default IsBetween; export default IsBetween;
+7 -2
View File
@@ -21,7 +21,9 @@ import Comparison from '../filter/Comparison.js';
* @extends {module:ol/format/filter/Comparison} * @extends {module:ol/format/filter/Comparison}
* @api * @api
*/ */
const IsLike = function(propertyName, pattern, opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { class IsLike {
constructor(propertyName, pattern, opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
Comparison.call(this, 'PropertyIsLike', propertyName); Comparison.call(this, 'PropertyIsLike', propertyName);
/** /**
@@ -48,7 +50,10 @@ const IsLike = function(propertyName, pattern, opt_wildCard, opt_singleChar, opt
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.matchCase = opt_matchCase; this.matchCase = opt_matchCase;
};
}
}
inherits(IsLike, Comparison); inherits(IsLike, Comparison);
export default IsLike; export default IsLike;
+8 -2
View File
@@ -13,9 +13,15 @@ import Comparison from '../filter/Comparison.js';
* @extends {module:ol/format/filter/Comparison} * @extends {module:ol/format/filter/Comparison}
* @api * @api
*/ */
const IsNull = function(propertyName) { class IsNull {
constructor(propertyName) {
Comparison.call(this, 'PropertyIsNull', propertyName); Comparison.call(this, 'PropertyIsNull', propertyName);
}; }
}
inherits(IsNull, Comparison); inherits(IsNull, Comparison);
export default IsNull; export default IsNull;
+7 -2
View File
@@ -14,9 +14,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const LessThan = function(propertyName, expression) { class LessThan {
constructor(propertyName, expression) {
ComparisonBinary.call(this, 'PropertyIsLessThan', propertyName, expression); ComparisonBinary.call(this, 'PropertyIsLessThan', propertyName, expression);
}; }
}
inherits(LessThan, ComparisonBinary); inherits(LessThan, ComparisonBinary);
export default LessThan; export default LessThan;
+7 -2
View File
@@ -14,9 +14,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const LessThanOrEqualTo = function(propertyName, expression) { class LessThanOrEqualTo {
constructor(propertyName, expression) {
ComparisonBinary.call(this, 'PropertyIsLessThanOrEqualTo', propertyName, expression); ComparisonBinary.call(this, 'PropertyIsLessThanOrEqualTo', propertyName, expression);
}; }
}
inherits(LessThanOrEqualTo, ComparisonBinary); inherits(LessThanOrEqualTo, ComparisonBinary);
export default LessThanOrEqualTo; export default LessThanOrEqualTo;
+7 -2
View File
@@ -16,7 +16,9 @@ import Filter from '../filter/Filter.js';
* @param {...module:ol/format/filter/Filter} conditions Conditions. * @param {...module:ol/format/filter/Filter} conditions Conditions.
* @extends {module:ol/format/filter/Filter} * @extends {module:ol/format/filter/Filter}
*/ */
const LogicalNary = function(tagName, conditions) { class LogicalNary {
constructor(tagName, conditions) {
Filter.call(this, tagName); Filter.call(this, tagName);
@@ -25,7 +27,10 @@ const LogicalNary = function(tagName, conditions) {
*/ */
this.conditions = Array.prototype.slice.call(arguments, 1); this.conditions = Array.prototype.slice.call(arguments, 1);
assert(this.conditions.length >= 2, 57); // At least 2 conditions are required. assert(this.conditions.length >= 2, 57); // At least 2 conditions are required.
}; }
}
inherits(LogicalNary, Filter); inherits(LogicalNary, Filter);
export default LogicalNary; export default LogicalNary;
+7 -2
View File
@@ -13,7 +13,9 @@ import Filter from '../filter/Filter.js';
* @extends {module:ol/format/filter/Filter} * @extends {module:ol/format/filter/Filter}
* @api * @api
*/ */
const Not = function(condition) { class Not {
constructor(condition) {
Filter.call(this, 'Not'); Filter.call(this, 'Not');
@@ -21,7 +23,10 @@ const Not = function(condition) {
* @type {!module:ol/format/filter/Filter} * @type {!module:ol/format/filter/Filter}
*/ */
this.condition = condition; this.condition = condition;
};
}
}
inherits(Not, Filter); inherits(Not, Filter);
export default Not; export default Not;
+7 -2
View File
@@ -15,9 +15,14 @@ import ComparisonBinary from '../filter/ComparisonBinary.js';
* @extends {module:ol/format/filter/ComparisonBinary} * @extends {module:ol/format/filter/ComparisonBinary}
* @api * @api
*/ */
const NotEqualTo = function(propertyName, expression, opt_matchCase) { class NotEqualTo {
constructor(propertyName, expression, opt_matchCase) {
ComparisonBinary.call(this, 'PropertyIsNotEqualTo', propertyName, expression, opt_matchCase); ComparisonBinary.call(this, 'PropertyIsNotEqualTo', propertyName, expression, opt_matchCase);
}; }
}
inherits(NotEqualTo, ComparisonBinary); inherits(NotEqualTo, ComparisonBinary);
export default NotEqualTo; export default NotEqualTo;
+7 -2
View File
@@ -13,10 +13,15 @@ import LogicalNary from '../filter/LogicalNary.js';
* @extends {module:ol/format/filter/LogicalNary} * @extends {module:ol/format/filter/LogicalNary}
* @api * @api
*/ */
const Or = function(conditions) { class Or {
constructor(conditions) {
const params = ['Or'].concat(Array.prototype.slice.call(arguments)); const params = ['Or'].concat(Array.prototype.slice.call(arguments));
LogicalNary.apply(this, params); LogicalNary.apply(this, params);
}; }
}
inherits(Or, LogicalNary); inherits(Or, LogicalNary);
export default Or; export default Or;
+6 -2
View File
@@ -19,7 +19,9 @@ import Filter from '../filter/Filter.js';
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @extends {module:ol/format/filter/Filter} * @extends {module:ol/format/filter/Filter}
*/ */
const Spatial = function(tagName, geometryName, geometry, opt_srsName) { class Spatial {
constructor(tagName, geometryName, geometry, opt_srsName) {
Filter.call(this, tagName); Filter.call(this, tagName);
@@ -37,7 +39,9 @@ const Spatial = function(tagName, geometryName, geometry, opt_srsName) {
* @type {string|undefined} * @type {string|undefined}
*/ */
this.srsName = opt_srsName; this.srsName = opt_srsName;
}; }
}
inherits(Spatial, Filter); inherits(Spatial, Filter);
+5 -2
View File
@@ -17,11 +17,14 @@ import Spatial from '../filter/Spatial.js';
* @extends {module:ol/format/filter/Spatial} * @extends {module:ol/format/filter/Spatial}
* @api * @api
*/ */
const Within = function(geometryName, geometry, opt_srsName) { class Within {
constructor(geometryName, geometry, opt_srsName) {
Spatial.call(this, 'Within', geometryName, geometry, opt_srsName); Spatial.call(this, 'Within', geometryName, geometry, opt_srsName);
}
}; }
inherits(Within, Spatial); inherits(Within, Spatial);
export default Within; export default Within;
+6 -2
View File
@@ -22,7 +22,9 @@ import Interaction, {zoomByDelta} from '../interaction/Interaction.js';
* @param {module:ol/interaction/DoubleClickZoom~Options=} opt_options Options. * @param {module:ol/interaction/DoubleClickZoom~Options=} opt_options Options.
* @api * @api
*/ */
const DoubleClickZoom = function(opt_options) { class DoubleClickZoom {
constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -42,7 +44,9 @@ const DoubleClickZoom = function(opt_options) {
*/ */
this.duration_ = options.duration !== undefined ? options.duration : 250; this.duration_ = options.duration !== undefined ? options.duration : 250;
}; }
}
inherits(DoubleClickZoom, Interaction); inherits(DoubleClickZoom, Interaction);
+7 -2
View File
@@ -50,7 +50,9 @@ const DragAndDropEventType = {
* @param {Array.<module:ol/Feature>=} opt_features Features. * @param {Array.<module:ol/Feature>=} opt_features Features.
* @param {module:ol/proj/Projection=} opt_projection Projection. * @param {module:ol/proj/Projection=} opt_projection Projection.
*/ */
const DragAndDropEvent = function(type, file, opt_features, opt_projection) { class DragAndDropEvent {
constructor(type, file, opt_features, opt_projection) {
Event.call(this, type); Event.call(this, type);
@@ -75,7 +77,10 @@ const DragAndDropEvent = function(type, file, opt_features, opt_projection) {
*/ */
this.projection = opt_projection; this.projection = opt_projection;
}; }
}
inherits(DragAndDropEvent, Event); inherits(DragAndDropEvent, Event);
+6 -2
View File
@@ -70,7 +70,9 @@ const DragBoxEventType = {
* @extends {module:ol/events/Event} * @extends {module:ol/events/Event}
* @constructor * @constructor
*/ */
const DragBoxEvent = function(type, coordinate, mapBrowserEvent) { class DragBoxEvent {
constructor(type, coordinate, mapBrowserEvent) {
Event.call(this, type); Event.call(this, type);
/** /**
@@ -88,7 +90,9 @@ const DragBoxEvent = function(type, coordinate, mapBrowserEvent) {
*/ */
this.mapBrowserEvent = mapBrowserEvent; this.mapBrowserEvent = mapBrowserEvent;
}; }
}
inherits(DragBoxEvent, Event); inherits(DragBoxEvent, Event);
+5 -2
View File
@@ -28,7 +28,8 @@ import PointerInteraction, {centroid as centroidFromPointers} from '../interacti
* @param {module:ol/interaction/DragPan~Options=} opt_options Options. * @param {module:ol/interaction/DragPan~Options=} opt_options Options.
* @api * @api
*/ */
const DragPan = function(opt_options) { class DragPan {
constructor(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: handleDownEvent, handleDownEvent: handleDownEvent,
@@ -66,7 +67,9 @@ const DragPan = function(opt_options) {
*/ */
this.noKinetic_ = false; this.noKinetic_ = false;
}; }
}
inherits(DragPan, PointerInteraction); inherits(DragPan, PointerInteraction);
+7 -2
View File
@@ -33,7 +33,9 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {module:ol/interaction/DragRotate~Options=} opt_options Options. * @param {module:ol/interaction/DragRotate~Options=} opt_options Options.
* @api * @api
*/ */
const DragRotate = function(opt_options) { class DragRotate {
constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -60,7 +62,10 @@ const DragRotate = function(opt_options) {
* @type {number} * @type {number}
*/ */
this.duration_ = options.duration !== undefined ? options.duration : 250; this.duration_ = options.duration !== undefined ? options.duration : 250;
};
}
}
inherits(DragRotate, PointerInteraction); inherits(DragRotate, PointerInteraction);
+6 -2
View File
@@ -34,7 +34,9 @@ import PointerInteraction from '../interaction/Pointer.js';
* @param {module:ol/interaction/DragRotateAndZoom~Options=} opt_options Options. * @param {module:ol/interaction/DragRotateAndZoom~Options=} opt_options Options.
* @api * @api
*/ */
const DragRotateAndZoom = function(opt_options) { class DragRotateAndZoom {
constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -74,7 +76,9 @@ const DragRotateAndZoom = function(opt_options) {
*/ */
this.duration_ = options.duration !== undefined ? options.duration : 400; this.duration_ = options.duration !== undefined ? options.duration : 400;
}; }
}
inherits(DragRotateAndZoom, PointerInteraction); inherits(DragRotateAndZoom, PointerInteraction);
+6 -2
View File
@@ -134,7 +134,9 @@ const DrawEventType = {
* @param {module:ol/interaction/Draw~DrawEventType} type Type. * @param {module:ol/interaction/Draw~DrawEventType} type Type.
* @param {module:ol/Feature} feature The feature drawn. * @param {module:ol/Feature} feature The feature drawn.
*/ */
const DrawEvent = function(type, feature) { class DrawEvent {
constructor(type, feature) {
Event.call(this, type); Event.call(this, type);
@@ -145,7 +147,9 @@ const DrawEvent = function(type, feature) {
*/ */
this.feature = feature; this.feature = feature;
}; }
}
inherits(DrawEvent, Event); inherits(DrawEvent, Event);
+6 -2
View File
@@ -56,7 +56,9 @@ const ExtentEventType = {
* @param {module:ol/extent~Extent} extent the new extent * @param {module:ol/extent~Extent} extent the new extent
* @extends {module:ol/events/Event} * @extends {module:ol/events/Event}
*/ */
const ExtentInteractionEvent = function(extent) { class ExtentInteractionEvent {
constructor(extent) {
Event.call(this, ExtentEventType.EXTENTCHANGED); Event.call(this, ExtentEventType.EXTENTCHANGED);
/** /**
@@ -65,8 +67,10 @@ const ExtentInteractionEvent = function(extent) {
* @api * @api
*/ */
this.extent = extent; this.extent = extent;
}
}
};
inherits(ExtentInteractionEvent, Event); inherits(ExtentInteractionEvent, Event);
+6 -2
View File
@@ -39,7 +39,9 @@ import Interaction, {pan} from '../interaction/Interaction.js';
* @param {module:ol/interaction/KeyboardPan~Options=} opt_options Options. * @param {module:ol/interaction/KeyboardPan~Options=} opt_options Options.
* @api * @api
*/ */
const KeyboardPan = function(opt_options) { class KeyboardPan {
constructor(opt_options) {
Interaction.call(this, { Interaction.call(this, {
handleEvent: handleEvent handleEvent: handleEvent
@@ -77,7 +79,9 @@ const KeyboardPan = function(opt_options) {
this.pixelDelta_ = options.pixelDelta !== undefined ? this.pixelDelta_ = options.pixelDelta !== undefined ?
options.pixelDelta : 128; options.pixelDelta : 128;
}; }
}
inherits(KeyboardPan, Interaction); inherits(KeyboardPan, Interaction);
+6 -2
View File
@@ -35,7 +35,9 @@ import Interaction, {zoomByDelta} from '../interaction/Interaction.js';
* @extends {module:ol/interaction/Interaction} * @extends {module:ol/interaction/Interaction}
* @api * @api
*/ */
const KeyboardZoom = function(opt_options) { class KeyboardZoom {
constructor(opt_options) {
Interaction.call(this, { Interaction.call(this, {
handleEvent: handleEvent handleEvent: handleEvent
@@ -61,7 +63,9 @@ const KeyboardZoom = function(opt_options) {
*/ */
this.duration_ = options.duration !== undefined ? options.duration : 100; this.duration_ = options.duration !== undefined ? options.duration : 100;
}; }
}
inherits(KeyboardZoom, Interaction); inherits(KeyboardZoom, Interaction);
+7 -2
View File
@@ -99,7 +99,9 @@ const ModifyEventType = {
* @param {module:ol/MapBrowserPointerEvent} mapBrowserPointerEvent * @param {module:ol/MapBrowserPointerEvent} mapBrowserPointerEvent
* Associated {@link module:ol/MapBrowserPointerEvent}. * Associated {@link module:ol/MapBrowserPointerEvent}.
*/ */
export const ModifyEvent = function(type, features, mapBrowserPointerEvent) { export class ModifyEvent {
constructor(type, features, mapBrowserPointerEvent) {
Event.call(this, type); Event.call(this, type);
@@ -116,7 +118,10 @@ export const ModifyEvent = function(type, features, mapBrowserPointerEvent) {
* @api * @api
*/ */
this.mapBrowserEvent = mapBrowserPointerEvent; this.mapBrowserEvent = mapBrowserPointerEvent;
};
}
}
inherits(ModifyEvent, Event); inherits(ModifyEvent, Event);
+6 -2
View File
@@ -27,7 +27,9 @@ import {disable} from '../rotationconstraint.js';
* @param {module:ol/interaction/PinchRotate~Options=} opt_options Options. * @param {module:ol/interaction/PinchRotate~Options=} opt_options Options.
* @api * @api
*/ */
const PinchRotate = function(opt_options) { class PinchRotate {
constructor(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: handleDownEvent, handleDownEvent: handleDownEvent,
@@ -73,7 +75,9 @@ const PinchRotate = function(opt_options) {
*/ */
this.duration_ = options.duration !== undefined ? options.duration : 250; this.duration_ = options.duration !== undefined ? options.duration : 250;
}; }
}
inherits(PinchRotate, PointerInteraction); inherits(PinchRotate, PointerInteraction);
+6 -2
View File
@@ -26,7 +26,9 @@ import PointerInteraction, {centroid as centroidFromPointers} from '../interacti
* @param {module:ol/interaction/PinchZoom~Options=} opt_options Options. * @param {module:ol/interaction/PinchZoom~Options=} opt_options Options.
* @api * @api
*/ */
const PinchZoom = function(opt_options) { class PinchZoom {
constructor(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: handleDownEvent, handleDownEvent: handleDownEvent,
@@ -66,7 +68,9 @@ const PinchZoom = function(opt_options) {
*/ */
this.lastScaleDelta_ = 1; this.lastScaleDelta_ = 1;
}; }
}
inherits(PinchZoom, PointerInteraction); inherits(PinchZoom, PointerInteraction);
+7 -2
View File
@@ -110,7 +110,9 @@ const SelectEventType = {
* @extends {module:ol/events/Event} * @extends {module:ol/events/Event}
* @constructor * @constructor
*/ */
const SelectEvent = function(type, selected, deselected, mapBrowserEvent) { class SelectEvent {
constructor(type, selected, deselected, mapBrowserEvent) {
Event.call(this, type); Event.call(this, type);
/** /**
@@ -133,7 +135,10 @@ const SelectEvent = function(type, selected, deselected, mapBrowserEvent) {
* @api * @api
*/ */
this.mapBrowserEvent = mapBrowserEvent; this.mapBrowserEvent = mapBrowserEvent;
};
}
}
inherits(SelectEvent, Event); inherits(SelectEvent, Event);
+7 -2
View File
@@ -63,7 +63,9 @@ const TranslateEventType = {
* @param {module:ol/Collection.<module:ol/Feature>} features The features translated. * @param {module:ol/Collection.<module:ol/Feature>} features The features translated.
* @param {module:ol/coordinate~Coordinate} coordinate The event coordinate. * @param {module:ol/coordinate~Coordinate} coordinate The event coordinate.
*/ */
export const TranslateEvent = function(type, features, coordinate) { export class TranslateEvent {
constructor(type, features, coordinate) {
Event.call(this, type); Event.call(this, type);
@@ -81,7 +83,10 @@ export const TranslateEvent = function(type, features, coordinate) {
* @api * @api
*/ */
this.coordinate = coordinate; this.coordinate = coordinate;
};
}
}
inherits(TranslateEvent, Event); inherits(TranslateEvent, Event);
+6 -2
View File
@@ -40,7 +40,9 @@ import Layer from '../layer/Layer.js';
* @param {module:ol/layer/Image~Options=} opt_options Layer options. * @param {module:ol/layer/Image~Options=} opt_options Layer options.
* @api * @api
*/ */
const ImageLayer = function(opt_options) { class ImageLayer {
constructor(opt_options) {
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (options)); Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (options));
@@ -51,7 +53,9 @@ const ImageLayer = function(opt_options) {
*/ */
this.type = LayerType.IMAGE; this.type = LayerType.IMAGE;
}; }
}
inherits(ImageLayer, Layer); inherits(ImageLayer, Layer);
+7 -1
View File
@@ -48,7 +48,9 @@ export const WORLD_EXTENT = [-180, -85, 180, 85];
* @extends {module:ol/proj/Projection} * @extends {module:ol/proj/Projection}
* @param {string} code Code. * @param {string} code Code.
*/ */
function EPSG3857Projection(code) { class EPSG3857Projection {
constructor(code) {
Projection.call(this, { Projection.call(this, {
code: code, code: code,
units: Units.METERS, units: Units.METERS,
@@ -59,7 +61,11 @@ function EPSG3857Projection(code) {
return resolution / cosh(point[1] / RADIUS); return resolution / cosh(point[1] / RADIUS);
} }
}); });
}
} }
inherits(EPSG3857Projection, Projection); inherits(EPSG3857Projection, Projection);
+7 -1
View File
@@ -44,7 +44,9 @@ export const METERS_PER_UNIT = Math.PI * RADIUS / 180;
* @param {string} code Code. * @param {string} code Code.
* @param {string=} opt_axisOrientation Axis orientation. * @param {string=} opt_axisOrientation Axis orientation.
*/ */
function EPSG4326Projection(code, opt_axisOrientation) { class EPSG4326Projection {
constructor(code, opt_axisOrientation) {
Projection.call(this, { Projection.call(this, {
code: code, code: code,
units: Units.DEGREES, units: Units.DEGREES,
@@ -54,7 +56,11 @@ function EPSG4326Projection(code, opt_axisOrientation) {
metersPerUnit: METERS_PER_UNIT, metersPerUnit: METERS_PER_UNIT,
worldExtent: EXTENT worldExtent: EXTENT
}); });
}
} }
inherits(EPSG4326Projection, Projection); inherits(EPSG4326Projection, Projection);
+6 -4
View File
@@ -13,9 +13,9 @@ import Event from '../events/Event.js';
* @param {?CanvasRenderingContext2D=} opt_context Context. * @param {?CanvasRenderingContext2D=} opt_context Context.
* @param {?module:ol/webgl/Context=} opt_glContext WebGL Context. * @param {?module:ol/webgl/Context=} opt_glContext WebGL Context.
*/ */
const RenderEvent = function( class RenderEvent {
type, opt_vectorContext, opt_frameState, opt_context,
opt_glContext) { constructor(type, opt_vectorContext, opt_frameState, opt_context, opt_glContext) {
Event.call(this, type); Event.call(this, type);
@@ -49,7 +49,9 @@ const RenderEvent = function(
*/ */
this.glContext = opt_glContext; this.glContext = opt_glContext;
}; }
}
inherits(RenderEvent, Event); inherits(RenderEvent, Event);
export default RenderEvent; export default RenderEvent;
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -85,6 +87,9 @@ const Locations = function(gl, program) {
*/ */
this.a_radius = gl.getAttribLocation( this.a_radius = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_radius' : 'g'); program, DEBUG_WEBGL ? 'a_radius' : 'g');
};
}
}
export default Locations; export default Locations;
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -91,6 +93,9 @@ const Locations = function(gl, program) {
*/ */
this.a_direction = gl.getAttribLocation( this.a_direction = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_direction' : 'g'); program, DEBUG_WEBGL ? 'a_direction' : 'g');
};
}
}
export default Locations; export default Locations;
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -49,6 +51,9 @@ const Locations = function(gl, program) {
*/ */
this.a_position = gl.getAttribLocation( this.a_position = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_position' : 'a'); program, DEBUG_WEBGL ? 'a_position' : 'a');
};
}
}
export default Locations; export default Locations;
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -73,6 +75,9 @@ const Locations = function(gl, program) {
*/ */
this.a_rotateWithView = gl.getAttribLocation( this.a_rotateWithView = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_rotateWithView' : 'g'); program, DEBUG_WEBGL ? 'a_rotateWithView' : 'g');
};
}
}
export default Locations; export default Locations;
@@ -4,7 +4,7 @@
// This file is automatically generated, do not edit // This file is automatically generated, do not edit
// Run `make shaders` to generate, and commit the result. // Run `make shaders` to generate, and commit the result.
import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js'; import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
/** /**
* @constructor * @constructor
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -49,6 +51,9 @@ const Locations = function(gl, program) {
*/ */
this.a_texCoord = gl.getAttribLocation( this.a_texCoord = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_texCoord' : 'c'); program, DEBUG_WEBGL ? 'a_texCoord' : 'c');
};
}
}
export default Locations; export default Locations;
@@ -4,7 +4,7 @@
// This file is automatically generated, do not edit // This file is automatically generated, do not edit
// Run `make shaders` to generate, and commit the result. // Run `make shaders` to generate, and commit the result.
import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js'; import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
/** /**
* @constructor * @constructor
@@ -12,7 +12,9 @@ import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
constructor(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -37,6 +39,9 @@ const Locations = function(gl, program) {
*/ */
this.a_texCoord = gl.getAttribLocation( this.a_texCoord = gl.getAttribLocation(
program, DEBUG_WEBGL ? 'a_texCoord' : 'c'); program, DEBUG_WEBGL ? 'a_texCoord' : 'c');
};
}
}
export default Locations; export default Locations;
+7 -2
View File
@@ -51,7 +51,9 @@ const ImageSourceEventType = {
* @param {string} type Type. * @param {string} type Type.
* @param {module:ol/Image} image The image. * @param {module:ol/Image} image The image.
*/ */
const ImageSourceEvent = function(type, image) { class ImageSourceEvent {
constructor(type, image) {
Event.call(this, type); Event.call(this, type);
@@ -62,7 +64,10 @@ const ImageSourceEvent = function(type, image) {
*/ */
this.image = image; this.image = image;
}; }
}
inherits(ImageSourceEvent, Event); inherits(ImageSourceEvent, Event);
+6 -2
View File
@@ -50,7 +50,9 @@ export const ATTRIBUTION = '&copy; ' +
* @param {module:ol/source/OSM~Options=} [opt_options] Open Street Map options. * @param {module:ol/source/OSM~Options=} [opt_options] Open Street Map options.
* @api * @api
*/ */
const OSM = function(opt_options) { class OSM {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -79,7 +81,9 @@ const OSM = function(opt_options) {
wrapX: options.wrapX wrapX: options.wrapX
}); });
}; }
}
inherits(OSM, XYZ); inherits(OSM, XYZ);
+7 -2
View File
@@ -83,7 +83,9 @@ const RasterOperationType = {
* @param {module:ol/PluggableMap~FrameState} frameState The frame state. * @param {module:ol/PluggableMap~FrameState} frameState The frame state.
* @param {Object} data An object made available to operations. * @param {Object} data An object made available to operations.
*/ */
const RasterSourceEvent = function(type, frameState, data) { class RasterSourceEvent {
constructor(type, frameState, data) {
Event.call(this, type); Event.call(this, type);
/** /**
@@ -108,7 +110,10 @@ const RasterSourceEvent = function(type, frameState, data) {
*/ */
this.data = data; this.data = data;
}; }
}
inherits(RasterSourceEvent, Event); inherits(RasterSourceEvent, Event);
/** /**
+7 -2
View File
@@ -118,7 +118,9 @@ const ProviderConfig = {
* @param {module:ol/source/Stamen~Options=} options Stamen options. * @param {module:ol/source/Stamen~Options=} options Stamen options.
* @api * @api
*/ */
const Stamen = function(options) { class Stamen {
constructor(options) {
const i = options.layer.indexOf('-'); const i = options.layer.indexOf('-');
const provider = i == -1 ? options.layer : options.layer.slice(0, i); const provider = i == -1 ? options.layer : options.layer.slice(0, i);
const providerConfig = ProviderConfig[provider]; const providerConfig = ProviderConfig[provider];
@@ -141,7 +143,10 @@ const Stamen = function(options) {
url: url, url: url,
wrapX: options.wrapX wrapX: options.wrapX
}); });
};
}
}
inherits(Stamen, XYZ); inherits(Stamen, XYZ);
+7 -2
View File
@@ -318,7 +318,9 @@ TileSource.prototype.useTile = UNDEFINED;
* @param {string} type Type. * @param {string} type Type.
* @param {module:ol/Tile} tile The tile. * @param {module:ol/Tile} tile The tile.
*/ */
export const TileSourceEvent = function(type, tile) { export class TileSourceEvent {
constructor(type, tile) {
Event.call(this, type); Event.call(this, type);
@@ -329,7 +331,10 @@ export const TileSourceEvent = function(type, tile) {
*/ */
this.tile = tile; this.tile = tile;
}; }
}
inherits(TileSourceEvent, Event); inherits(TileSourceEvent, Event);
export default TileSource; export default TileSource;
+14 -4
View File
@@ -27,7 +27,9 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
* @param {boolean} preemptive Load the tile when visible (before it's needed). * @param {boolean} preemptive Load the tile when visible (before it's needed).
* @param {boolean} jsonp Load the tile as a script. * @param {boolean} jsonp Load the tile as a script.
*/ */
export const CustomTile = function(tileCoord, state, src, extent, preemptive, jsonp) { export class CustomTile {
constructor(tileCoord, state, src, extent, preemptive, jsonp) {
Tile.call(this, tileCoord, state); Tile.call(this, tileCoord, state);
@@ -74,7 +76,10 @@ export const CustomTile = function(tileCoord, state, src, extent, preemptive, js
*/ */
this.jsonp_ = jsonp; this.jsonp_ = jsonp;
}; }
}
inherits(CustomTile, Tile); inherits(CustomTile, Tile);
@@ -275,7 +280,9 @@ CustomTile.prototype.load = function() {
* @param {module:ol/source/UTFGrid~Options=} options Source options. * @param {module:ol/source/UTFGrid~Options=} options Source options.
* @api * @api
*/ */
const UTFGrid = function(options) { class UTFGrid {
constructor(options) {
TileSource.call(this, { TileSource.call(this, {
projection: getProjection('EPSG:3857'), projection: getProjection('EPSG:3857'),
state: SourceState.LOADING state: SourceState.LOADING
@@ -322,7 +329,10 @@ const UTFGrid = function(options) {
} else { } else {
assert(false, 51); // Either `url` or `tileJSON` options must be provided assert(false, 51); // Either `url` or `tileJSON` options must be provided
} }
};
}
}
inherits(UTFGrid, TileSource); inherits(UTFGrid, TileSource);
+13 -4
View File
@@ -41,7 +41,9 @@ import RBush from '../structs/RBush.js';
* @param {string} type Type. * @param {string} type Type.
* @param {module:ol/Feature=} opt_feature Feature. * @param {module:ol/Feature=} opt_feature Feature.
*/ */
export const VectorSourceEvent = function(type, opt_feature) { export class VectorSourceEvent {
constructor(type, opt_feature) {
Event.call(this, type); Event.call(this, type);
@@ -52,7 +54,10 @@ export const VectorSourceEvent = function(type, opt_feature) {
*/ */
this.feature = opt_feature; this.feature = opt_feature;
}; }
}
inherits(VectorSourceEvent, Event); inherits(VectorSourceEvent, Event);
@@ -158,7 +163,9 @@ inherits(VectorSourceEvent, Event);
* @param {module:ol/source/Vector~Options=} opt_options Vector source options. * @param {module:ol/source/Vector~Options=} opt_options Vector source options.
* @api * @api
*/ */
const VectorSource = function(opt_options) { class VectorSource {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -271,7 +278,9 @@ const VectorSource = function(opt_options) {
this.bindFeaturesCollection_(collection); this.bindFeaturesCollection_(collection);
} }
}; }
}
inherits(VectorSource, Source); inherits(VectorSource, Source);
+6 -2
View File
@@ -74,7 +74,9 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.
* @param {module:ol/source/VectorTile~Options=} options Vector tile options. * @param {module:ol/source/VectorTile~Options=} options Vector tile options.
* @api * @api
*/ */
const VectorTile = function(options) { class VectorTile {
constructor(options) {
const projection = options.projection || 'EPSG:3857'; const projection = options.projection || 'EPSG:3857';
const extent = options.extent || extentFromProjection(projection); const extent = options.extent || extentFromProjection(projection);
@@ -133,7 +135,9 @@ const VectorTile = function(options) {
*/ */
this.tileGrids_ = {}; this.tileGrids_ = {};
}; }
}
inherits(VectorTile, UrlTile); inherits(VectorTile, UrlTile);
+6 -2
View File
@@ -65,7 +65,9 @@ import {appendParams} from '../uri.js';
* @param {module:ol/source/WMTS~Options=} options WMTS options. * @param {module:ol/source/WMTS~Options=} options WMTS options.
* @api * @api
*/ */
const WMTS = function(options) { class WMTS {
constructor(options) {
// TODO: add support for TileMatrixLimits // TODO: add support for TileMatrixLimits
@@ -215,7 +217,9 @@ const WMTS = function(options) {
this.setKey(this.getKeyForDimensions_()); this.setKey(this.getKeyForDimensions_());
}; }
}
inherits(WMTS, TileImage); inherits(WMTS, TileImage);
+7 -2
View File
@@ -66,7 +66,9 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
* @param {module:ol/source/XYZ~Options=} opt_options XYZ options. * @param {module:ol/source/XYZ~Options=} opt_options XYZ options.
* @api * @api
*/ */
const XYZ = function(opt_options) { class XYZ {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
const projection = options.projection !== undefined ? const projection = options.projection !== undefined ?
options.projection : 'EPSG:3857'; options.projection : 'EPSG:3857';
@@ -96,7 +98,10 @@ const XYZ = function(opt_options) {
transition: options.transition transition: options.transition
}); });
}; }
}
inherits(XYZ, TileImage); inherits(XYZ, TileImage);
export default XYZ; export default XYZ;
+14 -6
View File
@@ -34,8 +34,9 @@ const TierSizeCalculation = {
* @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function. * @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function.
* @param {module:ol/Tile~Options=} opt_options Tile options. * @param {module:ol/Tile~Options=} opt_options Tile options.
*/ */
export const CustomTile = function( export class CustomTile {
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
constructor(tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options); ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
@@ -50,7 +51,11 @@ export const CustomTile = function(
* @type {module:ol/size~Size} * @type {module:ol/size~Size}
*/ */
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0])); this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
};
}
}
inherits(CustomTile, ImageTile); inherits(CustomTile, ImageTile);
@@ -124,7 +129,9 @@ CustomTile.prototype.getImage = function() {
* @param {module:ol/source/Zoomify~Options=} opt_options Options. * @param {module:ol/source/Zoomify~Options=} opt_options Options.
* @api * @api
*/ */
const Zoomify = function(opt_options) { class Zoomify {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -250,9 +257,10 @@ const Zoomify = function(opt_options) {
transition: options.transition transition: options.transition
}); });
}; }
}
inherits(Zoomify, TileImage); inherits(Zoomify, TileImage);
export default Zoomify; export default Zoomify;
+60 -55
View File
@@ -27,7 +27,9 @@ import EventType from '../events/EventType.js';
* @template T * @template T
* @param {number=} opt_highWaterMark High water mark. * @param {number=} opt_highWaterMark High water mark.
*/ */
const LRUCache = function(opt_highWaterMark) { class LRUCache {
constructor(opt_highWaterMark) {
EventTarget.call(this); EventTarget.call(this);
@@ -60,41 +62,39 @@ const LRUCache = function(opt_highWaterMark) {
*/ */
this.newest_ = null; this.newest_ = null;
}; }
inherits(LRUCache, EventTarget);
/** /**
* @return {boolean} Can expire cache. * @return {boolean} Can expire cache.
*/ */
LRUCache.prototype.canExpireCache = function() { canExpireCache() {
return this.getCount() > this.highWaterMark; return this.getCount() > this.highWaterMark;
}; }
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
LRUCache.prototype.clear = function() { clear() {
this.count_ = 0; this.count_ = 0;
this.entries_ = {}; this.entries_ = {};
this.oldest_ = null; this.oldest_ = null;
this.newest_ = null; this.newest_ = null;
this.dispatchEvent(EventType.CLEAR); this.dispatchEvent(EventType.CLEAR);
}; }
/** /**
* @param {string} key Key. * @param {string} key Key.
* @return {boolean} Contains key. * @return {boolean} Contains key.
*/ */
LRUCache.prototype.containsKey = function(key) { containsKey(key) {
return this.entries_.hasOwnProperty(key); return this.entries_.hasOwnProperty(key);
}; }
/** /**
* @param {function(this: S, T, string, module:ol/structs/LRUCache): ?} f The function * @param {function(this: S, T, string, module:ol/structs/LRUCache): ?} f The function
* to call for every entry from the oldest to the newer. This function takes * to call for every entry from the oldest to the newer. This function takes
* 3 arguments (the entry value, the entry key and the LRUCache object). * 3 arguments (the entry value, the entry key and the LRUCache object).
@@ -102,20 +102,20 @@ LRUCache.prototype.containsKey = function(key) {
* @param {S=} opt_this The object to use as `this` in `f`. * @param {S=} opt_this The object to use as `this` in `f`.
* @template S * @template S
*/ */
LRUCache.prototype.forEach = function(f, opt_this) { forEach(f, opt_this) {
let entry = this.oldest_; let entry = this.oldest_;
while (entry) { while (entry) {
f.call(opt_this, entry.value_, entry.key_, this); f.call(opt_this, entry.value_, entry.key_, this);
entry = entry.newer; entry = entry.newer;
} }
}; }
/** /**
* @param {string} key Key. * @param {string} key Key.
* @return {T} Value. * @return {T} Value.
*/ */
LRUCache.prototype.get = function(key) { get(key) {
const entry = this.entries_[key]; const entry = this.entries_[key];
assert(entry !== undefined, assert(entry !== undefined,
15); // Tried to get a value for a key that does not exist in the cache 15); // Tried to get a value for a key that does not exist in the cache
@@ -133,15 +133,15 @@ LRUCache.prototype.get = function(key) {
this.newest_.newer = entry; this.newest_.newer = entry;
this.newest_ = entry; this.newest_ = entry;
return entry.value_; return entry.value_;
}; }
/** /**
* Remove an entry from the cache. * Remove an entry from the cache.
* @param {string} key The entry key. * @param {string} key The entry key.
* @return {T} The removed entry. * @return {T} The removed entry.
*/ */
LRUCache.prototype.remove = function(key) { remove(key) {
const entry = this.entries_[key]; const entry = this.entries_[key];
assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
if (entry === this.newest_) { if (entry === this.newest_) {
@@ -161,21 +161,21 @@ LRUCache.prototype.remove = function(key) {
delete this.entries_[key]; delete this.entries_[key];
--this.count_; --this.count_;
return entry.value_; return entry.value_;
}; }
/** /**
* @return {number} Count. * @return {number} Count.
*/ */
LRUCache.prototype.getCount = function() { getCount() {
return this.count_; return this.count_;
}; }
/** /**
* @return {Array.<string>} Keys. * @return {Array.<string>} Keys.
*/ */
LRUCache.prototype.getKeys = function() { getKeys() {
const keys = new Array(this.count_); const keys = new Array(this.count_);
let i = 0; let i = 0;
let entry; let entry;
@@ -183,13 +183,13 @@ LRUCache.prototype.getKeys = function() {
keys[i++] = entry.key_; keys[i++] = entry.key_;
} }
return keys; return keys;
}; }
/** /**
* @return {Array.<T>} Values. * @return {Array.<T>} Values.
*/ */
LRUCache.prototype.getValues = function() { getValues() {
const values = new Array(this.count_); const values = new Array(this.count_);
let i = 0; let i = 0;
let entry; let entry;
@@ -197,38 +197,38 @@ LRUCache.prototype.getValues = function() {
values[i++] = entry.value_; values[i++] = entry.value_;
} }
return values; return values;
}; }
/** /**
* @return {T} Last value. * @return {T} Last value.
*/ */
LRUCache.prototype.peekLast = function() { peekLast() {
return this.oldest_.value_; return this.oldest_.value_;
}; }
/** /**
* @return {string} Last key. * @return {string} Last key.
*/ */
LRUCache.prototype.peekLastKey = function() { peekLastKey() {
return this.oldest_.key_; return this.oldest_.key_;
}; }
/** /**
* Get the key of the newest item in the cache. Throws if the cache is empty. * Get the key of the newest item in the cache. Throws if the cache is empty.
* @return {string} The newest key. * @return {string} The newest key.
*/ */
LRUCache.prototype.peekFirstKey = function() { peekFirstKey() {
return this.newest_.key_; return this.newest_.key_;
}; }
/** /**
* @return {T} value Value. * @return {T} value Value.
*/ */
LRUCache.prototype.pop = function() { pop() {
const entry = this.oldest_; const entry = this.oldest_;
delete this.entries_[entry.key_]; delete this.entries_[entry.key_];
if (entry.newer) { if (entry.newer) {
@@ -240,24 +240,24 @@ LRUCache.prototype.pop = function() {
} }
--this.count_; --this.count_;
return entry.value_; return entry.value_;
}; }
/** /**
* @param {string} key Key. * @param {string} key Key.
* @param {T} value Value. * @param {T} value Value.
*/ */
LRUCache.prototype.replace = function(key, value) { replace(key, value) {
this.get(key); // update `newest_` this.get(key); // update `newest_`
this.entries_[key].value_ = value; this.entries_[key].value_ = value;
}; }
/** /**
* @param {string} key Key. * @param {string} key Key.
* @param {T} value Value. * @param {T} value Value.
*/ */
LRUCache.prototype.set = function(key, value) { set(key, value) {
assert(!(key in this.entries_), assert(!(key in this.entries_),
16); // Tried to set a value for a key that is used already 16); // Tried to set a value for a key that is used already
const entry = /** @type {module:ol/structs/LRUCache~Entry} */ ({ const entry = /** @type {module:ol/structs/LRUCache~Entry} */ ({
@@ -274,25 +274,30 @@ LRUCache.prototype.set = function(key, value) {
this.newest_ = entry; this.newest_ = entry;
this.entries_[key] = entry; this.entries_[key] = entry;
++this.count_; ++this.count_;
}; }
/** /**
* Set a maximum number of entries for the cache. * Set a maximum number of entries for the cache.
* @param {number} size Cache size. * @param {number} size Cache size.
* @api * @api
*/ */
LRUCache.prototype.setSize = function(size) { setSize(size) {
this.highWaterMark = size; this.highWaterMark = size;
}; }
/** /**
* Prune the cache. * Prune the cache.
*/ */
LRUCache.prototype.prune = function() { prune() {
while (this.canExpireCache()) { while (this.canExpireCache()) {
this.pop(); this.pop();
} }
}; }
}
inherits(LRUCache, EventTarget);
export default LRUCache; export default LRUCache;
+49 -42
View File
@@ -19,7 +19,9 @@
* @param {boolean=} opt_circular The last item is connected to the first one, * @param {boolean=} opt_circular The last item is connected to the first one,
* and the first item to the last one. Default is true. * and the first item to the last one. Default is true.
*/ */
const LinkedList = function(opt_circular) { class LinkedList {
constructor(opt_circular) {
/** /**
* @private * @private
@@ -50,14 +52,15 @@ const LinkedList = function(opt_circular) {
* @type {number} * @type {number}
*/ */
this.length_ = 0; this.length_ = 0;
};
/** }
/**
* Inserts an item into the linked list right after the current one. * Inserts an item into the linked list right after the current one.
* *
* @param {?} data Item data. * @param {?} data Item data.
*/ */
LinkedList.prototype.insertItem = function(data) { insertItem(data) {
/** @type {module:ol/structs/LinkedList~Item} */ /** @type {module:ol/structs/LinkedList~Item} */
const item = { const item = {
@@ -92,13 +95,13 @@ LinkedList.prototype.insertItem = function(data) {
} }
this.head_ = item; this.head_ = item;
this.length_++; this.length_++;
}; }
/** /**
* Removes the current item from the list. Sets the cursor to the next item, * Removes the current item from the list. Sets the cursor to the next item,
* if possible. * if possible.
*/ */
LinkedList.prototype.removeItem = function() { removeItem() {
const head = this.head_; const head = this.head_;
if (head) { if (head) {
const next = head.next; const next = head.next;
@@ -122,112 +125,112 @@ LinkedList.prototype.removeItem = function() {
} }
this.length_--; this.length_--;
} }
}; }
/** /**
* Sets the cursor to the first item, and returns the associated data. * Sets the cursor to the first item, and returns the associated data.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.firstItem = function() { firstItem() {
this.head_ = this.first_; this.head_ = this.first_;
if (this.head_) { if (this.head_) {
return this.head_.data; return this.head_.data;
} }
return undefined; return undefined;
}; }
/** /**
* Sets the cursor to the last item, and returns the associated data. * Sets the cursor to the last item, and returns the associated data.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.lastItem = function() { lastItem() {
this.head_ = this.last_; this.head_ = this.last_;
if (this.head_) { if (this.head_) {
return this.head_.data; return this.head_.data;
} }
return undefined; return undefined;
}; }
/** /**
* Sets the cursor to the next item, and returns the associated data. * Sets the cursor to the next item, and returns the associated data.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.nextItem = function() { nextItem() {
if (this.head_ && this.head_.next) { if (this.head_ && this.head_.next) {
this.head_ = this.head_.next; this.head_ = this.head_.next;
return this.head_.data; return this.head_.data;
} }
return undefined; return undefined;
}; }
/** /**
* Returns the next item's data without moving the cursor. * Returns the next item's data without moving the cursor.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.getNextItem = function() { getNextItem() {
if (this.head_ && this.head_.next) { if (this.head_ && this.head_.next) {
return this.head_.next.data; return this.head_.next.data;
} }
return undefined; return undefined;
}; }
/** /**
* Sets the cursor to the previous item, and returns the associated data. * Sets the cursor to the previous item, and returns the associated data.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.prevItem = function() { prevItem() {
if (this.head_ && this.head_.prev) { if (this.head_ && this.head_.prev) {
this.head_ = this.head_.prev; this.head_ = this.head_.prev;
return this.head_.data; return this.head_.data;
} }
return undefined; return undefined;
}; }
/** /**
* Returns the previous item's data without moving the cursor. * Returns the previous item's data without moving the cursor.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.getPrevItem = function() { getPrevItem() {
if (this.head_ && this.head_.prev) { if (this.head_ && this.head_.prev) {
return this.head_.prev.data; return this.head_.prev.data;
} }
return undefined; return undefined;
}; }
/** /**
* Returns the current item's data. * Returns the current item's data.
* *
* @return {?} Item data. * @return {?} Item data.
*/ */
LinkedList.prototype.getCurrItem = function() { getCurrItem() {
if (this.head_) { if (this.head_) {
return this.head_.data; return this.head_.data;
} }
return undefined; return undefined;
}; }
/** /**
* Sets the first item of the list. This only works for circular lists, and sets * Sets the first item of the list. This only works for circular lists, and sets
* the last item accordingly. * the last item accordingly.
*/ */
LinkedList.prototype.setFirstItem = function() { setFirstItem() {
if (this.circular_ && this.head_) { if (this.circular_ && this.head_) {
this.first_ = this.head_; this.first_ = this.head_;
this.last_ = this.head_.prev; this.last_ = this.head_.prev;
} }
}; }
/** /**
* Concatenates two lists. * Concatenates two lists.
* @param {module:ol/structs/LinkedList} list List to merge into the current list. * @param {module:ol/structs/LinkedList} list List to merge into the current list.
*/ */
LinkedList.prototype.concat = function(list) { concat(list) {
if (list.head_) { if (list.head_) {
if (this.head_) { if (this.head_) {
const end = this.head_.next; const end = this.head_.next;
@@ -247,14 +250,18 @@ LinkedList.prototype.concat = function(list) {
list.last_ = undefined; list.last_ = undefined;
list.length_ = 0; list.length_ = 0;
} }
}; }
/** /**
* Returns the current length of the list. * Returns the current length of the list.
* *
* @return {number} Length. * @return {number} Length.
*/ */
LinkedList.prototype.getLength = function() { getLength() {
return this.length_; return this.length_;
}; }
}
export default LinkedList; export default LinkedList;
+57 -51
View File
@@ -4,6 +4,13 @@
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import {clear} from '../obj.js'; import {clear} from '../obj.js';
/**
* @type {number}
*/
export const DROP = Infinity;
/** /**
* Priority queue. * Priority queue.
* *
@@ -19,7 +26,9 @@ import {clear} from '../obj.js';
* @struct * @struct
* @template T * @template T
*/ */
const PriorityQueue = function(priorityFunction, keyFunction) { class PriorityQueue {
constructor(priorityFunction, keyFunction) {
/** /**
* @type {function(T): number} * @type {function(T): number}
@@ -51,30 +60,23 @@ const PriorityQueue = function(priorityFunction, keyFunction) {
*/ */
this.queuedElements_ = {}; this.queuedElements_ = {};
}; }
/**
/**
* @type {number}
*/
export const DROP = Infinity;
/**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
PriorityQueue.prototype.clear = function() { clear() {
this.elements_.length = 0; this.elements_.length = 0;
this.priorities_.length = 0; this.priorities_.length = 0;
clear(this.queuedElements_); clear(this.queuedElements_);
}; }
/** /**
* Remove and return the highest-priority element. O(log N). * Remove and return the highest-priority element. O(log N).
* @return {T} Element. * @return {T} Element.
*/ */
PriorityQueue.prototype.dequeue = function() { dequeue() {
const elements = this.elements_; const elements = this.elements_;
const priorities = this.priorities_; const priorities = this.priorities_;
const element = elements[0]; const element = elements[0];
@@ -89,15 +91,15 @@ PriorityQueue.prototype.dequeue = function() {
const elementKey = this.keyFunction_(element); const elementKey = this.keyFunction_(element);
delete this.queuedElements_[elementKey]; delete this.queuedElements_[elementKey];
return element; return element;
}; }
/** /**
* Enqueue an element. O(log N). * Enqueue an element. O(log N).
* @param {T} element Element. * @param {T} element Element.
* @return {boolean} The element was added to the queue. * @return {boolean} The element was added to the queue.
*/ */
PriorityQueue.prototype.enqueue = function(element) { enqueue(element) {
assert(!(this.keyFunction_(element) in this.queuedElements_), assert(!(this.keyFunction_(element) in this.queuedElements_),
31); // Tried to enqueue an `element` that was already added to the queue 31); // Tried to enqueue an `element` that was already added to the queue
const priority = this.priorityFunction_(element); const priority = this.priorityFunction_(element);
@@ -109,93 +111,93 @@ PriorityQueue.prototype.enqueue = function(element) {
return true; return true;
} }
return false; return false;
}; }
/** /**
* @return {number} Count. * @return {number} Count.
*/ */
PriorityQueue.prototype.getCount = function() { getCount() {
return this.elements_.length; return this.elements_.length;
}; }
/** /**
* Gets the index of the left child of the node at the given index. * Gets the index of the left child of the node at the given index.
* @param {number} index The index of the node to get the left child for. * @param {number} index The index of the node to get the left child for.
* @return {number} The index of the left child. * @return {number} The index of the left child.
* @private * @private
*/ */
PriorityQueue.prototype.getLeftChildIndex_ = function(index) { getLeftChildIndex_(index) {
return index * 2 + 1; return index * 2 + 1;
}; }
/** /**
* Gets the index of the right child of the node at the given index. * Gets the index of the right child of the node at the given index.
* @param {number} index The index of the node to get the right child for. * @param {number} index The index of the node to get the right child for.
* @return {number} The index of the right child. * @return {number} The index of the right child.
* @private * @private
*/ */
PriorityQueue.prototype.getRightChildIndex_ = function(index) { getRightChildIndex_(index) {
return index * 2 + 2; return index * 2 + 2;
}; }
/** /**
* Gets the index of the parent of the node at the given index. * Gets the index of the parent of the node at the given index.
* @param {number} index The index of the node to get the parent for. * @param {number} index The index of the node to get the parent for.
* @return {number} The index of the parent. * @return {number} The index of the parent.
* @private * @private
*/ */
PriorityQueue.prototype.getParentIndex_ = function(index) { getParentIndex_(index) {
return (index - 1) >> 1; return (index - 1) >> 1;
}; }
/** /**
* Make this a heap. O(N). * Make this a heap. O(N).
* @private * @private
*/ */
PriorityQueue.prototype.heapify_ = function() { heapify_() {
let i; let i;
for (i = (this.elements_.length >> 1) - 1; i >= 0; i--) { for (i = (this.elements_.length >> 1) - 1; i >= 0; i--) {
this.siftUp_(i); this.siftUp_(i);
} }
}; }
/** /**
* @return {boolean} Is empty. * @return {boolean} Is empty.
*/ */
PriorityQueue.prototype.isEmpty = function() { isEmpty() {
return this.elements_.length === 0; return this.elements_.length === 0;
}; }
/** /**
* @param {string} key Key. * @param {string} key Key.
* @return {boolean} Is key queued. * @return {boolean} Is key queued.
*/ */
PriorityQueue.prototype.isKeyQueued = function(key) { isKeyQueued(key) {
return key in this.queuedElements_; return key in this.queuedElements_;
}; }
/** /**
* @param {T} element Element. * @param {T} element Element.
* @return {boolean} Is queued. * @return {boolean} Is queued.
*/ */
PriorityQueue.prototype.isQueued = function(element) { isQueued(element) {
return this.isKeyQueued(this.keyFunction_(element)); return this.isKeyQueued(this.keyFunction_(element));
}; }
/** /**
* @param {number} index The index of the node to move down. * @param {number} index The index of the node to move down.
* @private * @private
*/ */
PriorityQueue.prototype.siftUp_ = function(index) { siftUp_(index) {
const elements = this.elements_; const elements = this.elements_;
const priorities = this.priorities_; const priorities = this.priorities_;
const count = elements.length; const count = elements.length;
@@ -219,15 +221,15 @@ PriorityQueue.prototype.siftUp_ = function(index) {
elements[index] = element; elements[index] = element;
priorities[index] = priority; priorities[index] = priority;
this.siftDown_(startIndex, index); this.siftDown_(startIndex, index);
}; }
/** /**
* @param {number} startIndex The index of the root. * @param {number} startIndex The index of the root.
* @param {number} index The index of the node to move up. * @param {number} index The index of the node to move up.
* @private * @private
*/ */
PriorityQueue.prototype.siftDown_ = function(startIndex, index) { siftDown_(startIndex, index) {
const elements = this.elements_; const elements = this.elements_;
const priorities = this.priorities_; const priorities = this.priorities_;
const element = elements[index]; const element = elements[index];
@@ -245,13 +247,13 @@ PriorityQueue.prototype.siftDown_ = function(startIndex, index) {
} }
elements[index] = element; elements[index] = element;
priorities[index] = priority; priorities[index] = priority;
}; }
/** /**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
PriorityQueue.prototype.reprioritize = function() { reprioritize() {
const priorityFunction = this.priorityFunction_; const priorityFunction = this.priorityFunction_;
const elements = this.elements_; const elements = this.elements_;
const priorities = this.priorities_; const priorities = this.priorities_;
@@ -271,5 +273,9 @@ PriorityQueue.prototype.reprioritize = function() {
elements.length = index; elements.length = index;
priorities.length = index; priorities.length = index;
this.heapify_(); this.heapify_();
}; }
}
export default PriorityQueue; export default PriorityQueue;
+47 -42
View File
@@ -24,7 +24,9 @@ import {isEmpty} from '../obj.js';
* @struct * @struct
* @template T * @template T
*/ */
const RBush = function(opt_maxEntries) { class RBush {
constructor(opt_maxEntries) {
/** /**
* @private * @private
@@ -39,15 +41,14 @@ const RBush = function(opt_maxEntries) {
*/ */
this.items_ = {}; this.items_ = {};
}; }
/**
/**
* Insert a value into the RBush. * Insert a value into the RBush.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @param {T} value Value. * @param {T} value Value.
*/ */
RBush.prototype.insert = function(extent, value) { insert(extent, value) {
/** @type {module:ol/structs/RBush~Entry} */ /** @type {module:ol/structs/RBush~Entry} */
const item = { const item = {
minX: extent[0], minX: extent[0],
@@ -59,15 +60,15 @@ RBush.prototype.insert = function(extent, value) {
this.rbush_.insert(item); this.rbush_.insert(item);
this.items_[getUid(value)] = item; this.items_[getUid(value)] = item;
}; }
/** /**
* Bulk-insert values into the RBush. * Bulk-insert values into the RBush.
* @param {Array.<module:ol/extent~Extent>} extents Extents. * @param {Array.<module:ol/extent~Extent>} extents Extents.
* @param {Array.<T>} values Values. * @param {Array.<T>} values Values.
*/ */
RBush.prototype.load = function(extents, values) { load(extents, values) {
const items = new Array(values.length); const items = new Array(values.length);
for (let i = 0, l = values.length; i < l; i++) { for (let i = 0, l = values.length; i < l; i++) {
const extent = extents[i]; const extent = extents[i];
@@ -85,15 +86,15 @@ RBush.prototype.load = function(extents, values) {
this.items_[getUid(value)] = item; this.items_[getUid(value)] = item;
} }
this.rbush_.load(items); this.rbush_.load(items);
}; }
/** /**
* Remove a value from the RBush. * Remove a value from the RBush.
* @param {T} value Value. * @param {T} value Value.
* @return {boolean} Removed. * @return {boolean} Removed.
*/ */
RBush.prototype.remove = function(value) { remove(value) {
const uid = getUid(value); const uid = getUid(value);
// get the object in which the value was wrapped when adding to the // get the object in which the value was wrapped when adding to the
@@ -101,42 +102,42 @@ RBush.prototype.remove = function(value) {
const item = this.items_[uid]; const item = this.items_[uid];
delete this.items_[uid]; delete this.items_[uid];
return this.rbush_.remove(item) !== null; return this.rbush_.remove(item) !== null;
}; }
/** /**
* Update the extent of a value in the RBush. * Update the extent of a value in the RBush.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @param {T} value Value. * @param {T} value Value.
*/ */
RBush.prototype.update = function(extent, value) { update(extent, value) {
const item = this.items_[getUid(value)]; const item = this.items_[getUid(value)];
const bbox = [item.minX, item.minY, item.maxX, item.maxY]; const bbox = [item.minX, item.minY, item.maxX, item.maxY];
if (!equals(bbox, extent)) { if (!equals(bbox, extent)) {
this.remove(value); this.remove(value);
this.insert(extent, value); this.insert(extent, value);
} }
}; }
/** /**
* Return all values in the RBush. * Return all values in the RBush.
* @return {Array.<T>} All. * @return {Array.<T>} All.
*/ */
RBush.prototype.getAll = function() { getAll() {
const items = this.rbush_.all(); const items = this.rbush_.all();
return items.map(function(item) { return items.map(function(item) {
return item.value; return item.value;
}); });
}; }
/** /**
* Return all values in the given extent. * Return all values in the given extent.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @return {Array.<T>} All in extent. * @return {Array.<T>} All in extent.
*/ */
RBush.prototype.getInExtent = function(extent) { getInExtent(extent) {
/** @type {module:ol/structs/RBush~Entry} */ /** @type {module:ol/structs/RBush~Entry} */
const bbox = { const bbox = {
minX: extent[0], minX: extent[0],
@@ -148,10 +149,10 @@ RBush.prototype.getInExtent = function(extent) {
return items.map(function(item) { return items.map(function(item) {
return item.value; return item.value;
}); });
}; }
/** /**
* Calls a callback function with each value in the tree. * Calls a callback function with each value in the tree.
* If the callback returns a truthy value, this value is returned without * If the callback returns a truthy value, this value is returned without
* checking the rest of the tree. * checking the rest of the tree.
@@ -160,12 +161,12 @@ RBush.prototype.getInExtent = function(extent) {
* @return {*} Callback return value. * @return {*} Callback return value.
* @template S * @template S
*/ */
RBush.prototype.forEach = function(callback, opt_this) { forEach(callback, opt_this) {
return this.forEach_(this.getAll(), callback, opt_this); return this.forEach_(this.getAll(), callback, opt_this);
}; }
/** /**
* Calls a callback function with each value in the provided extent. * Calls a callback function with each value in the provided extent.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @param {function(this: S, T): *} callback Callback. * @param {function(this: S, T): *} callback Callback.
@@ -173,12 +174,12 @@ RBush.prototype.forEach = function(callback, opt_this) {
* @return {*} Callback return value. * @return {*} Callback return value.
* @template S * @template S
*/ */
RBush.prototype.forEachInExtent = function(extent, callback, opt_this) { forEachInExtent(extent, callback, opt_this) {
return this.forEach_(this.getInExtent(extent), callback, opt_this); return this.forEach_(this.getInExtent(extent), callback, opt_this);
}; }
/** /**
* @param {Array.<T>} values Values. * @param {Array.<T>} values Values.
* @param {function(this: S, T): *} callback Callback. * @param {function(this: S, T): *} callback Callback.
* @param {S=} opt_this The object to use as `this` in `callback`. * @param {S=} opt_this The object to use as `this` in `callback`.
@@ -186,7 +187,7 @@ RBush.prototype.forEachInExtent = function(extent, callback, opt_this) {
* @return {*} Callback return value. * @return {*} Callback return value.
* @template S * @template S
*/ */
RBush.prototype.forEach_ = function(values, callback, opt_this) { forEach_(values, callback, opt_this) {
let result; let result;
for (let i = 0, l = values.length; i < l; i++) { for (let i = 0, l = values.length; i < l; i++) {
result = callback.call(opt_this, values[i]); result = callback.call(opt_this, values[i]);
@@ -195,44 +196,48 @@ RBush.prototype.forEach_ = function(values, callback, opt_this) {
} }
} }
return result; return result;
}; }
/** /**
* @return {boolean} Is empty. * @return {boolean} Is empty.
*/ */
RBush.prototype.isEmpty = function() { isEmpty() {
return isEmpty(this.items_); return isEmpty(this.items_);
}; }
/** /**
* Remove all values from the RBush. * Remove all values from the RBush.
*/ */
RBush.prototype.clear = function() { clear() {
this.rbush_.clear(); this.rbush_.clear();
this.items_ = {}; this.items_ = {};
}; }
/** /**
* @param {module:ol/extent~Extent=} opt_extent Extent. * @param {module:ol/extent~Extent=} opt_extent Extent.
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
*/ */
RBush.prototype.getExtent = function(opt_extent) { getExtent(opt_extent) {
// FIXME add getExtent() to rbush // FIXME add getExtent() to rbush
const data = this.rbush_.data; const data = this.rbush_.data;
return createOrUpdate(data.minX, data.minY, data.maxX, data.maxY, opt_extent); return createOrUpdate(data.minX, data.minY, data.maxX, data.maxY, opt_extent);
}; }
/** /**
* @param {module:ol/structs/RBush} rbush R-Tree. * @param {module:ol/structs/RBush} rbush R-Tree.
*/ */
RBush.prototype.concat = function(rbush) { concat(rbush) {
this.rbush_.load(rbush.rbush_.all()); this.rbush_.load(rbush.rbush_.all());
for (const i in rbush.items_) { for (const i in rbush.items_) {
this.items_[i | 0] = rbush.items_[i | 0]; this.items_[i | 0] = rbush.items_[i | 0];
} }
}; }
}
export default RBush; export default RBush;
+17 -18
View File
@@ -38,7 +38,8 @@ import {createCanvasContext2D} from '../dom.js';
* edges overlap when being rendered). To avoid this we add a * edges overlap when being rendered). To avoid this we add a
* padding around each image. * padding around each image.
*/ */
const Atlas = function(size, space) { class Atlas {
constructor(size, space) {
/** /**
* @private * @private
@@ -69,19 +70,17 @@ const Atlas = function(size, space) {
* @type {HTMLCanvasElement} * @type {HTMLCanvasElement}
*/ */
this.canvas_ = this.context_.canvas; this.canvas_ = this.context_.canvas;
}; }
/**
/**
* @param {string} id The identifier of the entry to check. * @param {string} id The identifier of the entry to check.
* @return {?module:ol/style/Atlas~AtlasInfo} The atlas info. * @return {?module:ol/style/Atlas~AtlasInfo} The atlas info.
*/ */
Atlas.prototype.get = function(id) { get(id) {
return this.entries_[id] || null; return this.entries_[id] || null;
}; }
/**
/**
* @param {string} id The identifier of the entry to add. * @param {string} id The identifier of the entry to add.
* @param {number} width The width. * @param {number} width The width.
* @param {number} height The height. * @param {number} height The height.
@@ -91,7 +90,7 @@ Atlas.prototype.get = function(id) {
* `renderCallback`. * `renderCallback`.
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry. * @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry.
*/ */
Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) { add(id, width, height, renderCallback, opt_this) {
for (let i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) { for (let i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) {
const block = this.emptyBlocks_[i]; const block = this.emptyBlocks_[i];
if (block.width >= width + this.space_ && if (block.width >= width + this.space_ &&
@@ -117,17 +116,16 @@ Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) {
// there is no space for the new entry in this atlas // there is no space for the new entry in this atlas
return null; return null;
}; }
/**
/**
* @private * @private
* @param {number} index The index of the block. * @param {number} index The index of the block.
* @param {module:ol/style/Atlas~AtlasBlock} block The block to split. * @param {module:ol/style/Atlas~AtlasBlock} block The block to split.
* @param {number} width The width of the entry to insert. * @param {number} width The width of the entry to insert.
* @param {number} height The height of the entry to insert. * @param {number} height The height of the entry to insert.
*/ */
Atlas.prototype.split_ = function(index, block, width, height) { split_(index, block, width, height) {
const deltaWidth = block.width - width; const deltaWidth = block.width - width;
const deltaHeight = block.height - height; const deltaHeight = block.height - height;
@@ -173,10 +171,9 @@ Atlas.prototype.split_ = function(index, block, width, height) {
}; };
this.updateBlocks_(index, newBlock1, newBlock2); this.updateBlocks_(index, newBlock1, newBlock2);
} }
}; }
/**
/**
* Remove the old block and insert new blocks at the same array position. * Remove the old block and insert new blocks at the same array position.
* The new blocks are inserted at the same position, so that splitted * The new blocks are inserted at the same position, so that splitted
* blocks (that are potentially smaller) are filled first. * blocks (that are potentially smaller) are filled first.
@@ -185,7 +182,7 @@ Atlas.prototype.split_ = function(index, block, width, height) {
* @param {module:ol/style/Atlas~AtlasBlock} newBlock1 The 1st block to add. * @param {module:ol/style/Atlas~AtlasBlock} newBlock1 The 1st block to add.
* @param {module:ol/style/Atlas~AtlasBlock} newBlock2 The 2nd block to add. * @param {module:ol/style/Atlas~AtlasBlock} newBlock2 The 2nd block to add.
*/ */
Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) { updateBlocks_(index, newBlock1, newBlock2) {
const args = [index, 1]; const args = [index, 1];
if (newBlock1.width > 0 && newBlock1.height > 0) { if (newBlock1.width > 0 && newBlock1.height > 0) {
args.push(newBlock1); args.push(newBlock1);
@@ -194,5 +191,7 @@ Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) {
args.push(newBlock2); args.push(newBlock2);
} }
this.emptyBlocks_.splice.apply(this.emptyBlocks_, args); this.emptyBlocks_.splice.apply(this.emptyBlocks_, args);
}; }
}
export default Atlas; export default Atlas;
+20 -23
View File
@@ -58,7 +58,8 @@ const MAX_ATLAS_SIZE = -1;
* @api * @api
* @param {module:ol/style/AtlasManager~Options=} opt_options Options. * @param {module:ol/style/AtlasManager~Options=} opt_options Options.
*/ */
const AtlasManager = function(opt_options) { class AtlasManager {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -105,15 +106,14 @@ const AtlasManager = function(opt_options) {
* @type {Array.<module:ol/style/Atlas>} * @type {Array.<module:ol/style/Atlas>}
*/ */
this.hitAtlases_ = [new Atlas(this.currentHitSize_, this.space_)]; this.hitAtlases_ = [new Atlas(this.currentHitSize_, this.space_)];
}; }
/**
/**
* @param {string} id The identifier of the entry to check. * @param {string} id The identifier of the entry to check.
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the * @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the entry is not part of the atlas manager. * entry, or `null` if the entry is not part of the atlas manager.
*/ */
AtlasManager.prototype.getInfo = function(id) { getInfo(id) {
/** @type {?module:ol/style/Atlas~AtlasInfo} */ /** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.getInfo_(this.atlases_, id); const info = this.getInfo_(this.atlases_, id);
@@ -123,17 +123,16 @@ AtlasManager.prototype.getInfo = function(id) {
const hitInfo = /** @type {module:ol/style/Atlas~AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id)); const hitInfo = /** @type {module:ol/style/Atlas~AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id));
return this.mergeInfos_(info, hitInfo); return this.mergeInfos_(info, hitInfo);
}; }
/**
/**
* @private * @private
* @param {Array.<module:ol/style/Atlas>} atlases The atlases to search. * @param {Array.<module:ol/style/Atlas>} atlases The atlases to search.
* @param {string} id The identifier of the entry to check. * @param {string} id The identifier of the entry to check.
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry, * @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the entry is not part of the atlases. * or `null` if the entry is not part of the atlases.
*/ */
AtlasManager.prototype.getInfo_ = function(atlases, id) { getInfo_(atlases, id) {
for (let i = 0, ii = atlases.length; i < ii; ++i) { for (let i = 0, ii = atlases.length; i < ii; ++i) {
const atlas = atlases[i]; const atlas = atlases[i];
const info = atlas.get(id); const info = atlas.get(id);
@@ -142,10 +141,9 @@ AtlasManager.prototype.getInfo_ = function(atlases, id) {
} }
} }
return null; return null;
}; }
/**
/**
* @private * @private
* @param {module:ol/style/Atlas~AtlasInfo} info The info for the real image. * @param {module:ol/style/Atlas~AtlasInfo} info The info for the real image.
* @param {module:ol/style/Atlas~AtlasInfo} hitInfo The info for the hit-detection * @param {module:ol/style/Atlas~AtlasInfo} hitInfo The info for the hit-detection
@@ -153,7 +151,7 @@ AtlasManager.prototype.getInfo_ = function(atlases, id) {
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the * @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the entry is not part of the atlases. * entry, or `null` if the entry is not part of the atlases.
*/ */
AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) { mergeInfos_(info, hitInfo) {
return ( return (
/** @type {module:ol/style/AtlasManager~AtlasManagerInfo} */ ({ /** @type {module:ol/style/AtlasManager~AtlasManagerInfo} */ ({
offsetX: info.offsetX, offsetX: info.offsetX,
@@ -162,10 +160,9 @@ AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
hitImage: hitInfo.image hitImage: hitInfo.image
}) })
); );
}; }
/**
/**
* Add an image to the atlas manager. * Add an image to the atlas manager.
* *
* If an entry for the given id already exists, the entry will * If an entry for the given id already exists, the entry will
@@ -187,8 +184,7 @@ AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the * @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the image is too big. * entry, or `null` if the image is too big.
*/ */
AtlasManager.prototype.add = function(id, width, height, add(id, width, height, renderCallback, opt_renderHitCallback, opt_this) {
renderCallback, opt_renderHitCallback, opt_this) {
if (width + this.space_ > this.maxSize_ || if (width + this.space_ > this.maxSize_ ||
height + this.space_ > this.maxSize_) { height + this.space_ > this.maxSize_) {
return null; return null;
@@ -210,10 +206,9 @@ AtlasManager.prototype.add = function(id, width, height,
id, width, height, renderHitCallback, opt_this)); id, width, height, renderHitCallback, opt_this));
return this.mergeInfos_(info, hitInfo); return this.mergeInfos_(info, hitInfo);
}; }
/**
/**
* @private * @private
* @param {boolean} isHitAtlas If the hit-detection atlases are used. * @param {boolean} isHitAtlas If the hit-detection atlases are used.
* @param {string} id The identifier of the entry to add. * @param {string} id The identifier of the entry to add.
@@ -226,7 +221,7 @@ AtlasManager.prototype.add = function(id, width, height,
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry, * @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the image is too big. * or `null` if the image is too big.
*/ */
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, renderCallback, opt_this) { add_(isHitAtlas, id, width, height, renderCallback, opt_this) {
const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_; const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_;
let atlas, info, i, ii; let atlas, info, i, ii;
for (i = 0, ii = atlases.length; i < ii; ++i) { for (i = 0, ii = atlases.length; i < ii; ++i) {
@@ -252,5 +247,7 @@ AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, renderCall
} }
} }
return null; return null;
}; }
}
export default AtlasManager; export default AtlasManager;
+14 -12
View File
@@ -29,7 +29,8 @@ import RegularShape from '../style/RegularShape.js';
* @extends {module:ol/style/RegularShape} * @extends {module:ol/style/RegularShape}
* @api * @api
*/ */
const CircleStyle = function(opt_options) { class CircleStyle {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -42,18 +43,15 @@ const CircleStyle = function(opt_options) {
atlasManager: options.atlasManager atlasManager: options.atlasManager
}); });
}; }
inherits(CircleStyle, RegularShape); /**
/**
* 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
*/ */
CircleStyle.prototype.clone = function() { 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,
@@ -64,17 +62,21 @@ CircleStyle.prototype.clone = function() {
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
*/ */
CircleStyle.prototype.setRadius = function(radius) { setRadius(radius) {
this.radius_ = radius; this.radius_ = radius;
this.render_(this.atlasManager_); this.render_(this.atlasManager_);
}; }
}
inherits(CircleStyle, RegularShape);
export default CircleStyle; export default CircleStyle;
+17 -18
View File
@@ -21,7 +21,8 @@ import {asString} from '../color.js';
* @param {module:ol/style/Fill~Options=} opt_options Options. * @param {module:ol/style/Fill~Options=} opt_options Options.
* @api * @api
*/ */
const Fill = function(opt_options) { class Fill {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -36,48 +37,44 @@ const Fill = function(opt_options) {
* @type {string|undefined} * @type {string|undefined}
*/ */
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Clones the style. The color is not cloned if it is an {@link module:ol/colorlike~ColorLike}. * Clones the style. The color is not cloned if it is an {@link module:ol/colorlike~ColorLike}.
* @return {module:ol/style/Fill} The cloned style. * @return {module:ol/style/Fill} The cloned style.
* @api * @api
*/ */
Fill.prototype.clone = function() { clone() {
const color = this.getColor(); const color = this.getColor();
return new Fill({ return new Fill({
color: (color && color.slice) ? color.slice() : color || undefined color: (color && color.slice) ? color.slice() : color || undefined
}); });
}; }
/**
/**
* Get the fill color. * Get the fill color.
* @return {module:ol/color~Color|module:ol/colorlike~ColorLike} Color. * @return {module:ol/color~Color|module:ol/colorlike~ColorLike} Color.
* @api * @api
*/ */
Fill.prototype.getColor = function() { getColor() {
return this.color_; return this.color_;
}; }
/**
/**
* Set the color. * Set the color.
* *
* @param {module:ol/color~Color|module:ol/colorlike~ColorLike} color Color. * @param {module:ol/color~Color|module:ol/colorlike~ColorLike} color Color.
* @api * @api
*/ */
Fill.prototype.setColor = function(color) { setColor(color) {
this.color_ = color; this.color_ = color;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* @return {string} The checksum. * @return {string} The checksum.
*/ */
Fill.prototype.getChecksum = function() { getChecksum() {
if (this.checksum_ === undefined) { if (this.checksum_ === undefined) {
if ( if (
this.color_ instanceof CanvasPattern || this.color_ instanceof CanvasPattern ||
@@ -90,5 +87,7 @@ Fill.prototype.getChecksum = function() {
} }
return this.checksum_; return this.checksum_;
}; }
}
export default Fill; export default Fill;
+53 -63
View File
@@ -61,7 +61,8 @@ import ImageStyle from '../style/Image.js';
* @extends {module:ol/style/Image} * @extends {module:ol/style/Image}
* @api * @api
*/ */
const Icon = function(opt_options) { class Icon {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -210,17 +211,14 @@ const Icon = function(opt_options) {
rotateWithView: rotateWithView rotateWithView: rotateWithView
}); });
}; }
inherits(Icon, ImageStyle); /**
/**
* Clones the style. The underlying Image/HTMLCanvasElement is not cloned. * Clones the style. The underlying Image/HTMLCanvasElement is not cloned.
* @return {module:ol/style/Icon} The cloned style. * @return {module:ol/style/Icon} The cloned style.
* @api * @api
*/ */
Icon.prototype.clone = function() { clone() {
return new Icon({ return new Icon({
anchor: this.anchor_.slice(), anchor: this.anchor_.slice(),
anchorOrigin: this.anchorOrigin_, anchorOrigin: this.anchorOrigin_,
@@ -238,14 +236,13 @@ Icon.prototype.clone = function() {
rotation: this.getRotation(), rotation: this.getRotation(),
rotateWithView: this.getRotateWithView() rotateWithView: this.getRotateWithView()
}); });
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
Icon.prototype.getAnchor = function() { getAnchor() {
if (this.normalizedAnchor_) { if (this.normalizedAnchor_) {
return this.normalizedAnchor_; return this.normalizedAnchor_;
} }
@@ -283,80 +280,73 @@ Icon.prototype.getAnchor = function() {
} }
this.normalizedAnchor_ = anchor; this.normalizedAnchor_ = anchor;
return this.normalizedAnchor_; return this.normalizedAnchor_;
}; }
/** /**
* Set the anchor point. The anchor determines the center point for the * Set the anchor point. The anchor determines the center point for the
* symbolizer. * symbolizer.
* *
* @param {Array.<number>} anchor Anchor. * @param {Array.<number>} anchor Anchor.
* @api * @api
*/ */
Icon.prototype.setAnchor = function(anchor) { setAnchor(anchor) {
this.anchor_ = anchor; this.anchor_ = anchor;
this.normalizedAnchor_ = null; this.normalizedAnchor_ = null;
}; }
/**
/**
* Get the icon color. * Get the icon color.
* @return {module:ol/color~Color} Color. * @return {module:ol/color~Color} Color.
* @api * @api
*/ */
Icon.prototype.getColor = function() { getColor() {
return this.color_; return this.color_;
}; }
/**
/**
* Get the image icon. * Get the image icon.
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element. * @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element.
* @override * @override
* @api * @api
*/ */
Icon.prototype.getImage = function(pixelRatio) { getImage(pixelRatio) {
return this.iconImage_.getImage(pixelRatio); return this.iconImage_.getImage(pixelRatio);
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.getImageSize = function() { getImageSize() {
return this.iconImage_.getSize(); return this.iconImage_.getSize();
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.getHitDetectionImageSize = function() { getHitDetectionImageSize() {
return this.getImageSize(); return this.getImageSize();
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.getImageState = function() { getImageState() {
return this.iconImage_.getImageState(); return this.iconImage_.getImageState();
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.getHitDetectionImage = function(pixelRatio) { getHitDetectionImage(pixelRatio) {
return this.iconImage_.getHitDetectionImage(pixelRatio); return this.iconImage_.getHitDetectionImage(pixelRatio);
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
Icon.prototype.getOrigin = function() { getOrigin() {
if (this.origin_) { if (this.origin_) {
return this.origin_; return this.origin_;
} }
@@ -380,38 +370,34 @@ Icon.prototype.getOrigin = function() {
} }
this.origin_ = offset; this.origin_ = offset;
return this.origin_; return this.origin_;
}; }
/**
/**
* Get the image URL. * Get the image URL.
* @return {string|undefined} Image src. * @return {string|undefined} Image src.
* @api * @api
*/ */
Icon.prototype.getSrc = function() { getSrc() {
return this.iconImage_.getSrc(); return this.iconImage_.getSrc();
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
Icon.prototype.getSize = function() { getSize() {
return !this.size_ ? this.iconImage_.getSize() : this.size_; return !this.size_ ? this.iconImage_.getSize() : this.size_;
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.listenImageChange = function(listener, thisArg) { listenImageChange(listener, thisArg) {
return listen(this.iconImage_, EventType.CHANGE, return listen(this.iconImage_, EventType.CHANGE,
listener, thisArg); listener, thisArg);
}; }
/**
/**
* Load not yet loaded URI. * Load not yet loaded URI.
* When rendering a feature with an icon style, the vector renderer will * When rendering a feature with an icon style, the vector renderer will
* automatically call this method. However, you might want to call this * automatically call this method. However, you might want to call this
@@ -419,16 +405,20 @@ Icon.prototype.listenImageChange = function(listener, thisArg) {
* @override * @override
* @api * @api
*/ */
Icon.prototype.load = function() { load() {
this.iconImage_.load(); this.iconImage_.load();
}; }
/**
/**
* @override * @override
*/ */
Icon.prototype.unlistenImageChange = function(listener, thisArg) { unlistenImageChange(listener, thisArg) {
unlisten(this.iconImage_, EventType.CHANGE, unlisten(this.iconImage_, EventType.CHANGE,
listener, thisArg); listener, thisArg);
}; }
}
inherits(Icon, ImageStyle);
export default Icon; export default Icon;
+155 -163
View File
@@ -19,7 +19,8 @@ import {shared as iconImageCache} from '../style/IconImageCache.js';
* @param {module:ol/color~Color} color Color. * @param {module:ol/color~Color} color Color.
* @extends {module:ol/events/EventTarget} * @extends {module:ol/events/EventTarget}
*/ */
const IconImage = function(image, src, size, crossOrigin, imageState, color) { class IconImage {
constructor(image, src, size, crossOrigin, imageState, color) {
EventTarget.call(this); EventTarget.call(this);
@@ -86,7 +87,159 @@ const IconImage = function(image, src, size, crossOrigin, imageState, color) {
this.determineTainting_(); this.determineTainting_();
} }
}; }
/**
* @private
*/
determineTainting_() {
const context = createCanvasContext2D(1, 1);
try {
context.drawImage(this.image_, 0, 0);
context.getImageData(0, 0, 1, 1);
} catch (e) {
this.tainting_ = true;
}
}
/**
* @private
*/
dispatchChangeEvent_() {
this.dispatchEvent(EventType.CHANGE);
}
/**
* @private
*/
handleImageError_() {
this.imageState_ = ImageState.ERROR;
this.unlistenImage_();
this.dispatchChangeEvent_();
}
/**
* @private
*/
handleImageLoad_() {
this.imageState_ = ImageState.LOADED;
if (this.size_) {
this.image_.width = this.size_[0];
this.image_.height = this.size_[1];
}
this.size_ = [this.image_.width, this.image_.height];
this.unlistenImage_();
this.determineTainting_();
this.replaceColor_();
this.dispatchChangeEvent_();
}
/**
* @param {number} pixelRatio Pixel ratio.
* @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element.
*/
getImage(pixelRatio) {
return this.canvas_ ? this.canvas_ : this.image_;
}
/**
* @return {module:ol/ImageState} Image state.
*/
getImageState() {
return this.imageState_;
}
/**
* @param {number} pixelRatio Pixel ratio.
* @return {HTMLImageElement|HTMLCanvasElement} Image element.
*/
getHitDetectionImage(pixelRatio) {
if (!this.hitDetectionImage_) {
if (this.tainting_) {
const width = this.size_[0];
const height = this.size_[1];
const context = createCanvasContext2D(width, height);
context.fillRect(0, 0, width, height);
this.hitDetectionImage_ = context.canvas;
} else {
this.hitDetectionImage_ = this.image_;
}
}
return this.hitDetectionImage_;
}
/**
* @return {module:ol/size~Size} Image size.
*/
getSize() {
return this.size_;
}
/**
* @return {string|undefined} Image src.
*/
getSrc() {
return this.src_;
}
/**
* Load not yet loaded URI.
*/
load() {
if (this.imageState_ == ImageState.IDLE) {
this.imageState_ = ImageState.LOADING;
this.imageListenerKeys_ = [
listenOnce(this.image_, EventType.ERROR,
this.handleImageError_, this),
listenOnce(this.image_, EventType.LOAD,
this.handleImageLoad_, this)
];
try {
this.image_.src = this.src_;
} catch (e) {
this.handleImageError_();
}
}
}
/**
* @private
*/
replaceColor_() {
if (this.tainting_ || this.color_ === null) {
return;
}
this.canvas_.width = this.image_.width;
this.canvas_.height = this.image_.height;
const ctx = this.canvas_.getContext('2d');
ctx.drawImage(this.image_, 0, 0);
const imgData = ctx.getImageData(0, 0, this.image_.width, this.image_.height);
const data = imgData.data;
const r = this.color_[0] / 255.0;
const g = this.color_[1] / 255.0;
const b = this.color_[2] / 255.0;
for (let i = 0, ii = data.length; i < ii; i += 4) {
data[i] *= r;
data[i + 1] *= g;
data[i + 2] *= b;
}
ctx.putImageData(imgData, 0, 0);
}
/**
* Discards event handlers which listen for load completion or errors.
*
* @private
*/
unlistenImage_() {
this.imageListenerKeys_.forEach(unlistenByKey);
this.imageListenerKeys_ = null;
}
}
inherits(IconImage, EventTarget); inherits(IconImage, EventTarget);
@@ -110,165 +263,4 @@ export function get(image, src, size, crossOrigin, imageState, color) {
} }
/**
* @private
*/
IconImage.prototype.determineTainting_ = function() {
const context = createCanvasContext2D(1, 1);
try {
context.drawImage(this.image_, 0, 0);
context.getImageData(0, 0, 1, 1);
} catch (e) {
this.tainting_ = true;
}
};
/**
* @private
*/
IconImage.prototype.dispatchChangeEvent_ = function() {
this.dispatchEvent(EventType.CHANGE);
};
/**
* @private
*/
IconImage.prototype.handleImageError_ = function() {
this.imageState_ = ImageState.ERROR;
this.unlistenImage_();
this.dispatchChangeEvent_();
};
/**
* @private
*/
IconImage.prototype.handleImageLoad_ = function() {
this.imageState_ = ImageState.LOADED;
if (this.size_) {
this.image_.width = this.size_[0];
this.image_.height = this.size_[1];
}
this.size_ = [this.image_.width, this.image_.height];
this.unlistenImage_();
this.determineTainting_();
this.replaceColor_();
this.dispatchChangeEvent_();
};
/**
* @param {number} pixelRatio Pixel ratio.
* @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element.
*/
IconImage.prototype.getImage = function(pixelRatio) {
return this.canvas_ ? this.canvas_ : this.image_;
};
/**
* @return {module:ol/ImageState} Image state.
*/
IconImage.prototype.getImageState = function() {
return this.imageState_;
};
/**
* @param {number} pixelRatio Pixel ratio.
* @return {HTMLImageElement|HTMLCanvasElement} Image element.
*/
IconImage.prototype.getHitDetectionImage = function(pixelRatio) {
if (!this.hitDetectionImage_) {
if (this.tainting_) {
const width = this.size_[0];
const height = this.size_[1];
const context = createCanvasContext2D(width, height);
context.fillRect(0, 0, width, height);
this.hitDetectionImage_ = context.canvas;
} else {
this.hitDetectionImage_ = this.image_;
}
}
return this.hitDetectionImage_;
};
/**
* @return {module:ol/size~Size} Image size.
*/
IconImage.prototype.getSize = function() {
return this.size_;
};
/**
* @return {string|undefined} Image src.
*/
IconImage.prototype.getSrc = function() {
return this.src_;
};
/**
* Load not yet loaded URI.
*/
IconImage.prototype.load = function() {
if (this.imageState_ == ImageState.IDLE) {
this.imageState_ = ImageState.LOADING;
this.imageListenerKeys_ = [
listenOnce(this.image_, EventType.ERROR,
this.handleImageError_, this),
listenOnce(this.image_, EventType.LOAD,
this.handleImageLoad_, this)
];
try {
this.image_.src = this.src_;
} catch (e) {
this.handleImageError_();
}
}
};
/**
* @private
*/
IconImage.prototype.replaceColor_ = function() {
if (this.tainting_ || this.color_ === null) {
return;
}
this.canvas_.width = this.image_.width;
this.canvas_.height = this.image_.height;
const ctx = this.canvas_.getContext('2d');
ctx.drawImage(this.image_, 0, 0);
const imgData = ctx.getImageData(0, 0, this.image_.width, this.image_.height);
const data = imgData.data;
const r = this.color_[0] / 255.0;
const g = this.color_[1] / 255.0;
const b = this.color_[2] / 255.0;
for (let i = 0, ii = data.length; i < ii; i += 4) {
data[i] *= r;
data[i + 1] *= g;
data[i + 2] *= b;
}
ctx.putImageData(imgData, 0, 0);
};
/**
* Discards event handlers which listen for load completion or errors.
*
* @private
*/
IconImage.prototype.unlistenImage_ = function() {
this.imageListenerKeys_.forEach(unlistenByKey);
this.imageListenerKeys_ = null;
};
export default IconImage; export default IconImage;
+63 -64
View File
@@ -7,7 +7,8 @@ import {asString} from '../color.js';
* Singleton class. Available through {@link module:ol/style/IconImageCache~shared}. * Singleton class. Available through {@link module:ol/style/IconImageCache~shared}.
* @constructor * @constructor
*/ */
const IconImageCache = function() { class IconImageCache {
constructor() {
/** /**
* @type {!Object.<string, module:ol/style/IconImage>} * @type {!Object.<string, module:ol/style/IconImage>}
@@ -26,7 +27,67 @@ const IconImageCache = function() {
* @private * @private
*/ */
this.maxCacheSize_ = 32; this.maxCacheSize_ = 32;
}; }
/**
* FIXME empty description for jsdoc
*/
clear() {
this.cache_ = {};
this.cacheSize_ = 0;
}
/**
* FIXME empty description for jsdoc
*/
expire() {
if (this.cacheSize_ > this.maxCacheSize_) {
let i = 0;
for (const key in this.cache_) {
const iconImage = this.cache_[key];
if ((i++ & 3) === 0 && !iconImage.hasListener()) {
delete this.cache_[key];
--this.cacheSize_;
}
}
}
}
/**
* @param {string} src Src.
* @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color.
* @return {module:ol/style/IconImage} Icon image.
*/
get(src, crossOrigin, color) {
const key = getKey(src, crossOrigin, color);
return key in this.cache_ ? this.cache_[key] : null;
}
/**
* @param {string} src Src.
* @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color.
* @param {module:ol/style/IconImage} iconImage Icon image.
*/
set(src, crossOrigin, color, iconImage) {
const key = getKey(src, crossOrigin, color);
this.cache_[key] = iconImage;
++this.cacheSize_;
}
/**
* 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
* styles on the application level.
* @param {number} maxCacheSize Cache max size.
* @api
*/
setSize(maxCacheSize) {
this.maxCacheSize_ = maxCacheSize;
this.expire();
}
}
/** /**
@@ -41,68 +102,6 @@ function getKey(src, crossOrigin, color) {
} }
/**
* FIXME empty description for jsdoc
*/
IconImageCache.prototype.clear = function() {
this.cache_ = {};
this.cacheSize_ = 0;
};
/**
* FIXME empty description for jsdoc
*/
IconImageCache.prototype.expire = function() {
if (this.cacheSize_ > this.maxCacheSize_) {
let i = 0;
for (const key in this.cache_) {
const iconImage = this.cache_[key];
if ((i++ & 3) === 0 && !iconImage.hasListener()) {
delete this.cache_[key];
--this.cacheSize_;
}
}
}
};
/**
* @param {string} src Src.
* @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color.
* @return {module:ol/style/IconImage} Icon image.
*/
IconImageCache.prototype.get = function(src, crossOrigin, color) {
const key = getKey(src, crossOrigin, color);
return key in this.cache_ ? this.cache_[key] : null;
};
/**
* @param {string} src Src.
* @param {?string} crossOrigin Cross origin.
* @param {module:ol/color~Color} color Color.
* @param {module:ol/style/IconImage} iconImage Icon image.
*/
IconImageCache.prototype.set = function(src, crossOrigin, color, iconImage) {
const key = getKey(src, crossOrigin, color);
this.cache_[key] = iconImage;
++this.cacheSize_;
};
/**
* 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
* styles on the application level.
* @param {number} maxCacheSize Cache max size.
* @api
*/
IconImageCache.prototype.setSize = function(maxCacheSize) {
this.maxCacheSize_ = maxCacheSize;
this.expire();
};
export default IconImageCache; export default IconImageCache;
+57 -75
View File
@@ -24,7 +24,8 @@
* @param {module:ol/style/Image~Options} options Options. * @param {module:ol/style/Image~Options} options Options.
* @api * @api
*/ */
const ImageStyle = function(options) { class ImageStyle {
constructor(options) {
/** /**
* @private * @private
@@ -56,199 +57,180 @@ const ImageStyle = function(options) {
*/ */
this.snapToPixel_ = options.snapToPixel; this.snapToPixel_ = options.snapToPixel;
}; }
/**
/**
* Get the symbolizer opacity. * Get the symbolizer opacity.
* @return {number} Opacity. * @return {number} Opacity.
* @api * @api
*/ */
ImageStyle.prototype.getOpacity = function() { 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
*/ */
ImageStyle.prototype.getRotateWithView = function() { getRotateWithView() {
return this.rotateWithView_; return this.rotateWithView_;
}; }
/**
/**
* Get the symoblizer rotation. * Get the symoblizer rotation.
* @return {number} Rotation. * @return {number} Rotation.
* @api * @api
*/ */
ImageStyle.prototype.getRotation = function() { getRotation() {
return this.rotation_; return this.rotation_;
}; }
/**
/**
* Get the symbolizer scale. * Get the symbolizer scale.
* @return {number} Scale. * @return {number} Scale.
* @api * @api
*/ */
ImageStyle.prototype.getScale = function() { 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
*/ */
ImageStyle.prototype.getSnapToPixel = function() { 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.
*/ */
ImageStyle.prototype.getAnchor = function() {}; 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.
*/ */
ImageStyle.prototype.getImage = function(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.
*/ */
ImageStyle.prototype.getHitDetectionImage = function(pixelRatio) {}; getHitDetectionImage(pixelRatio) {}
/**
/**
* @abstract * @abstract
* @return {module:ol/ImageState} Image state. * @return {module:ol/ImageState} Image state.
*/ */
ImageStyle.prototype.getImageState = function() {}; getImageState() {}
/**
/**
* @abstract * @abstract
* @return {module:ol/size~Size} Image size. * @return {module:ol/size~Size} Image size.
*/ */
ImageStyle.prototype.getImageSize = function() {}; 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.
*/ */
ImageStyle.prototype.getHitDetectionImageSize = function() {}; getHitDetectionImageSize() {}
/**
/**
* Get the origin of the symbolizer. * Get the origin of the symbolizer.
* @abstract * @abstract
* @return {Array.<number>} Origin. * @return {Array.<number>} Origin.
*/ */
ImageStyle.prototype.getOrigin = function() {}; 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.
*/ */
ImageStyle.prototype.getSize = function() {}; getSize() {}
/**
/**
* Set the opacity. * Set the opacity.
* *
* @param {number} opacity Opacity. * @param {number} opacity Opacity.
* @api * @api
*/ */
ImageStyle.prototype.setOpacity = function(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
*/ */
ImageStyle.prototype.setRotateWithView = function(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
*/ */
ImageStyle.prototype.setRotation = function(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
*/ */
ImageStyle.prototype.setScale = function(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
*/ */
ImageStyle.prototype.setSnapToPixel = function(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
*/ */
ImageStyle.prototype.listenImageChange = function(listener, thisArg) {}; listenImageChange(listener, thisArg) {}
/**
/**
* Load not yet loaded URI. * Load not yet loaded URI.
* @abstract * @abstract
*/ */
ImageStyle.prototype.load = function() {}; 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
*/ */
ImageStyle.prototype.unlistenImageChange = function(listener, thisArg) {}; unlistenImageChange(listener, thisArg) {}
}
export default ImageStyle; export default ImageStyle;
+74 -93
View File
@@ -57,7 +57,8 @@ import ImageStyle from '../style/Image.js';
* @extends {module:ol/style/Image} * @extends {module:ol/style/Image}
* @api * @api
*/ */
const RegularShape = function(options) { class RegularShape {
constructor(options) {
/** /**
* @private * @private
* @type {Array.<string>} * @type {Array.<string>}
@@ -170,17 +171,14 @@ const RegularShape = function(options) {
scale: 1, scale: 1,
snapToPixel: snapToPixel snapToPixel: snapToPixel
}); });
}; }
inherits(RegularShape, ImageStyle); /**
/**
* 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/RegularShape} The cloned style. * @return {module:ol/style/RegularShape} The cloned style.
* @api * @api
*/ */
RegularShape.prototype.clone = function() { clone() {
const style = new RegularShape({ const style = new RegularShape({
fill: this.getFill() ? this.getFill().clone() : undefined, fill: this.getFill() ? this.getFill().clone() : undefined,
points: this.getPoints(), points: this.getPoints(),
@@ -196,160 +194,142 @@ RegularShape.prototype.clone = function() {
style.setOpacity(this.getOpacity()); style.setOpacity(this.getOpacity());
style.setScale(this.getScale()); style.setScale(this.getScale());
return style; return style;
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
RegularShape.prototype.getAnchor = function() { getAnchor() {
return this.anchor_; return this.anchor_;
}; }
/**
/**
* Get the angle used in generating the shape. * Get the angle used in generating the shape.
* @return {number} Shape's rotation in radians. * @return {number} Shape's rotation in radians.
* @api * @api
*/ */
RegularShape.prototype.getAngle = function() { getAngle() {
return this.angle_; return this.angle_;
}; }
/**
/**
* Get the fill style for the shape. * Get the fill style for the shape.
* @return {module:ol/style/Fill} Fill style. * @return {module:ol/style/Fill} Fill style.
* @api * @api
*/ */
RegularShape.prototype.getFill = function() { getFill() {
return this.fill_; return this.fill_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.getHitDetectionImage = function(pixelRatio) { getHitDetectionImage(pixelRatio) {
return this.hitDetectionCanvas_; return this.hitDetectionCanvas_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
RegularShape.prototype.getImage = function(pixelRatio) { getImage(pixelRatio) {
return this.canvas_; return this.canvas_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.getImageSize = function() { getImageSize() {
return this.imageSize_; return this.imageSize_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.getHitDetectionImageSize = function() { getHitDetectionImageSize() {
return this.hitDetectionImageSize_; return this.hitDetectionImageSize_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.getImageState = function() { getImageState() {
return ImageState.LOADED; return ImageState.LOADED;
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
RegularShape.prototype.getOrigin = function() { getOrigin() {
return this.origin_; return this.origin_;
}; }
/**
/**
* Get the number of points for generating the shape. * Get the number of points for generating the shape.
* @return {number} Number of points for stars and regular polygons. * @return {number} Number of points for stars and regular polygons.
* @api * @api
*/ */
RegularShape.prototype.getPoints = function() { getPoints() {
return this.points_; return this.points_;
}; }
/**
/**
* Get the (primary) radius for the shape. * Get the (primary) radius for the shape.
* @return {number} Radius. * @return {number} Radius.
* @api * @api
*/ */
RegularShape.prototype.getRadius = function() { getRadius() {
return this.radius_; return this.radius_;
}; }
/**
/**
* Get the secondary radius for the shape. * Get the secondary radius for the shape.
* @return {number|undefined} Radius2. * @return {number|undefined} Radius2.
* @api * @api
*/ */
RegularShape.prototype.getRadius2 = function() { getRadius2() {
return this.radius2_; return this.radius2_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
RegularShape.prototype.getSize = function() { getSize() {
return this.size_; return this.size_;
}; }
/**
/**
* Get the stroke style for the shape. * Get the stroke style for the shape.
* @return {module:ol/style/Stroke} Stroke style. * @return {module:ol/style/Stroke} Stroke style.
* @api * @api
*/ */
RegularShape.prototype.getStroke = function() { getStroke() {
return this.stroke_; return this.stroke_;
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.listenImageChange = function(listener, thisArg) {}; listenImageChange(listener, thisArg) {}
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.load = function() {}; load() {}
/**
/**
* @inheritDoc * @inheritDoc
*/ */
RegularShape.prototype.unlistenImageChange = function(listener, thisArg) {}; unlistenImageChange(listener, thisArg) {}
/**
/**
* @protected * @protected
* @param {module:ol/style/AtlasManager|undefined} atlasManager An atlas manager. * @param {module:ol/style/AtlasManager|undefined} atlasManager An atlas manager.
*/ */
RegularShape.prototype.render_ = function(atlasManager) { render_(atlasManager) {
let imageSize; let imageSize;
let lineCap = ''; let lineCap = '';
let lineJoin = ''; let lineJoin = '';
@@ -449,17 +429,16 @@ RegularShape.prototype.render_ = function(atlasManager) {
this.anchor_ = [size / 2, size / 2]; this.anchor_ = [size / 2, size / 2];
this.size_ = [size, size]; this.size_ = [size, size];
this.imageSize_ = [imageSize, imageSize]; this.imageSize_ = [imageSize, imageSize];
}; }
/**
/**
* @private * @private
* @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options. * @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options.
* @param {CanvasRenderingContext2D} context The rendering context. * @param {CanvasRenderingContext2D} context The rendering context.
* @param {number} x The origin for the symbol (x). * @param {number} x The origin for the symbol (x).
* @param {number} y The origin for the symbol (y). * @param {number} y The origin for the symbol (y).
*/ */
RegularShape.prototype.draw_ = function(renderOptions, context, x, y) { draw_(renderOptions, context, x, y) {
let i, angle0, radiusC; let i, angle0, radiusC;
// reset transform // reset transform
context.setTransform(1, 0, 0, 1, 0, 0); context.setTransform(1, 0, 0, 1, 0, 0);
@@ -510,14 +489,13 @@ RegularShape.prototype.draw_ = function(renderOptions, context, x, y) {
context.stroke(); context.stroke();
} }
context.closePath(); context.closePath();
}; }
/**
/**
* @private * @private
* @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options. * @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options.
*/ */
RegularShape.prototype.createHitDetectionCanvas_ = function(renderOptions) { createHitDetectionCanvas_(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size]; this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
if (this.fill_) { if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_; this.hitDetectionCanvas_ = this.canvas_;
@@ -530,17 +508,16 @@ RegularShape.prototype.createHitDetectionCanvas_ = function(renderOptions) {
this.hitDetectionCanvas_ = context.canvas; this.hitDetectionCanvas_ = context.canvas;
this.drawHitDetectionCanvas_(renderOptions, context, 0, 0); this.drawHitDetectionCanvas_(renderOptions, context, 0, 0);
}; }
/**
/**
* @private * @private
* @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options. * @param {module:ol/style/RegularShape~RenderOptions} renderOptions Render options.
* @param {CanvasRenderingContext2D} context The context. * @param {CanvasRenderingContext2D} context The context.
* @param {number} x The origin for the symbol (x). * @param {number} x The origin for the symbol (x).
* @param {number} y The origin for the symbol (y). * @param {number} y The origin for the symbol (y).
*/ */
RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions, context, x, y) { drawHitDetectionCanvas_(renderOptions, context, x, y) {
// reset transform // reset transform
context.setTransform(1, 0, 0, 1, 0, 0); context.setTransform(1, 0, 0, 1, 0, 0);
@@ -581,13 +558,12 @@ RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions, context
context.stroke(); context.stroke();
} }
context.closePath(); context.closePath();
}; }
/**
/**
* @return {string} The checksum. * @return {string} The checksum.
*/ */
RegularShape.prototype.getChecksum = function() { getChecksum() {
const strokeChecksum = this.stroke_ ? const strokeChecksum = this.stroke_ ?
this.stroke_.getChecksum() : '-'; this.stroke_.getChecksum() : '-';
const fillChecksum = this.fill_ ? const fillChecksum = this.fill_ ?
@@ -612,5 +588,10 @@ RegularShape.prototype.getChecksum = function() {
} }
return this.checksums_[0]; return this.checksums_[0];
}; }
}
inherits(RegularShape, ImageStyle);
export default RegularShape; export default RegularShape;
+53 -66
View File
@@ -31,7 +31,8 @@ import {getUid} from '../util.js';
* @param {module:ol/style/Stroke~Options=} opt_options Options. * @param {module:ol/style/Stroke~Options=} opt_options Options.
* @api * @api
*/ */
const Stroke = function(opt_options) { class Stroke {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -82,15 +83,14 @@ const Stroke = function(opt_options) {
* @type {string|undefined} * @type {string|undefined}
*/ */
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Clones the style. * Clones the style.
* @return {module:ol/style/Stroke} The cloned style. * @return {module:ol/style/Stroke} The cloned style.
* @api * @api
*/ */
Stroke.prototype.clone = function() { clone() {
const color = this.getColor(); const color = this.getColor();
return new Stroke({ return new Stroke({
color: (color && color.slice) ? color.slice() : color || undefined, color: (color && color.slice) ? color.slice() : color || undefined,
@@ -101,104 +101,94 @@ Stroke.prototype.clone = function() {
miterLimit: this.getMiterLimit(), miterLimit: this.getMiterLimit(),
width: this.getWidth() width: this.getWidth()
}); });
}; }
/**
/**
* Get the stroke color. * Get the stroke color.
* @return {module:ol/color~Color|module:ol/colorlike~ColorLike} Color. * @return {module:ol/color~Color|module:ol/colorlike~ColorLike} Color.
* @api * @api
*/ */
Stroke.prototype.getColor = function() { getColor() {
return this.color_; return this.color_;
}; }
/**
/**
* Get the line cap type for the stroke. * Get the line cap type for the stroke.
* @return {string|undefined} Line cap. * @return {string|undefined} Line cap.
* @api * @api
*/ */
Stroke.prototype.getLineCap = function() { getLineCap() {
return this.lineCap_; return this.lineCap_;
}; }
/**
/**
* Get the line dash style for the stroke. * Get the line dash style for the stroke.
* @return {Array.<number>} Line dash. * @return {Array.<number>} Line dash.
* @api * @api
*/ */
Stroke.prototype.getLineDash = function() { getLineDash() {
return this.lineDash_; return this.lineDash_;
}; }
/**
/**
* Get the line dash offset for the stroke. * Get the line dash offset for the stroke.
* @return {number|undefined} Line dash offset. * @return {number|undefined} Line dash offset.
* @api * @api
*/ */
Stroke.prototype.getLineDashOffset = function() { getLineDashOffset() {
return this.lineDashOffset_; return this.lineDashOffset_;
}; }
/**
/**
* Get the line join type for the stroke. * Get the line join type for the stroke.
* @return {string|undefined} Line join. * @return {string|undefined} Line join.
* @api * @api
*/ */
Stroke.prototype.getLineJoin = function() { getLineJoin() {
return this.lineJoin_; return this.lineJoin_;
}; }
/**
/**
* Get the miter limit for the stroke. * Get the miter limit for the stroke.
* @return {number|undefined} Miter limit. * @return {number|undefined} Miter limit.
* @api * @api
*/ */
Stroke.prototype.getMiterLimit = function() { getMiterLimit() {
return this.miterLimit_; return this.miterLimit_;
}; }
/**
/**
* Get the stroke width. * Get the stroke width.
* @return {number|undefined} Width. * @return {number|undefined} Width.
* @api * @api
*/ */
Stroke.prototype.getWidth = function() { getWidth() {
return this.width_; return this.width_;
}; }
/**
/**
* Set the color. * Set the color.
* *
* @param {module:ol/color~Color|module:ol/colorlike~ColorLike} color Color. * @param {module:ol/color~Color|module:ol/colorlike~ColorLike} color Color.
* @api * @api
*/ */
Stroke.prototype.setColor = function(color) { setColor(color) {
this.color_ = color; this.color_ = color;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the line cap. * Set the line cap.
* *
* @param {string|undefined} lineCap Line cap. * @param {string|undefined} lineCap Line cap.
* @api * @api
*/ */
Stroke.prototype.setLineCap = function(lineCap) { setLineCap(lineCap) {
this.lineCap_ = lineCap; this.lineCap_ = lineCap;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the line dash. * Set the line dash.
* *
* Please note that Internet Explorer 10 and lower [do not support][mdn] the * Please note that Internet Explorer 10 and lower [do not support][mdn] the
@@ -210,64 +200,59 @@ Stroke.prototype.setLineCap = function(lineCap) {
* @param {Array.<number>} lineDash Line dash. * @param {Array.<number>} lineDash Line dash.
* @api * @api
*/ */
Stroke.prototype.setLineDash = function(lineDash) { setLineDash(lineDash) {
this.lineDash_ = lineDash; this.lineDash_ = lineDash;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the line dash offset. * Set the line dash offset.
* *
* @param {number|undefined} lineDashOffset Line dash offset. * @param {number|undefined} lineDashOffset Line dash offset.
* @api * @api
*/ */
Stroke.prototype.setLineDashOffset = function(lineDashOffset) { setLineDashOffset(lineDashOffset) {
this.lineDashOffset_ = lineDashOffset; this.lineDashOffset_ = lineDashOffset;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the line join. * Set the line join.
* *
* @param {string|undefined} lineJoin Line join. * @param {string|undefined} lineJoin Line join.
* @api * @api
*/ */
Stroke.prototype.setLineJoin = function(lineJoin) { setLineJoin(lineJoin) {
this.lineJoin_ = lineJoin; this.lineJoin_ = lineJoin;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the miter limit. * Set the miter limit.
* *
* @param {number|undefined} miterLimit Miter limit. * @param {number|undefined} miterLimit Miter limit.
* @api * @api
*/ */
Stroke.prototype.setMiterLimit = function(miterLimit) { setMiterLimit(miterLimit) {
this.miterLimit_ = miterLimit; this.miterLimit_ = miterLimit;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* Set the width. * Set the width.
* *
* @param {number|undefined} width Width. * @param {number|undefined} width Width.
* @api * @api
*/ */
Stroke.prototype.setWidth = function(width) { setWidth(width) {
this.width_ = width; this.width_ = width;
this.checksum_ = undefined; this.checksum_ = undefined;
}; }
/**
/**
* @return {string} The checksum. * @return {string} The checksum.
*/ */
Stroke.prototype.getChecksum = function() { getChecksum() {
if (this.checksum_ === undefined) { if (this.checksum_ === undefined) {
this.checksum_ = 's'; this.checksum_ = 's';
if (this.color_) { if (this.color_) {
@@ -295,5 +280,7 @@ Stroke.prototype.getChecksum = function() {
} }
return this.checksum_; return this.checksum_;
}; }
}
export default Stroke; export default Stroke;
+52 -66
View File
@@ -149,7 +149,8 @@ import Stroke from '../style/Stroke.js';
* @param {module:ol/style/Style~Options=} opt_options Style options. * @param {module:ol/style/Style~Options=} opt_options Style options.
* @api * @api
*/ */
const Style = function(opt_options) { class Style {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -205,15 +206,14 @@ const Style = function(opt_options) {
*/ */
this.zIndex_ = options.zIndex; this.zIndex_ = options.zIndex;
}; }
/**
/**
* Clones the style. * Clones the style.
* @return {module:ol/style/Style} The cloned style. * @return {module:ol/style/Style} The cloned style.
* @api * @api
*/ */
Style.prototype.clone = function() { clone() {
let geometry = this.getGeometry(); let geometry = this.getGeometry();
if (geometry && geometry.clone) { if (geometry && geometry.clone) {
geometry = geometry.clone(); geometry = geometry.clone();
@@ -226,145 +226,131 @@ Style.prototype.clone = function() {
text: this.getText() ? this.getText().clone() : undefined, text: this.getText() ? this.getText().clone() : undefined,
zIndex: this.getZIndex() zIndex: this.getZIndex()
}); });
}; }
/**
/**
* Get the custom renderer function that was configured with * Get the custom renderer function that was configured with
* {@link #setRenderer} or the `renderer` constructor option. * {@link #setRenderer} or the `renderer` constructor option.
* @return {module:ol/style/Style~RenderFunction|null} Custom renderer function. * @return {module:ol/style/Style~RenderFunction|null} Custom renderer function.
* @api * @api
*/ */
Style.prototype.getRenderer = function() { getRenderer() {
return this.renderer_; return this.renderer_;
}; }
/**
/**
* Sets a custom renderer function for this style. When set, `fill`, `stroke` * Sets a custom renderer function for this style. When set, `fill`, `stroke`
* and `image` options of the style will be ignored. * and `image` options of the style will be ignored.
* @param {module:ol/style/Style~RenderFunction|null} renderer Custom renderer function. * @param {module:ol/style/Style~RenderFunction|null} renderer Custom renderer function.
* @api * @api
*/ */
Style.prototype.setRenderer = function(renderer) { setRenderer(renderer) {
this.renderer_ = renderer; this.renderer_ = renderer;
}; }
/**
/**
* Get the geometry to be rendered. * Get the geometry to be rendered.
* @return {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction} * @return {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction}
* Feature property or geometry or function that returns the geometry that will * Feature property or geometry or function that returns the geometry that will
* be rendered with this style. * be rendered with this style.
* @api * @api
*/ */
Style.prototype.getGeometry = function() { getGeometry() {
return this.geometry_; return this.geometry_;
}; }
/**
/**
* Get the function used to generate a geometry for rendering. * Get the function used to generate a geometry for rendering.
* @return {!module:ol/style/Style~GeometryFunction} Function that is called with a feature * @return {!module:ol/style/Style~GeometryFunction} Function that is called with a feature
* and returns the geometry to render instead of the feature's geometry. * and returns the geometry to render instead of the feature's geometry.
* @api * @api
*/ */
Style.prototype.getGeometryFunction = function() { getGeometryFunction() {
return this.geometryFunction_; return this.geometryFunction_;
}; }
/**
/**
* Get the fill style. * Get the fill style.
* @return {module:ol/style/Fill} Fill style. * @return {module:ol/style/Fill} Fill style.
* @api * @api
*/ */
Style.prototype.getFill = function() { getFill() {
return this.fill_; return this.fill_;
}; }
/**
/**
* Set the fill style. * Set the fill style.
* @param {module:ol/style/Fill} fill Fill style. * @param {module:ol/style/Fill} fill Fill style.
* @api * @api
*/ */
Style.prototype.setFill = function(fill) { setFill(fill) {
this.fill_ = fill; this.fill_ = fill;
}; }
/**
/**
* Get the image style. * Get the image style.
* @return {module:ol/style/Image} Image style. * @return {module:ol/style/Image} Image style.
* @api * @api
*/ */
Style.prototype.getImage = function() { getImage() {
return this.image_; return this.image_;
}; }
/**
/**
* Set the image style. * Set the image style.
* @param {module:ol/style/Image} image Image style. * @param {module:ol/style/Image} image Image style.
* @api * @api
*/ */
Style.prototype.setImage = function(image) { setImage(image) {
this.image_ = image; this.image_ = image;
}; }
/**
/**
* Get the stroke style. * Get the stroke style.
* @return {module:ol/style/Stroke} Stroke style. * @return {module:ol/style/Stroke} Stroke style.
* @api * @api
*/ */
Style.prototype.getStroke = function() { getStroke() {
return this.stroke_; return this.stroke_;
}; }
/**
/**
* Set the stroke style. * Set the stroke style.
* @param {module:ol/style/Stroke} stroke Stroke style. * @param {module:ol/style/Stroke} stroke Stroke style.
* @api * @api
*/ */
Style.prototype.setStroke = function(stroke) { setStroke(stroke) {
this.stroke_ = stroke; this.stroke_ = stroke;
}; }
/**
/**
* Get the text style. * Get the text style.
* @return {module:ol/style/Text} Text style. * @return {module:ol/style/Text} Text style.
* @api * @api
*/ */
Style.prototype.getText = function() { getText() {
return this.text_; return this.text_;
}; }
/**
/**
* Set the text style. * Set the text style.
* @param {module:ol/style/Text} text Text style. * @param {module:ol/style/Text} text Text style.
* @api * @api
*/ */
Style.prototype.setText = function(text) { setText(text) {
this.text_ = text; this.text_ = text;
}; }
/**
/**
* Get the z-index for the style. * Get the z-index for the style.
* @return {number|undefined} ZIndex. * @return {number|undefined} ZIndex.
* @api * @api
*/ */
Style.prototype.getZIndex = function() { getZIndex() {
return this.zIndex_; return this.zIndex_;
}; }
/**
/**
* Set a geometry that is rendered instead of the feature's geometry. * Set a geometry that is rendered instead of the feature's geometry.
* *
* @param {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction} geometry * @param {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction} geometry
@@ -372,7 +358,7 @@ Style.prototype.getZIndex = function() {
* for this style. * for this style.
* @api * @api
*/ */
Style.prototype.setGeometry = function(geometry) { setGeometry(geometry) {
if (typeof geometry === 'function') { if (typeof geometry === 'function') {
this.geometryFunction_ = geometry; this.geometryFunction_ = geometry;
} else if (typeof geometry === 'string') { } else if (typeof geometry === 'string') {
@@ -391,18 +377,18 @@ Style.prototype.setGeometry = function(geometry) {
}; };
} }
this.geometry_ = geometry; this.geometry_ = geometry;
}; }
/**
/**
* Set the z-index. * Set the z-index.
* *
* @param {number|undefined} zIndex ZIndex. * @param {number|undefined} zIndex ZIndex.
* @api * @api
*/ */
Style.prototype.setZIndex = function(zIndex) { setZIndex(zIndex) {
this.zIndex_ = zIndex; this.zIndex_ = zIndex;
}; }
}
/** /**
+107 -138
View File
@@ -53,7 +53,8 @@ const DEFAULT_FILL_COLOR = '#333';
* @param {module:ol/style/Text~Options=} opt_options Options. * @param {module:ol/style/Text~Options=} opt_options Options.
* @api * @api
*/ */
const Text = function(opt_options) { class Text {
constructor(opt_options) {
const options = opt_options || {}; const options = opt_options || {};
@@ -159,15 +160,14 @@ const Text = function(opt_options) {
* @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
*/ */
Text.prototype.clone = function() { clone() {
return new Text({ return new Text({
font: this.getFont(), font: this.getFont(),
placement: this.getPlacement(), placement: this.getPlacement(),
@@ -186,351 +186,320 @@ Text.prototype.clone = function() {
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
*/ */
Text.prototype.getOverflow = function() { 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
*/ */
Text.prototype.getFont = function() { 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
*/ */
Text.prototype.getMaxAngle = function() { 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
*/ */
Text.prototype.getPlacement = function() { 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
*/ */
Text.prototype.getOffsetX = function() { 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
*/ */
Text.prototype.getOffsetY = function() { 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
*/ */
Text.prototype.getFill = function() { 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
*/ */
Text.prototype.getRotateWithView = function() { 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
*/ */
Text.prototype.getRotation = function() { 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
*/ */
Text.prototype.getScale = function() { 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
*/ */
Text.prototype.getStroke = function() { 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
*/ */
Text.prototype.getText = function() { 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
*/ */
Text.prototype.getTextAlign = function() { 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
*/ */
Text.prototype.getTextBaseline = function() { 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
*/ */
Text.prototype.getBackgroundFill = function() { 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
*/ */
Text.prototype.getBackgroundStroke = function() { 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
*/ */
Text.prototype.getPadding = function() { 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
*/ */
Text.prototype.setOverflow = function(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
*/ */
Text.prototype.setFont = function(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
*/ */
Text.prototype.setMaxAngle = function(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
*/ */
Text.prototype.setOffsetX = function(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
*/ */
Text.prototype.setOffsetY = function(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
*/ */
Text.prototype.setPlacement = function(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
*/ */
Text.prototype.setFill = function(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
*/ */
Text.prototype.setRotation = function(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
*/ */
Text.prototype.setScale = function(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
*/ */
Text.prototype.setStroke = function(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
*/ */
Text.prototype.setText = function(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
*/ */
Text.prototype.setTextAlign = function(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
*/ */
Text.prototype.setTextBaseline = function(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
*/ */
Text.prototype.setBackgroundFill = function(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
*/ */
Text.prototype.setBackgroundStroke = function(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
*/ */
Text.prototype.setPadding = function(padding) { setPadding(padding) {
this.padding_ = padding; this.padding_ = padding;
}; }
}
export default Text; export default Text;
+79 -98
View File
@@ -47,7 +47,8 @@ import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js';
* @struct * @struct
* @api * @api
*/ */
const TileGrid = function(options) { class TileGrid {
constructor(options) {
/** /**
* @protected * @protected
@@ -175,17 +176,9 @@ const TileGrid = function(options) {
this.calculateTileRanges_(extent); this.calculateTileRanges_(extent);
} }
}; }
/**
/**
* @private
* @type {module:ol/tilecoord~TileCoord}
*/
const tmpTileCoord = [0, 0, 0];
/**
* Call a function with each tile coordinate for a given extent and zoom level. * Call a function with each tile coordinate for a given extent and zoom level.
* *
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
@@ -193,17 +186,16 @@ const tmpTileCoord = [0, 0, 0];
* @param {function(module:ol/tilecoord~TileCoord)} callback Function called with each tile coordinate. * @param {function(module:ol/tilecoord~TileCoord)} callback Function called with each tile coordinate.
* @api * @api
*/ */
TileGrid.prototype.forEachTileCoord = function(extent, zoom, callback) { forEachTileCoord(extent, zoom, callback) {
const tileRange = this.getTileRangeForExtentAndZ(extent, zoom); const tileRange = this.getTileRangeForExtentAndZ(extent, zoom);
for (let i = tileRange.minX, ii = tileRange.maxX; i <= ii; ++i) { for (let i = tileRange.minX, ii = tileRange.maxX; i <= ii; ++i) {
for (let j = tileRange.minY, jj = tileRange.maxY; j <= jj; ++j) { for (let j = tileRange.minY, jj = tileRange.maxY; j <= jj; ++j) {
callback([zoom, i, j]); callback([zoom, i, j]);
} }
} }
}; }
/**
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @param {function(this: T, number, module:ol/TileRange): boolean} callback Callback. * @param {function(this: T, number, module:ol/TileRange): boolean} callback Callback.
* @param {T=} opt_this The object to use as `this` in `callback`. * @param {T=} opt_this The object to use as `this` in `callback`.
@@ -212,7 +204,7 @@ TileGrid.prototype.forEachTileCoord = function(extent, zoom, callback) {
* @return {boolean} Callback succeeded. * @return {boolean} Callback succeeded.
* @template T * @template T
*/ */
TileGrid.prototype.forEachTileCoordParentTileRange = function(tileCoord, callback, opt_this, opt_tileRange, opt_extent) { forEachTileCoordParentTileRange(tileCoord, callback, opt_this, opt_tileRange, opt_extent) {
let tileRange, x, y; let tileRange, x, y;
let tileCoordExtent = null; let tileCoordExtent = null;
let z = tileCoord[0] - 1; let z = tileCoord[0] - 1;
@@ -236,81 +228,74 @@ TileGrid.prototype.forEachTileCoordParentTileRange = function(tileCoord, callbac
--z; --z;
} }
return false; return false;
}; }
/**
/**
* Get the extent for this tile grid, if it was configured. * Get the extent for this tile grid, if it was configured.
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
*/ */
TileGrid.prototype.getExtent = function() { getExtent() {
return this.extent_; return this.extent_;
}; }
/**
/**
* Get the maximum zoom level for the grid. * Get the maximum zoom level for the grid.
* @return {number} Max zoom. * @return {number} Max zoom.
* @api * @api
*/ */
TileGrid.prototype.getMaxZoom = function() { getMaxZoom() {
return this.maxZoom; return this.maxZoom;
}; }
/**
/**
* Get the minimum zoom level for the grid. * Get the minimum zoom level for the grid.
* @return {number} Min zoom. * @return {number} Min zoom.
* @api * @api
*/ */
TileGrid.prototype.getMinZoom = function() { getMinZoom() {
return this.minZoom; return this.minZoom;
}; }
/**
/**
* Get the origin for the grid at the given zoom level. * Get the origin for the grid at the given zoom level.
* @param {number} z Integer zoom level. * @param {number} z Integer zoom level.
* @return {module:ol/coordinate~Coordinate} Origin. * @return {module:ol/coordinate~Coordinate} Origin.
* @api * @api
*/ */
TileGrid.prototype.getOrigin = function(z) { getOrigin(z) {
if (this.origin_) { if (this.origin_) {
return this.origin_; return this.origin_;
} else { } else {
return this.origins_[z]; return this.origins_[z];
} }
}; }
/**
/**
* Get the resolution for the given zoom level. * Get the resolution for the given zoom level.
* @param {number} z Integer zoom level. * @param {number} z Integer zoom level.
* @return {number} Resolution. * @return {number} Resolution.
* @api * @api
*/ */
TileGrid.prototype.getResolution = function(z) { getResolution(z) {
return this.resolutions_[z]; return this.resolutions_[z];
}; }
/**
/**
* Get the list of resolutions for the tile grid. * Get the list of resolutions for the tile grid.
* @return {Array.<number>} Resolutions. * @return {Array.<number>} Resolutions.
* @api * @api
*/ */
TileGrid.prototype.getResolutions = function() { getResolutions() {
return this.resolutions_; return this.resolutions_;
}; }
/**
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @param {module:ol/TileRange=} opt_tileRange Temporary module:ol/TileRange object. * @param {module:ol/TileRange=} opt_tileRange Temporary module:ol/TileRange object.
* @param {module:ol/extent~Extent=} opt_extent Temporary module:ol/extent~Extent object. * @param {module:ol/extent~Extent=} opt_extent Temporary module:ol/extent~Extent object.
* @return {module:ol/TileRange} Tile range. * @return {module:ol/TileRange} Tile range.
*/ */
TileGrid.prototype.getTileCoordChildTileRange = function(tileCoord, opt_tileRange, opt_extent) { getTileCoordChildTileRange(tileCoord, opt_tileRange, opt_extent) {
if (tileCoord[0] < this.maxZoom) { if (tileCoord[0] < this.maxZoom) {
if (this.zoomFactor_ === 2) { if (this.zoomFactor_ === 2) {
const minX = tileCoord[1] * 2; const minX = tileCoord[1] * 2;
@@ -322,17 +307,16 @@ TileGrid.prototype.getTileCoordChildTileRange = function(tileCoord, opt_tileRang
tileCoordExtent, tileCoord[0] + 1, opt_tileRange); tileCoordExtent, tileCoord[0] + 1, opt_tileRange);
} }
return null; return null;
}; }
/**
/**
* Get the extent for a tile range. * Get the extent for a tile range.
* @param {number} z Integer zoom level. * @param {number} z Integer zoom level.
* @param {module:ol/TileRange} tileRange Tile range. * @param {module:ol/TileRange} tileRange Tile range.
* @param {module:ol/extent~Extent=} opt_extent Temporary module:ol/extent~Extent object. * @param {module:ol/extent~Extent=} opt_extent Temporary module:ol/extent~Extent object.
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
*/ */
TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) { getTileRangeExtent(z, tileRange, opt_extent) {
const origin = this.getOrigin(z); const origin = this.getOrigin(z);
const resolution = this.getResolution(z); const resolution = this.getResolution(z);
const tileSize = toSize(this.getTileSize(z), this.tmpSize_); const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
@@ -341,31 +325,29 @@ TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) {
const minY = origin[1] + tileRange.minY * tileSize[1] * resolution; const minY = origin[1] + tileRange.minY * tileSize[1] * resolution;
const maxY = origin[1] + (tileRange.maxY + 1) * tileSize[1] * resolution; const maxY = origin[1] + (tileRange.maxY + 1) * tileSize[1] * resolution;
return createOrUpdate(minX, minY, maxX, maxY, opt_extent); return createOrUpdate(minX, minY, maxX, maxY, opt_extent);
}; }
/**
/**
* Get a tile range for the given extent and integer zoom level. * Get a tile range for the given extent and integer zoom level.
* @param {module:ol/extent~Extent} extent Extent. * @param {module:ol/extent~Extent} extent Extent.
* @param {number} z Integer zoom level. * @param {number} z Integer zoom level.
* @param {module:ol/TileRange=} opt_tileRange Temporary tile range object. * @param {module:ol/TileRange=} opt_tileRange Temporary tile range object.
* @return {module:ol/TileRange} Tile range. * @return {module:ol/TileRange} Tile range.
*/ */
TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange) { getTileRangeForExtentAndZ(extent, z, opt_tileRange) {
const tileCoord = tmpTileCoord; const tileCoord = tmpTileCoord;
this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord); this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord);
const minX = tileCoord[1]; const minX = tileCoord[1];
const minY = tileCoord[2]; const minY = tileCoord[2];
this.getTileCoordForXYAndZ_(extent[2], extent[3], z, true, tileCoord); this.getTileCoordForXYAndZ_(extent[2], extent[3], z, true, tileCoord);
return createOrUpdateTileRange(minX, tileCoord[1], minY, tileCoord[2], opt_tileRange); return createOrUpdateTileRange(minX, tileCoord[1], minY, tileCoord[2], opt_tileRange);
}; }
/**
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @return {module:ol/coordinate~Coordinate} Tile center. * @return {module:ol/coordinate~Coordinate} Tile center.
*/ */
TileGrid.prototype.getTileCoordCenter = function(tileCoord) { getTileCoordCenter(tileCoord) {
const origin = this.getOrigin(tileCoord[0]); const origin = this.getOrigin(tileCoord[0]);
const resolution = this.getResolution(tileCoord[0]); const resolution = this.getResolution(tileCoord[0]);
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_); const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
@@ -373,10 +355,9 @@ TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution, origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution,
origin[1] + (tileCoord[2] + 0.5) * tileSize[1] * resolution origin[1] + (tileCoord[2] + 0.5) * tileSize[1] * resolution
]; ];
}; }
/**
/**
* Get the extent of a tile coordinate. * Get the extent of a tile coordinate.
* *
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
@@ -384,7 +365,7 @@ TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
* @return {module:ol/extent~Extent} Extent. * @return {module:ol/extent~Extent} Extent.
* @api * @api
*/ */
TileGrid.prototype.getTileCoordExtent = function(tileCoord, opt_extent) { getTileCoordExtent(tileCoord, opt_extent) {
const origin = this.getOrigin(tileCoord[0]); const origin = this.getOrigin(tileCoord[0]);
const resolution = this.getResolution(tileCoord[0]); const resolution = this.getResolution(tileCoord[0]);
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_); const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
@@ -393,10 +374,9 @@ TileGrid.prototype.getTileCoordExtent = function(tileCoord, opt_extent) {
const maxX = minX + tileSize[0] * resolution; const maxX = minX + tileSize[0] * resolution;
const maxY = minY + tileSize[1] * resolution; const maxY = minY + tileSize[1] * resolution;
return createOrUpdate(minX, minY, maxX, maxY, opt_extent); return createOrUpdate(minX, minY, maxX, maxY, opt_extent);
}; }
/**
/**
* Get the tile coordinate for the given map coordinate and resolution. This * Get the tile coordinate for the given map coordinate and resolution. This
* method considers that coordinates that intersect tile boundaries should be * method considers that coordinates that intersect tile boundaries should be
* assigned the higher tile coordinate. * assigned the higher tile coordinate.
@@ -407,13 +387,12 @@ TileGrid.prototype.getTileCoordExtent = function(tileCoord, opt_extent) {
* @return {module:ol/tilecoord~TileCoord} Tile coordinate. * @return {module:ol/tilecoord~TileCoord} Tile coordinate.
* @api * @api
*/ */
TileGrid.prototype.getTileCoordForCoordAndResolution = function(coordinate, resolution, opt_tileCoord) { getTileCoordForCoordAndResolution(coordinate, resolution, opt_tileCoord) {
return this.getTileCoordForXYAndResolution_( return this.getTileCoordForXYAndResolution_(
coordinate[0], coordinate[1], resolution, false, opt_tileCoord); coordinate[0], coordinate[1], resolution, false, opt_tileCoord);
}; }
/**
/**
* Note that this method should not be called for resolutions that correspond * Note that this method should not be called for resolutions that correspond
* to an integer zoom level. Instead call the `getTileCoordForXYAndZ_` method. * to an integer zoom level. Instead call the `getTileCoordForXYAndZ_` method.
* @param {number} x X. * @param {number} x X.
@@ -426,8 +405,7 @@ TileGrid.prototype.getTileCoordForCoordAndResolution = function(coordinate, reso
* @return {module:ol/tilecoord~TileCoord} Tile coordinate. * @return {module:ol/tilecoord~TileCoord} Tile coordinate.
* @private * @private
*/ */
TileGrid.prototype.getTileCoordForXYAndResolution_ = function( getTileCoordForXYAndResolution_(x, y, resolution, reverseIntersectionPolicy, opt_tileCoord) {
x, y, resolution, reverseIntersectionPolicy, opt_tileCoord) {
const z = this.getZForResolution(resolution); const z = this.getZForResolution(resolution);
const scale = resolution / this.getResolution(z); const scale = resolution / this.getResolution(z);
const origin = this.getOrigin(z); const origin = this.getOrigin(z);
@@ -449,10 +427,9 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
} }
return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord); return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord);
}; }
/**
/**
* Although there is repetition between this method and `getTileCoordForXYAndResolution_`, * Although there is repetition between this method and `getTileCoordForXYAndResolution_`,
* they should have separate implementations. This method is for integer zoom * they should have separate implementations. This method is for integer zoom
* levels. The other method should only be called for resolutions corresponding * levels. The other method should only be called for resolutions corresponding
@@ -467,7 +444,7 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
* @return {module:ol/tilecoord~TileCoord} Tile coordinate. * @return {module:ol/tilecoord~TileCoord} Tile coordinate.
* @private * @private
*/ */
TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectionPolicy, opt_tileCoord) { getTileCoordForXYAndZ_(x, y, z, reverseIntersectionPolicy, opt_tileCoord) {
const origin = this.getOrigin(z); const origin = this.getOrigin(z);
const resolution = this.getResolution(z); const resolution = this.getResolution(z);
const tileSize = toSize(this.getTileSize(z), this.tmpSize_); const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
@@ -488,10 +465,9 @@ TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectio
} }
return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord); return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord);
}; }
/**
/**
* Get a tile coordinate given a map coordinate and zoom level. * Get a tile coordinate given a map coordinate and zoom level.
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate. * @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
* @param {number} z Zoom level. * @param {number} z Zoom level.
@@ -499,22 +475,20 @@ TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectio
* @return {module:ol/tilecoord~TileCoord} Tile coordinate. * @return {module:ol/tilecoord~TileCoord} Tile coordinate.
* @api * @api
*/ */
TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z, opt_tileCoord) { getTileCoordForCoordAndZ(coordinate, z, opt_tileCoord) {
return this.getTileCoordForXYAndZ_( return this.getTileCoordForXYAndZ_(
coordinate[0], coordinate[1], z, false, opt_tileCoord); coordinate[0], coordinate[1], z, false, opt_tileCoord);
}; }
/**
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate. * @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @return {number} Tile resolution. * @return {number} Tile resolution.
*/ */
TileGrid.prototype.getTileCoordResolution = function(tileCoord) { getTileCoordResolution(tileCoord) {
return this.resolutions_[tileCoord[0]]; return this.resolutions_[tileCoord[0]];
}; }
/**
/**
* Get the tile size for a zoom level. The type of the return value matches the * Get the tile size for a zoom level. The type of the return value matches the
* `tileSize` or `tileSizes` that the tile grid was configured with. To always * `tileSize` or `tileSizes` that the tile grid was configured with. To always
* get an `module:ol/size~Size`, run the result through `module:ol/size~Size.toSize()`. * get an `module:ol/size~Size`, run the result through `module:ol/size~Size.toSize()`.
@@ -522,29 +496,27 @@ TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
* @return {number|module:ol/size~Size} Tile size. * @return {number|module:ol/size~Size} Tile size.
* @api * @api
*/ */
TileGrid.prototype.getTileSize = function(z) { getTileSize(z) {
if (this.tileSize_) { if (this.tileSize_) {
return this.tileSize_; return this.tileSize_;
} else { } else {
return this.tileSizes_[z]; return this.tileSizes_[z];
} }
}; }
/**
/**
* @param {number} z Zoom level. * @param {number} z Zoom level.
* @return {module:ol/TileRange} Extent tile range for the specified zoom level. * @return {module:ol/TileRange} Extent tile range for the specified zoom level.
*/ */
TileGrid.prototype.getFullTileRange = function(z) { getFullTileRange(z) {
if (!this.fullTileRanges_) { if (!this.fullTileRanges_) {
return null; return null;
} else { } else {
return this.fullTileRanges_[z]; return this.fullTileRanges_[z];
} }
}; }
/**
/**
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @param {number=} opt_direction If 0, the nearest resolution will be used. * @param {number=} opt_direction If 0, the nearest resolution will be used.
* If 1, the nearest lower resolution will be used. If -1, the nearest * If 1, the nearest lower resolution will be used. If -1, the nearest
@@ -552,22 +524,31 @@ TileGrid.prototype.getFullTileRange = function(z) {
* @return {number} Z. * @return {number} Z.
* @api * @api
*/ */
TileGrid.prototype.getZForResolution = function(resolution, opt_direction) { getZForResolution(resolution, opt_direction) {
const z = linearFindNearest(this.resolutions_, resolution, opt_direction || 0); const z = linearFindNearest(this.resolutions_, resolution, opt_direction || 0);
return clamp(z, this.minZoom, this.maxZoom); return clamp(z, this.minZoom, this.maxZoom);
}; }
/**
/**
* @param {!module:ol/extent~Extent} extent Extent for this tile grid. * @param {!module:ol/extent~Extent} extent Extent for this tile grid.
* @private * @private
*/ */
TileGrid.prototype.calculateTileRanges_ = function(extent) { calculateTileRanges_(extent) {
const length = this.resolutions_.length; const length = this.resolutions_.length;
const fullTileRanges = new Array(length); const fullTileRanges = new Array(length);
for (let z = this.minZoom; z < length; ++z) { for (let z = this.minZoom; z < length; ++z) {
fullTileRanges[z] = this.getTileRangeForExtentAndZ(extent, z); fullTileRanges[z] = this.getTileRangeForExtentAndZ(extent, z);
} }
this.fullTileRanges_ = fullTileRanges; this.fullTileRanges_ = fullTileRanges;
}; }
}
/**
* @private
* @type {module:ol/tilecoord~TileCoord}
*/
const tmpTileCoord = [0, 0, 0];
export default TileGrid; export default TileGrid;
+13 -12
View File
@@ -55,7 +55,8 @@ import TileGrid from '../tilegrid/TileGrid.js';
* @struct * @struct
* @api * @api
*/ */
const WMTSTileGrid = function(options) { class WMTSTileGrid {
constructor(options) {
/** /**
* @private * @private
* @type {!Array.<string>} * @type {!Array.<string>}
@@ -72,28 +73,28 @@ const WMTSTileGrid = function(options) {
tileSizes: options.tileSizes, tileSizes: options.tileSizes,
sizes: options.sizes sizes: options.sizes
}); });
}; }
inherits(WMTSTileGrid, TileGrid); /**
/**
* @param {number} z Z. * @param {number} z Z.
* @return {string} MatrixId.. * @return {string} MatrixId..
*/ */
WMTSTileGrid.prototype.getMatrixId = function(z) { getMatrixId(z) {
return this.matrixIds_[z]; return this.matrixIds_[z];
}; }
/**
/**
* Get the list of matrix identifiers. * Get the list of matrix identifiers.
* @return {Array.<string>} MatrixIds. * @return {Array.<string>} MatrixIds.
* @api * @api
*/ */
WMTSTileGrid.prototype.getMatrixIds = function() { getMatrixIds() {
return this.matrixIds_; return this.matrixIds_;
}; }
}
inherits(WMTSTileGrid, TileGrid);
export default WMTSTileGrid; export default WMTSTileGrid;
+10 -10
View File
@@ -18,7 +18,8 @@ const BufferUsage = {
* @param {number=} opt_usage Usage. * @param {number=} opt_usage Usage.
* @struct * @struct
*/ */
const WebGLBuffer = function(opt_arr, opt_usage) { class WebGLBuffer {
constructor(opt_arr, opt_usage) {
/** /**
* @private * @private
@@ -32,22 +33,21 @@ const WebGLBuffer = function(opt_arr, opt_usage) {
*/ */
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.
*/ */
WebGLBuffer.prototype.getArray = function() { getArray() {
return this.arr_; return this.arr_;
}; }
/**
/**
* @return {number} Usage. * @return {number} Usage.
*/ */
WebGLBuffer.prototype.getUsage = function() { getUsage() {
return this.usage_; return this.usage_;
}; }
}
export default WebGLBuffer; export default WebGLBuffer;
+42 -52
View File
@@ -27,7 +27,8 @@ import ContextEventType from '../webgl/ContextEventType.js';
* @param {HTMLCanvasElement} canvas Canvas. * @param {HTMLCanvasElement} canvas Canvas.
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
*/ */
const WebGLContext = function(canvas, gl) { class WebGLContext {
constructor(canvas, gl) {
/** /**
* @private * @private
@@ -98,19 +99,16 @@ const WebGLContext = function(canvas, gl) {
listen(this.canvas_, ContextEventType.RESTORED, listen(this.canvas_, ContextEventType.RESTORED,
this.handleWebGLContextRestored, this); this.handleWebGLContextRestored, this);
}; }
inherits(WebGLContext, Disposable); /**
/**
* Just bind the buffer if it's in the cache. Otherwise create * Just bind the buffer if it's in the cache. Otherwise create
* the WebGL buffer, bind it, populate it, and add an entry to * the WebGL buffer, bind it, populate it, and add an entry to
* the cache. * the cache.
* @param {number} target Target. * @param {number} target Target.
* @param {module:ol/webgl/Buffer} buf Buffer. * @param {module:ol/webgl/Buffer} buf Buffer.
*/ */
WebGLContext.prototype.bindBuffer = function(target, buf) { bindBuffer(target, buf) {
const gl = this.getGL(); const gl = this.getGL();
const arr = buf.getArray(); const arr = buf.getArray();
const bufferKey = String(getUid(buf)); const bufferKey = String(getUid(buf));
@@ -133,13 +131,12 @@ WebGLContext.prototype.bindBuffer = function(target, buf) {
buffer: buffer buffer: buffer
}; };
} }
}; }
/**
/**
* @param {module:ol/webgl/Buffer} buf Buffer. * @param {module:ol/webgl/Buffer} buf Buffer.
*/ */
WebGLContext.prototype.deleteBuffer = function(buf) { deleteBuffer(buf) {
const gl = this.getGL(); const gl = this.getGL();
const bufferKey = String(getUid(buf)); const bufferKey = String(getUid(buf));
const bufferCacheEntry = this.bufferCache_[bufferKey]; const bufferCacheEntry = this.bufferCache_[bufferKey];
@@ -147,13 +144,12 @@ WebGLContext.prototype.deleteBuffer = function(buf) {
gl.deleteBuffer(bufferCacheEntry.buffer); gl.deleteBuffer(bufferCacheEntry.buffer);
} }
delete this.bufferCache_[bufferKey]; delete this.bufferCache_[bufferKey];
}; }
/**
/**
* @inheritDoc * @inheritDoc
*/ */
WebGLContext.prototype.disposeInternal = function() { disposeInternal() {
unlistenAll(this.canvas_); unlistenAll(this.canvas_);
const gl = this.getGL(); const gl = this.getGL();
if (!gl.isContextLost()) { if (!gl.isContextLost()) {
@@ -171,46 +167,42 @@ WebGLContext.prototype.disposeInternal = function() {
gl.deleteRenderbuffer(this.hitDetectionRenderbuffer_); gl.deleteRenderbuffer(this.hitDetectionRenderbuffer_);
gl.deleteTexture(this.hitDetectionTexture_); gl.deleteTexture(this.hitDetectionTexture_);
} }
}; }
/**
/**
* @return {HTMLCanvasElement} Canvas. * @return {HTMLCanvasElement} Canvas.
*/ */
WebGLContext.prototype.getCanvas = function() { getCanvas() {
return this.canvas_; return this.canvas_;
}; }
/**
/**
* Get the WebGL rendering context * Get the WebGL rendering context
* @return {WebGLRenderingContext} The rendering context. * @return {WebGLRenderingContext} The rendering context.
* @api * @api
*/ */
WebGLContext.prototype.getGL = function() { getGL() {
return this.gl_; return this.gl_;
}; }
/**
/**
* Get the frame buffer for hit detection. * Get the frame buffer for hit detection.
* @return {WebGLFramebuffer} The hit detection frame buffer. * @return {WebGLFramebuffer} The hit detection frame buffer.
*/ */
WebGLContext.prototype.getHitDetectionFramebuffer = function() { getHitDetectionFramebuffer() {
if (!this.hitDetectionFramebuffer_) { if (!this.hitDetectionFramebuffer_) {
this.initHitDetectionFramebuffer_(); this.initHitDetectionFramebuffer_();
} }
return this.hitDetectionFramebuffer_; return this.hitDetectionFramebuffer_;
}; }
/**
/**
* Get shader from the cache if it's in the cache. Otherwise, create * Get shader from the cache if it's in the cache. Otherwise, create
* the WebGL shader, compile it, and add entry to cache. * the WebGL shader, compile it, and add entry to cache.
* @param {module:ol/webgl/Shader} shaderObject Shader object. * @param {module:ol/webgl/Shader} shaderObject Shader object.
* @return {WebGLShader} Shader. * @return {WebGLShader} Shader.
*/ */
WebGLContext.prototype.getShader = function(shaderObject) { getShader(shaderObject) {
const shaderKey = String(getUid(shaderObject)); const shaderKey = String(getUid(shaderObject));
if (shaderKey in this.shaderCache_) { if (shaderKey in this.shaderCache_) {
return this.shaderCache_[shaderKey]; return this.shaderCache_[shaderKey];
@@ -222,10 +214,9 @@ WebGLContext.prototype.getShader = function(shaderObject) {
this.shaderCache_[shaderKey] = shader; this.shaderCache_[shaderKey] = shader;
return shader; return shader;
} }
}; }
/**
/**
* Get the program from the cache if it's in the cache. Otherwise create * Get the program from the cache if it's in the cache. Otherwise create
* the WebGL program, attach the shaders to it, and add an entry to the * the WebGL program, attach the shaders to it, and add an entry to the
* cache. * cache.
@@ -233,7 +224,7 @@ WebGLContext.prototype.getShader = function(shaderObject) {
* @param {module:ol/webgl/Vertex} vertexShaderObject Vertex shader. * @param {module:ol/webgl/Vertex} vertexShaderObject Vertex shader.
* @return {WebGLProgram} Program. * @return {WebGLProgram} Program.
*/ */
WebGLContext.prototype.getProgram = function(fragmentShaderObject, vertexShaderObject) { getProgram(fragmentShaderObject, vertexShaderObject) {
const programKey = getUid(fragmentShaderObject) + '/' + getUid(vertexShaderObject); const programKey = getUid(fragmentShaderObject) + '/' + getUid(vertexShaderObject);
if (programKey in this.programCache_) { if (programKey in this.programCache_) {
return this.programCache_[programKey]; return this.programCache_[programKey];
@@ -246,13 +237,12 @@ WebGLContext.prototype.getProgram = function(fragmentShaderObject, vertexShaderO
this.programCache_[programKey] = program; this.programCache_[programKey] = program;
return program; return program;
} }
}; }
/**
/**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
WebGLContext.prototype.handleWebGLContextLost = function() { handleWebGLContextLost() {
clear(this.bufferCache_); clear(this.bufferCache_);
clear(this.shaderCache_); clear(this.shaderCache_);
clear(this.programCache_); clear(this.programCache_);
@@ -260,21 +250,19 @@ WebGLContext.prototype.handleWebGLContextLost = function() {
this.hitDetectionFramebuffer_ = null; this.hitDetectionFramebuffer_ = null;
this.hitDetectionTexture_ = null; this.hitDetectionTexture_ = null;
this.hitDetectionRenderbuffer_ = null; this.hitDetectionRenderbuffer_ = null;
}; }
/**
/**
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
WebGLContext.prototype.handleWebGLContextRestored = function() { handleWebGLContextRestored() {
}; }
/**
/**
* Creates a 1x1 pixel framebuffer for the hit-detection. * Creates a 1x1 pixel framebuffer for the hit-detection.
* @private * @private
*/ */
WebGLContext.prototype.initHitDetectionFramebuffer_ = function() { initHitDetectionFramebuffer_() {
const gl = this.gl_; const gl = this.gl_;
const framebuffer = gl.createFramebuffer(); const framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
@@ -295,16 +283,15 @@ WebGLContext.prototype.initHitDetectionFramebuffer_ = function() {
this.hitDetectionFramebuffer_ = framebuffer; this.hitDetectionFramebuffer_ = framebuffer;
this.hitDetectionTexture_ = texture; this.hitDetectionTexture_ = texture;
this.hitDetectionRenderbuffer_ = renderbuffer; this.hitDetectionRenderbuffer_ = renderbuffer;
}; }
/**
/**
* Use a program. If the program is already in use, this will return `false`. * Use a program. If the program is already in use, this will return `false`.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @return {boolean} Changed. * @return {boolean} Changed.
* @api * @api
*/ */
WebGLContext.prototype.useProgram = function(program) { useProgram(program) {
if (program == this.currentProgram_) { if (program == this.currentProgram_) {
return false; return false;
} else { } else {
@@ -313,7 +300,10 @@ WebGLContext.prototype.useProgram = function(program) {
this.currentProgram_ = program; this.currentProgram_ = program;
return true; return true;
} }
}; }
}
inherits(WebGLContext, Disposable);
/** /**
+11 -8
View File
@@ -11,17 +11,20 @@ import WebGLShader from '../webgl/Shader.js';
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
const WebGLFragment = function(source) { class WebGLFragment {
constructor(source) {
WebGLShader.call(this, source); WebGLShader.call(this, source);
}; }
/**
* @inheritDoc
*/
getType() {
return FRAGMENT_SHADER;
}
}
inherits(WebGLFragment, WebGLShader); inherits(WebGLFragment, WebGLShader);
/**
* @inheritDoc
*/
WebGLFragment.prototype.getType = function() {
return FRAGMENT_SHADER;
};
export default WebGLFragment; export default WebGLFragment;
+9 -9
View File
@@ -9,7 +9,8 @@ import {FALSE} from '../functions.js';
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
const WebGLShader = function(source) { class WebGLShader {
constructor(source) {
/** /**
* @private * @private
@@ -17,22 +18,21 @@ const WebGLShader = function(source) {
*/ */
this.source_ = source; this.source_ = source;
}; }
/**
/**
* @abstract * @abstract
* @return {number} Type. * @return {number} Type.
*/ */
WebGLShader.prototype.getType = function() {}; getType() {}
/**
/**
* @return {string} Source. * @return {string} Source.
*/ */
WebGLShader.prototype.getSource = function() { getSource() {
return this.source_; return this.source_;
}; }
}
/** /**
+11 -8
View File
@@ -11,17 +11,20 @@ import WebGLShader from '../webgl/Shader.js';
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
const WebGLVertex = function(source) { class WebGLVertex {
constructor(source) {
WebGLShader.call(this, source); WebGLShader.call(this, source);
}; }
/**
* @inheritDoc
*/
getType() {
return VERTEX_SHADER;
}
}
inherits(WebGLVertex, WebGLShader); inherits(WebGLVertex, WebGLShader);
/**
* @inheritDoc
*/
WebGLVertex.prototype.getType = function() {
return VERTEX_SHADER;
};
export default WebGLVertex; export default WebGLVertex;
+11 -6
View File
@@ -12,23 +12,28 @@ import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
const Locations = function(gl, program) { class Locations {
{{#uniforms}}
constructor(gl, program) {
{{#uniforms}}
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
*/ */
this.{{originalName}} = gl.getUniformLocation( this.{{originalName}} = gl.getUniformLocation(
program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}'); program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
{{/uniforms}} {{/uniforms}}
{{#attributes}} {{#attributes}}
/** /**
* @type {number} * @type {number}
*/ */
this.{{originalName}} = gl.getAttribLocation( this.{{originalName}} = gl.getAttribLocation(
program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}'); program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
{{/attributes}} {{/attributes}}
};
}
}
export default Locations; export default Locations;