Geoserver通过SLD配置字段值在面边线内侧显示,如下图所示:
参考配置SLD代码如下:
<sld:Rule>
<sld:Name>aaa</sld:Name>
<sld:Title>aaa</sld:Title>
<sld:MinScaleDenominator>100000</sld:MinScaleDenominator>
<sld:MaxScaleDenominator>5000000000</sld:MaxScaleDenominator>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>TYPE</ogc:PropertyName>
<ogc:Literal>aaa</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Stroke>
<sld:CssParameter name="stroke">#FFC90E</sld:CssParameter>
<sld:CssParameter name="stroke-width">1</sld:CssParameter>
<sld:CssParameter name="stroke-opacity">1</sld:CssParameter>
</sld:Stroke>
</sld:PolygonSymbolizer>
<sld:TextSymbolizer>
<Geometry>
<ogc:Function name="boundary">
<ogc:Function name="buffer">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="Categorize">
<!-- Value to transform -->
<ogc:Function name="env">
<ogc:Literal>wms_scale_denominator</ogc:Literal>
</ogc:Function>
<ogc:Literal>-0.005</ogc:Literal>
<ogc:Literal>200000</ogc:Literal>
<ogc:Literal>-0.01</ogc:Literal>
<ogc:Literal>500000</ogc:Literal>
<ogc:Literal>-0.02</ogc:Literal>
<ogc:Literal>1000000</ogc:Literal>
<ogc:Literal>-0.04</ogc:Literal>
<ogc:Literal>2000000</ogc:Literal>
<ogc:Literal>-0.08</ogc:Literal>
<ogc:Literal>4000000</ogc:Literal>
<ogc:Literal>-0.16</ogc:Literal>
<ogc:Literal>8000000</ogc:Literal>
<ogc:Literal>-0.24</ogc:Literal>
<ogc:Literal>16000000</ogc:Literal>
<ogc:Literal>-0.32</ogc:Literal>
<ogc:Literal>32000000</ogc:Literal>
<ogc:Literal>-0.64</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Function>
</Geometry>
<sld:Label>
<ogc:PropertyName>NAME</ogc:PropertyName>
</sld:Label>
<sld:Font>
<sld:CssParameter name="font-family">.PingFang SC Medium</sld:CssParameter>
<sld:CssParameter name="font-family">0</sld:CssParameter>
<sld:CssParameter name="font-size">
<ogc:Function name="Categorize">
<!-- Value to transform -->
<ogc:Function name="env">
<ogc:Literal>wms_scale_denominator</ogc:Literal>
</ogc:Function>
<!-- Output values and thresholds -->
<!-- Ranges: -->
<!-- [scale <= 100000, font 16] -->
<!-- [scale 100000 - 5000000, font 14] -->
<!-- [...] -->
<!-- [scale 50000000 - 100000000, font 8] -->
<!-- [scale > 100000000, font 0] -->
<ogc:Literal>16</ogc:Literal>
<ogc:Literal>100000</ogc:Literal>
<ogc:Literal>14</ogc:Literal>
<ogc:Literal>5000000</ogc:Literal>
<ogc:Literal>12</ogc:Literal>
<ogc:Literal>10000000</ogc:Literal>
<ogc:Literal>10</ogc:Literal>
<ogc:Literal>50000000</ogc:Literal>
<ogc:Literal>8</ogc:Literal>
<ogc:Literal>100000000</ogc:Literal>
<ogc:Literal>0</ogc:Literal>
</ogc:Function>
</sld:CssParameter>
<sld:CssParameter name="font-style">normal</sld:CssParameter>
<sld:CssParameter name="font-weight">normal</sld:CssParameter>
</sld:Font>
<sld:Fill>
<!--<sld:CssParameter name="fill">#FFC90E</sld:CssParameter>-->
<sld:CssParameter name="fill">#FFF</sld:CssParameter>
<sld:CssParameter name="fill-opacity">1.0</sld:CssParameter>
</sld:Fill>
<ogc:LabelPlacement>
<ogc:PointPlacement>
<ogc:AnchorPoint>
<ogc:AnchorPointX>0.5</ogc:AnchorPointX>
<ogc:AnchorPointY>0.0</ogc:AnchorPointY>
</ogc:AnchorPoint>
<ogc:Displacement>
<ogc:DisplacementX>0</ogc:DisplacementX>
<ogc:DisplacementY>0</ogc:DisplacementY>
</ogc:Displacement>
</ogc:PointPlacement>
</ogc:LabelPlacement>
<VendorOption name="followLine">true</VendorOption><!-- 文字沿着直线方向显示 -->
<VendorOption name="spaceAround">10</VendorOption><!--Overlapping and Separating Labels-->
<VendorOption name="repeat">400</VendorOption>
</sld:TextSymbolizer>
</sld:Rule>