Fix IIFE invoking Canvas APIs that don't exist in early IE

Changed ol.interaction.Draw.defaultStyleFunction to be a getter, so
that it only calls Canvas APIs when needed, rather than on script load
This commit is contained in:
Austin Hyde
2014-01-22 11:44:20 -05:00
parent b0849cc85c
commit 48cf5926b8

View File

@@ -148,18 +148,16 @@ ol.interaction.Draw = function(opt_options) {
*/ */
this.overlay_ = new ol.render.FeaturesOverlay(); this.overlay_ = new ol.render.FeaturesOverlay();
this.overlay_.setStyleFunction(goog.isDef(opt_options.styleFunction) ? this.overlay_.setStyleFunction(goog.isDef(opt_options.styleFunction) ?
opt_options.styleFunction : ol.interaction.Draw.defaultStyleFunction opt_options.styleFunction : ol.interaction.Draw.getDefaultStyleFunction()
); );
}; };
goog.inherits(ol.interaction.Draw, ol.interaction.Interaction); goog.inherits(ol.interaction.Draw, ol.interaction.Interaction);
/** /**
* @param {ol.Feature} feature Feature. * @return {ol.feature.StyleFunction} Styles.
* @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Styles.
*/ */
ol.interaction.Draw.defaultStyleFunction = (function() { ol.interaction.Draw.getDefaultStyleFunction = function() {
/** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */ /** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */
var styles = {}; var styles = {};
styles[ol.geom.GeometryType.POLYGON] = [ styles[ol.geom.GeometryType.POLYGON] = [
@@ -210,7 +208,7 @@ ol.interaction.Draw.defaultStyleFunction = (function() {
return function(feature, resolution) { return function(feature, resolution) {
return styles[feature.getGeometry().getType()]; return styles[feature.getGeometry().getType()];
}; };
})(); };
/** /**