|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 5 | + <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> |
| 6 | + <style> |
| 7 | + #map { |
| 8 | + bottom: 0; |
| 9 | + left: 0; |
| 10 | + position: absolute; |
| 11 | + right: 0; |
| 12 | + top: 0; |
| 13 | + } |
| 14 | + </style> |
| 15 | + </head> |
| 16 | + <body> |
| 17 | + <div id="map"></div> |
| 18 | + <script src="https://unpkg.com/browse/whatwg-fetch@3.2.0/dist/fetch.umd.js"></script> |
| 19 | + <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> |
| 20 | + <script src="https://unpkg.com/georaster"></script> |
| 21 | + <script src="../dist/georaster-layer-for-leaflet.min.js"></script> |
| 22 | + <script> |
| 23 | + // initalize leaflet map |
| 24 | + var map = L.map("map").setView([0, 0], 5); |
| 25 | + |
| 26 | + // add OpenStreetMap basemap |
| 27 | + L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", { |
| 28 | + attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' |
| 29 | + }).addTo(map); |
| 30 | + |
| 31 | + var url_to_geotiff_file = "https://geotiff.github.io/georaster-layer-for-leaflet-example/example_4326.tif"; |
| 32 | + |
| 33 | + fetch(url_to_geotiff_file) |
| 34 | + .then(function (response) { |
| 35 | + return response.arrayBuffer(); |
| 36 | + }) |
| 37 | + .then(function (arrayBuffer) { |
| 38 | + parseGeoraster(arrayBuffer).then(function (georaster) { |
| 39 | + console.log("georaster:", georaster); |
| 40 | + var layer = new GeoRasterLayer({ |
| 41 | + georaster: georaster, |
| 42 | + resolution: { |
| 43 | + 0: 2, // Zoom level 0 or higher: resolution 2 |
| 44 | + 16: 512 // Zoom level 16 or higher: resolution 512 |
| 45 | + } |
| 46 | + }); |
| 47 | + layer.addTo(map); |
| 48 | + map.fitBounds(layer.getBounds()); |
| 49 | + }); |
| 50 | + }); |
| 51 | + </script> |
| 52 | + </body> |
| 53 | +</html> |
0 commit comments