Lazily create default style

This commit is contained in:
Tim Schaub
2013-09-04 07:17:08 -06:00
parent cc11efa420
commit 13a937fad7
4 changed files with 121 additions and 73 deletions

View File

@@ -18,6 +18,7 @@ goog.require('ol.layer.Layer');
goog.require('ol.proj');
goog.require('ol.source.Vector');
goog.require('ol.structs.RTree');
goog.require('ol.style');
goog.require('ol.style.Style');
goog.require('ol.style.TextLiteral');
@@ -436,12 +437,11 @@ ol.layer.Vector.prototype.groupFeaturesBySymbolizerLiteral =
if (!goog.isNull(symbolizers)) {
literals = ol.style.Style.createLiterals(symbolizers, feature);
} else {
if (!goog.isNull(style)) {
// layer style second
literals = style.createLiterals(feature);
} else {
literals = ol.style.Style.defaults.createLiterals(feature);
// layer style second
if (goog.isNull(style)) {
style = ol.style.getDefault();
}
literals = style.createLiterals(feature);
}
numLiterals = literals.length;
for (j = 0; j < numLiterals; ++j) {

View File

@@ -123,13 +123,3 @@ ol.style.FillDefaults = {
color: '#ffffff',
opacity: 0.4
};
/**
* @typedef {{color: (string),
* opacity: (number)}}
*/
ol.style.FillDefaultsSelect = {
color: '#ffffff',
opacity: 0.7
};

View File

@@ -1,7 +1,12 @@
goog.provide('ol.style');
goog.provide('ol.style.Style');
goog.require('goog.object');
goog.require('ol.Feature');
goog.require('ol.expr.Call');
goog.require('ol.expr.Identifier');
goog.require('ol.expr.Literal');
goog.require('ol.expr.functions');
goog.require('ol.geom.GeometryType');
goog.require('ol.style.Fill');
goog.require('ol.style.Literal');
@@ -65,30 +70,70 @@ ol.style.Style.prototype.createLiterals = function(feature) {
/**
* The default style.
* @type {ol.style.Style}
* @private
*/
ol.style.Style.defaults = new ol.style.Style({
rules: [
new ol.style.Rule({
filter: 'renderIntent("select")',
ol.style.default_ = null;
/**
* Get the default style.
* @return {ol.style.Style} The default style.
*/
ol.style.getDefault = function() {
if (goog.isNull(ol.style.default_)) {
ol.style.default_ = new ol.style.Style({
rules: [
new ol.style.Rule({
filter: new ol.expr.Call(
new ol.expr.Identifier(ol.expr.functions.RENDER_INTENT),
[new ol.expr.Literal('select')]),
symbolizers: [
new ol.style.Shape({
fill: new ol.style.Fill({
color: '#ffffff',
opacity: 0.7
}),
stroke: new ol.style.Stroke({
color: '#696969',
opacity: 0.9,
width: 2.0
})
}),
new ol.style.Fill({
color: '#ffffff',
opacity: 0.7
}),
new ol.style.Stroke({
color: '#696969',
opacity: 0.9,
width: 2.0
})
]
})
],
symbolizers: [
new ol.style.Shape({
fill: new ol.style.Fill(ol.style.FillDefaultsSelect),
stroke: new ol.style.Stroke(ol.style.StrokeDefaultsSelect)
fill: new ol.style.Fill(),
stroke: new ol.style.Stroke()
}),
new ol.style.Fill(ol.style.FillDefaultsSelect),
new ol.style.Stroke(ol.style.StrokeDefaultsSelect)
new ol.style.Fill(),
new ol.style.Stroke()
]
})
],
symbolizers: [
new ol.style.Shape({
fill: new ol.style.Fill(),
stroke: new ol.style.Stroke()
}),
new ol.style.Fill(),
new ol.style.Stroke()
]
});
});
}
return ol.style.default_;
};
/**
* Set the default style.
* @param {ol.style.Style} style The new default style.
* @return {ol.style.Style} The default style.
*/
ol.style.setDefault = function(style) {
ol.style.default_ = style;
return style;
};
/**