Add skeleton for SLD parser

This commit is contained in:
Bart van den Eijnden
2013-09-24 11:33:53 +02:00
committed by Bart van den Eijnden
parent 20d5a45b7d
commit 76454516f5
9 changed files with 883 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
goog.provide('ol.test.parser.ogc.SLD_v1_0_0');
describe('ol.parser.ogc.SLD_v1_0_0', function() {
var parser = new ol.parser.ogc.SLD();
describe('reading and writing', function() {
it('Handles reading', function(done) {
var url = 'spec/ol/parser/ogc/xml/sld_v1_0_0.xml';
afterLoadXml(url, function(xml) {
var obj = parser.read(xml);
expect(obj.version).to.equal('1.0.0');
var style = obj.namedLayers['AAA161'].userStyles[0];
expect(style).to.be.a(ol.style.Style);
expect(style.rules_.length).to.equal(2);
var first = style.rules_[0];
expect(first).to.be.a(ol.style.Rule);
expect(first.filter_).to.be.a(ol.expr.Comparison);
expect(first.filter_.getLeft()).to.be.a(ol.expr.Identifier);
expect(first.filter_.getLeft().getName()).to.equal('CTE');
expect(first.filter_.getOperator()).to.equal(ol.expr.ComparisonOp.EQ);
expect(first.filter_.getRight()).to.be.a(ol.expr.Literal);
expect(first.filter_.getRight().getValue()).to.equal('V0305');
expect(first.getSymbolizers().length).to.equal(3);
expect(first.getSymbolizers()[0]).to.be.a(ol.style.Fill);
expect(first.getSymbolizers()[0].getColor().getValue()).to.equal(
'#ffffff');
expect(first.getSymbolizers()[0].getOpacity().getValue()).to.equal(0.4);
expect(first.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
expect(first.getSymbolizers()[1].getColor().getValue()).to.equal(
'#000000');
expect(first.getSymbolizers()[2]).to.be.a(ol.style.Text);
expect(first.getSymbolizers()[2].getText()).to.be.a(ol.expr.Call);
expect(first.getSymbolizers()[2].getText().getArgs().length).to.equal(
3);
expect(first.getSymbolizers()[2].getText().getArgs()[0]).to.be.a(
ol.expr.Literal);
expect(first.getSymbolizers()[2].getText().getArgs()[0].getValue()).
to.equal('A');
expect(first.getSymbolizers()[2].getText().getArgs()[1]).to.be.a(
ol.expr.Identifier);
expect(first.getSymbolizers()[2].getText().getArgs()[1].getName()).
to.equal('FOO');
expect(first.getSymbolizers()[2].getText().getArgs()[2]).to.be.a(
ol.expr.Literal);
expect(first.getSymbolizers()[2].getText().getArgs()[2].getValue()).
to.equal('label');
expect(first.getSymbolizers()[2].getColor().getValue()).to.equal(
ol.style.TextDefaults.color);
expect(first.getSymbolizers()[2].getFontFamily().getValue()).to.equal(
'Arial');
// TODO add tests for haloRadius and haloColor
var second = style.rules_[1];
expect(second.filter_).to.be.a(ol.expr.Comparison);
expect(second.getSymbolizers().length).to.equal(2);
expect(second.getSymbolizers()[0]).to.be.a(ol.style.Fill);
expect(second.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
done();
});
});
});
});
goog.require('goog.net.XhrIo');
goog.require('ol.parser.ogc.SLD_v1_0_0');
goog.require('ol.parser.ogc.SLD');
goog.require('ol.expr.Call');
goog.require('ol.expr.Comparison');
goog.require('ol.expr.ComparisonOp');
goog.require('ol.expr.Identifier');
goog.require('ol.expr.Literal');
goog.require('ol.style.Fill');
goog.require('ol.style.Rule');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
goog.require('ol.style.Text');

View File

@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld"
xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>AAA161</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<Name>stortsteen</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>CTE</ogc:PropertyName>
<ogc:Literal>V0305</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<MaxScaleDenominator>50000</MaxScaleDenominator>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#ffffff</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#000000</CssParameter>
</Stroke>
</PolygonSymbolizer>
<TextSymbolizer>
<Label> A <ogc:PropertyName>FOO</ogc:PropertyName> label </Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">14</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
<CssParameter name="font-style">normal</CssParameter>
</Font>
<LabelPlacement>
<PointPlacement>
<AnchorPoint>
<AnchorPointX>0.5</AnchorPointX>
<AnchorPointY>0.5</AnchorPointY>
</AnchorPoint>
<Displacement>
<DisplacementX>5</DisplacementX>
<DisplacementY>5</DisplacementY>
</Displacement>
<Rotation>45</Rotation>
</PointPlacement>
</LabelPlacement>
<Halo>
<Radius>3</Radius>
<Fill>
<CssParameter name="fill">#ffffff</CssParameter>
</Fill>
</Halo>
<Fill>
<CssParameter name="fill">#000000</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
<Rule>
<Name>betonbekleding</Name>
<ogc:Filter>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>CTE</ogc:PropertyName>
<ogc:Literal>1000</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:Filter>
<MaxScaleDenominator>50000</MaxScaleDenominator>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#ffff00</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#0000ff</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
<NamedLayer>
<Name>Second Layer</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<Name>first rule second layer</Name>
<ogc:Filter>
<ogc:Or>
<ogc:PropertyIsBetween>
<ogc:PropertyName>number</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>1064866676</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>1065512599</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
<ogc:PropertyName>cat</ogc:PropertyName>
<ogc:Literal>*dog.food!*good</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:Not>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>FOO</ogc:PropertyName>
<ogc:Literal>5000</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:Not>
</ogc:Or>
</ogc:Filter>
<MaxScaleDenominator>10000</MaxScaleDenominator>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>star</WellKnownName>
<Fill>
<CssParameter name="fill">lime</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">olive</CssParameter>
<CssParameter name="stroke-width">2</CssParameter>
</Stroke>
</Mark>
<Size><ogc:PropertyName>SIZE</ogc:PropertyName></Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>