question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong coordinates on MVTLayer

See original GitHub issue

Description

Bellow I have two screenshots and you can see what coordinates I get from MVTLayer (the black one) which are wrong. On the white background are the correct ones from the TileLayer with some code I used in getTileData.

I assume that the issue is somewhere in the calculations happening inside the MVTLayer’s renderSubLayers.

  renderSubLayers(props) {
    const {tile} = props;
    const worldScale = Math.pow(2, tile.z);

    const xScale = WORLD_SIZE / worldScale;
    const yScale = -xScale;

    const xOffset = (WORLD_SIZE * tile.x) / worldScale;
    const yOffset = WORLD_SIZE * (1 - tile.y / worldScale);

    const modelMatrix = new Matrix4().scale([xScale, yScale, 1]);

    props.autoHighlight = false;
    props.modelMatrix = modelMatrix;
    props.coordinateOrigin = [xOffset, yOffset, 0];
    props.coordinateSystem = COORDINATE_SYSTEM.CARTESIAN;
    props.extensions = [...(props.extensions || []), new ClipExtension()];

    return super.renderSubLayers(props);
  }
Screenshot 2020-08-20 at 13 16 12 Screenshot 2020-08-20 at 13 21 06

Repro Steps

Check the object in the onHover/onClick events

Environment

  • Framework Version: deck.gl 8.2.5
  • Browser Version: Chrome 84.0
  • OS: Mac OS X 10.15

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
Pessimistresscommented, Aug 20, 2020

Overriding the loadOptions in MVTLayer will not fix your problem, as the default renderSubLayers expect Cartesian coordinates.

In your pickingInfo there should also be a tile object that contains the bounding box of the tile. The feature coordinates are normalized to 0-1 inside this bounding box. You can find the lnglat like this:

const {viewport} = layer.context:
const {bbox} = tile;
const [minX, minY] = viewport.projectFlat([bbox.west, bbox.north]);
const [maxX, maxY] = viewport.projectFlat([bbox.east, bbox.south]);

function cartesianToWGS84(x, y) {
  const x0 = lerp(minX, maxX, x);
  const y0 = lerp(minY, maxY, y);
  return viewport.unprojectFlat([x0, y0]);
}

0reactions
geobourazanascommented, Aug 20, 2020

Thanks so much @Pessimistress for clarifying, that makes so much sense. Cheers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coordinate Systems - deck.gl
It is the default coordinate system when rendering into non-geospatial views. When combined with geospatial views, the positions are treated as common space ......
Read more >
Can't reference an MVT layer from Mapfile - GIS Stack Exchange
I'm trying to add an MVT layer to my Mapfile, but it doesn't work and I ... [Thu Dec 30 12:17:43 2021].133000 msOGRFileOpen():...
Read more >
MVTLayer | XYZ Maps Documentation
The error message of the failing request. name: "NetworkError". The name property represents a name for the type of error. The value is ......
Read more >
mvt_layer: MVT Layer in anthonynorth/rdeck: Deck.gl Widget
< "XY" | "XYZ" > Determines whether each coordinate has two (XY) or three (XYZ) ... < boolean > If TRUE , circles...
Read more >
How can I get onHover to work for deck.gl MVTLayer?
What am I doing wrong? Strawson on Free Will: What are the most persuasive challenges to his position? Do I deserve to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found