This commit is contained in:
djes
2016-09-01 15:24:35 +02:00
parent d7f7a2442b
commit 37197745c5

View File

@@ -391,7 +391,7 @@ Module PBMap
Procedure LatLon2XY(*Location.Location, *Coords.Position) Procedure LatLon2XY(*Location.Location, *Coords.Position)
Protected n.d = Pow(2.0, PBMap\Zoom) Protected n.d = Pow(2.0, PBMap\Zoom)
Protected LatRad.d = Radian(*Location\Latitude) Protected LatRad.d = Radian(*Location\Latitude)
*Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0) *Coords\x = n * (Mod( *Location\Longitude + 180.0, 360) / 360.0 )
*Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 *Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude), 5) MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude), 5)
MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y), 5) MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y), 5)
@@ -406,17 +406,32 @@ Module PBMap
If *Location\Longitude < 0 If *Location\Longitude < 0
*Location\Longitude + 360 *Location\Longitude + 360
EndIf EndIf
*Location\Longitude - 180.0 *Location\Longitude = Mod(*Location\Longitude, 360.0) - 180
LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n))) LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n)))
*Location\Latitude = Degree(LatitudeRad) *Location\Latitude = Degree(LatitudeRad)
EndProcedure EndProcedure
Procedure LatLon2Pixel(*Location.Location, *Pixel.PixelPosition) Procedure LatLon2Pixel(*Location.Location, *Pixel.PixelPosition)
;Return the position of the coordinates relatively to the canvas center
Protected Pos.Position Protected Pos.Position
LatLon2XY(*Location, @Pos) LatLon2XY(*Location, @Pos)
Debug "Longitude : " + StrD(*Location\Longitude) + " ; Pos : " + StrD(Pos\x) + " ; Drawing pos : " + StrD(PBMap\Drawing\Position\x) + "/" + Str(Pow(2.0, PBMap\Zoom))
*Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x) * PBMap\TileSize *Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x) * PBMap\TileSize
*Pixel\y = PBMap\Drawing\CenterY + (Pos\y - PBMap\Drawing\Position\y) * PBMap\TileSize *Pixel\y = PBMap\Drawing\CenterY + (Pos\y - PBMap\Drawing\Position\y) * PBMap\TileSize
; Protected Pos.Position
; Protected Center.Location, Pnt.Location
; ;Return the position of the coordinates relatively to the canvas center
; If Abs(PBMap\Drawing\TargetLocation\Longitude - *Location\Longitude) > 180 And Sign(PBMap\Drawing\TargetLocation\Longitude) <> Sign(*Location\Longitude)
; Pnt\Longitude = PBMap\Drawing\TargetLocation\Longitude - (360 - (PBMap\Drawing\TargetLocation\Longitude - *Location\Longitude))
; Pnt\Latitude = *Location\Latitude
; LatLon2XY(@Pnt, @Pos)
; *Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x) * PBMap\TileSize
; *Pixel\y = PBMap\Drawing\CenterY + (Pos\y - PBMap\Drawing\Position\y) * PBMap\TileSize
; Else
; LatLon2XY(*Location, @Pos)
; *Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x) * PBMap\TileSize
; *Pixel\y = PBMap\Drawing\CenterY + (Pos\y - PBMap\Drawing\Position\y) * PBMap\TileSize
; EndIf
EndProcedure EndProcedure
; HaversineAlgorithm ; HaversineAlgorithm
@@ -744,6 +759,7 @@ Module PBMap
Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192) Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192)
Protected tx, ty, nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d Protected tx, ty, nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d
Protected pos1.PixelPosition,pos2.PixelPosition,Degrees1.Location,degrees2.Location Protected pos1.PixelPosition,pos2.PixelPosition,Degrees1.Location,degrees2.Location
Protected realx
tx = Int(*Drawing\Position\x) tx = Int(*Drawing\Position\x)
ty = Int(*Drawing\Position\y) ty = Int(*Drawing\Position\y)
@@ -769,40 +785,42 @@ Module PBMap
nx1 = Round(Degrees2\Longitude, #PB_Round_Up) +1 nx1 = Round(Degrees2\Longitude, #PB_Round_Up) +1
ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1 ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1
;ensure we stay positive for the drawing
realx = nx
If nx < 0
nx + 360
EndIf
If nx1 < 0
nx1 + 360
EndIf
nx % 360
nx1 % 360
Debug "---"
Debug nx
Debug nx1
Debug ny1
Debug ny
Degrees1\Longitude = nx Degrees1\Longitude = nx
Degrees1\Latitude = ny Degrees1\Latitude = ny
Degrees2\Longitude = nx1 Degrees2\Longitude = nx1
Degrees2\Latitude = ny1 Degrees2\Latitude = ny1
; Debug "lon lat center"
; Debug *Drawing\TargetLocation\Longitude
; Debug *Drawing\TargetLocation\Latitude
; Debug "lon lat 1"
; Debug Degrees1\Longitude
; Debug Degrees1\Latitude
; Debug "lon lat 2"
; Debug Degrees2\Longitude
; Debug Degrees2\Latitude
LatLon2Pixel(@Degrees1, @pos1) LatLon2Pixel(@Degrees1, @pos1)
; Debug "pos1"
; Debug pos1\x
; Debug pos1\y
LatLon2Pixel(@Degrees2, @pos2) LatLon2Pixel(@Degrees2, @pos2)
; Debug "pos2"
; Debug pos2\x Debug "---"
; Debug pos2\y Debug pos1\x
Debug pos1\y
Debug pos2\x
Debug pos2\y
VectorFont(FontID(PBMap\Font), 10) VectorFont(FontID(PBMap\Font), 10)
VectorSourceColor(RGBA(0, 0, 0,alpha)) VectorSourceColor(RGBA(0, 0, 0,alpha))
x = nx ;draw latitudes
If ny < ny1
Swap ny, ny1
x = nx1
EndIf
For y = ny1 To ny For y = ny1 To ny
Degrees1\Longitude = x Degrees1\Longitude = x
Degrees1\Latitude = y Degrees1\Latitude = y
@@ -812,12 +830,8 @@ Module PBMap
MovePathCursor(10, pos1\y) MovePathCursor(10, pos1\y)
DrawVectorText(StrD(y, 1)) DrawVectorText(StrD(y, 1))
Next Next
y = ny ;draw longitudes
If nx > nx1
Swap nx, nx1
y = ny1
EndIf
For x = nx To nx1 For x = nx To nx1
Degrees1\Longitude = x Degrees1\Longitude = x
Degrees1\Latitude = y Degrees1\Latitude = y
@@ -825,7 +839,7 @@ Module PBMap
MovePathCursor(pos1\x, pos1\y) MovePathCursor(pos1\x, pos1\y)
AddPathLine( pos1\x, pos2\y) AddPathLine( pos1\x, pos2\y)
MovePathCursor(pos1\x,10) MovePathCursor(pos1\x,10)
DrawVectorText(StrD(x, 1)) DrawVectorText(Str(x))
Next Next
StrokePath(1) StrokePath(1)
@@ -1105,10 +1119,8 @@ Module PBMap
;Centered Zoom ;Centered Zoom
LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing) LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing)
;Convert X, Y in tile.decimal into real pixels ;Convert X, Y in tile.decimal into real pixels
PBMap\Position\x = PBMap\Drawing\Position\x * PBMap\TileSize MouseX = PBMap\Drawing\Position\x * PBMap\TileSize + GadgetWidth(PBMap\Gadget) / 2 - x
PBMap\Position\y = PBMap\Drawing\Position\y * PBMap\TileSize MouseY = PBMap\Drawing\Position\y * PBMap\TileSize + GadgetHeight(PBMap\Gadget) / 2 - y
MouseX = PBMap\Position\x + GadgetWidth(PBMap\Gadget) / 2 - x
MouseY = PBMap\Position\y + GadgetHeight(PBMap\Gadget) / 2 - y
;Cross-multiply to get the new center ;Cross-multiply to get the new center
PBMap\Position\x = (OldPx * MouseX) / OldMx PBMap\Position\x = (OldPx * MouseX) / OldMx
PBMap\Position\y = (OldPy * MouseY) / OldMy PBMap\Position\y = (OldPy * MouseY) / OldMy
@@ -1396,8 +1408,8 @@ CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 416 ; CursorPosition = 1020
; FirstLine = 401 ; FirstLine = 999
; Folding = ---------- ; Folding = ----------
; EnableThread ; EnableThread
; EnableXP ; EnableXP