您可以重用 XML 片段(以某种变量/引用的方式)吗?
我正在使用 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...
I am using SLD to style output from my geoserver. I have couple types of objects to be displayed. Each type have different icons, but text description is generated from the same information (text field in the database). I cannot use object_type as image name because you cannot use variable in image name (or I do not know how to do it...). So I Have SLD like (without unimportant parts):
<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>
And the thing I'd love to do would be writing TextSymbolizer once and using it in two or more places... I have not heard of anything like that in XML, but maybe you have? :-)
One solution that comes to me, is to write some very simple generator (xml.erb? :P) and let it generate XML...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GeoServer 对 SLD 的“动态符号生成器”扩展允许您使用数据库属性作为图标 URL 的全部或部分。 如果需要,您甚至可以执行计算并调用过滤器函数(它们在 URL 中使用嵌入式 CQL。
以下是有关该功能的博客文章:http://blog.geoserver.org/2008/12/08/dynamic-symbolizers-part-1/
GeoServer's "Dynamic Symbolizer" extension to SLD does allow you to use database properties as all or part of icon URLs. You can even perform calculations and call filter functions if you want (they use embedded CQL in the URL.
Here's a blog post on the feature: http://blog.geoserver.org/2008/12/08/dynamic-symbolizers-part-1/
您是否尝试过定义 XML 架构 或可选的 XML DTD 用于您的 XML,然后使用 元素标识符 http://www.w3.org/TR/xmlschema-0/#schemaConstraintsVsXML1,类似:
Did you tried defining an XML Schema or optionally an XML DTD for your XML, and then using element identifiers http://www.w3.org/TR/xmlschema-0/#schemaConstraintsVsXML1, something like:
XML 包括? http://www.xml.com/pub/a/ 2002/07/31/xinclude.html
XML includes? http://www.xml.com/pub/a/2002/07/31/xinclude.html