forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add thumbnail-on-map example (warping)
- Loading branch information
Showing
10 changed files
with
554 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
gdal.js | ||
*.swp | ||
*.mem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,4 @@ onmessage = function(msg) { | |
return; | ||
} | ||
inspectTiff(msg.data); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
This shows an example of how to use the GDAL API from within a web browser to | ||
generate a thumbnail from a GeoTIFF using GDALTranslate and then display it on | ||
a Leaflet map. | ||
|
||
To use, first make sure that `gdal.js`, `gdal.js.mem`, and `gdal.data` are | ||
available in this directory. There are some symlinks provided that will do this | ||
automatically if you build the project from source. Alternatively, you can | ||
[download a release](https://github.com/ddohler/gdal-js/releases) and place the | ||
files in this directory manually. | ||
|
||
Next, start up an HTTP server to serve this folder. For example, `python -m | ||
SimpleHTTPServer`. Navigate to whatever port your server is listening at, and | ||
follow the instructions on the page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../gdal.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" | ||
integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" | ||
crossorigin=""/> | ||
<title>Test GDAL.js</title> | ||
</head> | ||
<body> | ||
<input type="file" id="geotiff-select"> | ||
<button onclick="makeThumbnail()">Thumbnail</button> | ||
<p>Select a GeoTIFF using the Browse... button. | ||
Click on the "Thumbnail" button and a thumbnail of the image will be | ||
displayed on the map below.</p> | ||
|
||
<div id="leaflet" style="height: 600px"></div> | ||
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" | ||
integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" | ||
crossorigin=""></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var thumbnailer = new Worker('worker.js'); | ||
|
||
var map = L.map('leaflet').setView([0,0],3); | ||
|
||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { | ||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors', | ||
maxZoom: 18, | ||
}).addTo(map); | ||
|
||
var overlay = null; | ||
|
||
function makeThumbnail() { | ||
var files = document.querySelector('#geotiff-select').files; | ||
thumbnailer.postMessage(files); | ||
} | ||
|
||
thumbnailer.onmessage = function(evt) { | ||
displayMapImage(evt.data); | ||
}; | ||
|
||
function displayMapImage(data) { | ||
if (overlay !== null) { | ||
overlay.remove(); | ||
} | ||
var imageBytes = data.bytes; | ||
var coords = data.coords; | ||
var outputBlob = new Blob([imageBytes], { type: 'image/png' }); | ||
var imageURL = window.URL.createObjectURL(outputBlob); | ||
var lats = Array.from(coords[1]); | ||
var lngs = Array.from(coords[0]); | ||
|
||
// Zip | ||
var latLngs = lats.map(function(lat, i, arr) { | ||
return new Array(lat, lngs[i]); | ||
}); | ||
overlay = L.imageOverlay(imageURL, latLngs).addTo(map); | ||
map.fitBounds(overlay.getBounds()); | ||
} |
Oops, something went wrong.