Separate load requests from feature requests
This separates the action of requesting an extent to be loaded from the action of requesting cached features. The renderer (or any other consumer of a vector source) calls load to request a data extent. A `featureload` event fires when new features are loaded. The renderer (or any other consumer) separately asks for cached features given an extent. This vector source only loads features once, but this separation will also work with sources that make multiple requests for data in different extents. This also removes the `data` option from the vector source in favor of a `features` option. Since we no longer have shared data structures for geometries, people can manually create features and pass them to a vector source. The `addFeatures` method is exported as well. This is used to add features to a source that don't have a representation on the "remote" (or server).
This commit is contained in:
@@ -92,6 +92,7 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, layer) {
|
||||
|
||||
var source = layer.getSource();
|
||||
goog.events.listen(source, [
|
||||
ol.source.VectorEventType.LOAD,
|
||||
ol.source.VectorEventType.ADD,
|
||||
ol.source.VectorEventType.CHANGE,
|
||||
ol.source.VectorEventType.REMOVE,
|
||||
@@ -427,6 +428,15 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
this.tileArchetype_.height = tileSize[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the source to know what data extent we want loaded. As there may
|
||||
* already be features loaded, we continue with rendering after this request.
|
||||
* If this results in loading new features, a new rendering will be triggered.
|
||||
*/
|
||||
var layer = this.getVectorLayer();
|
||||
var source = layer.getVectorSource();
|
||||
source.load(tileRangeExtent, projection);
|
||||
|
||||
/**
|
||||
* Prepare the sketch canvas. This covers the currently visible tile range
|
||||
* and will have rendered all newly visible features.
|
||||
@@ -474,8 +484,6 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
var tile, tileCoord, key, x, y, i, type;
|
||||
var deferred = false;
|
||||
var dirty = false;
|
||||
var layer = this.getVectorLayer();
|
||||
var source = layer.getSource();
|
||||
var tileExtent, featuresObject, tileHasFeatures;
|
||||
fetchTileData:
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
@@ -491,8 +499,8 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
tileExtent[1] -= tileGutter;
|
||||
tileExtent[3] += tileGutter;
|
||||
tileHasFeatures = false;
|
||||
featuresObject = source.getFeaturesObjectForExtent(tileExtent,
|
||||
projection, this.requestMapRenderFrame_);
|
||||
featuresObject = source.getFeaturesObjectForExtent(
|
||||
tileExtent, projection);
|
||||
if (goog.isNull(featuresObject)) {
|
||||
deferred = true;
|
||||
break fetchTileData;
|
||||
|
||||
Reference in New Issue
Block a user