Merge pull request #7578 from tschaub/undeprecated
Remove deprecated functionality from 4.x
This commit is contained in:
@@ -1,318 +0,0 @@
|
||||
/**
|
||||
* @module ol/source/ImageVector
|
||||
*/
|
||||
import {getUid, inherits} from '../index.js';
|
||||
import _ol_dom_ from '../dom.js';
|
||||
import _ol_events_ from '../events.js';
|
||||
import _ol_events_EventType_ from '../events/EventType.js';
|
||||
import _ol_ext_rbush_ from 'rbush';
|
||||
import _ol_extent_ from '../extent.js';
|
||||
import _ol_render_canvas_ReplayGroup_ from '../render/canvas/ReplayGroup.js';
|
||||
import _ol_renderer_vector_ from '../renderer/vector.js';
|
||||
import _ol_source_ImageCanvas_ from '../source/ImageCanvas.js';
|
||||
import _ol_style_Style_ from '../style/Style.js';
|
||||
import _ol_transform_ from '../transform.js';
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @classdesc
|
||||
* **Deprecated**. Use an `ol.layer.Vector` with `renderMode: 'image'` and an
|
||||
* `ol.source.Vector` instead.
|
||||
*
|
||||
* An image source whose images are canvas elements into which vector features
|
||||
* read from a vector source (`ol.source.Vector`) are drawn. An
|
||||
* `ol.source.ImageVector` object is to be used as the `source` of an image
|
||||
* layer (`ol.layer.Image`). Image layers are rotated, scaled, and translated,
|
||||
* as opposed to being re-rendered, during animations and interactions. So, like
|
||||
* any other image layer, an image layer configured with an
|
||||
* `ol.source.ImageVector` will exhibit this behaviour. This is in contrast to a
|
||||
* vector layer, where vector features are re-drawn during animations and
|
||||
* interactions.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.ImageCanvas}
|
||||
* @param {olx.source.ImageVectorOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
var _ol_source_ImageVector_ = function(options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.source.Vector}
|
||||
*/
|
||||
this.source_ = options.source;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Transform}
|
||||
*/
|
||||
this.transform_ = _ol_transform_.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
this.canvasContext_ = _ol_dom_.createCanvasContext2D();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Size}
|
||||
*/
|
||||
this.canvasSize_ = [0, 0];
|
||||
|
||||
/**
|
||||
* Declutter tree.
|
||||
* @private
|
||||
*/
|
||||
this.declutterTree_ = _ol_ext_rbush_(9);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.renderBuffer_ = options.renderBuffer == undefined ? 100 : options.renderBuffer;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.render.canvas.ReplayGroup}
|
||||
*/
|
||||
this.replayGroup_ = null;
|
||||
|
||||
_ol_source_ImageCanvas_.call(this, {
|
||||
attributions: options.attributions,
|
||||
canvasFunction: this.canvasFunctionInternal_.bind(this),
|
||||
logo: options.logo,
|
||||
projection: options.projection,
|
||||
ratio: options.ratio,
|
||||
resolutions: options.resolutions,
|
||||
state: this.source_.getState()
|
||||
});
|
||||
|
||||
/**
|
||||
* User provided style.
|
||||
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
|
||||
* @private
|
||||
*/
|
||||
this.style_ = null;
|
||||
|
||||
/**
|
||||
* Style function for use within the library.
|
||||
* @type {ol.StyleFunction|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.styleFunction_ = undefined;
|
||||
|
||||
this.setStyle(options.style);
|
||||
|
||||
_ol_events_.listen(this.source_, _ol_events_EventType_.CHANGE,
|
||||
this.handleSourceChange_, this);
|
||||
|
||||
};
|
||||
|
||||
inherits(_ol_source_ImageVector_, _ol_source_ImageCanvas_);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {ol.proj.Projection} projection Projection;
|
||||
* @return {HTMLCanvasElement} Canvas element.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.canvasFunctionInternal_ = function(extent, resolution, pixelRatio, size, projection) {
|
||||
|
||||
var replayGroup = new _ol_render_canvas_ReplayGroup_(
|
||||
_ol_renderer_vector_.getTolerance(resolution, pixelRatio), extent,
|
||||
resolution, pixelRatio, this.source_.getOverlaps(), this.declutterTree_, this.renderBuffer_);
|
||||
|
||||
this.source_.loadFeatures(extent, resolution, projection);
|
||||
|
||||
var loading = false;
|
||||
this.source_.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
function(feature) {
|
||||
loading = loading ||
|
||||
this.renderFeature_(feature, resolution, pixelRatio, replayGroup);
|
||||
}, this);
|
||||
replayGroup.finish();
|
||||
|
||||
if (loading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.canvasSize_[0] != size[0] || this.canvasSize_[1] != size[1]) {
|
||||
this.canvasContext_.canvas.width = size[0];
|
||||
this.canvasContext_.canvas.height = size[1];
|
||||
this.canvasSize_[0] = size[0];
|
||||
this.canvasSize_[1] = size[1];
|
||||
} else {
|
||||
this.canvasContext_.clearRect(0, 0, size[0], size[1]);
|
||||
}
|
||||
|
||||
this.declutterTree_.clear();
|
||||
|
||||
var transform = this.getTransform_(_ol_extent_.getCenter(extent),
|
||||
resolution, pixelRatio, size);
|
||||
replayGroup.replay(this.canvasContext_, transform, 0, {});
|
||||
|
||||
this.replayGroup_ = replayGroup;
|
||||
|
||||
return this.canvasContext_.canvas;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.forEachFeatureAtCoordinate = function(
|
||||
coordinate, resolution, rotation, hitTolerance, skippedFeatureUids, callback) {
|
||||
if (!this.replayGroup_) {
|
||||
return undefined;
|
||||
} else {
|
||||
/** @type {Object.<string, boolean>} */
|
||||
var features = {};
|
||||
var result = this.replayGroup_.forEachFeatureAtCoordinate(
|
||||
coordinate, resolution, 0, hitTolerance, skippedFeatureUids,
|
||||
/**
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
var key = getUid(feature).toString();
|
||||
if (!(key in features)) {
|
||||
features[key] = true;
|
||||
return callback(feature);
|
||||
}
|
||||
}, null);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get a reference to the wrapped source.
|
||||
* @return {ol.source.Vector} Source.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.getSource = function() {
|
||||
return this.source_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the style for features. This returns whatever was passed to the `style`
|
||||
* option at construction or to the `setStyle` method.
|
||||
* @return {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
|
||||
* Layer style.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.getStyle = function() {
|
||||
return this.style_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the style function.
|
||||
* @return {ol.StyleFunction|undefined} Layer style function.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.getStyleFunction = function() {
|
||||
return this.styleFunction_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.Size} size Size.
|
||||
* @return {!ol.Transform} Transform.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.getTransform_ = function(center, resolution, pixelRatio, size) {
|
||||
var dx1 = size[0] / 2;
|
||||
var dy1 = size[1] / 2;
|
||||
var sx = pixelRatio / resolution;
|
||||
var sy = -sx;
|
||||
var dx2 = -center[0];
|
||||
var dy2 = -center[1];
|
||||
|
||||
return _ol_transform_.compose(this.transform_, dx1, dy1, sx, sy, 0, dx2, dy2);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle changes in image style state.
|
||||
* @param {ol.events.Event} event Image style change event.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.handleImageChange_ = function(event) {
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.handleSourceChange_ = function() {
|
||||
// setState will trigger a CHANGE event, so we always rely
|
||||
// change events by calling setState.
|
||||
this.setState(this.source_.getState());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
|
||||
* @return {boolean} `true` if an image is loading.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.renderFeature_ = function(feature, resolution, pixelRatio, replayGroup) {
|
||||
var styles;
|
||||
var styleFunction = feature.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction.call(feature, resolution);
|
||||
} else if (this.styleFunction_) {
|
||||
styles = this.styleFunction_(feature, resolution);
|
||||
}
|
||||
if (!styles) {
|
||||
return false;
|
||||
}
|
||||
var i, ii, loading = false;
|
||||
if (!Array.isArray(styles)) {
|
||||
styles = [styles];
|
||||
}
|
||||
for (i = 0, ii = styles.length; i < ii; ++i) {
|
||||
loading = _ol_renderer_vector_.renderFeature(
|
||||
replayGroup, feature, styles[i],
|
||||
_ol_renderer_vector_.getSquaredTolerance(resolution, pixelRatio),
|
||||
this.handleImageChange_, this) || loading;
|
||||
}
|
||||
return loading;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the style for features. This can be a single style object, an array
|
||||
* of styles, or a function that takes a feature and resolution and returns
|
||||
* an array of styles. If it is `undefined` the default style is used. If
|
||||
* it is `null` the layer has no style (a `null` style), so only features
|
||||
* that have their own styles will be rendered in the layer. See
|
||||
* {@link ol.style} for information on the default style.
|
||||
* @param {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined}
|
||||
* style Layer style.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_ImageVector_.prototype.setStyle = function(style) {
|
||||
this.style_ = style !== undefined ? style : _ol_style_Style_.defaultFunction;
|
||||
this.styleFunction_ = !style ?
|
||||
undefined : _ol_style_Style_.createFunction(this.style_);
|
||||
this.changed();
|
||||
};
|
||||
export default _ol_source_ImageVector_;
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/source/Source
|
||||
*/
|
||||
import {inherits, nullFunction} from '../index.js';
|
||||
import _ol_Attribution_ from '../Attribution.js';
|
||||
import _ol_Object_ from '../Object.js';
|
||||
import _ol_proj_ from '../proj.js';
|
||||
import _ol_source_State_ from '../source/State.js';
|
||||
@@ -33,15 +32,9 @@ var _ol_source_Source_ = function(options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.Attribution>}
|
||||
* @type {?ol.Attribution}
|
||||
*/
|
||||
this.attributions_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?ol.Attribution2}
|
||||
*/
|
||||
this.attributions2_ = this.adaptAttributions_(options.attributions);
|
||||
this.attributions_ = this.adaptAttributions_(options.attributions);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -68,42 +61,14 @@ inherits(_ol_source_Source_, _ol_Object_);
|
||||
|
||||
/**
|
||||
* Turns the attributions option into an attributions function.
|
||||
* @suppress {deprecated}
|
||||
* @param {ol.AttributionLike|undefined} attributionLike The attribution option.
|
||||
* @return {?ol.Attribution2} An attribution function (or null).
|
||||
* @return {?ol.Attribution} An attribution function (or null).
|
||||
*/
|
||||
_ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) {
|
||||
if (!attributionLike) {
|
||||
return null;
|
||||
}
|
||||
if (attributionLike instanceof _ol_Attribution_) {
|
||||
|
||||
// TODO: remove attributions_ in next major release
|
||||
this.attributions_ = [attributionLike];
|
||||
|
||||
return function(frameState) {
|
||||
return [attributionLike.getHTML()];
|
||||
};
|
||||
}
|
||||
if (Array.isArray(attributionLike)) {
|
||||
if (attributionLike[0] instanceof _ol_Attribution_) {
|
||||
|
||||
// TODO: remove attributions_ in next major release
|
||||
this.attributions_ = attributionLike;
|
||||
|
||||
var attributions = attributionLike.map(function(attribution) {
|
||||
return attribution.getHTML();
|
||||
});
|
||||
return function(frameState) {
|
||||
return attributions;
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: remove attributions_ in next major release
|
||||
this.attributions_ = attributionLike.map(function(attribution) {
|
||||
return new _ol_Attribution_({html: attribution});
|
||||
});
|
||||
|
||||
return function(frameState) {
|
||||
return attributionLike;
|
||||
};
|
||||
@@ -113,11 +78,6 @@ _ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) {
|
||||
return attributionLike;
|
||||
}
|
||||
|
||||
// TODO: remove attributions_ in next major release
|
||||
this.attributions_ = [
|
||||
new _ol_Attribution_({html: attributionLike})
|
||||
];
|
||||
|
||||
return function(frameState) {
|
||||
return [attributionLike];
|
||||
};
|
||||
@@ -138,24 +98,14 @@ _ol_source_Source_.prototype.forEachFeatureAtCoordinate = nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Get the attributions of the source.
|
||||
* @return {Array.<ol.Attribution>} Attributions.
|
||||
* @api
|
||||
* Get the attribution function for the source.
|
||||
* @return {?ol.Attribution} Attribution function.
|
||||
*/
|
||||
_ol_source_Source_.prototype.getAttributions = function() {
|
||||
return this.attributions_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the attribution function for the source.
|
||||
* @return {?ol.Attribution2} Attribution function.
|
||||
*/
|
||||
_ol_source_Source_.prototype.getAttributions2 = function() {
|
||||
return this.attributions2_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the logo of the source.
|
||||
* @return {string|olx.LogoOptions|undefined} Logo.
|
||||
@@ -213,12 +163,12 @@ _ol_source_Source_.prototype.refresh = function() {
|
||||
/**
|
||||
* Set the attributions of the source.
|
||||
* @param {ol.AttributionLike|undefined} attributions Attributions.
|
||||
* Can be passed as `string`, `Array<string>`, `{@link ol.Attribution2}`,
|
||||
* Can be passed as `string`, `Array<string>`, `{@link ol.Attribution}`,
|
||||
* or `undefined`.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_Source_.prototype.setAttributions = function(attributions) {
|
||||
this.attributions2_ = this.adaptAttributions_(attributions);
|
||||
this.attributions_ = this.adaptAttributions_(attributions);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ _ol_source_TileJSON_.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||
this.tileUrlFunction =
|
||||
_ol_TileUrlFunction_.createFromTemplates(tileJSON.tiles, tileGrid);
|
||||
|
||||
if (tileJSON.attribution !== undefined && !this.getAttributions2()) {
|
||||
if (tileJSON.attribution !== undefined && !this.getAttributions()) {
|
||||
var attributionExtent = extent !== undefined ?
|
||||
extent : epsg4326Projection.getExtent();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user