Skip to content

Commit

Permalink
Fix layer.projectPositions with default coordinate system (#4056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored and chrisgervang committed Jan 31, 2020
1 parent 1d48c85 commit 7117b3f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
20 changes: 10 additions & 10 deletions modules/aggregation-layers/src/heatmap-layer/heatmap-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,19 @@ export default class HeatmapLayer extends AggregationLayer {

const size = (textureSize * RESOLUTION) / viewport.scale;

let topLeftCommon;
let bottomRightCommon;
let bottomLeftCommon;
let topRightCommon;

// Y-axis is flipped between World and Common bounds
if (useLayerCoordinateSystem) {
topLeftCommon = this.projectPosition([minLong, maxLat, 0]);
bottomRightCommon = this.projectPosition([maxLong, minLat, 0]);
bottomLeftCommon = this.projectPosition([minLong, minLat, 0]);
topRightCommon = this.projectPosition([maxLong, maxLat, 0]);
} else {
topLeftCommon = viewport.projectPosition([minLong, maxLat, 0]);
bottomRightCommon = viewport.projectPosition([maxLong, minLat, 0]);
bottomLeftCommon = viewport.projectPosition([minLong, minLat, 0]);
topRightCommon = viewport.projectPosition([maxLong, maxLat, 0]);
}
// Ignore z component
let commonBounds = topLeftCommon.slice(0, 2).concat(bottomRightCommon.slice(0, 2));
let commonBounds = bottomLeftCommon.slice(0, 2).concat(topRightCommon.slice(0, 2));
commonBounds = scaleToAspectRatio(commonBounds, size, size);
return commonBounds;
}
Expand All @@ -557,10 +557,10 @@ export default class HeatmapLayer extends AggregationLayer {
_commonToWorldBounds(commonBounds) {
const [xMin, yMin, xMax, yMax] = commonBounds;
const {viewport} = this.context;
const topLeftWorld = viewport.unprojectPosition([xMin, yMin]);
const bottomRightWorld = viewport.unprojectPosition([xMax, yMax]);
const bottomLeftWorld = viewport.unprojectPosition([xMin, yMin]);
const topRightWorld = viewport.unprojectPosition([xMax, yMax]);

return topLeftWorld.slice(0, 2).concat(bottomRightWorld.slice(0, 2));
return bottomLeftWorld.slice(0, 2).concat(topRightWorld.slice(0, 2));
}
}

Expand Down
20 changes: 10 additions & 10 deletions modules/core/src/shaderlib/project/project-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ function lngLatZToWorldPosition(lngLatZ, viewport, offsetMode = false) {
function normalizeParameters(opts) {
const normalizedParams = Object.assign({}, opts);

const {
viewport,
coordinateSystem,
coordinateOrigin,
fromCoordinateSystem,
fromCoordinateOrigin
} = opts;
let {coordinateSystem} = opts;
const {viewport, coordinateOrigin, fromCoordinateSystem, fromCoordinateOrigin} = opts;

if (coordinateSystem === COORDINATE_SYSTEM.DEFAULT) {
coordinateSystem = viewport.isGeospatial
? COORDINATE_SYSTEM.LNGLAT
: COORDINATE_SYSTEM.CARTESIAN;
}

if (fromCoordinateSystem === undefined) {
normalizedParams.fromCoordinateSystem = coordinateSystem;
Expand All @@ -42,12 +43,13 @@ function normalizeParameters(opts) {
coordinateSystem === COORDINATE_SYSTEM.LNGLAT &&
viewport.zoom >= LNGLAT_AUTO_OFFSET_ZOOM_THRESHOLD
) {
normalizedParams.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
normalizedParams.coordinateOrigin = [
Math.fround(viewport.longitude),
Math.fround(viewport.latitude)
];
}
normalizedParams.coordinateSystem = coordinateSystem;

return normalizedParams;
}
Expand All @@ -64,7 +66,6 @@ export function getWorldPosition(

switch (coordinateSystem) {
case COORDINATE_SYSTEM.LNGLAT:
case COORDINATE_SYSTEM.LNGLAT_DEPRECATED:
return lngLatZToWorldPosition([x, y, z], viewport, offsetMode);

case COORDINATE_SYSTEM.LNGLAT_OFFSETS:
Expand Down Expand Up @@ -132,7 +133,6 @@ export function projectPosition(position, params) {
}

case COORDINATE_SYSTEM.LNGLAT:
case COORDINATE_SYSTEM.LNGLAT_DEPRECATED:
case COORDINATE_SYSTEM.CARTESIAN:
default:
return getWorldPosition(position, {
Expand Down
4 changes: 2 additions & 2 deletions test/modules/core/shaderlib/project/project-functions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TEST_CASES = [
position: [-70, 41, 1000],
params: {
viewport: TEST_VIEWPORT_2,
coordinateSystem: COORDINATE_SYSTEM.LNGLAT
coordinateSystem: COORDINATE_SYSTEM.DEFAULT
},
result: [156.44444444444446, 320.0378755678335, 0.01687089818244227]
},
Expand All @@ -54,7 +54,7 @@ const TEST_CASES = [
position: [-122.46, 37.8, 1000],
params: {
viewport: TEST_VIEWPORT,
coordinateSystem: COORDINATE_SYSTEM.LNGLAT
coordinateSystem: COORDINATE_SYSTEM.DEFAULT
},
result: [-0.014226562499999318, 0.03599588695612965, 0.016187212628251565]
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/render/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,28 @@ export const TEST_CASES = [
],
goldenImage: './test/render/golden-images/heatmap-lnglat.png'
},
{
name: 'heatmap-lnglat-high-zoom',
viewState: {
latitude: 37.76,
longitude: -122.42,
zoom: 14,
pitch: 30,
bearing: 0
},
layers: [
new HeatmapLayer({
id: 'heatmap-lnglat-2',
data: dataSamples.points,
opacity: 0.8,
pickable: false,
getPosition: d => d.COORDINATES,
radiusPixels: 35,
threshold: 0.1
})
],
goldenImage: './test/render/golden-images/heatmap-lnglat-high-zoom.png'
},
{
name: 'pointcloud-lnglat',
viewState: {
Expand Down

0 comments on commit 7117b3f

Please sign in to comment.