Removing unused methods and changing getFeaturesObjectForExtent
With this change, getFeaturesObjectForExtent may return null if the source does not have data loaded for the provided extent. A callback can be passed to getFeaturesObjectForExtent to get notified when the requested data is available.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
@exportClass ol.layer.Vector ol.layer.VectorLayerOptions
|
||||
|
||||
@exportProperty ol.layer.Vector.prototype.addFeatures
|
||||
@exportProperty ol.layer.Vector.prototype.parseFeatures
|
||||
|
||||
@@ -279,34 +279,26 @@ ol.layer.Vector.prototype.getVectorSource = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression=} opt_expr Expression for filtering.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.layer.Vector.prototype.getFeatures = function(opt_expr) {
|
||||
return goog.object.getValues(
|
||||
this.featureCache_.getFeaturesObject(opt_expr));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression=} opt_expr Expression for filtering.
|
||||
* @return {Object.<string, ol.Feature>} Features.
|
||||
*/
|
||||
ol.layer.Vector.prototype.getFeaturesObject = function(opt_expr) {
|
||||
return this.featureCache_.getFeaturesObject(opt_expr);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get all features whose bounding box intersects the provided extent.
|
||||
* Get all features whose bounding box intersects the provided extent. This
|
||||
* method is intended for being called by the renderer. When null is returned,
|
||||
* the renderer should not waste time rendering, and `opt_callback` is
|
||||
* usually a function that requests a renderFrame, which will be called as soon
|
||||
* as the data for `extent` is available.
|
||||
*
|
||||
* @param {ol.Extent} extent Bounding extent.
|
||||
* @param {ol.Projection} projection Target projection.
|
||||
* @param {ol.geom.GeometryType=} opt_type Optional geometry type.
|
||||
* @return {Object.<string, ol.Feature>} Features.
|
||||
* @param {Function=} opt_callback Callback to call when data is parsed.
|
||||
* @return {Object.<string, ol.Feature>} Features or null if source is loading
|
||||
* data for `extent`.
|
||||
*/
|
||||
ol.layer.Vector.prototype.getFeaturesObjectForExtent = function(extent,
|
||||
opt_type) {
|
||||
return this.featureCache_.getFeaturesObjectForExtent(extent, opt_type);
|
||||
projection, opt_type, opt_callback) {
|
||||
var source = this.getSource();
|
||||
return source.prepareFeatures(this, extent, projection, opt_callback) ==
|
||||
ol.source.VectorLoadState.LOADING ?
|
||||
null :
|
||||
this.featureCache_.getFeaturesObjectForExtent(extent, opt_type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -228,9 +228,12 @@ ol.renderer.canvas.VectorLayer.prototype.getFeatureInfoForPixel =
|
||||
* @param {function(Array.<ol.Feature>, ol.layer.Layer)} success Callback for
|
||||
* successful queries. The passed arguments are the resulting features
|
||||
* and the layer.
|
||||
* @param {function(Object)=} opt_error Callback for
|
||||
* unsuccessful queries.
|
||||
*/
|
||||
ol.renderer.canvas.VectorLayer.prototype.getFeaturesForPixel =
|
||||
function(pixel, success) {
|
||||
function(pixel, success, opt_error) {
|
||||
// TODO What do we want to pass to the error callback?
|
||||
var map = this.getMap();
|
||||
var result = [];
|
||||
|
||||
@@ -247,7 +250,15 @@ ol.renderer.canvas.VectorLayer.prototype.getFeaturesForPixel =
|
||||
var locationMin = [location[0] - halfMaxWidth, location[1] - halfMaxHeight];
|
||||
var locationMax = [location[0] + halfMaxWidth, location[1] + halfMaxHeight];
|
||||
var locationBbox = ol.extent.boundingExtent([locationMin, locationMax]);
|
||||
var candidates = layer.getFeaturesObjectForExtent(locationBbox);
|
||||
var candidates = layer.getFeaturesObjectForExtent(locationBbox,
|
||||
map.getView().getView2D().getProjection());
|
||||
if (goog.isNull(candidates)) {
|
||||
// data is not loaded
|
||||
if (goog.isDef(opt_error)) {
|
||||
goog.global.setTimeout(function() { opt_error({}); }, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var candidate, geom, type, symbolBounds, symbolSize, halfWidth, halfHeight,
|
||||
coordinates, j;
|
||||
@@ -446,6 +457,7 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
dirty = false,
|
||||
i, type, tileExtent,
|
||||
groups, group, j, numGroups, featuresObject, tileHasFeatures;
|
||||
fetchTileData:
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
tileCoord = new ol.TileCoord(0, x, y);
|
||||
@@ -464,7 +476,12 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
if (!goog.isDef(featuresToRender[type])) {
|
||||
featuresToRender[type] = {};
|
||||
}
|
||||
featuresObject = layer.getFeaturesObjectForExtent(tileExtent, type);
|
||||
featuresObject = layer.getFeaturesObjectForExtent(tileExtent,
|
||||
projection, type, this.requestMapRenderFrame_);
|
||||
if (goog.isNull(featuresObject)) {
|
||||
deferred = true;
|
||||
break fetchTileData;
|
||||
}
|
||||
tileHasFeatures = tileHasFeatures ||
|
||||
!goog.object.isEmpty(featuresObject);
|
||||
goog.object.extend(featuresToRender[type], featuresObject);
|
||||
|
||||
Reference in New Issue
Block a user