Show Legend on Map

Hi, I am using your services to show different layers on the map (NDVI, LAI etc.) I also want to show a legend with values for better understanding of the satellite imagery. I tried following your tutorial (How can I define a custom legend?), but I always get an error calling this API:

https://services.sentinel-hub.com/ogc/wms/instanceId?service=WMS&request=GetLegendGraphic&layer=NDVI

The error I get is 404:
message: “Not Found”
servlet: “org.glassfish.jersey.servlet.ServletContainer-5fa9247b”
status: “404”
url: “/ogc/wms/{redacted-instance-id}”

The instanceId is correct, since I tried other requests and it works fine

Hey,
I removed the instance id from the error text, so it won’t get abused by others. I will write an answer shortly.

1 Like

The URL looks correct.
There is some mistake in the code for legend or somewhere else in the code for the advanced layer settings, so the legend is not created.

To check if the legend exists, you can check in the getCapabilities

example for legend item in getCapabilities:

<LegendURL>
  <Format>image/png</Format>
  <OnlineResource xlink:type="simple" xlink:href="https://services.sentinel-hub.com/ogc/wms/{instance-id}?request=GetLegendGraphic&service=WMS&layer={layer-id}&style=default"/>
</LegendURL>

You can also paste the code for the legend (or, if you are ok with sharing the evalscript of the layer, for the whole styles object in the advanced layer settings) here and we can debug it together.

Cheers

I succeded, thanks, I have another question now, are these numbers always the same?
image

Yes, they are fixed - they should be the same as the values defined in the code for the legend.

1 Like

Do you have some predefined legend values for different layers, now every legend in my app is the same (I have NDVI, LAI, NBR etc.)?

We don’t have predefined legends gathered in one place yet, but some layers / custom scripts in the Custom scripts repository have legend in their description, like Sentinel-2 L2A NDVI.

You can also see the legends of different layers in EO Browser and create a similar ones.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.