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.

esps3857.fromEPSG4326() is returning NaN for Y when Math.tan() returns negative value

See original GitHub issue

In the output file for proj.js I noticed that the function only converts the longitude.

_ol_proj_.toLonLat = function(coordinate, opt_projection) {
  var lonLat = _ol_proj_.transform(coordinate, opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
  var lon = lonLat[0];
  if (lon < -180 || lon > 180) {
    lonLat[0] = _ol_math_.modulo(lon + 180, 360) - 180;
  }
  return lonLat;
};

I am not 100% sure why the latitude is being untouched

I was able to finish this function by added a few lines.

_ol_proj_.toLonLat = function(coordinate, opt_projection) {
  var lonLat = _ol_proj_.transform(coordinate, opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
  var lon = lonLat[0];
  var lat = lonLat[1];
  if (lon < -180 || lon > 180) {
    lonLat[0] = _ol_math_.modulo(lon + 180, 360) - 180;
  }
  if (lat < -90 || lat > 90) {
    lonLat[1] = _ol_math_.modulo(lat + 90, 360) - 90;
  }
  return lonLat;
};

Things were working properly after that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ahocevarcommented, Feb 25, 2019

Latitudes are expected to be in the range of -85.06 to 85.06. You are probably passing projected coordinates instead of longitudes and latitudes to ol/proj/fromLonLat or epst3857/fromEPSG4326.

2reactions
ahocevarcommented, Feb 21, 2019

This is expected for coordinates outside the projection’s validity extent. For EPSG:3857, this is latitude -85.06 to 85.06 (see https://epsg.io/3857).

The change you suggested above would not change the latitude if it was NaN already.

Have you checked the input values you pass as xy to toLonLat()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Math.tan() - JavaScript - MDN Web Docs
The Math.tan() function returns the tangent of a number in radians.
Read more >
Java is outputting the wrong value for a Math.tan() calculation
The argument of Math.tan() has to be in radians. Unless there is a compelling reason not to do so, I'd use radians for...
Read more >
What is Math.tan() in Scala? - Educative.io
Return value. tan() returns the tangent of a number in radians that is sent as a parameter. If the parameter value is NaN...
Read more >
Java Math tan() method with Examples - GeeksforGeeks
Math.tan() returns the trigonometric tangent of an angle. If the argument is NaN or an infinity, then the result returned is NaN.
Read more >
Math.Tan(Double) Method (System) - Microsoft Learn
Returns the tangent of the specified angle. ... Tan() using System; class Sample { public static void Main() { double x = 1.0;...
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