GeoTIFF / georaster-layer-for-leaflet

Display GeoTIFFs and soon other types of raster on your Leaflet Map
https://geotiff.github.io/georaster-layer-for-leaflet-example/
Apache License 2.0
286 stars 57 forks source link

Get valueson click #15

Closed pierrethiriet closed 5 years ago

pierrethiriet commented 5 years ago

Thank you for this leaflet plug-in! It seems very promising and it could indeed smooth the process for prototyping map with raster by avoiding the need of a specific server.

I have more a question than a bug to report. From my understanding, the Plug-In rely on Leaflet GridLayer and it seems that it does not allow to access on click to the underlying tile values (in the present case, the rater values). Is it indeed true or is there an easy path for retrieving those values? Thanks in advance, Pierre

DanielJDufour commented 5 years ago

Hi, @pierrethiriet . That's an excellent question and thank you for your kind words :-)

We currently implement this functionality for geotiff.io. You can see how we did it here: https://github.com/GeoTIFF/geotiff.io/blob/e6cd0b5c458dd388be46ca8e272bbfa352ba7f94/src/Map.js#L59

Here's a trimmed down version:

map.on('click', e => {
  const latlng = [e.latlng.lng, e.latlng.lat];
  // results is an array, which each item representing a separate band
  const results = geoblaze.identify(georaster, latlng);
  console.log(results);
});

We separate the visualization (georaster-layer-for-leaflet) from analysis (geoblaze.io) because the raster that you see is a sampled version of the real raster. The value you see clicked on the map isn't necessarily the same as the actual value at that point. (You can boost the resolution of georaster-layer-for-leaflet if this is a concern and the default nearest-neighbor algorithm isn't sufficient). We do this because visualizing many geotiffs at full resolution would crash your browser.

Here's the source code for the identification via geoblaze if you're curious: https://github.com/GeoTIFF/geoblaze/blob/master/src/identify/identify.module.js

Let me know if you have any more questions and happy to hear suggestions on how to make things easier :-)

pierrethiriet commented 5 years ago

Thanks a lot. It works great. I just didn't realize that node was required, with the corresponding skills.

DanielJDufour commented 5 years ago

I'm closing this issue as it seems you have a solution. Feel free to open more in the future :-)