ted-piotrowski / mapbox-gl-shadow-simulator

Simulate terrain and structure shadows in a custom map layer
46 stars 5 forks source link

unclear documentation #10

Open Thebigbignooby opened 1 year ago

Thebigbignooby commented 1 year ago

Hi, thanks for this library!

I'm trying to make it work with my map, I have followed the guide and I'm a little confused.

I have a mapbox map using mabox-gl, with 3d buildings and terrain from mapbox.

Given that I'm getting terrain from mapbox, do I still need this block? what exactly does this block do?

      terrainSource: {
        tileSize: 256,       // DEM tile size
        maxZoom: 15,         // Maximum zoom of DEM tile set
        getSourceUrl: ({ x, y, z }) => {
          // return DEM tile url for given x,y,z coordinates
          return `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`
        },
        getElevation: ({ r, g, b, a }) => {
          // return elevation in meters for a given DEM tile pixel
          return (r * 256 + g + b / 256) - 32768
        }
      },
ted-piotrowski commented 1 year ago

Valid question.

ShadeMap renders shadows based on elevation data and the position of the sun. ShadeMap doesn't have access to the 3D terrain and buildings rendered on a mapbox-gl map (but also due to the fact that it needs to work with libraries like Leaflet which have no 3D terrain capabilities) so it needs to load its own elevation data.

This data can some from S3, or your own server or even from Mapbox's terrain tiles (I'm actually starting to use LiDAR surface models as the data source on shademap.app), but you have to tell ShadeMap where to download the elevation data tiles from, what the tile sizes are, up to what zoom level tiles are available for and how to decode them.

If you remove this property from the configuration object, it will actually default to the Amazon AWS elevation dataset, so it's not really necessary but you should know that under the covers you do need an elevation data source.

As far as building elevation data goes, the getFeatures() function needs to return the building data and I have an example on how to extract building data from Mapbox vector tiles in the README.md

ted-piotrowski commented 1 year ago

PS. I probably just need a 5 minute YouTube code-along tutorial don't I?