Skip to content

Commit

Permalink
Listen for layer changes and expire tiles
Browse files Browse the repository at this point in the history
We need a more flexible event system.  We could have a VectorLayerEvent type and dispatch 'featuresadded' here.  But listeners want features typically and perhaps extent.  This won't be true for all vector layer events (suggesting a more specific VectorFeatureEvent type or something).
  • Loading branch information
tschaub committed Mar 7, 2013
1 parent d7c547f commit 00fa7ff
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ol/renderer/canvas/canvasvectorlayerrenderer.js
Expand Up @@ -69,6 +69,9 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, layer) {
*/
this.tileCache_ = new ol.TileCache(
ol.renderer.canvas.VectorLayer.TILECACHE_SIZE);
// TODO: this is far too coarse, we want extent of added features
goog.events.listenOnce(layer, goog.events.EventType.CHANGE,
this.handleLayerChange_, false, this);

/**
* @private
Expand Down Expand Up @@ -139,6 +142,20 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, layer) {
goog.inherits(ol.renderer.canvas.VectorLayer, ol.renderer.canvas.Layer);


/**
* Get rid cached tiles. If the optional extent is provided, only tiles that
* intersect that extent will be removed.
* @param {ol.Extent=} opt_extent extent Expire tiles within this extent only.
* @private
*/
ol.renderer.canvas.VectorLayer.prototype.expireTiles_ = function(opt_extent) {
if (goog.isDef(opt_extent)) {
// TODO: implement this
}
this.tileCache_.clear();
};


/**
* @inheritDoc
*/
Expand All @@ -163,6 +180,17 @@ ol.renderer.canvas.VectorLayer.prototype.getTransform = function() {
};


/**
* @param {goog.events.Event} event Layer change event.
* @private
*/
ol.renderer.canvas.VectorLayer.prototype.handleLayerChange_ = function(event) {
// TODO: get rid of this in favor of vector specific events
this.expireTiles_();
this.requestMapRenderFrame_();
};


/**
* @inheritDoc
*/
Expand Down

0 comments on commit 00fa7ff

Please sign in to comment.