1

In the following CSS styling:

* {
   mark: url(smileyface.png);
   mark-mime: "image/png";
   mark-rotation: 45;
}

How can I make the URL value dynamic (to be read from a layer's field image_url)?

I've tried the following:

* {
   mark: url([image_url]);
   mark-mime: "image/png";
   mark-rotation: [rotation_angle];
} 

But didn't work. The server console says:

WARN [renderer.style] - Unable to read image at file:/Applications/GeoServer.app/Contents/Java/data_dir/workspaces/tst/styles/%5Bdescription%5D : Can't get input stream from URL! 

The auto-generated SLD is:

<sld:PointSymbolizer>
            <sld:Graphic>
              <sld:ExternalGraphic>
                <sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="[image_url]"/>
                <sld:Format>image/png</sld:Format>
              </sld:ExternalGraphic>
              <sld:Rotation>
                <ogc:PropertyName>rotation_angle</ogc:PropertyName>
              </sld:Rotation>
            </sld:Graphic>
</sld:PointSymbolizer>

Although the same works for mark-rotation.

2
  • Does it work with mark: url(${image_url}); or mark: url('${image_url}');?
    – JGH
    Commented Mar 15, 2018 at 12:10
  • Thanks a lot JGH, mark: url('${image_url}'); works perfectly.
    – Faz B
    Commented Mar 15, 2018 at 12:32

1 Answer 1

1

In the SLD, you would need to use a CQL filter for the dynamic external graphic. One trick in CSS is to write this CQL filter as plain text that will later be interpreted in SLD.

* {
   mark: url('${image_url}');
   mark-mime: "image/png";
   mark-rotation: [rotation_angle];
} 

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.