2

I am trying to label a layer of line vectors using SLD in Geoserver. It is simple enough, and it's pretty much copied from the SLD cookbook: http://docs.geoserver.org/latest/en/user/styling/sld-cookbook/lines.html

The thing that's getting me is that when I view the Openlayers preview in Geoserver, everything seems to render correctly. Each road is only labeled once and it's not extremely busy looking. However, when I import the layer via WMS to my Openlayers map, it doesn't seem to recognize this line:

<VendorOption name="repeat">400</VendorOption> 

Which is supposed to keep it from repeating within 400 pixels.

I've also tried:

<VendorOption name="group">yes</VendorOption> 

Which should only display a single label on a map per unique text.

Any idea what is going on here? I need the labels to look like the Geoserver preview.

Map displayed in openlayers after importing layer via WMS: WMS Served Map

Map displayed in Geoserver Openlayers preview: Openlayers preview

<?xml version="1.0" encoding="UTF-8"?> <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>Roads</Name> <UserStyle> <FeatureTypeStyle> <Rule> <Title>Roads</Title> <LineSymbolizer> <Stroke> <CssParameter name="stroke"> <ogc:Literal>#000000</ogc:Literal> </CssParameter> <CssParameter name="stroke-width"> <ogc:Literal>1</ogc:Literal> </CssParameter> </Stroke> </LineSymbolizer> <TextSymbolizer> <Label> <ogc:PropertyName>name</ogc:PropertyName> </Label> <LabelPlacement> <LinePlacement> <PerpendicularOffset> 10 </PerpendicularOffset> </LinePlacement> </LabelPlacement> <Fill> <CssParameter name="fill">#000000</CssParameter> </Fill> <VendorOption name="repeat">400</VendorOption> </TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>

2 Answers 2

2

This is probably an artifact due to tiling. The layer preview map defaults to a single tile, but I'm guessing your openlayers map uses tiling.

Geoserver insists on labeling every tile. GeoServer doesn't know that each request is for a tile in a larger map, so it treats a tile as a complete map and dutifully applies a label to it. So basically, if a road stretches across three tiles, it will be labelled three times.

Unfortunately, there's not much you can do about it. I was advised to enable meta-tiling. This does allow GeoServer to think of requests as tile components to some extent, and this can minimise the label repeating. However, I believe it's on by default in recent versions.

2
  • 1
    You are right, it is due to tiling. I found that in the Openlayers preview you can click the button in the top left in order to change it to single tile or tiled; when changing to tiled it showed the same problems. This is how I resolved it: When adding the WMS layer in openlayers, you have to specify the "tiled: true, tilesorigin: [map.maxExtent.left, map.maxExtent.bottom]" parameters. Finally, in the Geoserver layer tile caching tab, you can change the metatiling factors to something larger than 4x4.
    – scavok
    Commented Jul 21, 2014 at 8:05
  • Thanks, @scavok! by larger than 4x4 you mean 5x5? Does it seem more labels will be repeated as the number of tiles increased? Commented Sep 22, 2018 at 10:58
0

You can try this on Ol side

import TileLayer from "ol/layer/Image";
import ImageWMS from 'ol/source/ImageWMS';
import { geoserverURL } from '../config';

const BuildingWMS = new TileLayer({
    source: new ImageWMS({
        ratio:1,
        projection: 'EPSG:3857',
        url: `${geoserverURL}/wms?`,
        params: {
            'LAYERS': 'Baku:Buildings',
            'FORMAT': 'image/png',
            'VERSION': '1.1.1',
        },
        serverType: 'geoserver',
        crossOrigin: 'anonymous'
    }),
    visible: true,
    name: 'BuildingWMS'
});
export {
    BuildingWMS
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.