SLD format rewrite. Adds a versioned parser with read and write support. This does not come with full support for ogc:expression parsing, but makes for easy future enhancements. r=ahocevar (closes #1458)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6645 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-03-27 17:18:05 +00:00
parent 6b1903b5a3
commit 3b267f5334
11 changed files with 1620 additions and 719 deletions

View File

@@ -17,17 +17,16 @@
}
function test_Format_SLD_read(t) {
t.plan(5);
var styles = new OpenLayers.Format.SLD().read(this.test_content,
{withNamedLayer: true});
t.plan(4);
var sld = new OpenLayers.Format.SLD().read(this.test_content);
var testLayer = styles[1].TestLayer;
var testLayer = sld.namedLayers["TestLayer"];
var userStyles = testLayer.userStyles;
t.ok(testLayer.foo != undefined, "SLD correctly reads a UserStyle named \"foo\"");
t.eq(testLayer.foo.rules.length, 1, "The number of rules for the UserStyle is correct");
t.eq(testLayer.foo.rules[0].name, "bar", "The first rule's name is \"bar\"");
t.eq(testLayer.foo.rules[0].symbolizer.Polygon.fillColor, "blue", "The fillColor for the Polygon symbolizer is correct");
t.eq(testLayer.foo.name, styles[0][0].name, "The content hash of the Format contains the correct rules.");
t.eq(userStyles[0].name, "foo", "SLD correctly reads a UserStyle named 'foo'");
t.eq(userStyles[0].rules.length, 1, "The number of rules for the UserStyle is correct");
t.eq(userStyles[0].rules[0].name, "bar", "The first rule's name is 'bar'");
t.eq(userStyles[0].rules[0].symbolizer.Polygon.fillColor, "blue", "The fillColor for the Polygon symbolizer is correct");
}
</script>

View File

@@ -37,26 +37,50 @@
t.eq(rule.value, ".*b.r\\%\\..*", "Regular expression with different wildcard and escape chars generated correctly.");
}
function test_regex2value(t) {
t.plan(8);
function r2v(regex) {
return OpenLayers.Rule.Comparison.prototype.regex2value.call(
{value: regex}
);
}
t.eq(r2v("foo"), "foo", "doesn't change string without special chars");
t.eq(r2v("foo.*foo"), "foo*foo", "wildCard replaced");
t.eq(r2v("foo.foo"), "foo.foo", "singleChar replaced");
t.eq(r2v("foo\\\\foo"), "foo\\foo", "escape removed");
t.eq(r2v("foo!foo"), "foo!!foo", "escapes !");
t.eq(r2v("foo\\*foo"), "foo!*foo", "replaces escape on *");
t.eq(r2v("foo\\.foo"), "foo!.foo", "replaces escape on .");
t.eq(r2v("foo\\\\.foo"), "foo\\.foo", "unescapes only \\ before .");
}
function test_Comparison_evaluate(t) {
t.plan(4);
t.plan(5);
var rule = new OpenLayers.Rule.Comparison({
property: "area",
lowerBoundary: 1000,
upperBoundary: 5000,
upperBoundary: 4999,
type: OpenLayers.Rule.Comparison.BETWEEN});
var features = [
new OpenLayers.Feature.Vector(null, {
area: 2000}),
area: 999}),
new OpenLayers.Feature.Vector(null, {
area: 6000}),
area: 1000}),
new OpenLayers.Feature.Vector(null, {
area: 4999})];
area: 4999}),
new OpenLayers.Feature.Vector(null, {
area: 5000})];
// PropertyIsBetween filter: lower and upper boundary are inclusive
var ruleResults = {
0: true,
1: false,
2: true};
0: false,
1: true,
2: true,
3: false};
for (var i in ruleResults) {
var result = rule.evaluate(features[i]);
t.eq(result, ruleResults[i], "feature "+i+