Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_updateVertices(viewport) {
if (this._shouldUseHighPrecision()) {
return;
}
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;
});