# Rust D3 Geo Rust 2021 Edition.
This is a port [d3-geo](https://github.com/d3/d3-geo) into RUST. It is part of a family of ported d3-modules * d3_geo_rs * [d3_delaunay_rs](https://crates.io/crates/d3_delaunay_rs) * [d3_geo_voronoi_rs](https://crates.io/crates/d3_geo_voronoi_rs) This library allows the development of custom maps. It provides a comprehensive set of projections along with the means to scale rotate and translate the final image. The projector processes polygons, lines and points in the form of [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) objects. Additionally this library can be used to calculate lengths, areas and the centroid of such objects [CHANGELOG.md](https://github.com/martinfrances107/rust_d3_geo/blob/v3.x-dev/CHANGELOG.md) contains a summary of breaking changes between v1.x, 2.x and 3.x Version 3.0.0 adds support for WGPU > "WGPU is a pure-rust graphics API. It runs natively on Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm." [\[wgpu\]](https://crates.io/crates/wgpu) ## When to use the rust version of the library The limits of the javascript library become obvious when developing interactive applications that process large datasets. For example the examples/globe applications operate on a highly detailed ( 1:50M resolution ) map of the earth. On a laptop this is beyond the javascript version. | Available Projections | | | | --------------------- | - | - | | Albers | ConicEqualArea | Gnomic| | AlbersUsa | Equidistant | Orthographic | | AzimuthalEqualArea | Equirectangular | Mercator | | AzimuthalEquiDistant | EqualArea | MercatorTransverse | | Conformal | EqualEarth | Stereographic | ## Examples These Examples are provided to help developers convert their existing javascript to rust. They can be found in the github repository associated with this crate.Description | |
---|---|
examples/globe/rotating This is a port into rust of this d3-geo example [www.d3indepth.com/geographic/](https://www.d3indepth.com/geographic/) The javascript version compromises by using a low resolution map. Here no such compromise is required. This globe is rendered to a HTML CANVAS element. For performance reasons this example is best viewed by running "npm run build" and then "npm run serve" which compiles the rust code using the --release flag. (Scale 1:50M) |
|
examples/globe/rotating_WGPU [WGPU](https://gpuweb.github.io/gpuweb/) support in the browser is partial and currently hidden behind experimental flags. See the browser-WGPU Implementation [Status](https://github.com/gpuweb/gpuweb/wiki/Implementation-Status). For now development in this library uses the [winit](https://crates.io/crates/winit) crate to make cross platform application. The promise of this approach is to bypass the bottlekneck in passing bulk data from RUST memory space, into javascript, and finally into GPU memory. GeoJson Geometry is streamed through this libraries rendering pipeline into a new **PolyLinesWPGU** endpoint. This endpoint's output is a (vertex_buffer,index_buffer) pair in the form of blocks of contiguous memory which can be passed directly to the GPU. A thin vertex and fragment shader is then responsible for rendering. The example requires the feature flag "wgpu". (Scale 1:50M) |
|
examples/globe/svg The globe is rendered as a SVG image. SVG are useful when the semantic meaning of the data needs to be preserved. The example shows how to load/parse/display the globe as individual SVG PATH elements. It also includes code samples that generates SVG graticules. (Scale 1:50M) |
|
examples/globe/drag_and_zoom This globe is rendered to a HTML CANVAS element It deliberately mixes typescript methods with rust. The typescript is responsible for handling the mouse events and manipulating the quaternion used to calculate the appropriate change in rotation. In a typescript render loop calls to a rust function render the globe. This example is currently undergoing rapid development. (Scale 1:50M) |
|
examples/projections All available projections are rendered to a HTML CANVAS element As a confidence building exercise, this demo shows a side by side comparison of the all the projections rendered by in both javascript and rust. (Scale 1:50M) |
|
examples/globe/albers_usa This show all the counties in the USA. AlbersUSA is unlike the other projections. Alaska and Hawaii are rendered as insets. As can be seen in the code a Multi-drain must be used to gather the three projections. (Scale of 1:10M) |
|
examples/ring SVG example Sample code in both RUST and javascript that renders a complex multi-polygon. ( Orthographic and Stereographic ) |
|