h3_dart 0.8.0
h3_dart: ^0.8.0 copied to clipboard
The package provides Dart version of the H3 Core library, a hexagon-based geographic grid system
H3 Dart #
If you are building a Flutter app use h3_flutter instead.
A platform neutral wrapper around Uber's H3 library. Internally it delegates to h3_ffi on the VM and to h3_web on the web.
final h3Factory = const H3Factory();
const kIsWeb = identical(0, 0.0); // taken from https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html
final h3 = kIsWeb
? await h3Factory.byUrl()
: h3Factory.byPath('path/to/library.dll');
// Get hexagons in specified triangle.
final hexagons = h3.polyfill(
resolution: 5,
coordinates: [
GeoCoord(20.4522, 54.7104),
GeoCoord(37.6173, 55.7558),
GeoCoord(39.7015, 47.2357),
],
);
There are also few methods ported from JS library Geojson2H3, to access them you should instantiate Geojson2H3 class using const Geojson2H3(h3). It uses package:geojson2h3 internally.
Setup #
If you are building a Flutter app use h3_flutter instead.
VM #
-
Build the native library using
scripts/build_h3.shor compile the C source manually. Theh3_ffi/cdirectory has a git submodule pointing to the original H3 repository, pinned to the correct version. -
Load the compiled binary with
H3Factory().byPath():final h3 = const H3Factory().byPath('path/to/library.dll')
Web #
Load H3 by URL. It adds h3-js v4.5.0 to the page if it is not there yet:
final h3 = await const H3Factory().byUrl();
Pass libraryUrl to load h3-js from another location, for example your own server.
Both dart2js and dart2wasm are supported.
If you add h3-js to index.html yourself, you can use the synchronous
const H3Factory().process() instead. Add the script before the script that loads your app,
and do not use defer on it when the app script is async.