leaflet-canvaslayer-field
Version:
A set of layers using canvas to draw ASCIIGrid or GeoTIFF files. This includes a basic raster layer (*ScalaField*) and an animated layer for vector fields, such as wind or currents (*VectorFieldAnim*)
64 lines (52 loc) • 2.45 kB
HTML
<html>
<head>
<title>ScalarField / Geotiff</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="//unpkg.com/leaflet@1.2.0/dist/leaflet.css" />
<link rel="stylesheet" href="examples.css" />
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400" rel="stylesheet">
</head>
<body>
<h1 class="title mapTitle">ScalarField GeoTIFF</h1>
<div id="map"></div>
<!-- CDN -->
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="//npmcdn.com/leaflet@1.2.0/dist/leaflet.js"></script>
<script src="//npmcdn.com/geotiff@0.3.6/dist/geotiff.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.0/chroma.min.js"></script>
<!-- Plugin -->
<script src="dist/leaflet.canvaslayer.field.js"></script>
<script>
let map = L.map('map');
/* Dark basemap */
let url = 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_nolabels/{z}/{x}/{y}.png';
L.tileLayer(url, {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://carto.com/attributions">CARTO</a>',
subdomains: 'abcd'
}).addTo(map);
/* NASA NDVI Index (2017-02) 0.1 deg (3600 x 1800): ~3.3MB with LZW (24.7MB uncompressed)
https://neo.sci.gsfc.nasa.gov/view.php?datasetId=MOD13A2_M_NDVI
*/
d3.request("data/ndvi_201702_LZW.tif").responseType('arraybuffer').get(
function (error, tiffData) {
let ndvi = L.ScalarField.fromGeoTIFF(tiffData.response);
let layer = L.canvasLayer.scalarField(ndvi, {
color: chroma.scale('YlGn').domain(ndvi.range),
inFilter: (v) => v !== 0
}).addTo(map);
layer.on('click', function (e) {
if (e.value !== null) {
let v = e.value.toFixed(2);
let html = (`<span class="popupText">NDVI ${v}</span>`);
let popup = L.popup()
.setLatLng(e.latlng)
.setContent(html)
.openOn(map);
}
});
map.fitBounds(layer.getBounds());
});
</script>
</body>
</html>