visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.24k stars 2.08k forks source link

Add a TopoJsonLayer #591

Closed jefffriesen closed 6 years ago

jefffriesen commented 7 years ago

You all have probably considered this internally but I didn't see any tickets or mention of it.

Creating a layer that takes topojson instead of geojson could, in some cases, significantly reduce the payload to the browser: https://github.com/topojson/topojson

From their docs:

TopoJSON is substantially more compact than GeoJSON, frequently offering a reduction of 80% or more even without simplification. Yet encoding topology also has numerous useful applications for maps and visualization above! It allows topology-preserving shape simplification, which ensures that adjacent features remain connected after simplification; this applies even across feature collections, such as simultaneous consistent simplification of state and county boundaries. Topology can also be used for Dorling or hexagonal cartograms, as well as other techniques that need shared boundary information such as automatic map coloring.

Not sure if it would be it's own layer or an alternative in the geojson layer. Either way, it seems like a useful addition to your library.

Thanks!

ibgreen commented 7 years ago

Creating a layer that takes topojson instead of geojson could, in some cases, significantly reduce the payload to the browse

@jefffriesen You are absolutely right.

The good news is that we foresaw this need and intentionally designed the GeoJsonLayer as a composite layer that separates parsing of GeoJson data into a parent layer and rendering into sub layers (PolygonLayer, PathLayer, ScatterplotLayer). Thus aTopoJsonLayer could now be created without touching any rendering.

The bad news is that we have no current plans for doing this work. However, we would be very happy to accept a PR.

It should be quite straightforward for someone who knows TopoJson to simply copy of the GeoJsonLayer folder into a TopJsonLayer folder and replace the geojson parsing with topojson support.

The main necessary change should be here

jefffriesen commented 7 years ago

Sounds like you were very thoughtful about the API design. That's great.

Unfortunately, I don't have the time to do a PR for this because of deadlines. I'm using fairly large geojson files (33 MB + 21 MB for a single view). Right now I'm using Electron so loading over the network is not an issue, but eventually I will want to use it in a regular browser context. Hopefully someone else comes across this with more time. You laid out a nice pathway to get started. Thanks.

ibgreen commented 6 years ago

Can be done by application through https://github.com/topojson/topojson-client, converting topojson to geojson.