TerriaJS / terriajs

A library for building rich, web-based geospatial data platforms.
https://terria.io
Apache License 2.0
1.16k stars 359 forks source link

WMS legend URLs vs WMS-SLD extension GetLegendGraphics #5021

Closed nf-s closed 3 years ago

nf-s commented 3 years ago

Paul Haesler on handling legends for ODC

Easy fix on OWS end. We basically only support GetLegendGraphic for Terria anyway. WMS 1.3.0 core spec (i.e. not the SLD extensions) provides for legend urls inside the Capabilities document, which is the preferred approach.

Note though, that for all DEA surface reflectance products, the default style will be "simple_rgb" which has no legend, so you are still going to get an exception on those products.

The OWS GetCaps documents has a LegendURL for each style that supports a legend, and our GetCaps does NOT advertise that it supports GetLegendGraphics, or any of the SLD extensions.

You are correct that the default style is not advertised. The OWS documentation strongly recommends making the first style in the list the default, and AFAIK DEA always does this - but yeah, you can't necessarily assume that.

You should probably just not display a legend if you get an XML document back with a 4xx or 5xx status code. (edited)

Therefore:

KeyboardSounds commented 3 years ago

UPDATE: 2020-12-01 - fixed

This legend doesn't play well with transparency and looks glitched out: https://neii-viewer.dev.saas.terria.io/#share=s-94BSdBh0gJp5q4DBghC8zzN32M3

KeyboardSounds commented 3 years ago

UPDATE: 2020-12-01 - fixed

The legend is completely broken and shows the broken image icon for neii-viewer v8: (Oceans --> Collaborative Australian Protected Areas Database (CAPAD) 2018 - Marine (DoEE))

KeyboardSounds commented 3 years ago

UPDATE: 2020-12-01 - fixed

image "It is difficult to read the text in the legend in dev (refer image in column d, and the prod image in column C). The font is too small and the black on dark grey doesn't have sufficient contrast. Please revert to current production standard. Similarly, the size of the colour blocks in dev (image in column E) are too small, to easily differentiate the colours, compared with the colour blocks in prod (column E)."

nf-s commented 3 years ago

Will fix ontop of https://github.com/TerriaJS/terriajs/pull/4922

KeyboardSounds commented 3 years ago

in NEII under Land > Victorian Soil Type Mapping, they want the image version of the legend rather than all the dimension selectors. Also it might be causing the layer to fail to load, see https://github.com/TerriaJS/neii-viewer/issues/165

nf-s commented 3 years ago

This is separate - there is something going on with the WMS layers

V8

Is trying to load a massive number of layers

image

V7

Is not

image

martin-bom commented 3 years ago

Hello,

If there is a WMS layer which the legendUrl is like this:

`

image/png

`

Can TerriaJS displayed the legend image instead of showing a link asking user to download the image?

Source: https://services.ga.gov.au/gis/great-artesian-basin/wms?REQUEST=GetCapabilities&SERVICE=WMS

Thank you.

Martin

nf-s commented 3 years ago

Hi @martin-bom

In the latest version of TerriaJS v8, the legend works for the default style:

image

But does not work for the Grayscale style:

image

This is due to the legend URL having Format="image/png;charset=UTF-8"

GetCapabilities

image

How Terria handles legend formats

We used to lookup the legend format in:

const DISPLAYABLE_MIME_TYPES = [
  "image/jpeg",
  "image/gif",
  "image/png",
  "image/svg+xml",
  "image/bmp",
  "image/x-bmp"
]

And if there isn't an exact match, we treat the legend as a link instead of image.
I have loosened this, so now it will also look at filename extension in the request.

image

I have rolled the change into this PR - https://github.com/TerriaJS/terriajs/pull/5247

I will post a link to test when the CI/CD has finished

martin-bom commented 3 years ago

Hi Nick,

Thank you for the reply.

In TerriaJS version 7 I tried to include both legend's URL into the parameter legendUrls like this: "legendUrls": ["https://services.ga.gov.au/gis/great-artesian-basin/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=gab%3APOTENTIOMETRIC_SURFACE_1980-2000", "https://services.ga.gov.au/gis/great-artesian-basin/styles/gab/legends/potentiometric_surface_grayscale_legend.png"]

And the outcome is: image

Which is exactly opposite to the default behavior. Thank you.

Regards, Martin

nf-s commented 3 years ago

Ahh I see!

This is happening because v7 won't identify the first legend as an image - due to lack of mimeType and .png extension.

Does this work for you:

"legendUrls": [
  {
    "mimeType": "image/png",
    "url": "https://services.ga.gov.au/gis/great-artesian-basin/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=gab%3APOTENTIOMETRIC_SURFACE_1980-2000"
  },
  "https://services.ga.gov.au/gis/great-artesian-basin/styles/gab/legends/potentiometric_surface_grayscale_legend.png"
]
nf-s commented 3 years ago

image

This is my catalog JSON:

{
  "homeCamera": {
    "north": -8,
    "east": 158,
    "south": -45,
    "west": 109
  },
  "catalog": [
    {
      "layers": "gab:POTENTIOMETRIC_SURFACE_1900-1920",
      "url": "https://services.ga.gov.au/gis/great-artesian-basin/wms?REQUEST=GetCapabilities&SERVICE=WMS",
      "type": "wms",
      "name": "POTENTIOMETRIC_SURFACE_1900-1920",
      "legendUrls": [
        {
          "mimeType": "image/png",
          "url": "https://services.ga.gov.au/gis/great-artesian-basin/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=gab%3APOTENTIOMETRIC_SURFACE_1980-2000"
        },
        "https://services.ga.gov.au/gis/great-artesian-basin/styles/gab/legends/potentiometric_surface_grayscale_legend.png"
      ]
    }
  ]
}
martin-bom commented 3 years ago

Hi Nick,

Excellent! Your suggestion works perfectly and both legends are showing now. Thank you very much!

Regards, Martin

nf-s commented 3 years ago

Great, no problem!

AnaBelgun commented 3 years ago

Thank you @nf-s

nf-s commented 3 years ago

Closed by https://github.com/TerriaJS/terriajs/pull/5247

How we determine WMS legends (in order)

  1. Defined manually in catalog JSON
  2. If style is undefined, and server doesn't support GetLegendGraphic, we must select first style as default - as there is no way to know what the default style is, and to request a legend for it
  3. If style is is set and it has a legendUrl -> use it!
  4. If server supports GetLegendGraphic, we can request a legend (with or without style parameter)