I am using CSS for styling roads in my geoserver. Here is my css :

 /* @title HSAMB Roads*/  
    * {
       stroke: #333333,#00CC00;
       stroke-width: 3px, 1px;
       z-index: 0, 1;
       label: [name_of_ro];
       font-family: Arial;
       font-weight: bold;
       font-fill: black;
       font-size: 10;
       halo-color: white;
       halo-radius: 1;
       -gt-label-follow-line: true;
       -gt-label-max-angle-delta: 90;
       -gt-label-max-displacement: 400;
       -gt-label-repeat: 150;

Everything is working fine but the client want the legend to be single line legend not the double line legend i.e inner line and outer line :

Here is my legendenter image description here Please Tell me how to combine both black and green line to single in map legend so that they are not shown as two separate line for a single road type.

| improve this question | | | | |

At the moment there is no way to show a single title, two SLD feature type styles with two rules are going to be generated no matter what language you use (CSS, ySLD and so on, all translate back to SLD internally) and GeoServer does not yet know to merge them back into a single representation for legend.

You can however provide your own hand-painted legend.

| improve this answer | | | | |

As an alternative to hand-painting your own, as suggested by @Andrea, if your client is using Leaflet, here is a handy plugin that will take some of the drudgery out of it: https://github.com/yohanboniface/Leaflet.TileLegend and give you a legend close to what you want.

Another alternative could be to save the CSS as SLD and then open the data in QGIS and apply the SLD. Create the Legend in Map Composer and save as a small image file then supply that to the client. It would be a bit more flexible than a Leaflet plugin (allowing the client to use OpenLayers etc). The slight gotcha here is that QGIS has a slightly different dialect of SLD to Geoserver, so while they usually work, I can't guarantee this method 100% (going either way).

| improve this answer | | | | |
  • Using QGIS didn't work for me -- the SLD was different enough that I would have to restyle everything, and this was using the simple shapes bundled with the Geoserver CSS extension – Ben Mearns Sep 12 '17 at 14:16

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.