0

Is it possible to create a PointSymbolizer together with a TextSymbolizer that will hide both the point and label when the label is not shown as a result of conflict-resolution? What I'm trying to achieve is to create a point and label for each capital city, but to hide both when the label cannot be shown. Currently, if the label is not shown the point sticks around and is not removed. The SLD snippet responsible for this is:

...
<FeatureTypeStyle>
    <Rule>
        <ogc:Filter>
            <ogc:And>
                <ogc:PropertyIsEqualTo>
                    <ogc:PropertyName>place</ogc:PropertyName>
                    <ogc:Literal>city</ogc:Literal>
                </ogc:PropertyIsEqualTo>
                <ogc:PropertyIsEqualTo>
                    <ogc:PropertyName>capital</ogc:PropertyName>
                    <ogc:Literal>yes</ogc:Literal>
                </ogc:PropertyIsEqualTo>
            </ogc:And>
        </ogc:Filter>
        <MinScaleDenominator>50000</MinScaleDenominator>
        <MaxScaleDenominator>20000000</MaxScaleDenominator>
        <PointSymbolizer>
            <Graphic>
                <Mark>
                    <WellKnownName>circle</WellKnownName>
                    <Fill>
                        <CssParameter name="fill">#ffffff</CssParameter>
                    </Fill>
                    <Stroke>
                        <CssParameter name="stroke">#000000</CssParameter>
                        <CssParameter name="stroke-width">1.5</CssParameter>
                    </Stroke>
                </Mark>
                <Size>8</Size>
            </Graphic>
            <VendorOption name="labelObstacle">true</VendorOption>
        </PointSymbolizer>
        <PointSymbolizer>
            <Graphic>
                <Mark>
                    <WellKnownName>circle</WellKnownName>
                    <Fill>
                        <CssParameter name="fill">#000000</CssParameter>
                    </Fill>
                </Mark>
                <Size>5</Size>
            </Graphic>
            <VendorOption name="labelObstacle">true</VendorOption>
        </PointSymbolizer>
        <TextSymbolizer>
            <Label>
                <ogc:PropertyName>name</ogc:PropertyName>
            </Label>
            <Font>
                <CssParameter name="font-family">Noto Sans Regular</CssParameter>
                <CssParameter name="font-style">normal</CssParameter>
                <CssParameter name="font-weight">bold</CssParameter>
                <CssParameter name="font-size">
                    <ogc:Function name="Categorize">
                        <ogc:Function name="env">
                            <ogc:Literal>wms_scale_denominator</ogc:Literal>
                        </ogc:Function>
                        <ogc:Literal>14</ogc:Literal>
                        <ogc:Literal>200000</ogc:Literal>
                        <ogc:Literal>12</ogc:Literal>
                        <ogc:Literal>1500000</ogc:Literal>
                        <ogc:Literal>10</ogc:Literal>
                    </ogc:Function>
                </CssParameter>
            </Font>
            <LabelPlacement>
                <PointPlacement>
                    <AnchorPoint>
                        <AnchorPointX>0.5</AnchorPointX>
                        <AnchorPointY>0</AnchorPointY>
                    </AnchorPoint>
                    <Displacement>
                        <DisplacementX>0</DisplacementX>
                        <DisplacementY>5</DisplacementY>
                    </Displacement>
                </PointPlacement>
            </LabelPlacement>
            <Halo>    
                <Radius>
                    <ogc:Literal>1</ogc:Literal>
                </Radius>
                <Fill>
                    <CssParameter name="fill">#f0f0f0</CssParameter>
                </Fill>
            </Halo>
            <Fill>
                <CssParameter name="fill">#ff0000</CssParameter>
            </Fill>
            <Priority>
                <ogc:PropertyName>population</ogc:PropertyName>
            </Priority>
            <VendorOption name="autoWrap">100</VendorOption>
            <VendorOption name="spaceAround">0</VendorOption>
        </TextSymbolizer>
    </Rule>
</FeatureTypeStyle>
...
0

This is not possible in SLD as the GeoServer labelling engine only runs after all the layers have been drawn. So, the point is drawn (long) before the label text is considered.

@J.R's suggestion should work and could be accurate if you adjust the label placement's anchor point and displacement to allow for the offset of the dot in the label.

1

I'm not familiar with geoserver so I don't know if this could be actually done but what I would try to do is to never show the actual point but integrate it in the label.

the label will look like this :

● label text

of course this only work if the left part of your label is draw reasonably close to the actual point location.

  • That might work. I'll give it a try. However, it will unfortunately not be as accurate as placing the point on the city's location. – wcmatthysen Sep 5 '18 at 16:43
0

Ok, I followed the advice of the other answers and I managed to get a semi-decent result. I modified the text-symbolizer's label-section as follows:

....
<TextSymbolizer>
    <Label>
        <ogc:PropertyName>name</ogc:PropertyName><![CDATA[
]]>●
    </Label>
....

This puts a solid black dot on a new-line just below the city's name. I also had to modify the label-placement from my original SLD snippet to look like this:

...
<LabelPlacement>
    <PointPlacement>
        <AnchorPoint>
            <AnchorPointX>0.5</AnchorPointX>
            <AnchorPointY>0</AnchorPointY>
        </AnchorPoint>
    </PointPlacement>
</LabelPlacement>
...

Due to the x-axis anchor-point being 0.5, the black dot will be centered below the city-name and be on the city's location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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