Merge pull request #2018 from fredj/featureoverlay-cleanup

Miscellaneous ol.FeatureOverlay cleanup
This commit is contained in:
Frédéric Junod
2014-04-28 15:24:35 +02:00
+6 -12
View File
@@ -113,8 +113,7 @@ ol.FeatureOverlay.prototype.handleFeatureChange_ = function() {
* @private * @private
* @param {ol.CollectionEvent} collectionEvent Collection event. * @param {ol.CollectionEvent} collectionEvent Collection event.
*/ */
ol.FeatureOverlay.prototype.handleFeaturesAdd_ = ol.FeatureOverlay.prototype.handleFeaturesAdd_ = function(collectionEvent) {
function(collectionEvent) {
goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_)); goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_));
var feature = /** @type {ol.Feature} */ (collectionEvent.element); var feature = /** @type {ol.Feature} */ (collectionEvent.element);
this.featureChangeListenerKeys_[goog.getUid(feature).toString()] = this.featureChangeListenerKeys_[goog.getUid(feature).toString()] =
@@ -128,8 +127,7 @@ ol.FeatureOverlay.prototype.handleFeaturesAdd_ =
* @private * @private
* @param {ol.CollectionEvent} collectionEvent Collection event. * @param {ol.CollectionEvent} collectionEvent Collection event.
*/ */
ol.FeatureOverlay.prototype.handleFeaturesRemove_ = ol.FeatureOverlay.prototype.handleFeaturesRemove_ = function(collectionEvent) {
function(collectionEvent) {
goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_)); goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_));
var feature = /** @type {ol.Feature} */ (collectionEvent.element); var feature = /** @type {ol.Feature} */ (collectionEvent.element);
var key = goog.getUid(feature).toString(); var key = goog.getUid(feature).toString();
@@ -153,7 +151,7 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
} }
var resolution = event.frameState.view2DState.resolution; var resolution = event.frameState.view2DState.resolution;
var vectorContext = event.vectorContext; var vectorContext = event.vectorContext;
var i, ii, feature, styles; var i, ii, styles;
this.features_.forEach(function(feature) { this.features_.forEach(function(feature) {
styles = styleFunction(feature, resolution); styles = styleFunction(feature, resolution);
if (!goog.isDefAndNotNull(styles)) { if (!goog.isDefAndNotNull(styles)) {
@@ -163,7 +161,7 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
for (i = 0; i < ii; ++i) { for (i = 0; i < ii; ++i) {
vectorContext.drawFeature(feature, styles[i]); vectorContext.drawFeature(feature, styles[i]);
} }
}, this); });
}; };
@@ -210,15 +208,11 @@ ol.FeatureOverlay.prototype.setFeatures = function(features) {
this.handleFeaturesRemove_, false, this) this.handleFeaturesRemove_, false, this)
]; ];
this.featureChangeListenerKeys_ = {}; this.featureChangeListenerKeys_ = {};
var featuresArray = features.getArray(); features.forEach(function(feature) {
var i, ii = featuresArray.length;
var feature;
for (i = 0; i < ii; ++i) {
feature = featuresArray[i];
this.featureChangeListenerKeys_[goog.getUid(feature).toString()] = this.featureChangeListenerKeys_[goog.getUid(feature).toString()] =
goog.events.listen(feature, goog.events.EventType.CHANGE, goog.events.listen(feature, goog.events.EventType.CHANGE,
this.handleFeatureChange_, false, this); this.handleFeatureChange_, false, this);
} }, this);
} }
this.render_(); this.render_();
}; };