Orcasa-Platform / orcasa

A Horizon Europe project to restore soil earth
https://orcasa-client.vercel.app
MIT License
2 stars 0 forks source link

[Geospatial Data] Add initial support to decode layers #105

Closed clementprdhomme closed 10 months ago

clementprdhomme commented 10 months ago

This PR adds support to decode layers that only use startYear and endYear decode parameters in the Geospatial Data module.

Testing

  1. On your local Strapi instance, create a new layer called “Tree Cover Loss” of type deckgl
  2. Paste the following config:
    {
    "@@type": "DecodeLayer",
    "source": {
    "type": "raster",
    "tiles": [
      "https://tiles.globalforestwatch.org/umd_tree_cover_loss/v1.10/tcd_30/{z}/{x}/{y}.png"
    ],
    "maxzoom": 12,
    "minzoom": 2
    },
    "styles": [
    {
      "id": "tree-cover-loss",
      "type": "raster",
      "paint": {
        "raster-opacity": {
          "o": "@@#params.opacity",
          "@@function": "setOpacity"
        }
      },
      "layout": {
        "visibility": {
          "v": "@@#params.visibility",
          "type": "deckgl",
          "@@function": "setVisibility"
        }
      }
    }
    ],
    "decodeParams": {
    "endYear": "@@#params.endYear",
    "startYear": "@@#params.startYear"
    },
    "decodeFunction": "// values for creating power scale, domain (input), and range (output)\nfloat domainMin = 0.;\nfloat domainMax = 255.;\nfloat rangeMin = 0.;\nfloat rangeMax = 255.;\nfloat exponent = zoom < 13. ? 0.3 + (zoom - 3.) / 20. : 1.;\nfloat intensity = color.r * 255.;\n// get the min, max, and current values on the power scale\nfloat minPow = pow(domainMin, exponent - domainMin);\nfloat maxPow = pow(domainMax, exponent);\nfloat currentPow = pow(intensity, exponent);\n// get intensity value mapped to range\nfloat scaleIntensity = ((currentPow - minPow) / (maxPow - minPow) * (rangeMax - rangeMin)) + rangeMin;\n// a value between 0 and 255\ncolor.a *= zoom < 13. ? scaleIntensity / 255. : color.g;\nfloat year = 2000.0 + (color.b * 255.);\n// map to years\nif (year >= startYear && year <= endYear && year >= 2001.) {\n  color.r = 220. / 255.;\n  color.g = (72. - zoom + 102. - 3. * scaleIntensity / zoom) / 255.;\n  color.b = (33. - zoom + 153. - intensity / zoom) / 255.;\n} else {\n  color.a = 0.;\n}"
    }
  3. Paste the following params_config:
    [
    {
    "key": "opacity",
    "default": 1
    },
    {
    "key": "visibility",
    "default": true
    },
    {
    "key": "startYear",
    "default": 2001
    },
    {
    "key": "endYear",
    "default": 2022
    }
    ]
  4. Paste the following legend_config:
    {
    "type": "basic",
    "items": [
    {
      "color": "#dc6c9a",
      "value": "Tree cover loss"
    }
    ]
    }
  5. Assign the layer to a layer group (and a page if you're creating a new layer group).
  6. Open the Geospatial Data module and toggle on the layer
  7. Test that you can hide and change the opacity of the layer
  8. Modify this line as follows:
    -      settings,
    +      settings: {
    +        ...settings,
    +        startYear: 2019,
    +      }
  9. Check that the data corresponds to this view in Global Forest Watch (Tree cover loss 2019 - 2022)

Note that the UI to change the startYear and endYear values will be implemented in a separate task: ORC-345.

Tracking

ORC-344 - FE - Implement support for decode functions

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orcasa-client ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2023 11:24am