h3_web 0.6.1 copy "h3_web: ^0.6.1" to clipboard
h3_web: ^0.6.1 copied to clipboard

Platformweb

The package provides Dart version of the H3 Core library, a hexagon-based geographic grid system

Build & Test codecov License: Apache 2.0

H3 Web #

In most cases you should not use this library directly, use h3_dart or h3_flutter instead.

This package provides implementation of H3 abstraction from package:h3_common through bindings to Ubers's h3-js library written on JS.

Bindings are generated using dart_js_facade_gen tool.

// Get hexagons in specified triangle.
final h3 = const H3Web();
final hexagons = h3.polyfill(
  resolution: 5,
  coordinates: [
    GeoCoord(20.4522, 54.7104),
    GeoCoord(37.6173, 55.7558),
    GeoCoord(39.7015, 47.2357),
  ],
);

Setup #

In most cases you should not use this library directly, use h3_dart or h3_flutter instead.

This library is built on top of h3-js, you have to import it.
Add next line to your index.html:

    <script defer src="https://unpkg.com/h3-js@3.7.2"></script>

Note, main.dart.js import should go after this line


For contributors: #

Facade for h3-js library is placed at h3_web/lib/src/generated/types.dart and generated by dart_js_facade_gen dependency.
To regenerate this file run npm run generate (Node.js should be installed)

dart_js_facade_gen is currently out-of-date and it does not support null-safety.
So, while using h3_js you should treat any response as nullable, even if dart analyzer says it's not.
If you want to check the response for null, you should first cast it, e.g.:

// ignore: unnecessary_cast
final res = h3_js.h3ToCenterChild(
    h3Index.toH3JS(),
    resolution,
) as String?;

Every responsed by h3_js list, you should also cast to avoid runtime errors:

h3_js
    .polyfill(coordinates.map((e) => [e.lat, e.lon]).toList(), resolution)
    .cast<String>() // here, althrough `polyfill` method declaration says it returns List<String>
    .map((e) => e.toBigInt())
0
likes
130
pub points
23%
popularity

Publisher

verified publisherfestelo.tk

The package provides Dart version of the H3 Core library, a hexagon-based geographic grid system

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

h3_common, js

More

Packages that depend on h3_web