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

The special characters cause it to fail in Chrome. #80

Closed
trusktr opened this issue Apr 7, 2020 · 2 comments
Closed

The special characters cause it to fail in Chrome. #80

trusktr opened this issue Apr 7, 2020 · 2 comments

Comments

@trusktr
Copy link

trusktr commented Apr 7, 2020

I'm unable to run the code, because if I run something like

var φ = 123

Google Chrome (actually Electron) says:

Uncaught SyntaxError: Invalid or unexpected token

It seems the characters φ are breaking it.

Would you mind using regular characters?

@trusktr
Copy link
Author

trusktr commented Apr 7, 2020

Oh, wait a second! The φ characters aren't in the source. It appears that the build tool (Webpack or TypeScript) is converting the characters erroneously.

This is the transformed code that I see in devtools:

        // x = (ν+h)⋅cosφ⋅cosλ, y = (ν+h)⋅cosφ⋅sinλ, z = (ν⋅(1-e²)+h)⋅sinφ
        // where ν = a/√(1−e²⋅sinφ⋅sinφ), e² = (a²-b²)/a² or (better conditioned) 2⋅f-f²
        const ellipsoid = this.datum
            ? this.datum.ellipsoid
            : this.referenceFrame ? this.referenceFrame.ellipsoid : ellipsoids.WGS84;

        const φ = this.lat.toRadians();
        const λ = this.lon.toRadians();
        const h = this.height;
        const { a, f } = ellipsoid;

        const sinφ = Math.sin(φ), cosφ = Math.cos(φ);
        const sinλ = Math.sin(λ), cosλ = Math.cos(λ);

        const eSq = 2*f - f*f;                      // 1st eccentricity squared ≡ (a²-b²)/a²
        const ν = a / Math.sqrt(1 - eSq*sinφ*sinφ); // radius of curvature in prime vertical

        const x = (ν+h) * cosφ * cosλ;
        const y = (ν+h) * cosφ * sinλ;
        const z = (ν*(1-eSq)+h) * sinφ;

        return new Cartesian(x, y, z);

@trusktr trusktr closed this as completed Apr 7, 2020
@trusktr
Copy link
Author

trusktr commented Apr 7, 2020

Aha! I was able to solve the problem by specifying the charset on my script tag:

<script src="./entry.js" charset="utf-8"></script>

I didn't need this before, but now that the characters are present, that made it work.

EDIT: a better way, for the whole HTML file:

<html>
  <head>
    <meta charset="utf8" />
  </head>
  <body>
    <script src="./entry.js"></script>
  </body>
</html>

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

1 participant