I have point of data in mysql server. I am displaying this layer as WMS using OpenLayers and GeoServer. How can I add label to this layer?
1 Answer
For labeling in WMS from geoserver, you will have to define <TextSymbolizer>
which determines what text to display in the label,i.e. the field in your attribute table of the point layer (eg. 'Name' in the following example). You can define font family, color, size, weight and placement of the label. A simple example of style description for points with label is as follows:
<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>
<Fill>
<CssParameter name="fill">#000000</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
For more complex examples go through this link:
http://docs.geoserver.org/stable/en/user/styling/sld-cookbook/points.html#point-with-styled-label
-
1If you need separate control of the point symbol and the point labels you should have two Layers in OL both pointing to the same published Layer in GeoServer but using two diferent SLD: one for rendering the point as <PointSymbolizer> and the other as TextSymbolizer. Commented Dec 23, 2011 at 18:05