Skip to content

Commit

Permalink
screenPositionToLngLat returns false if position has no LngLat
Browse files Browse the repository at this point in the history
  • Loading branch information
matteblair committed Jul 12, 2016
1 parent 998fb69 commit 89a2991
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions core/src/tangram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,15 @@ float getTilt() {

}

void screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat) {
bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat) {

m_view->screenToGroundPlane(_x, _y);
double intersection = m_view->screenToGroundPlane(_x, _y);
glm::dvec2 meters(_x + m_view->getPosition().x, _y + m_view->getPosition().y);
glm::dvec2 lngLat = m_view->getMapProjection().MetersToLonLat(meters);
*_lng = lngLat.x;
*_lat = lngLat.y;

return (intersection >= 0);
}

bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y) {
Expand Down
11 changes: 6 additions & 5 deletions core/src/tangram.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ void setTilt(float _radians, float _duration, EaseType _e = EaseType::quint);
// Get the tilt angle of the view in radians; 0 corresponds to straight down
float getTilt();

// Given coordinates in screen space (x right, y down), set the output longitude
// and latitude to the geographic location corresponding to that point
void screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat);
// Given coordinates in screen space (x right, y down), set the output longitude and
// latitude to the geographic location corresponding to that point; returns false if
// no geographic position corresponds to the screen location, otherwise returns true
bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat);

// Given longitude and latitude coordinates, set the output coordinates to the
// corresponding point in screen space (x right, y down); returns true if the
// point is visible on the screen, otherwise returns false
// corresponding point in screen space (x right, y down); returns false if the
// point is not visible on the screen, otherwise returns true
bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y);

// Set the ratio of hardware pixels to logical pixels (defaults to 1.0)
Expand Down

0 comments on commit 89a2991

Please sign in to comment.