Style constructor accepts a rules array. These rules will be added to the style. r=ahocevar (closes #1964)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8975 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+12
-4
@@ -85,21 +85,29 @@ OpenLayers.Style = OpenLayers.Class({
|
|||||||
* used as default style for this style object. This style
|
* used as default style for this style object. This style
|
||||||
* applies if no rules are specified. Symbolizers defined in
|
* applies if no rules are specified. Symbolizers defined in
|
||||||
* rules will extend this default style.
|
* rules will extend this default style.
|
||||||
* options - {Object} An optional object with properties to set on the
|
* options - {Object} An optional object with properties to set on the
|
||||||
* userStyle
|
* style.
|
||||||
|
*
|
||||||
|
* Valid options:
|
||||||
|
* rules - {Array(<OpenLayers.Rule>)} List of rules to be added to the
|
||||||
|
* style.
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* {<OpenLayers.Style>}
|
* {<OpenLayers.Style>}
|
||||||
*/
|
*/
|
||||||
initialize: function(style, options) {
|
initialize: function(style, options) {
|
||||||
|
|
||||||
|
OpenLayers.Util.extend(this, options);
|
||||||
this.rules = [];
|
this.rules = [];
|
||||||
|
if(options && options.rules) {
|
||||||
|
this.addRules(options.rules);
|
||||||
|
}
|
||||||
|
|
||||||
// use the default style from OpenLayers.Feature.Vector if no style
|
// use the default style from OpenLayers.Feature.Vector if no style
|
||||||
// was given in the constructor
|
// was given in the constructor
|
||||||
this.setDefaultStyle(style ||
|
this.setDefaultStyle(style ||
|
||||||
OpenLayers.Feature.Vector.style["default"]);
|
OpenLayers.Feature.Vector.style["default"]);
|
||||||
|
|
||||||
OpenLayers.Util.extend(this, options);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+26
-3
@@ -4,13 +4,36 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function test_Style_constructor(t) {
|
function test_Style_constructor(t) {
|
||||||
t.plan(3);
|
t.plan(6);
|
||||||
|
|
||||||
var options = {'foo': 'bar'};
|
var rules = [
|
||||||
var style = new OpenLayers.Style(null, options);
|
new OpenLayers.Rule({
|
||||||
|
symbolizer: {fillColor: "red"},
|
||||||
|
filter: new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.EQUAL_TO,
|
||||||
|
property: "type",
|
||||||
|
value: "fire engine"
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
new OpenLayers.Rule({
|
||||||
|
symbolizer: {fillColor: "yellow"},
|
||||||
|
filter: new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.EQUAL_TO,
|
||||||
|
property: "type",
|
||||||
|
value: "sports car"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
];
|
||||||
|
var style = new OpenLayers.Style(null, {
|
||||||
|
foo: "bar",
|
||||||
|
rules: rules
|
||||||
|
});
|
||||||
t.ok(style instanceof OpenLayers.Style,
|
t.ok(style instanceof OpenLayers.Style,
|
||||||
"new OpenLayers.Style returns object" );
|
"new OpenLayers.Style returns object" );
|
||||||
t.eq(style.foo, "bar", "constructor sets options correctly");
|
t.eq(style.foo, "bar", "constructor sets options correctly");
|
||||||
|
t.eq(style.rules.length, 2, "correct number of rules added");
|
||||||
|
t.ok(style.rules[0] === rules[0], "correct first rule added");
|
||||||
|
t.ok(style.rules[1] === rules[1], "correct second rule added");
|
||||||
t.eq(typeof style.createSymbolizer, "function", "style has a createSymbolizer function");
|
t.eq(typeof style.createSymbolizer, "function", "style has a createSymbolizer function");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user