我使用SLD来设置地理服务器的输出样式。我有几种类型的对象要显示。每种类型都有不同的图标,但文本描述是从相同的信息(数据库中的文本字段)生成的。我不能使用object_type作为图像名称,因为你不能在图像名称中使用变量(或者我不知道如何做...)。所以我喜欢SLD(没有不重要的部分):
<StyledLayerDescriptor>
<NamedLayer>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<Filter>
<PropertyIsEqualTo>
<PropertyName>object_type</PropertyName>
<Literal>1</Literal>
</PropertyIsEqualTo>
</Filter>
<PointSymbolizer>
<Graphic>
<ExternalGraphic>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/1.png" />
<Format>image/png</Format>
</ExternalGraphic>
<Size>16</Size>
<Opacity>1</Opacity>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>name</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Times New Roman</CssParameter>
<CssParameter name="font-style">Normal</CssParameter>
<CssParameter name="font-size">12</CssParameter>
</Font>
<Fill>
<CssParameter name="fill">#110011</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Halo />
</TextSymbolizer>
</Rule>
<Rule>
<Filter>
<PropertyIsEqualTo>
<PropertyName>object_type</PropertyName>
<Literal>2</Literal>
</PropertyIsEqualTo>
</Filter>
<PointSymbolizer>
<Graphic>
<ExternalGraphic>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/2.png" />
<Format>image/png</Format>
</ExternalGraphic>
<Size>16</Size>
<Opacity>1</Opacity>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>name</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Times New Roman</CssParameter>
<CssParameter name="font-style">Normal</CssParameter>
<CssParameter name="font-size">12</CssParameter>
</Font>
<Fill>
<CssParameter name="fill">#110011</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Halo />
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
我喜欢做的事情就是编写TextSymbolizer并在两个或更多的地方使用它......我没有听说过XML中的任何类似内容,但也许你有吗? : - )
我遇到的一个解决方案是编写一些非常简单的生成器(xml.erb?:P)并让它生成XML ......
答案 0 :(得分:1)
您是否尝试为您的XML定义XML Schema或可选的XML DTD,然后使用element identifiers http://www.w3.org/TR/xmlschema-0/#schemaConstraintsVsXML1,例如:
<StyledLayerDescriptor>
<NamedLayer>
<CommonStyles>
<TextSymbolizer id="name_times_normal_12">
<Label>
<ogc:PropertyName>name</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Times New Roman</CssParameter>
<CssParameter name="font-style">Normal</CssParameter>
<CssParameter name="font-size">12</CssParameter>
</Font>
<Fill>
<CssParameter name="fill">#110011</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Halo />
</TextSymbolizer>
</CommonStyles>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<Filter>
<PropertyIsEqualTo>
<PropertyName>object_type</PropertyName>
<Literal>1</Literal>
</PropertyIsEqualTo>
</Filter>
<PointSymbolizer>
<Graphic>
<ExternalGraphic>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/1.png" />
<Format>image/png</Format>
</ExternalGraphic>
<Size>16</Size>
<Opacity>1</Opacity>
</Graphic>
</PointSymbolizer>
<TextSymbolizer ref="#name_times_normal_12" />
</Rule>
<Rule>
<Filter>
<PropertyIsEqualTo>
<PropertyName>object_type</PropertyName>
<Literal>2</Literal>
</PropertyIsEqualTo>
</Filter>
<PointSymbolizer>
<Graphic>
<ExternalGraphic>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/2.png" />
<Format>image/png</Format>
</ExternalGraphic>
<Size>16</Size>
<Opacity>1</Opacity>
</Graphic>
</PointSymbolizer>
<TextSymbolizer ref="#name_times_normal_12" />
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
答案 1 :(得分:1)
答案 2 :(得分:1)
GeoServer对SLD的“动态符号化”扩展允许您将数据库属性用作全部或部分图标URL。如果需要,您甚至可以执行计算和调用过滤器函数(它们在URL中使用嵌入式CQL。
以下是有关该功能的博文:http://blog.geoserver.org/2008/12/08/dynamic-symbolizers-part-1/