Skip to content

Commit

Permalink
clean up www and js api
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Jul 16, 2024
1 parent d2002bf commit d3c75bb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 55 deletions.
19 changes: 8 additions & 11 deletions geomedea-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,24 @@ pub fn setup_logging() {
#[derive(Debug)]
pub struct HttpReader {
url: String,
inner: Option<geomedea::HttpReader>,
}

#[wasm_bindgen]
impl HttpReader {
#[wasm_bindgen(constructor)]
pub fn new(url: String) -> Self {
Self { url, inner: None }
Self { url }
}

pub async fn open(&mut self) -> Result<(), JsError> {
let http_reader = geomedea::HttpReader::open(&self.url).await?;
self.inner = Some(http_reader);
debug!("set http_reader to: {:?}", self.inner);
Ok(())
async fn open(&mut self) -> Result<geomedea::HttpReader, JsError> {
Ok(geomedea::HttpReader::open(&self.url).await?)
}

pub async fn select_all(&mut self) -> Result<JsValue, JsError> {
debug!("selecting all: {:?}", self.inner);
let http_reader = self.inner.as_mut().expect("must open before selecting");
debug!("selecting all");
let mut http_reader = self.open().await?;
debug!("http_reader: {:?}", http_reader);

let feature_stream = http_reader.select_all().await?;
debug!("opened iter");
Ok(FeatureCollection::new(feature_stream)
Expand All @@ -74,8 +71,8 @@ impl HttpReader {
bottom: f64,
left: f64,
) -> Result<JsValue, JsError> {
debug!("selecting all: {:?}", self.inner);
let http_reader = self.inner.as_mut().expect("must open before selecting");
debug!("selecting bbox");
let mut http_reader = self.open().await?;
debug!("http_reader: {:?}", http_reader);

let top_right = LngLat::degrees(right, top);
Expand Down
16 changes: 2 additions & 14 deletions geomedea-wasm/web_root/examples/maplibre/filtered.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<script src="https://unpkg.com/[email protected]/underscore-min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/flatgeobuf-geojson.min.js"></script>
<script src="https://unpkg.com/json-formatter-js"></script>

<style>
Expand Down Expand Up @@ -46,8 +45,7 @@

let httpReader = new wasm.HttpReader(input);
console.log('httpReader', httpReader);
// TODO: put in select_all?
await httpReader.open();
console.log('bbox', bbox);
let featureCollectionString = await httpReader.select_bbox(bbox.maxY, bbox.maxX, bbox.minY, bbox.minX);
const featureCollection = JSON.parse(featureCollectionString);
let i = 1;
Expand All @@ -69,13 +67,6 @@
maxZoom: 8,
});

// optionally show some meta-data about the FGB file
function handleHeaderMeta(headerMeta) {
const header = document.getElementById("header")
const formatter = new JSONFormatter(headerMeta, 10)
header.appendChild(formatter.render())
}

// get a rect around the map center
function getBoundingBox() {
const { lng, lat } = map.getCenter();
Expand Down Expand Up @@ -211,7 +202,7 @@
});
</script>
<p>
FlatGeobuf's spatial index allows you to fetch the features that
Geomedea's spatial index allows you to fetch the features that
intersect a given bounding box, without downloading the entire file.
This can be helpful when you have a very large file but are only
interested in a small portion of it, and want to keep your page loads
Expand All @@ -228,8 +219,5 @@
they are much smaller because we fetch only the relevant sections of
the file.
</p>
<div id="header">
<h3>Parsed header content</h3>
</div>
</body>
</html>
15 changes: 1 addition & 14 deletions geomedea-wasm/web_root/examples/maplibre/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
let input = siteOrigin + "/files/test_fixtures/USCounties-compressed.geomedea"
// let input = siteOrigin + "/files/test_fixtures/USCounties-uncompressed.geomedea"
let httpReader = new wasm.HttpReader(input);
console.log('httpReader', httpReader);

await httpReader.open();
let featureCollectionString = await httpReader.select_all();
const featureCollection = JSON.parse(featureCollectionString);
let i = 1;
Expand All @@ -65,13 +62,6 @@
maxZoom: 8,
});

// optionally show some meta-data about the FGB file
function handleHeaderMeta(headerMeta) {
const header = document.getElementById("header")
const formatter = new JSONFormatter(headerMeta, 10)
header.appendChild(formatter.render())
}

map.on("load", async () => {
const featureCollection = await window.getFeatureCollection();
map.addSource("counties", {
Expand Down Expand Up @@ -147,14 +137,11 @@
</script>

<p>
This basic example shows how to render all the features in a FlatGeobuf
This basic example shows how to render all the features in a Geomedea
onto a <a href="https://maplibre.org/maplibre-gl-js-docs/">MapLibre</a> map. It shows
per-feature properties when you click on each feature. This will work almost exactly
the same for Mapbox GL JS, just add an account key and load the Mapbox libraries instead.
</p>

<div id="header">
<h3>Parsed header content</h3>
</div>
</body>
</html>
22 changes: 6 additions & 16 deletions geomedea-wasm/web_root/examples/maplibre/large.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
</head>
<body>
<ul class="primary-navigation">
<!--
<li>
<a href="/examples/leaflet/">Leaflet Example</a>
</li>
<li>
<a href="/examples/openlayers/">OpenLayers Example</a>
</li>
-->
<li class="active">
MapLibre Example
</li>
Expand All @@ -41,8 +43,6 @@

let input = "https://d3imsg4yynhh83.cloudfront.net/test-data/population_areas.geomedea"
let httpReader = new wasm.HttpReader(input);
// TODO: put in select_all?
await httpReader.open();
console.log('bbox', bbox);
let featureCollectionString = await httpReader.select_bbox(bbox.maxY, bbox.maxX, bbox.minY, bbox.minX);
const featureCollection = JSON.parse(featureCollectionString);
Expand All @@ -66,13 +66,6 @@
minZoom: 12,
});

// optionally show some meta-data about the FGB file
function handleHeaderMeta(headerMeta) {
const header = document.getElementById("header")
const formatter = new JSONFormatter(headerMeta, 10)
header.appendChild(formatter.render())
}

// get a rect around the map center
function getBoundingBox() {
const { lng, lat } = map.getCenter();
Expand Down Expand Up @@ -223,9 +216,9 @@
</script>
<p>
This is a map of every census block in the USA, including its
population. The entire file is over 12GB, but FlatGeobuf fetches only
population. The entire file is 3.7GB, but Geomedea fetches only
the tiny subset of data that intersects with the bounding box (drawn
in yellow). Pan the map to move the query's bounding box.
in blue). Pan the map to move the query's bounding box.
</p>
<p>
When you have feature data that cover a large area in fine-grained
Expand All @@ -239,14 +232,11 @@
interested in an area on the boundary of slices.
</p>
<p>
For these cases, consider instead using a single indexed FlatGeobuf.
Because FlatGeobuf's spatial index allows you to fetch only the data
For these cases, consider instead using a single Geomedea.
Because Geomedea's spatial index allows you to fetch only the data
you're interested in, you can keep your page size down while avoiding
the tedium of slicing up files manually, or building and maintaining an
application server.
</p>
<div id="header">
<h3>Parsed header content</h3>
</div>
</body>
</html>

0 comments on commit d3c75bb

Please sign in to comment.