2

I want to visualize a line with Geoserver with multiple colors with CSS. Each 3 px, another color has to show. So I have red, green and yellow and I want a line with this 3 colors, each 3 px color should change. Is this possible with CSS?

4

The trick is to draw three dashed lines offset from each other so that a complete line is drawn. So first you draw a red dashed line with 3 pixel dashes and 6 pixel spaces, then an blue line with a 3 pixel offset and then 3 pixels and 6 spaces and the same for the green line.

In SLD this would look like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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>mulitcolor</Name>
    <UserStyle>
      <Title>A red line style</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>red line</Title>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#ff0000</CssParameter>
              <CssParameter name="stroke-dasharray" >6 12</CssParameter>
            </Stroke>
          </LineSymbolizer>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#00ff00</CssParameter>
              <CssParameter name="stroke-dasharray" >6 12</CssParameter>
              <CssParameter name="stroke-dashoffset">6</CssParameter>
            </Stroke>
          </LineSymbolizer>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#0000ff</CssParameter>
              <CssParameter name="stroke-dasharray" >6 12</CssParameter>
              <CssParameter name="stroke-dashoffset">12</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

This gives a line like this (though I doubled everything to make is more visible):

enter image description here

You can do the same in CSS (dasharray example) if that is your prefered language.

1

Geoserver uses SLD stylesheets by default. They are relatively simple and intuitive to use. You can acces them via Data/Styles in the main window. Geoserver has detailed documentation on this: http://docs.geoserver.org/latest/en/user/styling/index.html

There is also css extension that allows you to use css instead (it is converted to sld by geoserver): http://docs.geoserver.org/latest/en/user/styling/css/index.html

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.