deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

"simple" project into a 2d plain [x, y]

Open cschlueter opened this issue 7 years ago • 5 comments

Hi, I read through all the viewport etc docs, but I'm still not sure how to properly replicate project/unproject with pure DeckGL as you can do with MapBoxGL like so. Documentation from their side:

Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location.

**Parameters**
lnglat(LngLatLike)The geographical location to project.
**Returns**
Point: The Point corresponding to lnglat , relative to the map's container .
**Example**
var coordinate = [-122.420679, 37.772537];
var point = map.project(coordinate);

And it actually works like a charm :)

I'm aware that the project/unproject functions are available on the viewport object, but the results I'm getting are 'strange' and not what I'm looking for.

deckgl.viewManager._viewports[0].projectFlat([9.997488, 53.549555]);

Reveals big numbers

3648643.1076104506
2234374.5491718682

and nothing related to the 2d space which is 500x650px.

I'm sure I'm just doing it wrong, could you help me figure this one out? I assume I'm just using the wrong projection matrices. But how to I get the right one(s)?

Thanks.

cschlueter avatar Oct 16 '19 15:10 cschlueter

check project() , it projects position into pixel space.

1chandu avatar Oct 17 '19 17:10 1chandu

@1chandu thanks, but I tried all three project methods available to no avail.

This is how the deck object look likes:

image

Theses are the numbers I'm getting for all three methods:

[-454.6350867983807, -3689.3613040772807] [261632.4538694427, 160219.8074522336] [261632.4538694427, 160219.8074522336, 0]

None of these make sense in a 500x625 coordinate system?!

cschlueter avatar Oct 17 '19 19:10 cschlueter

Any other pointer?

cschlueter avatar Oct 22 '19 15:10 cschlueter

We are doing the same (projecting a lng/lat to viewport [width, height] bounds) in ScreenGridLayer, you can look at the following code (run ScreenGridLayer with gpuAggregation prop to false to activate below code)

https://github.com/uber/deck.gl/blob/b842628e12992b399acb35b5cc81caa8b76e8b7c/modules/aggregation-layers/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.js#L564

1chandu avatar Oct 22 '19 16:10 1chandu

@cschlueter viewport.project is the method you want to use. In your screenshot, the viewport has width: 1, height: 1 so you are probably logging it before Deck is fully initialized.

If you manage the view state external to Deck, you may also do this:

import {WebMercatorViewport} from '@deck.gl/core';

const viewport = new WebMercatorViewport({width, height, longitude, latitude, zoom, pitch, bearing});
viewport.project(...);

Pessimistress avatar Oct 30 '19 00:10 Pessimistress