您可以重用 XML 片段(以某种变量/引用的方式)吗?

发布于 2024-07-11 08:35:25 字数 3601 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云胡 2024-07-18 08:35:25

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/

素食主义者 2024-07-18 08:35:25

您是否尝试过定义 XML 架构 或可选的 XML DTD 用于您的 XML,然后使用 元素标识符 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>

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:



<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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文