显示大型 .tif 文件在 Leaflet 地图上 07.2023

huangapple go评论114阅读模式
英文:

Showing large .tif file on leaflet map 07.2023

问题

可以有人给我提供一个示例代码,演示如何在开源 leaflet 1.9.1 地图页面上将大型 .tiff 文件显示为 GeoTiff RGB 图像吗?我正在尝试编写这样的代码,但每当我尝试创建类似的东西时,要么地图无法正确显示,要么文件无法正确打开,因为HTML网站无法打开这种类型的文件。我知道 Webodm 使用 leaflet 地图,我想要像他们一样拥有一个地图,在这个地图上,我可以看到以 .tiff 扩展名保存的图像,例如,从 Webodm 程序中使用WGS84坐标数据创建的正射影像图。

我不知道我可以使用什么方法来使它工作,或者至少在页面上正确显示此文件。

英文:

Could someone give me a sample code on how to show large .tiff files as GeoTiff RGB images on the map in the open-source leaflet 1.9.1 map page? I'm struggling with writing code like this, but whenever I try to create something like this, either the map doesn't play correctly or the file can't be opened properly because the website in html is not able to open this type of file. I know that Webodm uses leaflet maps, and like them, I would like to have a map where I could see an image in the .tiff extension, taken, for example, from an orthophotomap already created in the webodm program with WGS84 coordinate data.

I have no ideas what I could use to make it work or at least correctly display this file on the page.

答案1

得分: 1

以下是您要翻译的代码部分:

var parse_georaster = require("georaster");

var GeoRasterLayer = require("georaster-layer-for-leaflet");
// or: import GeoRasterLayer from "georaster-layer-for-leaflet";

// initalize leaflet map
var map = L.map('map').setView([0, 0], 5);

// add OpenStreetMap basemap
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var url_to_geotiff_file = "example_4326.tif";

fetch(url_to_geotiff_file)
  .then(response => response.arrayBuffer())
  .then(arrayBuffer => {
    parse_georaster(arrayBuffer).then(georaster => {
      console.log("georaster:", georaster);

      /*
          GeoRasterLayer is an extension of GridLayer,
          which means can use GridLayer options like opacity.

          Just make sure to include the georaster option!

          Optionally set the pixelValuesToColorFn function option to customize
          how values for a pixel are translated to a color.

          https://leafletjs.com/reference.html#gridlayer
      */
      var layer = new GeoRasterLayer({
          georaster: georaster,
          opacity: 0.7,
          pixelValuesToColorFn: values => values[0] === 42 ? '#ffffff' : '#000000',
          resolution: 64 // optional parameter for adjusting display resolution
      });
      layer.addTo(map);

      map.fitBounds(layer.getBounds());

  });
});

Source / GeoRasterLayer documentation: https://github.com/geotiff/georaster-layer-for-leaflet#georaster-layer-for-leaflet

Full list of Leaflet plugins:
https://leafletjs.com/plugins.html

英文:

There are several Leaflet plugins which may be able to help you. Here’s an example from the GeoRasterLayer documentation:


var parse_georaster = require(&quot;georaster&quot;);

var GeoRasterLayer = require(&quot;georaster-layer-for-leaflet&quot;);
// or: import GeoRasterLayer from &quot;georaster-layer-for-leaflet&quot;;

// initalize leaflet map
var map = L.map(&#39;map&#39;).setView([0, 0], 5);

// add OpenStreetMap basemap
L.tileLayer(&#39;http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&#39;, {
    attribution: &#39;&amp;copy; &lt;a href=&quot;http://osm.org/copyright&quot;&gt;OpenStreetMap&lt;/a&gt; contributors&#39;
}).addTo(map);

var url_to_geotiff_file = &quot;example_4326.tif&quot;;

fetch(url_to_geotiff_file)
  .then(response =&gt; response.arrayBuffer())
  .then(arrayBuffer =&gt; {
    parse_georaster(arrayBuffer).then(georaster =&gt; {
      console.log(&quot;georaster:&quot;, georaster);

      /*
          GeoRasterLayer is an extension of GridLayer,
          which means can use GridLayer options like opacity.

          Just make sure to include the georaster option!

          Optionally set the pixelValuesToColorFn function option to customize
          how values for a pixel are translated to a color.

          https://leafletjs.com/reference.html#gridlayer
      */
      var layer = new GeoRasterLayer({
          georaster: georaster,
          opacity: 0.7,
          pixelValuesToColorFn: values =&gt; values[0] === 42 ? &#39;#ffffff&#39; : &#39;#000000&#39;,
          resolution: 64 // optional parameter for adjusting display resolution
      });
      layer.addTo(map);

      map.fitBounds(layer.getBounds());

  });
});

Source / GeoRasterLayer documentation: https://github.com/geotiff/georaster-layer-for-leaflet#georaster-layer-for-leaflet

Full list of Leaflet plugins:
https://leafletjs.com/plugins.html

huangapple
  • 本文由 发表于 2023年7月17日 17:46:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定