-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make the download button and wire it up to a method handler. * Fix issue where Mapbox layer was being used instead of maplibre. * Fix #10 by adding a download button that honors the current bbox and downloads everything. --------- Co-authored-by: Benjamin Clark <clarkben@meta.com>
- Loading branch information
Showing
6 changed files
with
338 additions
and
311 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
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,73 @@ | ||
import { useMap } from "react-map-gl/maplibre"; | ||
import { useEffect } from "react"; | ||
import { DownloadCatalog } from "./DownloadCatalog.js" | ||
import { ParquetDataset, set_panic_hook, writeGeoParquet } from "@geoarrow/geoarrow-wasm/esm/index.js" | ||
|
||
function DownloadButton() { | ||
const { myMap } = useMap(); | ||
|
||
useEffect(() => { | ||
if (myMap) { | ||
myMap.getBounds(); | ||
} | ||
}, [myMap]) | ||
|
||
|
||
const handleDownloadClick = async () => { | ||
|
||
//Get current map dimensions and convert to bbox | ||
const bounds = myMap.getBounds(); | ||
let bbox = [ | ||
bounds.getWest(), //minx | ||
bounds.getSouth(), //miny | ||
bounds.getEast(), //maxx | ||
bounds.getNorth() //maxy | ||
]; | ||
|
||
console.log(bounds); | ||
|
||
//Send those to the download engine | ||
const minxPath = ["bbox", "minx"]; | ||
const minyPath = ["bbox", "miny"]; | ||
const maxxPath = ["bbox", "maxx"]; | ||
const maxyPath = ["bbox", "maxy"]; | ||
|
||
const readOptions = { | ||
bbox: bbox, | ||
bboxPaths: { | ||
minxPath, | ||
minyPath, | ||
maxxPath, | ||
maxyPath, | ||
}, | ||
}; | ||
|
||
let parquetDataset = await new ParquetDataset(DownloadCatalog); | ||
const wasmTable = await parquetDataset.read(readOptions); | ||
|
||
set_panic_hook(); | ||
//Create a blob | ||
const binaryDataForDownload = writeGeoParquet(wasmTable); | ||
|
||
|
||
let blerb = new Blob([binaryDataForDownload], { | ||
type: "application/octet-stream" | ||
}); | ||
|
||
//Download the blob | ||
window.open(URL.createObjectURL(blerb)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button id="downloadButton" onClick={handleDownloadClick}> | ||
Download Visible | ||
</button> | ||
</> | ||
); | ||
} | ||
|
||
// DownloadButton.propTypes = { | ||
// onClick: PropTypes.func.isRequired | ||
// } | ||
export default DownloadButton; |
Oops, something went wrong.