Load the icon when needed in ol.FeatureOverlay
This commit is contained in:
@@ -10,6 +10,7 @@ goog.require('ol.CollectionEventType');
|
|||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.feature');
|
goog.require('ol.feature');
|
||||||
goog.require('ol.render.EventType');
|
goog.require('ol.render.EventType');
|
||||||
|
goog.require('ol.style.ImageState');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -92,6 +93,35 @@ ol.FeatureOverlay.prototype.addFeature = function(feature) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.render.IVectorContext|undefined} vectorContext Vector context.
|
||||||
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {ol.style.Style} style Style.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.FeatureOverlay.prototype.drawFeature_ = function(vectorContext, feature,
|
||||||
|
style) {
|
||||||
|
var imageStyle = style.getImage();
|
||||||
|
if (!goog.isNull(imageStyle)) {
|
||||||
|
var imageState = imageStyle.getImageState();
|
||||||
|
if (imageState == ol.style.ImageState.LOADED ||
|
||||||
|
imageState == ol.style.ImageState.ERROR) {
|
||||||
|
imageStyle.unlistenImageChange(this.handleImageChange_, this);
|
||||||
|
if (imageState == ol.style.ImageState.LOADED) {
|
||||||
|
vectorContext.drawFeature(feature, style);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (imageState == ol.style.ImageState.IDLE) {
|
||||||
|
imageStyle.load();
|
||||||
|
}
|
||||||
|
imageState = imageStyle.getImageState();
|
||||||
|
goog.asserts.assert(imageState == ol.style.ImageState.LOADING);
|
||||||
|
imageStyle.listenImageChange(this.handleImageChange_, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Collection} Features collection.
|
* @return {ol.Collection} Features collection.
|
||||||
* @todo api
|
* @todo api
|
||||||
@@ -137,6 +167,16 @@ ol.FeatureOverlay.prototype.handleFeaturesRemove_ = function(collectionEvent) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle changes in image style state.
|
||||||
|
* @param {goog.events.Event} event Image style change event.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.FeatureOverlay.prototype.handleImageChange_ = function(event) {
|
||||||
|
this.render_();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.render.Event} event Event.
|
* @param {ol.render.Event} event Event.
|
||||||
* @private
|
* @private
|
||||||
@@ -159,9 +199,9 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
|
|||||||
}
|
}
|
||||||
ii = styles.length;
|
ii = styles.length;
|
||||||
for (i = 0; i < ii; ++i) {
|
for (i = 0; i < ii; ++i) {
|
||||||
vectorContext.drawFeature(feature, styles[i]);
|
this.drawFeature_(vectorContext, feature, styles[i]);
|
||||||
}
|
}
|
||||||
});
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user