Use a private variable to cache the default style array

See #1815
Fixes #4063
This commit is contained in:
Frederic Junod
2015-08-31 17:19:22 +02:00
parent 965a27b115
commit 5371d8dd34
+29 -32
View File
@@ -239,48 +239,45 @@ ol.style.createStyleFunction = function(obj) {
}; };
/**
* @type {Array.<ol.style.Style>}
* @private
*/
ol.style.defaultStyle_ = null;
/** /**
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Style. * @return {Array.<ol.style.Style>} Style.
*/ */
ol.style.defaultStyleFunction = function(feature, resolution) { ol.style.defaultStyleFunction = function(feature, resolution) {
var fill = new ol.style.Fill({ // We don't use an immediately-invoked function
color: 'rgba(255,255,255,0.4)'
});
var stroke = new ol.style.Stroke({
color: '#3399CC',
width: 1.25
});
var styles = [
new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
];
// Now that we've run it the first time, replace the function with
// a constant version. We don't use an immediately-invoked function
// and a closure so we don't get an error at script evaluation time in // and a closure so we don't get an error at script evaluation time in
// browsers that do not support Canvas. (ol.style.Circle does // browsers that do not support Canvas. (ol.style.Circle does
// canvas.getContext('2d') at construction time, which will cause an.error // canvas.getContext('2d') at construction time, which will cause an.error
// in such browsers.) // in such browsers.)
if (goog.isNull(ol.style.defaultStyle_)) {
/** var fill = new ol.style.Fill({
* @param {ol.Feature} feature Feature. color: 'rgba(255,255,255,0.4)'
* @param {number} resolution Resolution. });
* @return {Array.<ol.style.Style>} Style. var stroke = new ol.style.Stroke({
*/ color: '#3399CC',
ol.style.defaultStyleFunction = function(feature, resolution) { width: 1.25
return styles; });
}; ol.style.defaultStyle_ = [
new ol.style.Style({
return styles; image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
];
}
return ol.style.defaultStyle_;
}; };