merged with upstream and improved key handling

This commit is contained in:
Dmitry Fedorov
2018-11-02 17:19:10 -07:00
252 changed files with 5980 additions and 3750 deletions
+53 -5
View File
@@ -45,6 +45,48 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
*/
/**
* @typedef {Object} BingMapsImageryMetadataResponse
* @property {number} statusCode The response status code
* @property {string} statusDescription The response status description
* @property {string} authenticationResultCode The authentication result code
* @property {Array<ResourceSet>} resourceSets The array of resource sets
*/
/**
* @typedef {Object} ResourceSet
* @property {Array<Resource>} resources
*/
/**
* @typedef {Object} Resource
* @property {number} imageHeight The image height
* @property {number} imageWidth The image width
* @property {number} zoomMin The minimum zoom level
* @property {number} zoomMax The maximum zoom level
* @property {string} imageUrl The image URL
* @property {Array<string>} imageUrlSubdomains The image URL subdomains for rotation
* @property {Array<ImageryProvider>} [imageryProviders] The array of ImageryProviders
*/
/**
* @typedef {Object} ImageryProvider
* @property {Array<CoverageArea>} coverageAreas The coverage areas
* @property {string} [attribution] The attribution
*/
/**
* @typedef {Object} CoverageArea
* @property {number} zoomMin The minimum zoom
* @property {number} zoomMax The maximum zoom
* @property {Array<number>} bbox The coverage bounding box
*/
/**
* @classdesc
* Layer source for Bing Maps tile data.
@@ -52,7 +94,7 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
*/
class BingMaps extends TileImage {
/**
* @param {Options=} options Bing Maps options.
* @param {Options} options Bing Maps options.
*/
constructor(options) {
@@ -150,13 +192,16 @@ class BingMaps extends TileImage {
const sourceProjection = this.getProjection();
const extent = extentFromProjection(sourceProjection);
const scale = this.hidpi_ ? 2 : 1;
const tileSize = resource.imageWidth == resource.imageHeight ?
resource.imageWidth : [resource.imageWidth, resource.imageHeight];
resource.imageWidth / scale :
[resource.imageWidth / scale, resource.imageHeight / scale];
const tileGrid = createXYZ({
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,
tileSize: tileSize / (this.hidpi_ ? 2 : 1)
tileSize: tileSize
});
this.tileGrid = tileGrid;
@@ -196,7 +241,10 @@ class BingMaps extends TileImage {
this.setAttributions(function(frameState) {
const attributions = [];
const zoom = frameState.viewState.zoom;
const viewState = frameState.viewState;
const tileGrid = this.getTileGrid();
const tileCoord = tileGrid.getTileCoordForCoordAndResolution(viewState.center, viewState.resolution);
const zoom = tileCoord[0];
resource.imageryProviders.map(function(imageryProvider) {
let intersecting = false;
const coverageAreas = imageryProvider.coverageAreas;
@@ -219,7 +267,7 @@ class BingMaps extends TileImage {
attributions.push(TOS_ATTRIBUTION);
return attributions;
});
}.bind(this));
}
this.setState(SourceState.READY);
+7 -2
View File
@@ -31,6 +31,12 @@ import XYZ from '../source/XYZ.js';
*/
/**
* @typedef {Object} CartoDBLayerInfo
* @property {string} layergroupid The layer group ID
* @property {{https: string}} cdn_url The CDN URL
*/
/**
* @classdesc
* Layer source for the CartoDB Maps API.
@@ -38,7 +44,7 @@ import XYZ from '../source/XYZ.js';
*/
class CartoDB extends XYZ {
/**
* @param {Options=} options CartoDB options.
* @param {Options} options CartoDB options.
*/
constructor(options) {
super({
@@ -48,7 +54,6 @@ class CartoDB extends XYZ {
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 18,
minZoom: options.minZoom,
projection: options.projection,
state: SourceState.LOADING,
wrapX: options.wrapX
});
+16 -19
View File
@@ -5,6 +5,7 @@
import {getUid} from '../util.js';
import {assert} from '../asserts.js';
import Feature from '../Feature.js';
import GeometryType from '../geom/GeometryType.js';
import {scale as scaleCoordinate, add as addCoordinate} from '../coordinate.js';
import {listen} from '../events.js';
import EventType from '../events/EventType.js';
@@ -16,8 +17,7 @@ import VectorSource from '../source/Vector.js';
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [distance=20] Minimum distance in pixels between clusters.
* @property {import("../extent.js").Extent} [extent] Extent.
* @property {function(import("../Feature.js").default):import("../geom/Point.js").default} [geometryFunction]
* @property {function(Feature):Point} [geometryFunction]
* Function that takes an {@link module:ol/Feature} as argument and returns an
* {@link module:ol/geom/Point} as cluster calculation point for the feature. When a
* feature should not be considered for clustering, the function should return
@@ -30,8 +30,7 @@ import VectorSource from '../source/Vector.js';
* ```
* See {@link module:ol/geom/Polygon~Polygon#getInteriorPoint} for a way to get a cluster
* calculation point for polygons.
* @property {import("../proj.js").ProjectionLike} projection Projection.
* @property {import("./Vector.js").default} source Source.
* @property {VectorSource} source Source.
* @property {boolean} [wrapX=true] Whether to wrap the world horizontally.
*/
@@ -45,13 +44,11 @@ import VectorSource from '../source/Vector.js';
*/
class Cluster extends VectorSource {
/**
* @param {Options=} options Cluster options.
* @param {Options} options Cluster options.
*/
constructor(options) {
super({
attributions: options.attributions,
extent: options.extent,
projection: options.projection,
wrapX: options.wrapX
});
@@ -68,25 +65,25 @@ class Cluster extends VectorSource {
this.distance = options.distance !== undefined ? options.distance : 20;
/**
* @type {Array<import("../Feature.js").default>}
* @type {Array<Feature>}
* @protected
*/
this.features = [];
/**
* @param {import("../Feature.js").default} feature Feature.
* @return {import("../geom/Point.js").default} Cluster calculation point.
* @param {Feature} feature Feature.
* @return {Point} Cluster calculation point.
* @protected
*/
this.geometryFunction = options.geometryFunction || function(feature) {
const geometry = /** @type {import("../geom/Point.js").default} */ (feature.getGeometry());
assert(geometry instanceof Point,
10); // The default `geometryFunction` can only handle `import("../geom/Point.js").Point` geometries
const geometry = /** @type {Point} */ (feature.getGeometry());
assert(geometry.getType() == GeometryType.POINT,
10); // The default `geometryFunction` can only handle `Point` geometries
return geometry;
};
/**
* @type {import("./Vector.js").default}
* @type {VectorSource}
* @protected
*/
this.source = options.source;
@@ -105,7 +102,7 @@ class Cluster extends VectorSource {
/**
* Get a reference to the wrapped source.
* @return {import("./Vector.js").default} Source.
* @return {VectorSource} Source.
* @api
*/
getSource() {
@@ -165,7 +162,7 @@ class Cluster extends VectorSource {
for (let i = 0, ii = features.length; i < ii; i++) {
const feature = features[i];
if (!(getUid(feature).toString() in clustered)) {
if (!(getUid(feature) in clustered)) {
const geometry = this.geometryFunction(feature);
if (geometry) {
const coordinates = geometry.getCoordinates();
@@ -174,7 +171,7 @@ class Cluster extends VectorSource {
let neighbors = this.source.getFeaturesInExtent(extent);
neighbors = neighbors.filter(function(neighbor) {
const uid = getUid(neighbor).toString();
const uid = getUid(neighbor);
if (!(uid in clustered)) {
clustered[uid] = true;
return true;
@@ -189,8 +186,8 @@ class Cluster extends VectorSource {
}
/**
* @param {Array<import("../Feature.js").default>} features Features
* @return {import("../Feature.js").default} The cluster feature.
* @param {Array<Feature>} features Features
* @return {Feature} The cluster feature.
* @protected
*/
createCluster(features) {
+6 -5
View File
@@ -1,8 +1,8 @@
/**
* @module ol/source/Image
*/
import {abstract} from '../util.js';
import {ENABLE_RASTER_REPROJECTION} from '../reproj/common.js';
import ImageState from '../ImageState.js';
import {linearFindNearest} from '../array.js';
import Event from '../events/Event.js';
@@ -70,7 +70,6 @@ class ImageSourceEvent extends Event {
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions]
* @property {import("../extent.js").Extent} [extent]
* @property {import("../proj.js").ProjectionLike} projection
* @property {Array<number>} [resolutions]
* @property {import("./State.js").default} [state]
@@ -82,6 +81,7 @@ class ImageSourceEvent extends Event {
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Base class for sources providing a single image.
* @abstract
* @api
*/
class ImageSource extends Source {
@@ -91,7 +91,6 @@ class ImageSource extends Source {
constructor(options) {
super({
attributions: options.attributions,
extent: options.extent,
projection: options.projection,
state: options.state
});
@@ -190,7 +189,9 @@ class ImageSource extends Source {
* @return {import("../ImageBase.js").default} Single image.
* @protected
*/
getImageInternal(extent, resolution, pixelRatio, projection) {}
getImageInternal(extent, resolution, pixelRatio, projection) {
return abstract();
}
/**
* Handle image change events.
@@ -232,7 +233,7 @@ class ImageSource extends Source {
* @param {string} src Source.
*/
export function defaultImageLoadFunction(image, src) {
image.getImage().src = src;
/** @type {HTMLImageElement|HTMLVideoElement} */ (image.getImage()).src = src;
}
+4 -4
View File
@@ -18,16 +18,16 @@ import {appendParams} from '../uri.js';
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
* you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to
* access pixel data with the Canvas renderer. See
* https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.
* {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image} for more detail.
* @property {boolean} [hidpi=true] Use the `ol/Map#pixelRatio` value when requesting the image from
* the remote server.
* @property {import("../Image.js").LoadFunction} [imageLoadFunction] Optional function to load an image given
* a URL.
* @property {Object<string,*>} params ArcGIS Rest parameters. This field is optional. Service
* @property {Object<string,*>} [params] ArcGIS Rest parameters. This field is optional. Service
* defaults will be used for any fields not specified. `FORMAT` is `PNG32` by default. `F` is
* `IMAGE` by default. `TRANSPARENT` is `true` by default. `BBOX, `SIZE`, `BBOXSR`, and `IMAGESR`
* `IMAGE` by default. `TRANSPARENT` is `true` by default. `BBOX`, `SIZE`, `BBOXSR`, and `IMAGESR`
* will be set dynamically. Set `LAYERS` to override the default service layer visibility. See
* http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/
* {@link http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/}
* for further reference.
* @property {import("../proj.js").ProjectionLike} projection Projection.
* @property {number} [ratio=1.5] Ratio. `1` means image requests are the size of the map viewport,
+7 -5
View File
@@ -32,7 +32,7 @@ import ImageSource from '../source/Image.js';
* projection. The canvas returned by this function is cached by the source. If
* the value returned by the function is later changed then
* `changed` should be called on the source for the source to
* invalidate the current cached image. See @link: {@link module:ol/Observable~Observable#changed}
* invalidate the current cached image. See: {@link module:ol/Observable~Observable#changed}
* @property {import("../proj.js").ProjectionLike} projection Projection.
* @property {number} [ratio=1.5] Ratio. 1 means canvases are the size of the map viewport, 2 means twice the
* width and height of the map viewport, and so on. Must be `1` or higher.
@@ -49,9 +49,11 @@ import ImageSource from '../source/Image.js';
*/
class ImageCanvasSource extends ImageSource {
/**
* @param {Options=} options ImageCanvas options.
* @param {Options=} opt_options ImageCanvas options.
*/
constructor(options) {
constructor(opt_options) {
const options = opt_options || /** @type {Options} */ ({});
super({
attributions: options.attributions,
@@ -108,8 +110,8 @@ class ImageCanvasSource extends ImageSource {
const height = getHeight(extent) / resolution;
const size = [width * pixelRatio, height * pixelRatio];
const canvasElement = this.canvasFunction_(
extent, resolution, pixelRatio, size, projection);
const canvasElement = this.canvasFunction_.call(
this, extent, resolution, pixelRatio, size, projection);
if (canvasElement) {
canvas = new ImageCanvas(extent, resolution, pixelRatio, canvasElement);
}
+1 -1
View File
@@ -41,7 +41,7 @@ import {appendParams} from '../uri.js';
*/
class ImageMapGuide extends ImageSource {
/**
* @param {Options=} options ImageMapGuide options.
* @param {Options} options ImageMapGuide options.
*/
constructor(options) {
+1 -1
View File
@@ -35,7 +35,7 @@ import ImageSource, {defaultImageLoadFunction} from '../source/Image.js';
*/
class Static extends ImageSource {
/**
* @param {Options=} options ImageStatic options.
* @param {Options} options ImageStatic options.
*/
constructor(options) {
const crossOrigin = options.crossOrigin !== undefined ?
+2 -1
View File
@@ -76,7 +76,8 @@ class OSM extends XYZ {
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
wrapX: options.wrapX,
attributionsCollapsible: false
});
}
+22 -16
View File
@@ -11,7 +11,6 @@ import EventType from '../events/EventType.js';
import {Processor} from 'pixelworks/lib/index';
import {equals, getCenter, getHeight, getWidth} from '../extent.js';
import LayerType from '../LayerType.js';
import Layer from '../layer/Layer.js';
import ImageLayer from '../layer/Image.js';
import TileLayer from '../layer/Tile.js';
import {assign} from '../obj.js';
@@ -19,7 +18,6 @@ import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js';
import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js';
import ImageSource from '../source/Image.js';
import SourceState from '../source/State.js';
import TileSource from '../source/Tile.js';
import {create as createTransform} from '../transform.js';
@@ -144,10 +142,12 @@ class RasterSourceEvent extends Event {
*/
class RasterSource extends ImageSource {
/**
* @param {Options=} options Options.
* @param {Options} options Options.
*/
constructor(options) {
super({});
super({
projection: null
});
/**
* @private
@@ -190,6 +190,10 @@ class RasterSource extends ImageSource {
this.changed.bind(this));
const layerStatesArray = getLayerStatesArray(this.renderers_);
/**
* @type {Object<string, import("../layer/Layer.js").State>}
*/
const layerStates = {};
for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) {
layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
@@ -467,7 +471,7 @@ function getLayerStatesArray(renderers) {
/**
* Create renderers for all sources.
* @param {Array<import("./Source.js").default>} sources The sources.
* @param {Array<import("./Source.js").default|import("../layer/Layer.js").default>} sources The sources.
* @return {Array<import("../renderer/canvas/Layer.js").default>} Array of layer renderers.
*/
function createRenderers(sources) {
@@ -482,20 +486,22 @@ function createRenderers(sources) {
/**
* Create a renderer for the provided source.
* @param {import("./Source.js").default} source The source.
* @param {import("./Source.js").default|import("../layer/Layer.js").default} layerOrSource The layer or source.
* @return {import("../renderer/canvas/Layer.js").default} The renderer.
*/
function createRenderer(source) {
function createRenderer(layerOrSource) {
const tileSource = /** @type {import("./Tile.js").default} */ (layerOrSource);
const imageSource = /** @type {import("./Image.js").default} */ (layerOrSource);
const layer = /** @type {import("../layer/Layer.js").default} */ (layerOrSource);
let renderer = null;
if (source instanceof TileSource) {
renderer = createTileRenderer(source);
} else if (source instanceof ImageSource) {
renderer = createImageRenderer(source);
} else if (source instanceof TileLayer) {
renderer = new CanvasTileLayerRenderer(source);
} else if (source instanceof Layer &&
(source.getType() == LayerType.IMAGE || source.getType() == LayerType.VECTOR)) {
renderer = new CanvasImageLayerRenderer(source);
if (typeof tileSource.getTile === 'function') {
renderer = createTileRenderer(tileSource);
} else if (typeof imageSource.getImage === 'function') {
renderer = createImageRenderer(imageSource);
} else if (layer.getType() === LayerType.TILE) {
renderer = new CanvasTileLayerRenderer(/** @type {import("../layer/Tile.js").default} */ (layer));
} else if (layer.getType() == LayerType.IMAGE || layer.getType() == LayerType.VECTOR) {
renderer = new CanvasImageLayerRenderer(/** @type {import("../layer/Image.js").default} */ (layer));
}
return renderer;
}
+87 -81
View File
@@ -1,8 +1,7 @@
/**
* @module ol/source/Source
*/
import {VOID} from '../functions.js';
import {abstract} from '../util.js';
import BaseObject from '../Object.js';
import {get as getProjection} from '../proj.js';
import SourceState from './State.js';
@@ -31,9 +30,10 @@ import SourceState from './State.js';
/**
* @typedef {Object} Options
* @property {AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {import("../proj.js").ProjectionLike} projection
* @property {SourceState} [state]
* @property {boolean} [wrapX]
* @property {SourceState} [state='ready']
* @property {boolean} [wrapX=false]
*/
@@ -44,6 +44,7 @@ import SourceState from './State.js';
* Base class for {@link module:ol/layer/Layer~Layer} sources.
*
* A generic `change` event is triggered when the state of the source changes.
* @abstract
* @api
*/
class Source extends BaseObject {
@@ -55,16 +56,23 @@ class Source extends BaseObject {
super();
/**
* @private
* @type {import("../proj/Projection.js").default}
*/
* @private
* @type {import("../proj/Projection.js").default}
*/
this.projection_ = getProjection(options.projection);
/**
* @private
* @type {?Attribution}
*/
this.attributions_ = this.adaptAttributions_(options.attributions);
* @private
* @type {?Attribution}
*/
this.attributions_ = adaptAttributions(options.attributions);
/**
* @private
* @type {boolean}
*/
this.attributionsCollapsible_ = options.attributionsCollapsible !== undefined ?
options.attributionsCollapsible : true;
/**
* This source is currently loading data. Sources that defer loading to the
@@ -74,125 +82,123 @@ class Source extends BaseObject {
this.loading = false;
/**
* @private
* @type {SourceState}
*/
* @private
* @type {SourceState}
*/
this.state_ = options.state !== undefined ?
options.state : SourceState.READY;
/**
* @private
* @type {boolean}
*/
* @private
* @type {boolean}
*/
this.wrapX_ = options.wrapX !== undefined ? options.wrapX : false;
}
/**
* Turns the attributions option into an attributions function.
* @param {AttributionLike|undefined} attributionLike The attribution option.
* @return {?Attribution} An attribution function (or null).
*/
adaptAttributions_(attributionLike) {
if (!attributionLike) {
return null;
}
if (Array.isArray(attributionLike)) {
return function(frameState) {
return attributionLike;
};
}
if (typeof attributionLike === 'function') {
return attributionLike;
}
return function(frameState) {
return [attributionLike];
};
}
/**
* Get the attribution function for the source.
* @return {?Attribution} Attribution function.
*/
* Get the attribution function for the source.
* @return {?Attribution} Attribution function.
*/
getAttributions() {
return this.attributions_;
}
/**
* Get the projection of the source.
* @return {import("../proj/Projection.js").default} Projection.
* @api
*/
* @return {boolean} Aattributions are collapsible.
*/
getAttributionsCollapsible() {
return this.attributionsCollapsible_;
}
/**
* Get the projection of the source.
* @return {import("../proj/Projection.js").default} Projection.
* @api
*/
getProjection() {
return this.projection_;
}
/**
* @abstract
* @return {Array<number>|undefined} Resolutions.
*/
getResolutions() {}
* @abstract
* @return {Array<number>|undefined} Resolutions.
*/
getResolutions() {
return abstract();
}
/**
* Get the state of the source, see {@link module:ol/source/State~State} for possible states.
* @return {SourceState} State.
* @api
*/
* Get the state of the source, see {@link module:ol/source/State~State} for possible states.
* @return {SourceState} State.
* @api
*/
getState() {
return this.state_;
}
/**
* @return {boolean|undefined} Wrap X.
*/
* @return {boolean|undefined} Wrap X.
*/
getWrapX() {
return this.wrapX_;
}
/**
* Refreshes the source and finally dispatches a 'change' event.
* @api
*/
* Refreshes the source and finally dispatches a 'change' event.
* @api
*/
refresh() {
this.changed();
}
/**
* Set the attributions of the source.
* @param {AttributionLike|undefined} attributions Attributions.
* Can be passed as `string`, `Array<string>`, `{@link module:ol/source/Source~Attribution}`,
* or `undefined`.
* @api
*/
* Set the attributions of the source.
* @param {AttributionLike|undefined} attributions Attributions.
* Can be passed as `string`, `Array<string>`, `{@link module:ol/source/Source~Attribution}`,
* or `undefined`.
* @api
*/
setAttributions(attributions) {
this.attributions_ = this.adaptAttributions_(attributions);
this.attributions_ = adaptAttributions(attributions);
this.changed();
}
/**
* Set the state of the source.
* @param {SourceState} state State.
* @protected
*/
* Set the state of the source.
* @param {SourceState} state State.
* @protected
*/
setState(state) {
this.state_ = state;
this.changed();
}
}
/**
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @param {number} rotation Rotation.
* @param {number} hitTolerance Hit tolerance in pixels.
* @param {Object<string, boolean>} skippedFeatureUids Skipped feature uids.
* @param {function((import("../Feature.js").default|import("../render/Feature.js").default)): T} callback Feature callback.
* @return {T|void} Callback result.
* @template T
* Turns the attributions option into an attributions function.
* @param {AttributionLike|undefined} attributionLike The attribution option.
* @return {?Attribution} An attribution function (or null).
*/
Source.prototype.forEachFeatureAtCoordinate = VOID;
function adaptAttributions(attributionLike) {
if (!attributionLike) {
return null;
}
if (Array.isArray(attributionLike)) {
return function(frameState) {
return attributionLike;
};
}
if (typeof attributionLike === 'function') {
return attributionLike;
}
return function(frameState) {
return [attributionLike];
};
}
export default Source;
+2 -3
View File
@@ -91,10 +91,9 @@ const ProviderConfig = {
/**
* @typedef {Object} Options
* @property {number} [cacheSize=2048] Cache size.
* @property {string} [layer] Layer.
* @property {string} layer Layer name.
* @property {number} [minZoom] Minimum zoom.
* @property {number} [maxZoom] Maximum zoom.
* @property {boolean} [opaque] Whether the layer is opaque.
* @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels).
* Higher values can increase reprojection performance, but decrease precision.
* @property {import("../Tile.js").LoadFunction} [tileLoadFunction]
@@ -116,7 +115,7 @@ const ProviderConfig = {
*/
class Stamen extends XYZ {
/**
* @param {Options=} options Stamen options.
* @param {Options} options Stamen options.
*/
constructor(options) {
const i = options.layer.indexOf('-');
+22 -18
View File
@@ -1,8 +1,7 @@
/**
* @module ol/source/Tile
*/
import {VOID} from '../functions.js';
import {abstract} from '../util.js';
import TileCache from '../TileCache.js';
import TileState from '../TileState.js';
import Event from '../events/Event.js';
@@ -15,8 +14,8 @@ import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.j
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize]
* @property {import("../extent.js").Extent} [extent]
* @property {boolean} [opaque]
* @property {number} [tilePixelRatio]
* @property {import("../proj.js").ProjectionLike} [projection]
@@ -24,6 +23,7 @@ import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.j
* @property {import("../tilegrid/TileGrid.js").default} [tileGrid]
* @property {boolean} [wrapX=true]
* @property {number} [transition]
* @property {string} [key]
*/
@@ -32,17 +32,18 @@ import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.j
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Base class for sources providing images divided into a tile grid.
* @abstract
* @api
*/
class TileSource extends Source {
/**
* @param {Options=} options SourceTile source options.
* @param {Options} options SourceTile source options.
*/
constructor(options) {
super({
attributions: options.attributions,
extent: options.extent,
attributionsCollapsible: options.attributionsCollapsible,
projection: options.projection,
state: options.state,
wrapX: options.wrapX
@@ -83,7 +84,7 @@ class TileSource extends Source {
* @private
* @type {string}
*/
this.key_ = '';
this.key_ = options.key || '';
/**
* @protected
@@ -115,7 +116,7 @@ class TileSource extends Source {
* @param {import("../proj/Projection.js").default} projection Projection.
* @param {number} z Zoom level.
* @param {import("../TileRange.js").default} tileRange Tile range.
* @param {function(import("../Tile.js").default):(boolean|undefined)} callback Called with each
* @param {function(import("../Tile.js").default):(boolean|void)} callback Called with each
* loaded tile. If the callback returns `false`, the tile will not be
* considered loaded.
* @return {boolean} The tile range is fully covered with loaded tiles.
@@ -200,7 +201,9 @@ class TileSource extends Source {
* @param {import("../proj/Projection.js").default} projection Projection.
* @return {!import("../Tile.js").default} Tile.
*/
getTile(z, x, y, pixelRatio, projection) {}
getTile(z, x, y, pixelRatio, projection) {
return abstract();
}
/**
* Return the tile grid of the tile source.
@@ -291,19 +294,20 @@ class TileSource extends Source {
this.tileCache.clear();
this.changed();
}
/**
* Marks a tile coord as being used, without triggering a load.
* @abstract
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @param {import("../proj/Projection.js").default} projection Projection.
*/
useTile(z, x, y, projection) {}
}
/**
* Marks a tile coord as being used, without triggering a load.
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @param {import("../proj/Projection.js").default} projection Projection.
*/
TileSource.prototype.useTile = VOID;
/**
* @classdesc
* Events emitted by {@link module:ol/source/Tile~TileSource} instances are instances of this
+42 -37
View File
@@ -21,7 +21,7 @@ import {appendParams} from '../uri.js';
* for more detail.
* @property {Object<string,*>} [params] ArcGIS Rest parameters. This field is optional. Service defaults will be
* used for any fields not specified. `FORMAT` is `PNG32` by default. `F` is `IMAGE` by
* default. `TRANSPARENT` is `true` by default. `BBOX, `SIZE`, `BBOXSR`,
* default. `TRANSPARENT` is `true` by default. `BBOX`, `SIZE`, `BBOXSR`,
* and `IMAGESR` will be set dynamically. Set `LAYERS` to
* override the default service layer visibility. See
* http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/
@@ -66,7 +66,7 @@ class TileArcGISRest extends TileImage {
*/
constructor(opt_options) {
const options = opt_options || {};
const options = opt_options || /** @type {Options} */ ({});
super({
attributions: options.attributions,
@@ -76,6 +76,7 @@ class TileArcGISRest extends TileImage {
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
@@ -169,41 +170,6 @@ class TileArcGISRest extends TileImage {
return /** @type {number} */ (pixelRatio);
}
/**
* @inheritDoc
*/
fixedTileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
const tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.
const baseParams = {
'F': 'image',
'FORMAT': 'PNG32',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
/**
* Update the user-provided params.
* @param {Object} params Params.
@@ -215,5 +181,44 @@ class TileArcGISRest extends TileImage {
}
}
/**
* @param {import("../tilecoord.js").TileCoord} tileCoord The tile coordinate
* @param {number} pixelRatio The pixel ratio
* @param {import("../proj/Projection.js").default} projection The projection
* @return {string|undefined} The tile URL
* @this {TileArcGISRest}
*/
function tileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
const tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.
const baseParams = {
'F': 'image',
'FORMAT': 'PNG32',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
export default TileArcGISRest;
+1 -1
View File
@@ -91,7 +91,7 @@ class LabeledTile extends Tile {
*/
class TileDebug extends TileSource {
/**
* @param {Options=} options Debug tile options.
* @param {Options} options Debug tile options.
*/
constructor(options) {
+3 -3
View File
@@ -9,7 +9,7 @@ export default {
/**
* Triggered when a tile starts loading.
* @event module:ol/source/Tile~TileSourceEvent#tileloadstart
* @event module:ol/source/Tile.TileSourceEvent#tileloadstart
* @api
*/
TILELOADSTART: 'tileloadstart',
@@ -17,14 +17,14 @@ export default {
/**
* Triggered when a tile finishes loading, either when its data is loaded,
* or when loading was aborted because the tile is no longer needed.
* @event module:ol/source/Tile~TileSourceEvent#tileloadend
* @event module:ol/source/Tile.TileSourceEvent#tileloadend
* @api
*/
TILELOADEND: 'tileloadend',
/**
* Triggered if tile loading results in an error.
* @event module:ol/source/Tile~TileSourceEvent#tileloaderror
* @event module:ol/source/Tile.TileSourceEvent#tileloaderror
* @api
*/
TILELOADERROR: 'tileloaderror'
+14 -14
View File
@@ -17,8 +17,8 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize=2048] Cache size.
* @property {import("../extent.js").Extent} [extent]
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
* you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to
* access pixel data with the Canvas renderer. See
@@ -28,7 +28,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
* @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels).
* Higher values can increase reprojection performance, but decrease precision.
* @property {import("./State.js").default} [state] Source state.
* @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles.
* @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles.
* Default is {@link module:ol/ImageTile~ImageTile}.
* @property {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid.
* @property {import("../Tile.js").LoadFunction} [tileLoadFunction] Optional function to load a tile given a URL. The default is
@@ -52,6 +52,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
* world only, but they will be wrapped horizontally to render multiple worlds.
* @property {number} [transition] Duration of the opacity transition for rendering.
* To disable the opacity transition, pass `transition: 0`.
* @property {string} [key] Optional tile key for proper cache fetching
*/
@@ -71,7 +72,6 @@ class TileImage extends UrlTile {
super({
attributions: options.attributions,
cacheSize: options.cacheSize,
extent: options.extent,
opaque: options.opaque,
projection: options.projection,
state: options.state,
@@ -84,7 +84,8 @@ class TileImage extends UrlTile {
urls: options.urls,
wrapX: options.wrapX,
transition: options.transition,
opt_key: options.opt_key
key: options.key,
attributionsCollapsible: options.attributionsCollapsible
});
/**
@@ -96,15 +97,14 @@ class TileImage extends UrlTile {
/**
* @protected
* @type {function(new: import("../ImageTile.js").default, import("../tilecoord.js").TileCoord, import("../TileState.js").default, string,
* ?string, import("../Tile.js").LoadFunction, import("../Tile.js").Options=)}
* @type {typeof ImageTile}
*/
this.tileClass = options.tileClass !== undefined ?
options.tileClass : ImageTile;
/**
* @protected
* @type {!Object<string, import("../TileCache.js").default>}
* @type {!Object<string, TileCache>}
*/
this.tileCacheForProjection = {};
@@ -199,13 +199,13 @@ class TileImage extends UrlTile {
*/
getTileGridForProjection(projection) {
if (!ENABLE_RASTER_REPROJECTION) {
return UrlTile.prototype.getTileGridForProjection.call(this, projection);
return super.getTileGridForProjection(projection);
}
const thisProj = this.getProjection();
if (this.tileGrid && (!thisProj || equivalent(thisProj, projection))) {
return this.tileGrid;
} else {
const projKey = getUid(projection).toString();
const projKey = getUid(projection);
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] = getTileGridForProjection(projection);
}
@@ -220,12 +220,12 @@ class TileImage extends UrlTile {
*/
getTileCacheForProjection(projection) {
if (!ENABLE_RASTER_REPROJECTION) {
return UrlTile.prototype.getTileCacheForProjection.call(this, projection);
return super.getTileCacheForProjection(projection);
}
const thisProj = this.getProjection(); if (!thisProj || equivalent(thisProj, projection)) {
return this.tileCache;
} else {
const projKey = getUid(projection).toString();
const projKey = getUid(projection);
if (!(projKey in this.tileCacheForProjection)) {
this.tileCacheForProjection[projKey] = new TileCache(this.tileCache.highWaterMark);
}
@@ -381,7 +381,7 @@ class TileImage extends UrlTile {
if (ENABLE_RASTER_REPROJECTION) {
const proj = getProjection(projection);
if (proj) {
const projKey = getUid(proj).toString();
const projKey = getUid(proj);
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] = tilegrid;
}
@@ -392,11 +392,11 @@ class TileImage extends UrlTile {
/**
* @param {import("../ImageTile.js").default} imageTile Image tile.
* @param {ImageTile} imageTile Image tile.
* @param {string} src Source.
*/
function defaultTileLoadFunction(imageTile, src) {
imageTile.getImage().src = src;
/** @type {HTMLImageElement|HTMLVideoElement} */ (imageTile.getImage()).src = src;
}
export default TileImage;
+1 -1
View File
@@ -70,7 +70,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
*/
class TileJSON extends TileImage {
/**
* @param {Options=} options TileJSON options.
* @param {Options} options TileJSON options.
*/
constructor(options) {
super({
+53 -48
View File
@@ -43,8 +43,8 @@ import {appendParams} from '../uri.js';
* @property {import("../proj.js").ProjectionLike} projection Projection.
* @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels).
* Higher values can increase reprojection performance, but decrease precision.
* @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles.
* Default is {@link module:ol/ImageTile~TileClass}.
* @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles.
* Default is {@link module:ol/ImageTile~ImageTile}.
* @property {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid. Base this on the resolutions,
* tilesize and extent supported by the server.
* If this is not defined, a default grid will be used: if there is a projection
@@ -98,6 +98,7 @@ class TileWMS extends TileImage {
tileClass: options.tileClass,
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
@@ -321,52 +322,6 @@ class TileWMS extends TileImage {
return res.join('/');
}
/**
* @inheritDoc
*/
fixedTileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
if (pixelRatio != 1 && (!this.hidpi_ || this.serverType_ === undefined)) {
pixelRatio = 1;
}
const tileResolution = tileGrid.getResolution(tileCoord[0]);
let tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
const gutter = this.gutter_;
if (gutter !== 0) {
tileSize = bufferSize(tileSize, gutter, this.tmpSize);
tileExtent = buffer(tileExtent, tileResolution * gutter, tileExtent);
}
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
const baseParams = {
'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetMap',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
/**
* Update the user-provided params.
* @param {Object} params Params.
@@ -387,5 +342,55 @@ class TileWMS extends TileImage {
}
}
/**
* @param {import("../tilecoord.js").TileCoord} tileCoord The tile coordinate
* @param {number} pixelRatio The pixel ratio
* @param {import("../proj/Projection.js").default} projection The projection
* @return {string|undefined} The tile URL
* @this {TileWMS}
*/
function tileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
if (pixelRatio != 1 && (!this.hidpi_ || this.serverType_ === undefined)) {
pixelRatio = 1;
}
const tileResolution = tileGrid.getResolution(tileCoord[0]);
let tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
const gutter = this.gutter_;
if (gutter !== 0) {
tileSize = bufferSize(tileSize, gutter, this.tmpSize);
tileExtent = buffer(tileExtent, tileResolution * gutter, tileExtent);
}
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
const baseParams = {
'SERVICE': 'WMS',
'VERSION': DEFAULT_WMS_VERSION,
'REQUEST': 'GetMap',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
export default TileWMS;
+2 -2
View File
@@ -28,7 +28,7 @@ export class CustomTile extends Tile {
/**
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
* @param {import("../TileState.js").default} state State.
* @param {TileState} state State.
* @param {string} src Image source URI.
* @param {import("../extent.js").Extent} extent Extent of the tile.
* @param {boolean} preemptive Load the tile when visible (before it's needed).
@@ -279,7 +279,7 @@ export class CustomTile extends Tile {
*/
class UTFGrid extends TileSource {
/**
* @param {Options=} options Source options.
* @param {Options} options Source options.
*/
constructor(options) {
super({
+27 -26
View File
@@ -11,8 +11,8 @@ import {getKeyZXY} from '../tilecoord.js';
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize]
* @property {import("../extent.js").Extent} [extent]
* @property {boolean} [opaque]
* @property {import("../proj.js").ProjectionLike} [projection]
* @property {import("./State.js").default} [state]
@@ -24,6 +24,7 @@ import {getKeyZXY} from '../tilecoord.js';
* @property {Array<string>} [urls]
* @property {boolean} [wrapX=true]
* @property {number} [transition]
* @property {string} [key]
*/
@@ -31,27 +32,34 @@ import {getKeyZXY} from '../tilecoord.js';
* @classdesc
* Base class for sources providing tiles divided into a tile grid over http.
*
* @fires import("./TileEvent.js").default
* @fires import("./Tile.js").TileSourceEvent
*/
class UrlTile extends TileSource {
/**
* @param {Options=} options Image tile options.
* @param {Options} options Image tile options.
*/
constructor(options) {
super({
attributions: options.attributions,
cacheSize: options.cacheSize,
extent: options.extent,
opaque: options.opaque,
projection: options.projection,
state: options.state,
tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio,
wrapX: options.wrapX,
transition: options.transition
transition: options.transition,
key: options.key,
attributionsCollapsible: options.attributionsCollapsible
});
/**
* @private
* @type {boolean}
*/
this.generateTileUrlFunction_ = !options.tileUrlFunction;
/**
* @protected
* @type {import("../Tile.js").LoadFunction}
@@ -62,9 +70,7 @@ class UrlTile extends TileSource {
* @protected
* @type {import("../Tile.js").UrlFunction}
*/
this.tileUrlFunction = this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) : nullTileUrlFunction;
this.key_ = options.opt_key || this.key_;
this.tileUrlFunction = options.tileUrlFunction ? options.tileUrlFunction.bind(this) : nullTileUrlFunction;
/**
* @protected
@@ -77,13 +83,14 @@ class UrlTile extends TileSource {
} else if (options.url) {
this.setUrl(options.url);
}
if (options.tileUrlFunction) {
this.setTileUrlFunction(options.tileUrlFunction, options.opt_key);
this.setTileUrlFunction(options.tileUrlFunction, this.key_);
}
/**
* @private
* @type {!Object<number, boolean>}
* @type {!Object<string, boolean>}
*/
this.tileLoadingKeys_ = {};
@@ -156,14 +163,14 @@ class UrlTile extends TileSource {
/**
* Set the tile URL function of the source.
* @param {import("../Tile.js").UrlFunction} tileUrlFunction Tile URL function.
* @param {string=} opt_key Optional new tile key for the source.
* @param {string=} key Optional new tile key for the source.
* @api
*/
setTileUrlFunction(tileUrlFunction, opt_key) {
setTileUrlFunction(tileUrlFunction, key) {
this.tileUrlFunction = tileUrlFunction;
this.tileCache.pruneExceptNewestZ();
if (typeof opt_key !== 'undefined') {
this.setKey(opt_key);
if (typeof key !== 'undefined') {
this.setKey(key);
} else {
this.changed();
}
@@ -176,9 +183,7 @@ class UrlTile extends TileSource {
*/
setUrl(url) {
const urls = this.urls = expandUrl(url);
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
createFromTemplates(urls, this.tileGrid), url);
this.setUrls(urls);
}
/**
@@ -189,9 +194,11 @@ class UrlTile extends TileSource {
setUrls(urls) {
this.urls = urls;
const key = urls.join('\n');
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
createFromTemplates(urls, this.tileGrid), key);
if (this.generateTileUrlFunction_) {
this.setTileUrlFunction(createFromTemplates(urls, this.tileGrid), key);
} else {
this.setKey(key);
}
}
/**
@@ -206,10 +213,4 @@ class UrlTile extends TileSource {
}
/**
* @type {import("../Tile.js").UrlFunction|undefined}
* @protected
*/
UrlTile.prototype.fixedTileUrlFunction;
export default UrlTile;
+34 -30
View File
@@ -61,7 +61,7 @@ export class VectorSourceEvent extends Event {
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {Array<import("../Feature.js").default>|import("../Collection.js").default<import("../Feature.js").default>} [features]
* @property {Array<import("../Feature.js").default>|Collection<import("../Feature.js").default>} [features]
* Features. If provided as {@link module:ol/Collection}, the features in the source
* and the collection will stay in sync.
* @property {import("../format/Feature.js").default} [format] The feature format used by the XHR
@@ -154,7 +154,7 @@ export class VectorSourceEvent extends Event {
* by this source are suitable for editing. See {@link module:ol/source/VectorTile~VectorTile} for
* vector data that is optimized for rendering.
*
* @fires ol/source/Vector~VectorSourceEvent
* @fires ol/source/Vector.VectorSourceEvent
* @api
*/
class VectorSource extends Source {
@@ -215,13 +215,13 @@ class VectorSource extends Source {
/**
* @private
* @type {import("../structs/RBush.js").default<import("../Feature.js").default>}
* @type {RBush<import("../Feature.js").default>}
*/
this.featuresRtree_ = useSpatialIndex ? new RBush() : null;
/**
* @private
* @type {import("../structs/RBush.js").default<{extent: import("../extent.js").Extent}>}
* @type {RBush<{extent: import("../extent.js").Extent}>}
*/
this.loadedExtentsRtree_ = new RBush();
@@ -253,16 +253,16 @@ class VectorSource extends Source {
/**
* @private
* @type {import("../Collection.js").default<import("../Feature.js").default>}
* @type {Collection<import("../Feature.js").default>}
*/
this.featuresCollection_ = null;
let collection, features;
if (options.features instanceof Collection) {
if (Array.isArray(options.features)) {
features = options.features;
} else if (options.features) {
collection = options.features;
features = collection.getArray();
} else if (Array.isArray(options.features)) {
features = options.features;
}
if (!useSpatialIndex && collection === undefined) {
collection = new Collection(features);
@@ -297,7 +297,7 @@ class VectorSource extends Source {
* @protected
*/
addFeatureInternal(feature) {
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
if (!this.addToIndex_(featureKey, feature)) {
return;
@@ -383,7 +383,7 @@ class VectorSource extends Source {
for (let i = 0, length = features.length; i < length; i++) {
const feature = features[i];
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
if (this.addToIndex_(featureKey, feature)) {
newFeatures.push(feature);
}
@@ -391,7 +391,7 @@ class VectorSource extends Source {
for (let i = 0, length = newFeatures.length; i < length; i++) {
const feature = newFeatures[i];
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
this.setupChangeEvents_(featureKey, feature);
const geometry = feature.getGeometry();
@@ -414,12 +414,15 @@ class VectorSource extends Source {
/**
* @param {!import("../Collection.js").default<import("../Feature.js").default>} collection Collection.
* @param {!Collection<import("../Feature.js").default>} collection Collection.
* @private
*/
bindFeaturesCollection_(collection) {
let modifyingCollection = false;
listen(this, VectorEventType.ADDFEATURE,
/**
* @param {VectorSourceEvent} evt The vector source event
*/
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -428,6 +431,9 @@ class VectorSource extends Source {
}
});
listen(this, VectorEventType.REMOVEFEATURE,
/**
* @param {VectorSourceEvent} evt The vector source event
*/
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -436,6 +442,9 @@ class VectorSource extends Source {
}
});
listen(collection, CollectionEventType.ADD,
/**
* @param {import("../Collection.js").CollectionEvent} evt The collection event
*/
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -444,6 +453,9 @@ class VectorSource extends Source {
}
}, this);
listen(collection, CollectionEventType.REMOVE,
/**
* @param {import("../Collection.js").CollectionEvent} evt The collection event
*/
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -457,7 +469,7 @@ class VectorSource extends Source {
/**
* Remove all features from the source.
* @param {boolean=} opt_fast Skip dispatching of {@link module:ol/source/Vector~VectorSourceEvent#removefeature} events.
* @param {boolean=} opt_fast Skip dispatching of {@link module:ol/source/Vector.VectorSourceEvent#removefeature} events.
* @api
*/
clear(opt_fast) {
@@ -511,7 +523,7 @@ class VectorSource extends Source {
if (this.featuresRtree_) {
return this.featuresRtree_.forEach(callback);
} else if (this.featuresCollection_) {
return this.featuresCollection_.forEach(callback);
this.featuresCollection_.forEach(callback);
}
}
@@ -564,7 +576,7 @@ class VectorSource extends Source {
if (this.featuresRtree_) {
return this.featuresRtree_.forEachInExtent(extent, callback);
} else if (this.featuresCollection_) {
return this.featuresCollection_.forEach(callback);
this.featuresCollection_.forEach(callback);
}
}
@@ -589,7 +601,6 @@ class VectorSource extends Source {
/**
* @param {import("../Feature.js").default} feature Feature.
* @return {T|undefined} The return value from the last call to the callback.
* @template T
*/
function(feature) {
const geometry = feature.getGeometry();
@@ -607,7 +618,7 @@ class VectorSource extends Source {
* Get the features collection associated with this source. Will be `null`
* unless the source was configured with `useSpatialIndex` set to `false`, or
* with an {@link module:ol/Collection} as `features`.
* @return {import("../Collection.js").default<import("../Feature.js").default>} The collection of features.
* @return {Collection<import("../Feature.js").default>} The collection of features.
* @api
*/
getFeaturesCollection() {
@@ -771,12 +782,6 @@ class VectorSource extends Source {
}
/**
* @override
*/
getResolutions() {}
/**
* Get the url associated with this source.
*
@@ -789,12 +794,12 @@ class VectorSource extends Source {
/**
* @param {import("../events/Event.js").default} event Event.
* @param {Event} event Event.
* @private
*/
handleFeatureChange_(event) {
const feature = /** @type {import("../Feature.js").default} */ (event.target);
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
const geometry = feature.getGeometry();
if (!geometry) {
if (!(featureKey in this.nullGeometryFeatures_)) {
@@ -850,8 +855,7 @@ class VectorSource extends Source {
if (id !== undefined) {
return id in this.idIndex_;
} else {
const featureKey = getUid(feature).toString();
return featureKey in this.undefIdIndex_;
return getUid(feature) in this.undefIdIndex_;
}
}
@@ -885,7 +889,7 @@ class VectorSource extends Source {
if (!alreadyLoaded) {
this.loader_.call(this, extentToLoad, resolution, projection);
loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()});
this.loading = true;
this.loading = this.loader_ !== VOID;
}
}
}
@@ -919,7 +923,7 @@ class VectorSource extends Source {
* @api
*/
removeFeature(feature) {
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
if (featureKey in this.nullGeometryFeatures_) {
delete this.nullGeometryFeatures_[featureKey];
} else {
@@ -938,7 +942,7 @@ class VectorSource extends Source {
* @protected
*/
removeFeatureInternal(feature) {
const featureKey = getUid(feature).toString();
const featureKey = getUid(feature);
this.featureChangeKeys_[featureKey].forEach(unlistenByKey);
delete this.featureChangeKeys_[featureKey];
const id = feature.getId();
+4 -4
View File
@@ -8,21 +8,21 @@
export default {
/**
* Triggered when a feature is added to the source.
* @event ol/source/Vector~VectorSourceEvent#addfeature
* @event ol/source/Vector.VectorSourceEvent#addfeature
* @api
*/
ADDFEATURE: 'addfeature',
/**
* Triggered when a feature is updated.
* @event ol/source/Vector~VectorSourceEvent#changefeature
* @event ol/source/Vector.VectorSourceEvent#changefeature
* @api
*/
CHANGEFEATURE: 'changefeature',
/**
* Triggered when the clear method is called on the source.
* @event ol/source/Vector~VectorSourceEvent#clear
* @event ol/source/Vector.VectorSourceEvent#clear
* @api
*/
CLEAR: 'clear',
@@ -30,7 +30,7 @@ export default {
/**
* Triggered when a feature is removed from the source.
* See {@link module:ol/source/Vector#clear source.clear()} for exceptions.
* @event ol/source/Vector~VectorSourceEvent#removefeature
* @event ol/source/Vector.VectorSourceEvent#removefeature
* @api
*/
REMOVEFEATURE: 'removefeature'
+5 -7
View File
@@ -22,7 +22,7 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.
* stroke operations.
* @property {import("../proj.js").ProjectionLike} projection Projection.
* @property {import("./State.js").default} [state] Source state.
* @property {import("../VectorTile.js").TileClass} [tileClass] Class used to instantiate image tiles.
* @property {typeof import("../VectorTile.js").default} [tileClass] Class used to instantiate image tiles.
* Default is {@link module:ol/VectorTile}.
* @property {number} [maxZoom=22] Optional max zoom level.
* @property {number} [minZoom] Optional min zoom level.
@@ -91,7 +91,6 @@ class VectorTile extends UrlTile {
super({
attributions: options.attributions,
cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128,
extent: extent,
opaque: false,
projection: projection,
state: options.state,
@@ -112,7 +111,7 @@ class VectorTile extends UrlTile {
/**
* @private
* @type {Object<string, import("../VectorTile.js").default>}
* @type {Object<string, Tile>}
*/
this.sourceTiles_ = {};
@@ -123,10 +122,9 @@ class VectorTile extends UrlTile {
this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
/**
* @protected
* @type {function(new: import("../VectorTile.js").default, import("../tilecoord.js").TileCoord, import("../TileState.js").default, string,
* import("../format/Feature.js").default, import("../Tile.js").LoadFunction)}
*/
* @protected
* @type {typeof import("../VectorTile.js").default}
*/
this.tileClass = options.tileClass ? options.tileClass : Tile;
/**
+7 -8
View File
@@ -27,13 +27,13 @@ import {appendParams} from '../uri.js';
* @property {import("./WMTSRequestEncoding.js").default|string} [requestEncoding='KVP'] Request encoding.
* @property {string} layer Layer name as advertised in the WMTS capabilities.
* @property {string} style Style name as advertised in the WMTS capabilities.
* @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles. Default is {@link module:ol/ImageTile~ImageTile}.
* @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles. Default is {@link module:ol/ImageTile~ImageTile}.
* @property {number} [tilePixelRatio=1] The pixel ratio used by the tile service.
* For example, if the tile service advertizes 256px by 256px tiles but actually sends 512px
* by 512px images (for retina/hidpi devices) then `tilePixelRatio`
* should be set to `2`.
* @property {string} [version='image/jpeg'] Image format.
* @property {string} [format='1.0.0'] WMTS version.
* @property {string} [format='image/jpeg'] Image format. Only used when `requestEncoding` is `'KVP'`.
* @property {string} [version='1.0.0'] WMTS version.
* @property {string} matrixSet Matrix set.
* @property {!Object} [dimensions] Additional "dimensions" for tile requests.
* This is an object with properties named like the advertised WMTS dimensions.
@@ -63,7 +63,7 @@ import {appendParams} from '../uri.js';
*/
class WMTS extends TileImage {
/**
* @param {Options=} options WMTS options.
* @param {Options} options WMTS options.
*/
constructor(options) {
@@ -159,9 +159,7 @@ class WMTS extends TileImage {
setUrls(urls) {
this.urls = urls;
const key = urls.join('\n');
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
this.setTileUrlFunction(createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
}
/**
@@ -492,7 +490,8 @@ function createFromWMTSTemplate(template) {
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
});
const tileGrid = this.tileGrid;
const tileGrid = /** @type {import("../tilegrid/WMTS.js").default} */ (
this.tileGrid);
const dimensions = this.dimensions_;
return (
+3 -1
View File
@@ -8,6 +8,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize=2048] Cache size.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
* you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to
@@ -93,7 +94,8 @@ class XYZ extends TileImage {
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition
transition: options.transition,
attributionsCollapsible: options.attributionsCollapsible
});
}
+3 -2
View File
@@ -28,7 +28,7 @@ export class CustomTile extends ImageTile {
/**
* @param {import("../tilegrid/TileGrid.js").default} tileGrid TileGrid that the tile belongs to.
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
* @param {import("../TileState.js").default} state State.
* @param {TileState} state State.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {import("../Tile.js").LoadFunction} tileLoadFunction Tile load function.
@@ -219,7 +219,8 @@ class Zoomify extends TileImage {
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0];
const tileSize = tileGrid.getTileSize(tileCoordZ);
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
const tileWidth = Array.isArray(tileSize) ? tileSize[0] : tileSize;
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileWidth) | 0;
const localContext = {
'z': tileCoordZ,
'x': tileCoordX,
+4
View File
@@ -1,3 +1,7 @@
/**
* @module ol/source/common
*/
/**
* Default WMS version.
* @type {string}