degrees bugfix
This commit is contained in:
93
PBMap.pb
93
PBMap.pb
@@ -402,11 +402,14 @@ Module PBMap
|
|||||||
Procedure XY2LatLon(*Coords.Position, *Location.Location)
|
Procedure XY2LatLon(*Coords.Position, *Location.Location)
|
||||||
Protected n.d = Pow(2.0, PBMap\Zoom)
|
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||||
Protected LatitudeRad.d
|
Protected LatitudeRad.d
|
||||||
*Location\Longitude = Mod(*Coords\x / n * 360.0, 360.0)
|
;Ensures the longitude to be in the range [-180;180[
|
||||||
If *Location\Longitude < 0
|
*Location\Longitude = Mod(Mod(*Coords\x / n * 360.0, 360.0) + 360.0, 360.0)
|
||||||
*Location\Longitude + 360
|
*Location\Longitude - 180
|
||||||
EndIf
|
; *Location\Longitude = Mod(*Coords\x / n * 360.0, 360.0)
|
||||||
*Location\Longitude = Mod(*Location\Longitude, 360.0) - 180
|
; If *Location\Longitude < 0
|
||||||
|
; *Location\Longitude + 360
|
||||||
|
; EndIf
|
||||||
|
; *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
|
||||||
@@ -414,18 +417,29 @@ Module PBMap
|
|||||||
Procedure LatLon2Pixel(*Location.Location, *Pixel.PixelPosition)
|
Procedure LatLon2Pixel(*Location.Location, *Pixel.PixelPosition)
|
||||||
Protected Pos.Position
|
Protected Pos.Position
|
||||||
Protected tilemax = Pow(2.0, PBMap\Zoom)
|
Protected tilemax = Pow(2.0, PBMap\Zoom)
|
||||||
|
Protected cx.d = PBMap\Drawing\CenterX, dpx.d = PBMap\Drawing\Position\x
|
||||||
LatLon2XY(*Location, @Pos)
|
LatLon2XY(*Location, @Pos)
|
||||||
;check the x boundaries of the map to adjust the position
|
Protected px.d = Pos\x
|
||||||
If PBMap\Drawing\Position\x - Pos\x > tilemax / 2
|
;check the x boundaries of the map to adjust the position (coz of the longitude wrapping)
|
||||||
*Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x + tilemax) * PBMap\TileSize
|
If dpx - px > tilemax / 2
|
||||||
ElseIf Pos\x - PBMap\Drawing\Position\x > tilemax / 2
|
;Debug "c1"
|
||||||
*Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x - tilemax) * PBMap\TileSize
|
*Pixel\x = cx + (px - dpx + tilemax) * PBMap\TileSize
|
||||||
|
ElseIf px - dpx > tilemax / 2
|
||||||
|
;Debug "c2"
|
||||||
|
*Pixel\x = cx + (px - dpx - tilemax) * PBMap\TileSize
|
||||||
|
ElseIf dpx - px < 0
|
||||||
|
;Debug "c3"
|
||||||
|
*Pixel\x = cx + (px - dpx) * PBMap\TileSize
|
||||||
|
ElseIf px - dpx < 0
|
||||||
|
;Debug "c4"
|
||||||
|
*Pixel\x = cx - (dpx - px) * PBMap\TileSize
|
||||||
Else
|
Else
|
||||||
*Pixel\x = PBMap\Drawing\CenterX + (Pos\x - PBMap\Drawing\Position\x) * PBMap\TileSize
|
;Debug "c0"
|
||||||
|
*Pixel\x = cx + (px - dpx) * PBMap\TileSize
|
||||||
EndIf
|
EndIf
|
||||||
*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
|
||||||
; Debug "Longitude : " + StrD(*Location\Longitude) + " ; Pos : " + StrD(Pos\x) + " ; Drawing pos : " + StrD(PBMap\Drawing\Position\x) + "/" + Str(tilemax) +
|
;Debug "Longitude : " + StrD(*Location\Longitude) + " ; Pos : " + StrD(Pos\x) + " ; Drawing pos : " + StrD(PBMap\Drawing\Position\x) + "/" + Str(tilemax) +
|
||||||
; " ; XY : " + Str(*Pixel\x) + "," + Str(*Pixel\y)
|
; " ; XY : " + Str(*Pixel\x) + "," + Str(*Pixel\y)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; HaversineAlgorithm
|
; HaversineAlgorithm
|
||||||
@@ -762,30 +776,32 @@ Module PBMap
|
|||||||
*Drawing\Bounds\NorthWest\y = ty-ny-1
|
*Drawing\Bounds\NorthWest\y = ty-ny-1
|
||||||
*Drawing\Bounds\SouthEast\x = tx+nx+1
|
*Drawing\Bounds\SouthEast\x = tx+nx+1
|
||||||
*Drawing\Bounds\SouthEast\y = ty+ny+1
|
*Drawing\Bounds\SouthEast\y = ty+ny+1
|
||||||
|
; Debug "------------------"
|
||||||
XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
|
XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
|
||||||
XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
|
XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
|
||||||
nx = Round(Degrees1\Longitude, #PB_Round_Down)-1
|
|
||||||
ny = Round(Degrees1\Latitude, #PB_Round_Up) +1
|
|
||||||
nx1 = Round(Degrees2\Longitude, #PB_Round_Up) +1
|
|
||||||
ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1
|
|
||||||
;ensure we stay positive for the drawing
|
;ensure we stay positive for the drawing
|
||||||
|
nx = Mod(Mod(Round(Degrees1\Longitude, #PB_Round_Down)-1, 360) + 360, 360)
|
||||||
|
ny = Round(Degrees1\Latitude, #PB_Round_Up) +1
|
||||||
|
nx1 = Mod(Mod(Round(Degrees2\Longitude, #PB_Round_Up) +1, 360) + 360, 360)
|
||||||
|
ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1
|
||||||
realx = nx
|
realx = nx
|
||||||
If nx < 0
|
; If nx < 0
|
||||||
nx + 360
|
; nx + 360
|
||||||
EndIf
|
; EndIf
|
||||||
If nx1 < 0
|
; If nx1 < 0
|
||||||
nx1 + 360
|
; nx1 + 360
|
||||||
EndIf
|
; EndIf
|
||||||
nx % 360
|
; nx % 360
|
||||||
nx1 % 360
|
; nx1 % 360
|
||||||
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 "NW : " + StrD(Degrees1\Longitude) + " ; NE : " + StrD(Degrees2\Longitude)
|
||||||
LatLon2Pixel(@Degrees1, @pos1)
|
LatLon2Pixel(@Degrees1, @pos1)
|
||||||
LatLon2Pixel(@Degrees2, @pos2)
|
LatLon2Pixel(@Degrees2, @pos2)
|
||||||
VectorFont(FontID(PBMap\Font), 10)
|
VectorFont(FontID(PBMap\Font), 10)
|
||||||
VectorSourceColor(RGBA(0, 0, 0,alpha))
|
VectorSourceColor(RGBA(0, 0, 0, alpha))
|
||||||
;draw latitudes
|
;draw latitudes
|
||||||
For y = ny1 To ny
|
For y = ny1 To ny
|
||||||
Degrees1\Longitude = nx
|
Degrees1\Longitude = nx
|
||||||
@@ -797,7 +813,8 @@ Module PBMap
|
|||||||
DrawVectorText(StrD(y, 1))
|
DrawVectorText(StrD(y, 1))
|
||||||
Next
|
Next
|
||||||
;draw longitudes
|
;draw longitudes
|
||||||
For x = nx To nx1
|
x = nx
|
||||||
|
Repeat
|
||||||
Degrees1\Longitude = x
|
Degrees1\Longitude = x
|
||||||
Degrees1\Latitude = ny
|
Degrees1\Latitude = ny
|
||||||
LatLon2Pixel(@Degrees1, @pos1)
|
LatLon2Pixel(@Degrees1, @pos1)
|
||||||
@@ -809,7 +826,8 @@ Module PBMap
|
|||||||
If realx > 180
|
If realx > 180
|
||||||
realx - 360
|
realx - 360
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
x = (x + 1)%360
|
||||||
|
Until x = nx1
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -894,7 +912,7 @@ Module PBMap
|
|||||||
Procedure AddMarker(Latitude.d, Longitude.d, color.l=-1, CallBackPointer.i = -1)
|
Procedure AddMarker(Latitude.d, Longitude.d, color.l=-1, CallBackPointer.i = -1)
|
||||||
AddElement(PBMap\Marker())
|
AddElement(PBMap\Marker())
|
||||||
PBMap\Marker()\Location\Latitude = Latitude
|
PBMap\Marker()\Location\Latitude = Latitude
|
||||||
PBMap\Marker()\Location\Longitude = Mod(Longitude + 360, 360)
|
PBMap\Marker()\Location\Longitude = Mod(Mod(Longitude, 360) + 360, 360)
|
||||||
PBMap\Marker()\color = color
|
PBMap\Marker()\color = color
|
||||||
PBMap\Marker()\CallBackPointer = CallBackPointer
|
PBMap\Marker()\CallBackPointer = CallBackPointer
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
@@ -1088,6 +1106,7 @@ Module PBMap
|
|||||||
;Convert X, Y in tile.decimal into real pixels
|
;Convert X, Y in tile.decimal into real pixels
|
||||||
MouseX = PBMap\Drawing\Position\x * PBMap\TileSize + GadgetWidth(PBMap\Gadget) / 2 - x
|
MouseX = PBMap\Drawing\Position\x * PBMap\TileSize + GadgetWidth(PBMap\Gadget) / 2 - x
|
||||||
MouseY = PBMap\Drawing\Position\y * PBMap\TileSize + GadgetHeight(PBMap\Gadget) / 2 - y
|
MouseY = PBMap\Drawing\Position\y * PBMap\TileSize + GadgetHeight(PBMap\Gadget) / 2 - y
|
||||||
|
Debug PBMap\Position\x
|
||||||
;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
|
||||||
@@ -1123,7 +1142,7 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure CanvasEvents()
|
Procedure CanvasEvents()
|
||||||
Protected MouseX.i, MouseY.i
|
Protected MouseX.i, MouseY.i
|
||||||
Protected Marker.Position, *Tile.Tile
|
Protected Marker.Position, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize
|
||||||
PBMap\Moving = #False
|
PBMap\Moving = #False
|
||||||
Select EventType()
|
Select EventType()
|
||||||
Case #PB_EventType_MouseWheel
|
Case #PB_EventType_MouseWheel
|
||||||
@@ -1139,12 +1158,7 @@ Module PBMap
|
|||||||
MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||||
MouseY = PBMap\Position\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
MouseY = PBMap\Position\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||||
;Clip MouseX to the map range (in X, the map is infinite)
|
;Clip MouseX to the map range (in X, the map is infinite)
|
||||||
If MouseX < 0
|
MouseX = Mod(Mod(MouseX, MapWidth) + MapWidth, MapWidth)
|
||||||
MouseX + Pow(2, PBMap\Zoom) * PBMap\TileSize
|
|
||||||
EndIf
|
|
||||||
MouseX = Mod(MouseX, Pow(2, PBMap\Zoom) * PBMap\TileSize)
|
|
||||||
; Debug "---"
|
|
||||||
; Debug "mx : " + Str(MouseX)
|
|
||||||
ForEach PBMap\Marker()
|
ForEach PBMap\Marker()
|
||||||
LatLon2XY(@PBMap\Marker()\Location, @Marker)
|
LatLon2XY(@PBMap\Marker()\Location, @Marker)
|
||||||
Marker\x * PBMap\TileSize
|
Marker\x * PBMap\TileSize
|
||||||
@@ -1173,7 +1187,7 @@ Module PBMap
|
|||||||
Else
|
Else
|
||||||
;New move values
|
;New move values
|
||||||
;PBMap\Position\x - MouseX
|
;PBMap\Position\x - MouseX
|
||||||
;Ensures that pixel position stay in the range [0..2^Zoom*PBMap\TileSize[
|
;Ensures that pixel position stay in the range [0..2^Zoom*PBMap\TileSize[ coz of the wrapping of the map
|
||||||
PBMap\Position\x = PBMap\Position\x - MouseX
|
PBMap\Position\x = PBMap\Position\x - MouseX
|
||||||
If PBMap\Position\x < 0
|
If PBMap\Position\x < 0
|
||||||
PBMap\Position\x + Pow(2, PBMap\Zoom) * PBMap\TileSize
|
PBMap\Position\x + Pow(2, PBMap\Zoom) * PBMap\TileSize
|
||||||
@@ -1348,6 +1362,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
PBMap::SetCallBackMainPointer(@MainPointer()) ;To change the Main Pointer
|
PBMap::SetCallBackMainPointer(@MainPointer()) ;To change the Main Pointer
|
||||||
PBMap::SetCallBackLocation(@UpdateLocation())
|
PBMap::SetCallBackLocation(@UpdateLocation())
|
||||||
PBMap::SetLocation(-36.81148, 175.08634,12)
|
PBMap::SetLocation(-36.81148, 175.08634,12)
|
||||||
|
; PBMap::SetLocation(0, 0)
|
||||||
PBMap::SetMapServer("http://t1.openseamap.org/seamark/") ;add a special osm overlay map
|
PBMap::SetMapServer("http://t1.openseamap.org/seamark/") ;add a special osm overlay map
|
||||||
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL)
|
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL)
|
||||||
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker())
|
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker())
|
||||||
@@ -1387,8 +1402,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
|
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 1353
|
; CursorPosition = 1364
|
||||||
; FirstLine = 1344
|
; FirstLine = 1352
|
||||||
; Folding = ----------
|
; Folding = ----------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user