https://docs.geoserver.org/latest/en/user/styling/sld/cookbook/points.html#example-points-layer
给图层的样式添加文字标签
该标签在设定<TextSymbolizer>
上 ,确定要在标签中显示的文本,在这种情况下,<ogc:PropertyName>num</ogc:PropertyName>是shp文件中的属性列的值。
<Fill> <CssParameter name=”fill”>#000000</CssParameter> </Fill>设置文本颜色。有关标签的所有其他详细信息均设置为渲染器默认值,这里是Times New Roman字体,黑色字体和10像素的字体大小。标签的左下方与该点的中心对齐。
-
-
<StyledLayerDescriptor version=“1.0.0”
-
xsi:schemaLocation=“http://www.opengis.net/sld StyledLayerDescriptor.xsd”
-
xmlns=“http://www.opengis.net/sld”
-
xmlns:ogc=“http://www.opengis.net/ogc”
-
xmlns:xlink=“http://www.w3.org/1999/xlink”
-
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
-
<NamedLayer>
-
<Name>Simple point</Name>
-
<UserStyle>
-
<Title>GeoServer SLD Cook Book: Simple point</Title>
-
<FeatureTypeStyle>
-
<Rule>
-
<PointSymbolizer>
-
<Graphic>
-
<Mark>
-
<WellKnownName>circle</WellKnownName>
-
<Fill>
-
<CssParameter name=“fill”>#FF0000</CssParameter>
-
</Fill>
-
</Mark>
-
<Size>6</Size>
-
</Graphic>
-
</PointSymbolizer>
-
<TextSymbolizer>
-
<Label>
-
<ogc:PropertyName>num</ogc:PropertyName>
-
</Label>
-
<Fill>
-
<CssParameter name=“fill”>#000000</CssParameter>
-
</Fill>
-
</TextSymbolizer>
-
</Rule>
-
</FeatureTypeStyle>
-
</UserStyle>
-
</NamedLayer>
-
</StyledLayerDescriptor>
将标签label放到点的上方
-
-
<StyledLayerDescriptor version=“1.0.0”
-
xsi:schemaLocation=“http://www.opengis.net/sld StyledLayerDescriptor.xsd”
-
xmlns=“http://www.opengis.net/sld”
-
xmlns:ogc=“http://www.opengis.net/ogc”
-
xmlns:xlink=“http://www.w3.org/1999/xlink”
-
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
-
<NamedLayer>
-
<Name>Simple point</Name>
-
<UserStyle>
-
<Title>GeoServer SLD Cook Book: Simple point</Title>
-
<FeatureTypeStyle>
-
<Rule>
-
<PointSymbolizer>
-
<Graphic>
-
<Mark>
-
<WellKnownName>circle</WellKnownName>
-
<Fill>
-
<CssParameter name=“fill”>#FF0000</CssParameter>
-
</Fill>
-
</Mark>
-
<Size>6</Size>
-
</Graphic>
-
</PointSymbolizer>
-
<TextSymbolizer>
-
<Label>
-
<ogc:PropertyName>name</ogc:PropertyName>
-
</Label>
-
<Font>
-
<CssParameter name=“font-family”>Arial</CssParameter>
-
<CssParameter name=“font-size”>12</CssParameter>
-
<CssParameter name=“font-style”>normal</CssParameter>
-
<CssParameter name=“font-weight”>bold</CssParameter>
-
</Font>
-
<LabelPlacement>
-
<PointPlacement>
-
<AnchorPoint>
-
<AnchorPointX>0.5</AnchorPointX>
-
<AnchorPointY>0.0</AnchorPointY>
-
</AnchorPoint>
-
<Displacement>
-
<DisplacementX>0</DisplacementX>
-
<DisplacementY>5</DisplacementY>
-
</Displacement>
-
</PointPlacement>
-
</LabelPlacement>
-
<Fill>
-
<CssParameter name=“fill”>#000000</CssParameter>
-
</Fill>
-
</TextSymbolizer>
-
</Rule>
-
</FeatureTypeStyle>
-
</UserStyle>
-
</NamedLayer>
-
</StyledLayerDescriptor>
-
- 转自:https://blog.csdn.net/u014572215/article/details/108752687