* new convenience method addUniqueValueRules in OL.!StyleMap. This can actually be used to achieve what I was trying to show in the example of this ticket's description. * some refactoring of OL.Style to remove duplicate code (with tests) * a new example showing how to add a "unique value" legend to a point layer using the new addUniqueValueRules method * Rule.symbolizer can now also be just a symbolizer, instead of a hash of symbolizers keyed by "Point", "Line", "Polygon". This will make things even simpler (as can be seen in the styles-unique.html example) r=tschaub (closes #1373) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6396 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
76 lines
2.5 KiB
HTML
76 lines
2.5 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_Comparison_constructor(t) {
|
|
t.plan(3);
|
|
|
|
var options = {'foo': 'bar'};
|
|
var rule = new OpenLayers.Rule.Comparison(options);
|
|
t.ok(rule instanceof OpenLayers.Rule.Comparison,
|
|
"new OpenLayers.Rule.Comparison returns object" );
|
|
t.eq(rule.foo, "bar", "constructor sets options correctly");
|
|
t.eq(typeof rule.evaluate, "function", "rule has an evaluate function");
|
|
}
|
|
|
|
function test_Comparison_destroy(t) {
|
|
t.plan(1);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison();
|
|
rule.destroy();
|
|
t.eq(rule.symbolizer, null, "symbolizer hash nulled properly");
|
|
}
|
|
|
|
function test_Comparison_value2regex(t) {
|
|
t.plan(2);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison({
|
|
property: "foo",
|
|
value: "*b?r\\*\\?*",
|
|
type: OpenLayers.Rule.Comparison.LIKE});
|
|
rule.value2regex("*", "?", "\\");
|
|
t.eq(rule.value, ".*b.r\\*\\?.*", "Regular expression generated correctly.");
|
|
|
|
rule.value = "%b.r!%!.%";
|
|
rule.value2regex("%", ".", "!");
|
|
t.eq(rule.value, ".*b.r\\%\\..*", "Regular expression with different wildcard and escape chars generated correctly.");
|
|
}
|
|
|
|
function test_Comparison_evaluate(t) {
|
|
t.plan(4);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison({
|
|
property: "area",
|
|
lowerBoundary: 1000,
|
|
upperBoundary: 5000,
|
|
type: OpenLayers.Rule.Comparison.BETWEEN});
|
|
|
|
var features = [
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 2000}),
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 6000}),
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 4999})];
|
|
var ruleResults = {
|
|
0: true,
|
|
1: false,
|
|
2: true};
|
|
for (var i in ruleResults) {
|
|
var result = rule.evaluate(features[i]);
|
|
t.eq(result, ruleResults[i], "feature "+i+
|
|
" evaluates to "+result.toString()+" correctly.");
|
|
}
|
|
rule.context = {
|
|
area: 4998
|
|
}
|
|
var result = rule.evaluate();
|
|
t.eq(result, true, "evaluation against custom rule context works.");
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|