Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVTs with bottom-left corner as the origin of coordinates #1393

Open
antoniocarlon opened this issue Jul 22, 2019 · 1 comment
Open

MVTs with bottom-left corner as the origin of coordinates #1393

antoniocarlon opened this issue Jul 22, 2019 · 1 comment

Comments

@antoniocarlon
Copy link
Contributor

We've been using CARTO-VL to draw geometries on a map using our own MVT server and it seems that the current implementation takes the bottom-left corner of the tile as the origin of the tile.

In particular, we've been diving into this function that transforms the tile's coordinates space (0 to 4096 for example) to a new coordinates space from -1 to 1:

function _getPreClippedVertices (geom, mvtExtent) {
return geom.map((coord) => {
let x = coord.x;
let y = coord.y;
x = 2 * x / mvtExtent - 1;
y = 2 * (1 - y / mvtExtent) - 1;
return [x, y];
});
}

It seems that this function is inverting the y coordinate, making the bottom edge of the tile the origin of the y axis. We have written a quick Python test to prove our point:

>>> # Original CARTO-VL definition
... def transform(x, y, mvtExtent=4096):
...     x = 2 * x / mvtExtent - 1
...     y = 2 * (1 - y / mvtExtent) - 1
...     return [x, y]
... 
>>> # "Fixed"
... def transform_fix(x, y, mvtExtent=4096):
...     x = 2 * x / mvtExtent - 1
...     y = 2 * y / mvtExtent - 1
...     return [x, y]
... 
>>> transform(0, 0)
[-1.0, 1.0]
>>> transform_fix(0, 0)
[-1.0, -1.0]
>>> transform(4096, 4096)
[1.0, -1.0]
>>> transform_fix(4096, 4096)
[1.0, 1.0]

Taking a look at the Mapbox Vector Tile Specification, it seems that from version 2.0, Geometry data in a Vector Tile is defined in a screen coordinate system. The upper left corner of the tile (as displayed by default) is the origin of the coordinate system. The X axis is positive to the right, and the Y axis is positive downward. (https://github.com/mapbox/vector-tile-spec/tree/master/2.0). We haven't found anything similar for versions 1.0.0 and 1.0.1.

Is it a bug or is this the intended behavior and we need to fix it in our server?

cc @VictorVelarde @juanignaciosl

@elenatorro
Copy link
Contributor

I've just done a very quick review, and I think the VL function is the correct one:

Comparing both coordinate systems:

  0,0     |1    1,0
          |
          |
-1 -------+------- 1
          |
          |
  0,1   -1|      1,1

Will result into:

0, 0 => -1, 1 
1, 0 => 1, 1 
0, 1 => -1, -1
1, 1 => 1, -1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants