wip
This commit is contained in:
101
PBMap.pb
101
PBMap.pb
@@ -29,7 +29,7 @@ DeclareModule PBMap
|
|||||||
#Red = 255
|
#Red = 255
|
||||||
;-Show debug infos
|
;-Show debug infos
|
||||||
Global Verbose = 0
|
Global Verbose = 0
|
||||||
Global MyDebugLevel = 3
|
Global MyDebugLevel = 5
|
||||||
;-Proxy ON/OFF
|
;-Proxy ON/OFF
|
||||||
Global Proxy = #False
|
Global Proxy = #False
|
||||||
|
|
||||||
@@ -393,8 +393,8 @@ Module PBMap
|
|||||||
Protected LatRad.d = Radian(*Location\Latitude)
|
Protected LatRad.d = Radian(*Location\Latitude)
|
||||||
*Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0)
|
*Coords\x = n * ( (*Location\Longitude + 180.0) / 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))
|
MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude), 5)
|
||||||
MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y))
|
MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y), 5)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;*** Converts tile.decimal to coords
|
;*** Converts tile.decimal to coords
|
||||||
@@ -407,10 +407,19 @@ Module PBMap
|
|||||||
*Location\Longitude + 360
|
*Location\Longitude + 360
|
||||||
EndIf
|
EndIf
|
||||||
*Location\Longitude - 180.0
|
*Location\Longitude - 180.0
|
||||||
|
|
||||||
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)
|
||||||
|
;Return the position of the coordinates relatively to the canvas center
|
||||||
|
Protected Pos.Position
|
||||||
|
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
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
; HaversineAlgorithm
|
; HaversineAlgorithm
|
||||||
; http://andrew.hedges.name/experiments/haversine/
|
; http://andrew.hedges.name/experiments/haversine/
|
||||||
Procedure.d HaversineInKM(*posA.Location, *posB.Location)
|
Procedure.d HaversineInKM(*posA.Location, *posB.Location)
|
||||||
@@ -429,27 +438,33 @@ Module PBMap
|
|||||||
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize
|
; Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize
|
||||||
Protected mapWidth.l = Pow(2, PBMap\Zoom + 8)
|
; Protected mapWidth.l = Pow(2, PBMap\Zoom + 8)
|
||||||
Protected mapHeight.l = Pow(2, PBMap\Zoom + 8)
|
; Protected mapHeight.l = Pow(2, PBMap\Zoom + 8)
|
||||||
Protected x1.l,y1.l
|
; Protected x1.l,y1.l
|
||||||
; get x value
|
; ; get x value
|
||||||
x1 = (*Location\Longitude+180)*(mapWidth/360)
|
; x1 = (*Location\Longitude+180)*(mapWidth/360)
|
||||||
; convert from degrees To radians
|
; ; convert from degrees To radians
|
||||||
Protected latRad.d = *Location\Latitude*#PI/180;
|
; Protected latRad.d = *Location\Latitude*#PI/180;
|
||||||
Protected mercN.d = Log(Tan((#PI/4)+(latRad/2)));
|
; Protected mercN.d = Log(Tan((#PI/4)+(latRad/2)));
|
||||||
y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
; y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
||||||
Protected x2.l, y2.l
|
; ; Debug "location"
|
||||||
; get x value
|
; ; Debug x1
|
||||||
x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360)
|
; ; Debug y1
|
||||||
; convert from degrees To radians
|
; Protected x2.l, y2.l
|
||||||
latRad = PBMap\TargetLocation\Latitude*#PI/180;
|
; ; get x value
|
||||||
; get y value
|
; x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360)
|
||||||
mercN = Log(Tan((#PI/4)+(latRad/2)))
|
; ; convert from degrees To radians
|
||||||
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
; latRad = PBMap\TargetLocation\Latitude*#PI/180;
|
||||||
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
; ; get y value
|
||||||
*Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
; mercN = Log(Tan((#PI/4)+(latRad/2)))
|
||||||
EndProcedure
|
; y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
||||||
|
; ; Debug "targetlocation"
|
||||||
|
; ; Debug x1
|
||||||
|
; ; Debug y1
|
||||||
|
; *Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
||||||
|
; *Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
||||||
|
; EndProcedure
|
||||||
|
|
||||||
Procedure LoadGpxFile(file.s)
|
Procedure LoadGpxFile(file.s)
|
||||||
If LoadXML(0, file.s)
|
If LoadXML(0, file.s)
|
||||||
@@ -743,7 +758,7 @@ Module PBMap
|
|||||||
|
|
||||||
VectorFont(FontID(PBMap\Font), 10)
|
VectorFont(FontID(PBMap\Font), 10)
|
||||||
VectorSourceColor(RGBA(0, 0, 0,alpha))
|
VectorSourceColor(RGBA(0, 0, 0,alpha))
|
||||||
|
|
||||||
XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
|
XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
|
||||||
XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
|
XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
|
||||||
|
|
||||||
@@ -752,15 +767,14 @@ 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
|
||||||
|
|
||||||
Debug nx
|
LatLon2Pixel(@Degrees2, @pos2)
|
||||||
Debug nx1
|
|
||||||
GetPixelCoordFromLocation(@Degrees2, @pos2)
|
|
||||||
|
|
||||||
x = nx
|
x = nx
|
||||||
For y = ny1 To ny
|
For y = ny1 To ny
|
||||||
Degrees1\Longitude = x
|
Degrees1\Longitude = x
|
||||||
Degrees1\Latitude = y
|
Degrees1\Latitude = y
|
||||||
GetPixelCoordFromLocation(@Degrees1, @pos1)
|
LatLon2Pixel(@Degrees1, @pos1)
|
||||||
MovePathCursor(pos1\x, pos1\y)
|
MovePathCursor(pos1\x, pos1\y)
|
||||||
AddPathLine( pos2\x, pos1\y)
|
AddPathLine( pos2\x, pos1\y)
|
||||||
MovePathCursor(10,pos1\y)
|
MovePathCursor(10,pos1\y)
|
||||||
@@ -769,14 +783,14 @@ Module PBMap
|
|||||||
|
|
||||||
y = ny
|
y = ny
|
||||||
For x = nx To nx1
|
For x = nx To nx1
|
||||||
Degrees1\Longitude = x
|
Degrees1\Longitude = x
|
||||||
Degrees1\Latitude = y
|
Degrees1\Latitude = y
|
||||||
GetPixelCoordFromLocation(@Degrees1, @pos1)
|
LatLon2Pixel(@Degrees1, @pos1)
|
||||||
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(StrD(x, 1))
|
||||||
Next
|
Next
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -808,7 +822,8 @@ Module PBMap
|
|||||||
;Trace Track
|
;Trace Track
|
||||||
ForEach PBMap\track()
|
ForEach PBMap\track()
|
||||||
If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0
|
If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0
|
||||||
GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
;GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
||||||
|
LatLon2Pixel(@PBMap\track(),@Pixel)
|
||||||
If ListIndex(PBMap\track())=0
|
If ListIndex(PBMap\track())=0
|
||||||
MovePathCursor(Pixel\X, Pixel\Y)
|
MovePathCursor(Pixel\X, Pixel\Y)
|
||||||
Else
|
Else
|
||||||
@@ -829,7 +844,8 @@ Module PBMap
|
|||||||
Location\Latitude=PBMap\track()\Latitude
|
Location\Latitude=PBMap\track()\Latitude
|
||||||
Location\Longitude=PBMap\track()\Longitude
|
Location\Longitude=PBMap\track()\Longitude
|
||||||
EndIf
|
EndIf
|
||||||
GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
;GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
||||||
|
LatLon2Pixel(@PBMap\track(),@Pixel)
|
||||||
If Int(km)<>memKm
|
If Int(km)<>memKm
|
||||||
memKm=Int(km)
|
memKm=Int(km)
|
||||||
If PBMap\Zoom>10
|
If PBMap\Zoom>10
|
||||||
@@ -871,7 +887,8 @@ Module PBMap
|
|||||||
Protected Pixel.PixelPosition
|
Protected Pixel.PixelPosition
|
||||||
ForEach PBMap\Marker()
|
ForEach PBMap\Marker()
|
||||||
If PBMap\Marker()\Location\Latitude <> 0 And PBMap\Marker()\Location\Longitude <> 0
|
If PBMap\Marker()\Location\Latitude <> 0 And PBMap\Marker()\Location\Longitude <> 0
|
||||||
GetPixelCoordFromLocation(PBMap\Marker()\Location, @Pixel)
|
;GetPixelCoordFromLocation(PBMap\Marker()\Location, @Pixel)
|
||||||
|
LatLon2Pixel(PBMap\Marker()\Location, @Pixel)
|
||||||
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^
|
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^
|
||||||
If PBMap\Marker()\CallBackPointer > 0
|
If PBMap\Marker()\CallBackPointer > 0
|
||||||
CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
||||||
@@ -1338,8 +1355,8 @@ CompilerEndIf
|
|||||||
|
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 755
|
; CursorPosition = 892
|
||||||
; FirstLine = 732
|
; FirstLine = 873
|
||||||
; Folding = ----------
|
; Folding = ----------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user