nixs
New Coder
Hello.
I successfully added the TIFF raster using CanvasLayer.Filed to my leaflet map using this code:
Нow I want to add it to the Leaflet Control Tree so it can be toggled on and off as a layer.
How can I do it?
Thanks.
I successfully added the TIFF raster using CanvasLayer.Filed to my leaflet map using this code:
JavaScript:
var tiff = "img/tifftest.tiff";
fetch(tiff)
.then((r) => r.arrayBuffer())
.then(function (buffer) {
var s = L.ScalarField.fromGeoTIFF(buffer);
let layer = L.canvasLayer
.scalarField(s, {
opacity: 0.7,
color: chroma
.scale(["#1a9641", "#ffff6d", "#ec344c", "#d7191c"])
.domain(s.range),
})
.addTo(map);
layer.on("click", function (e) {
if (e.value !== null) {
let v = e.value.toFixed(0);
let html = <span class="popupText"><strong>Mean Wind Speed:</strong> ${e.value} m/s</span>;
let popup = L.popup()
.setLatLng(e.latlng)
.setContent(html)
.openOn(map);
}
});
map.fitBounds(layer.getBounds());
});`
Нow I want to add it to the Leaflet Control Tree so it can be toggled on and off as a layer.
How can I do it?
Thanks.