How to use the viewport-mercator-project.lngLatToWorld function in viewport-mercator-project

To help you get started, we’ve selected a few viewport-mercator-project 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 uber-archive / viewport-mercator-project / test / spec / web-mercator-utils.spec.js View on Github external
delta * pixelsPerMeter[1],
        z * pixelsPerMeter[2]
      ];
      const coordsAdjusted = [
        delta * (pixelsPerMeter[0] + pixelsPerMeter2[0] * delta),
        delta * (pixelsPerMeter[1] + pixelsPerMeter2[1] * delta),
        z * (pixelsPerMeter[2] + pixelsPerMeter2[2] * delta)
      ];

      let pt = [longitude, latitude];
      // turf unit is kilometers
      pt = destination(pt, delta / 1000 * Math.sqrt(2), 45);
      pt = pt.geometry.coordinates;

      const realCoords = [
        lngLatToWorld(pt, scale)[0] - lngLatToWorld([longitude, latitude], scale)[0],
        lngLatToWorld(pt, scale)[1] - lngLatToWorld([longitude, latitude], scale)[1],
        z * getDistanceScales({longitude: pt[0], latitude: pt[1], scale}).pixelsPerMeter[2]
      ];

      const diff = getDiff(coords, realCoords);
      const diffAdjusted = getDiff(coordsAdjusted, realCoords);

      t.comment(`unadjusted: ${diff.message}`);
      t.comment(`adjusted: ${diffAdjusted.message}`);

      t.ok(diffAdjusted.error.every(e => e < DISTANCE_TOLERANCE),
        'Error within ratio tolerance');
      t.ok(diffAdjusted.errorPixels.every(p => p < DISTANCE_TOLERANCE_PIXELS),
        'Error within pixel tolerance');
    }
  }
github uber-archive / viewport-mercator-project / test / spec / web-mercator-utils.spec.js View on Github external
z * pixelsPerMeter[2]
      ];
      const coordsAdjusted = [
        delta * (pixelsPerMeter[0] + pixelsPerMeter2[0] * delta),
        delta * (pixelsPerMeter[1] + pixelsPerMeter2[1] * delta),
        z * (pixelsPerMeter[2] + pixelsPerMeter2[2] * delta)
      ];

      let pt = [longitude, latitude];
      // turf unit is kilometers
      pt = destination(pt, delta / 1000 * Math.sqrt(2), 45);
      pt = pt.geometry.coordinates;

      const realCoords = [
        lngLatToWorld(pt, scale)[0] - lngLatToWorld([longitude, latitude], scale)[0],
        lngLatToWorld(pt, scale)[1] - lngLatToWorld([longitude, latitude], scale)[1],
        z * getDistanceScales({longitude: pt[0], latitude: pt[1], scale}).pixelsPerMeter[2]
      ];

      const diff = getDiff(coords, realCoords);
      const diffAdjusted = getDiff(coordsAdjusted, realCoords);

      t.comment(`unadjusted: ${diff.message}`);
      t.comment(`adjusted: ${diffAdjusted.message}`);

      t.ok(diffAdjusted.error.every(e => e < DISTANCE_TOLERANCE),
        'Error within ratio tolerance');
      t.ok(diffAdjusted.errorPixels.every(p => p < DISTANCE_TOLERANCE_PIXELS),
        'Error within pixel tolerance');
    }
  }
  t.end();
github GlobalFishingWatch / map-client / app / src / util / heatmapTileData.js View on Github external
point = feature.properties;
      // WARNING: toGeoJSON is expensive. Avoid using raw coordinates in PBF tiles, pregenerate world coords
      // FIXME: this should not be done when headers declare worldX/Y -  if (!columns.worldX) {
      const geom = feature.toGeoJSON(tileCoordinates.x, tileCoordinates.y, zoom).geometry.coordinates;
      point.longitude = geom[0];
      point.latitude = geom[1];
    } else {
      point = {};
      columnsArr.forEach((c) => { point[c] = data[c][index]; });
    }

    const timeIndex = (columns.timeIndex)
      ? point.timeIndex : convert.getOffsetedTimeAtPrecision(point.datetime);

    // FIXME: this should not be done when headers declare worldX/Y -  if (!columns.worldX) {
    const [worldX, worldY] = lngLatToWorld([point.longitude, point.latitude], 1);
    point.worldX = worldX;
    point.worldY = worldY;

    if (columns.sigma) {
      point.radius = convert.sigmaToRadius(point.sigma, zoomFactorRadiusRenderingMode, zoomFactorRadius);
    }
    if (columns.weight) {
      point.opacity = convert.weightToOpacity(point.weight, zoomFactorOpacity);
    }
    if (columns.id) {
      point.series = point.id;
    }

    if (!tilePlaybackData[timeIndex]) {
      const frame = {};
      storedColumns.forEach((column) => {
github GlobalFishingWatch / map-client / app / src / _map / activity / ActivityLayers.jsx View on Github external
// bail if all heatmap layers are set to non-interactive
    if (this.props.heatmapLayers.every(l => l.interactive !== true)) {
      return;
    }

    const { viewport } = this._context;
    const [longitude, latitude] = viewport.unproject([x, y]);

    let wrappedLongitude = longitude;
    if (wrappedLongitude > 180) {
      wrappedLongitude -= 360;
    } else if (wrappedLongitude < -180) {
      wrappedLongitude += 360;
    }

    const [worldX, worldY] = lngLatToWorld([wrappedLongitude, latitude], 1);

    const toleranceRadiusInWorldUnits = VESSEL_CLICK_TOLERANCE_PX / viewport.scale;

    this.props.queryHeatmapVessels({
      longitude: wrappedLongitude,
      latitude,
      worldX,
      worldY,
      toleranceRadiusInWorldUnits
    });
  }
github uber-archive / viewport-mercator-project / test / spec / web-mercator-utils.spec.js View on Github external
test('lngLatToWorld', t => {
  t.throws(() => lngLatToWorld([38, -122], 128), /latitude/i, 'throws on invalid latitude');
  t.ok(equals(lngLatToWorld([-122, 38], 128), [10558.577777777778, 25279.113534227028]),
    'returns correct result');
  t.end();
});
github uber-archive / viewport-mercator-project / test / spec / web-mercator-utils.spec.js View on Github external
  t.throws(() => lngLatToWorld([38, -122], 128), /latitude/i, 'throws on invalid latitude');
  t.ok(equals(lngLatToWorld([-122, 38], 128), [10558.577777777778, 25279.113534227028]),
github uber / deck.gl / examples / website / tagmap / tagmap-layer / tagmap-wrapper.js View on Github external
getTags({zoom, bbox, minFontSize, maxFontSize, weightThreshold}) {
    if (weightThreshold !== this.weightThreshold) {
      this.weightThreshold = weightThreshold;
      this.clusterCache = {};
    }

    const scale = Math.pow(2, zoom);

    const cluster = this.clusterCache[zoom] || this.extractCluster({scale, weightThreshold});
    this.clusterCache[zoom] = cluster;

    let tagList;
    if (bbox) {
      const sw = lngLatToWorld([bbox.minX, bbox.minY], scale);
      const ne = lngLatToWorld([bbox.maxX, bbox.maxY], scale);
      tagList = cluster.search({
        minX: sw[0],
        minY: ne[1],
        maxX: ne[0],
        maxY: sw[1]
      });
    } else {
      tagList = cluster.all();
    }

    return this.layout({
      tagList,
      scale,
      minFontSize,
      maxFontSize
    });
github uber / deck.gl / examples / website / tagmap / tagmap-layer / tagmap-wrapper.js View on Github external
getTags({zoom, bbox, minFontSize, maxFontSize, weightThreshold}) {
    if (weightThreshold !== this.weightThreshold) {
      this.weightThreshold = weightThreshold;
      this.clusterCache = {};
    }

    const scale = Math.pow(2, zoom);

    const cluster = this.clusterCache[zoom] || this.extractCluster({scale, weightThreshold});
    this.clusterCache[zoom] = cluster;

    let tagList;
    if (bbox) {
      const sw = lngLatToWorld([bbox.minX, bbox.minY], scale);
      const ne = lngLatToWorld([bbox.maxX, bbox.maxY], scale);
      tagList = cluster.search({
        minX: sw[0],
        minY: ne[1],
        maxX: ne[0],
        maxY: sw[1]
      });
    } else {
      tagList = cluster.all();
    }

    return this.layout({
      tagList,
      scale,
      minFontSize,
      maxFontSize