Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map downloads now work #12

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"aws_deploy": "python3 scripts/deploy.py",
"preview": "vite preview"
},
"dependencies": {
"dependencies": {
"@geoarrow/geoarrow-wasm": "~0.2.0-beta.3",
"apache-arrow": "^15.0.2",
"maplibre-gl": "^4.1.0",
"maplibre-gl": "^4.1.3",
"pmtiles": "^3.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
6 changes: 3 additions & 3 deletions site/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import './App.css';
import Header from './Header';
import Footer from './Footer';
import Map from './Map';

import {MapProvider} from 'react-map-gl/maplibre';
function App() {
return (
<>
<MapProvider>
<Header />
<Map/>
<Footer />
</>
</MapProvider>
);
}

Expand Down
73 changes: 73 additions & 0 deletions site/src/DownloadButton.jsx
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;
Loading
Loading