Giter Site home page Giter Site logo

Comments (2)

neveldo avatar neveldo commented on June 12, 2024

Hi, I think this is because the tutorial is for the maps using equi-rectangular projection only, it can be applied for other projections. For the mercator, you will have to define the proper algorithm to convert the coordinates.

Feel free to take a look at this pull-request that includes a map with a mercator projection to see how the getCoords() function is built : #169

from jquery-mapael.

alfalf99 avatar alfalf99 commented on June 12, 2024

Thank you.

I have tried to translate the mercator getcoords function (from the link provided) in VBA.
Coordinates of my south america submap are hardcoded in the VBA script.

But when I test RIO DE JANEIRO, lat, long = (-43.23, -22.9)
I have the result :
x= -0,753617936081045
y = -0,689338045886754
which is wrong, but perhaps I have missed something :(
If it returns x, y I would expect values that are based on dim of my map: width = 510 and height : 792,25.
so something like that : x= 400 and y = 600

Below the VBA code :
`Option Explicit

'// Width of the map, in pixel
Public Const WWwidth As Double = 1008.77
'// Height of the map, in pixel
Public Const WWheight As Double = 651.44
'// Longitude of the left side of the map, in degree
'leftLongitude: -169.6,
'// Longitude of the right side of the map, in degree
'rightLongitude: 190.25,
'// Latitude of the top of the map, in degree
'topLatitude: 83.68,
'// Latitude of the bottom of the map, in degree
'bottomLatitude: -55.55,

Public Sub teste()

Call getCoords(-43.23, -22.9) 'RIO DE JANEIRO lat, lon

End Sub

'*
' * Get x,y point from lat,lon coordinate
' *
' * Principle:
' * (lat, lon) are inputs
' * Projection(lat, lon) = (x', y')
' * Transformation(x', y') = (x, y)
' *
' * Source: http://jkwiens.com/2009/01/23/miller-projection/
' *
' * @param lat latitude value in degree
' * @param lon longitude value in degree
' * @return {x, y} coordinate in pixel
' *
Sub getCoords(lat As Double, lon As Double)

Dim xLeftPrime As Double, xRightPrime As Double, yTopPrime As Double, yBottomPrime As Double
Dim leftLongitude As Double, rightLongitude As Double, topLatitude As Double, bottomLatitude As Double

Dim xPrime As Double, yPrime As Double
Dim x As Double, y As Double

'---------------INPUT  MAP INFO MANUALLY
xLeftPrime = 0
bottomLatitude = -86.66

xRightPrime = 510.9827 '-- sub map width
rightLongitude = -32.16

yTopPrime = 0
topLatitude = 13.5

yBottomPrime = 792.25 '-- sub map height
bottomLatitude = -58
'----------------------------------------


'Project map boundaries with projection (only once for performance)
'If (xLeftPrime Is Empty) Then xLeftPrime = projectLongitude(leftLongitude)
'If (xRightPrime Is Empty) Then xRightPrime = projectLongitude(rightLongitude)
'If (yTopPrime Is Empty) Then yTopPrime = projectLatitude(topLatitude)
'If (yBottomPrime Is Empty) Then yBottomPrime = projectLatitude(bottomLatitude)

'Compute x' and y' (projection-specific value)
xPrime = projectLongitude(lon)
yPrime = projectLatitude(lat)

'Compute x and y
x = (xPrime - xLeftPrime) * (WWwidth / (xRightPrime - xLeftPrime))
y = (yTopPrime - yPrime) * (WWheight / (yTopPrime - yBottomPrime))

Debug.Print x
Debug.Print y
'return {x: x, y: y}

End Sub

' * Transform a longitude coordinate into projection-specific x' coordinate
' * Note: this is not in pixel
' *
' * @param lon longitude value in degree
' * @return x' projection-specific value
' *
Public Function projectLongitude(lon As Double)

'Compute longitude in radian
projectLongitude = lon * Excel.WorksheetFunction.Pi / 180
End Function

'*
' * Transform a latitude coordinate into projection-specific y' coordinate
' * Note: this is not in pixel
' *
' * @param lat latitude value in degree
' * @return y' projection-specific value
' *
Public Function projectLatitude(lat As Double)
'Compute latitude in radian and get its SINUS
Dim latRadSinus As Double
latRadSinus = Math.Sin(lat * Excel.WorksheetFunction.Pi / 180)
projectLatitude = 0.5 * Math.Log((1 + latRadSinus) / (1 - latRadSinus))
End Function
`

from jquery-mapael.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.