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
? h3Factory.web()
: 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.sh
or compile the C source manually. Theh3_ffi/c
directory 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
-
Include
h3-js
in yourindex.html
:<script defer src="https://unpkg.com/h3-js@4.2.1"></script>
Note,
main.dart.js
import should go after this line -
Load the web implementation:
final h3 = const H3Factory().web();