Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
}
}
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();
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) => {
// 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
});
}
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();
});
t.throws(() => lngLatToWorld([38, -122], 128), /latitude/i, 'throws on invalid latitude');
t.ok(equals(lngLatToWorld([-122, 38], 128), [10558.577777777778, 25279.113534227028]),
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
});
const project = lngLat => lngLatToWorld(lngLat, scale);
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