camptocamp / GeoMapFish

6 stars 1 forks source link

Responsive Legends #63

Open metron-ag opened 2 years ago

metron-ag commented 2 years ago

Who requested this new feature?

Metron AG, Brugg/Switzerland

Problem & Solution

Legends are currently generated as static pictures. Styling trough HTML/CSS is not possible and long legend text is not fully visible to the users without scrolling sideways. It would be great to have responsive text breaks and the possibility to style the legend trough individual HTML classes.

Bildschirmfoto 2022-05-05 um 11 31 01
maltaesousa commented 2 years ago

@metron-ag What geographic server do you use? In Mapserver for instance, it is possible to style legends a little bit and to put line returns on it

metron-ag commented 2 years ago

@maltaesousa We use qgis server

maltaesousa commented 2 years ago

I've not found a way to wrap or style legends on qgis server or to give some basic styling to it but I'm not familiar with qgis server.

Another workaround would be to use a static legend:

  1. You create an image and save it in your static/images/ folder
  2. Then, in the admin interface, you add a legendImage metadata with an URL like static:///images/my_custom_legend.png
rbovard commented 2 years ago

I've not found a way to wrap or style legends on qgis server or to give some basic styling to it but I'm not familiar with qgis server.

You can use some style parameters in the legendImage metadata, something like:

config://local/mapserv_proxy?ogcserver=qgis%2Fxxx&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=yyy&SCALE=1000&BOXSPACE=0&SYMBOLSPACE=1&SYMBOLWIDTH=5&LAYERTITLE=FALSE&ITEMFONTFAMILY=Arial&ITEMFONTSIZE=8

See QGIS Server documentation for all possiblities.

maltaesousa commented 1 year ago

@metron-ag Did you try one of both workarounds?

Legends in HTML are not possible because it's not an OGC standard. Also, dynamically styling image legends depending on layer tree width is not supported as there's no standard to ask for a max width with a GetLegendGraphic request. Finally, qgis server and geoserver can handle FORMAT=application/json for a legend but not mapserver and I'm pretty sure each server will answer its own schema because there's no standard. For these reasons, I think implementing a css customizable legend will be expensive to develop.

Tell us if the workaround fulfill your needs or if you would like another solution.