How to use the h3-js.h3ToGeo function in h3-js

To help you get started, we’ve selected a few h3-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vasturiano / three-globe / src / layers / hexedPolygons.js View on Github external
createObj: ({ h3Idx }) => {
            const obj = new THREE.Mesh();
            obj.__hexCenter = h3ToGeo(h3Idx);
            obj.__hexGeoJson = h3ToGeoBoundary(h3Idx, true);

            // stitch longitudes at the anti-meridian
            const centerLng = obj.__hexCenter[1];
            obj.__hexGeoJson.forEach(d => {
              const edgeLng = d[0];
              if (Math.abs(centerLng - edgeLng) > 170) {
                // normalize large lng distances
                d[0] += (centerLng > edgeLng ? 360 : -360);
              }
            });

            return obj;
          },
          updateObj: obj => {
github uber / deck.gl / modules / geo-layers / src / h3-layers / h3-hexagon-layer.js View on Github external
export function scalePolygon(hexId, vertices, factor) {
  const [lat, lng] = h3ToGeo(hexId);
  const actualCount = vertices.length;

  // normalize with respect to center
  normalizeLongitudes(vertices, lng);

  // `h3ToGeoBoundary` returns same array object for first and last vertex (closed polygon),
  // if so skip scaling the last vertex
  const vertexCount = vertices[0] === vertices[actualCount - 1] ? actualCount - 1 : actualCount;
  for (let i = 0; i < vertexCount; i++) {
    vertices[i][0] = lerp(lng, vertices[i][0], factor);
    vertices[i][1] = lerp(lat, vertices[i][1], factor);
  }
}
github keplergl / kepler.gl / src / layers / h3-hexagon-layer / h3-utils.js View on Github external
export function getCentroid({id}) {
  // always reverse it to [lng, lat]
  return h3ToGeo(id).reverse();
}
github vasturiano / three-globe / src / layers / hexbin.js View on Github external
function createObj(d) {
      const obj = new THREE.Mesh();
      obj.__hexCenter = h3ToGeo(d.h3Idx);
      obj.__hexGeoJson = h3ToGeoBoundary(d.h3Idx, true);

      // stitch longitudes at the anti-meridian
      const centerLng = obj.__hexCenter[1];
      obj.__hexGeoJson.forEach(d => {
        const edgeLng = d[0];
        if (Math.abs(centerLng - edgeLng) > 170) {
          // normalize large lng distances
          d[0] += (centerLng > edgeLng ? 360 : -360);
        }
      });

      obj.__globeObjType = 'hexbin'; // Add object type
      return obj;
    }
github uber / deck.gl / test / modules / geo-layers / h3-layers.spec.js View on Github external
verify: (vertices, hexId) => {
        const [lat, lng] = h3ToGeo(hexId);
        return vertices.every(vertex => vertex[0] === lng || vertex[1] === lat);
      }
    },
github uber / deck.gl / modules / geo-layers / src / h3-layers / h3-hexagon-layer.js View on Github external
function getHexagonCentroid(getHexagon, object, objectInfo) {
  const hexagonId = getHexagon(object, objectInfo);
  const [lat, lng] = h3ToGeo(hexagonId);
  return [lng, lat];
}
github uber / deck.gl / modules / geo-layers / src / h3-layers / h3-hexagon-layer.js View on Github external
const {resolution, edgeLengthKM, centerHex} = this.state;
    if (resolution < 0) {
      return;
    }
    const hex = geoToH3(viewport.latitude, viewport.longitude, resolution);
    if (
      centerHex === hex ||
      (centerHex && h3Distance(centerHex, hex) * edgeLengthKM < UPDATE_THRESHOLD_KM)
    ) {
      return;
    }

    const {unitsPerMeter} = viewport.distanceScales;

    let vertices = h3ToPolygon(hex);
    const [centerLat, centerLng] = h3ToGeo(hex);

    const [centerX, centerY] = viewport.projectFlat([centerLng, centerLat]);
    vertices = vertices.map(p => {
      const worldPosition = viewport.projectFlat(p);
      worldPosition[0] = (worldPosition[0] - centerX) / unitsPerMeter[0];
      worldPosition[1] = (worldPosition[1] - centerY) / unitsPerMeter[1];
      return worldPosition;
    });

    this.setState({centerHex: hex, vertices});
  }

h3-js

Pure-Javascript version of the H3 library, a hexagon-based geographic grid system

Apache-2.0
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis