From 0e21d2c99ddd1b34fe6f78c9f1c78f3dcf920f1b Mon Sep 17 00:00:00 2001 From: Austin Hyde Date: Thu, 6 Mar 2014 15:31:26 -0500 Subject: [PATCH] Lazily create ol.defaultFeatureStyleFunction Besides the slight performance benefit of not prerendering the default circle style until we need to, this change also allows loading OL3 in browsers that don't support the canvas API (IE 7-8). If the circle style is rendered on load, the lack of HTMLCanvasElement#getContext causes IE 7-8 to bomb, regardless of if vector styles are used at all. --- src/ol/feature.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ol/feature.js b/src/ol/feature.js index 642b602d80..430b26eac7 100644 --- a/src/ol/feature.js +++ b/src/ol/feature.js @@ -222,7 +222,7 @@ ol.feature.FeatureStyleFunction; * @this {ol.Feature} * @todo stability experimental */ -ol.feature.defaultFeatureStyleFunction = (function() { +ol.feature.defaultFeatureStyleFunction = function(resolution) { var fill = new ol.style.Fill({ color: 'rgba(255,255,255,0.4)' }); @@ -241,10 +241,17 @@ ol.feature.defaultFeatureStyleFunction = (function() { stroke: stroke }) ]; - return function(resolution) { - return styles; - }; -})(); + + // now that we've run it the first time, + // replace the function with a constant version + ol.feature.defaultFeatureStyleFunction = + /** @type {function(this:ol.Feature):Array.} */( + function(resolution) { + return styles; + }); + + return styles; +}; /**