walkermatt / ol-layerswitcher

Layer control for OpenLayers
MIT License
384 stars 176 forks source link

Static legend in Layerswitcher in sidebar #502

Open JURASINTERGEO opened 5 months ago

JURASINTERGEO commented 5 months ago

Hi. Ol-layerswitcher is a really great job. I'm new to javascript and openlayers and I'm trying to do my first web map application. During the time I faced the problem with static legend display in sidebar. I don't know how to display it beside checkbox and layer name. GetLegendGraphic query works perfectly but I don't know where to put it in my code :( Sample of code:

new ol.layer.Group({ // A layer must have a title to appear in the layerswitcher title: "ZDW", fold: "open", layers: [
new ol.layer.Image({ // A layer must have a title to appear in the layerswitcher title: "dze", visible: true, zIndex: 0, source: new ol.source.ImageWMS({ ratio: 1, params: { LAYERS: "dw", VERSION: "1.3.0" }, url: "http://my_ip_adress/geoserver/wms", tiled: "true", projection: "EPSG:2177", crossOrigin: "anonymous", serverType: "geoserver", }), }),

Can You tell me please what should I do?

walkermatt commented 5 months ago

Hi, ol-layerswitcher doesn't support legend images, you would have to extend the renderLayer function to add the appropriate img element etc.