How to use the viewport-mercator-project.getDistanceScales 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
];
      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 uber / deck.gl / src / core / viewports / viewport.js View on Github external
// Silently allow apps to send in w,h = 0,0
    this.x = x;
    this.y = y;
    this.width = width || 1;
    this.height = height || 1;

    this.zoom = zoom;
    if (!Number.isFinite(this.zoom)) {
      this.zoom = this.isGeospatial ? getMeterZoom({latitude}) : DEFAULT_ZOOM;
    }
    this.scale = Math.pow(2, this.zoom);

    // Calculate distance scales if lng/lat/zoom are provided
    this.distanceScales = this.isGeospatial
      ? getDistanceScales({latitude, longitude, scale: this.scale})
      : distanceScales || DEFAULT_DISTANCE_SCALES;

    this.focalDistance = opts.focalDistance || 1;

    this.distanceScales.metersPerPixel = new Vector3(this.distanceScales.metersPerPixel);
    this.distanceScales.pixelsPerMeter = new Vector3(this.distanceScales.pixelsPerMeter);

    this.position = ZERO_VECTOR;
    this.meterOffset = ZERO_VECTOR;
    if (position) {
      // Apply model matrix if supplied
      this.position = position;
      this.modelMatrix = modelMatrix;
      this.meterOffset = modelMatrix ? modelMatrix.transformVector(position) : position;
    }
github uber-archive / viewport-mercator-project / test / spec / web-mercator-utils.spec.js View on Github external
test('getDistanceScales', t => {
  for (const vc in VIEWPORT_PROPS) {
    const props = VIEWPORT_PROPS[vc];
    const {
      metersPerPixel, pixelsPerMeter, degreesPerPixel, pixelsPerDegree
    } = getDistanceScales(props);

    t.deepEqual([
      toLowPrecision(metersPerPixel[0] * pixelsPerMeter[0]),
      toLowPrecision(metersPerPixel[1] * pixelsPerMeter[1]),
      toLowPrecision(metersPerPixel[2] * pixelsPerMeter[2])
    ], [1, 1, 1], 'metersPerPixel checks with pixelsPerMeter');

    t.deepEqual([
      toLowPrecision(degreesPerPixel[0] * pixelsPerDegree[0]),
      toLowPrecision(degreesPerPixel[1] * pixelsPerDegree[1]),
      toLowPrecision(degreesPerPixel[2] * pixelsPerDegree[2])
    ], [1, 1, 1], 'degreesPerPixel checks with pixelsPerDegree');
  }
  t.end();
});
github DefinitelyTyped / DefinitelyTyped / types / viewport-mercator-project / viewport-mercator-project-tests.ts View on Github external
});

const fittedMercator = mercatorWithOptions.fitBounds([[10, 20], [30, 40]], {
    padding: 10,
    offset: [10, 20],
});

const equal2 = fittedMercator.equals(mercatorWithOptions);

const distanceScalesInputZoom = {
    longitude: 1,
    latitude: 2,
    zoom: 1,
};

const { pixelsPerDegree } = getDistanceScales(distanceScalesInputZoom);

const { pixelsPerDegree2 } = getDistanceScales({
    ...distanceScalesInputZoom,
    highPrecision: true,
});

const distanceScalesInputScale = {
    longitude: 1,
    latitude: 2,
    scale: 1,
};

const { metersPerPixel } = getDistanceScales(distanceScalesInputScale);

const { pixelsPerMeter2 } = getDistanceScales({
    ...distanceScalesInputScale,
github DefinitelyTyped / DefinitelyTyped / types / viewport-mercator-project / viewport-mercator-project-tests.ts View on Github external
};

const { pixelsPerDegree } = getDistanceScales(distanceScalesInputZoom);

const { pixelsPerDegree2 } = getDistanceScales({
    ...distanceScalesInputZoom,
    highPrecision: true,
});

const distanceScalesInputScale = {
    longitude: 1,
    latitude: 2,
    scale: 1,
};

const { metersPerPixel } = getDistanceScales(distanceScalesInputScale);

const { pixelsPerMeter2 } = getDistanceScales({
    ...distanceScalesInputScale,
    highPrecision: true,
});

const worldPos = getWorldPosition({
    longitude: 1,
    latitude: 2,
    zoom: 10,
    scale: 1,
});

const length = worldPos.length;
github uber / deck.gl / src / core / viewports / viewport.js View on Github external
getDistanceScales(coordinateOrigin = null) {
    if (coordinateOrigin) {
      return getDistanceScales({
        longitude: coordinateOrigin[0],
        latitude: coordinateOrigin[1],
        scale: this.scale,
        highPrecision: true
      });
    }
    return this.distanceScales;
  }
github keplergl / kepler.gl / src / layers / point-layer / point-layer.js View on Github external
getTextOffset(config, radiusScale, getRadius, mapState) {
    const distanceScale = getDistanceScales(mapState);
    const xMult =
      config.anchor === 'middle' ? 0 : config.anchor === 'start' ? 1 : -1;
    const yMult =
      config.alignment === 'center' ? 0 : config.alignment === 'bottom' ? 1 : -1;

    const sizeOffset =
      config.alignment === 'center'
        ? 0
        : config.alignment === 'bottom'
        ? config.size
        : config.size;

    const pixelRadius = radiusScale * distanceScale.pixelsPerMeter[0];
    const padding = 20;

    return typeof getRadius === 'function'