DrawDegrees bugfix (not fully fixed...)

This commit is contained in:
djes
2016-08-30 16:48:28 +02:00
parent 295d0d72bc
commit 0e063a5623

View File

@@ -28,7 +28,7 @@ UsePNGImageEncoder()
DeclareModule PBMap DeclareModule PBMap
#Red = 255 #Red = 255
;-Show debug infos ;-Show debug infos
Global Verbose = 1 Global Verbose = 0
Global MyDebugLevel = 3 Global MyDebugLevel = 3
;-Proxy ON/OFF ;-Proxy ON/OFF
Global Proxy = #False Global Proxy = #False
@@ -615,12 +615,7 @@ Module PBMap
Protected ny = *Drawing\CenterY / PBMap\TileSize Protected ny = *Drawing\CenterY / PBMap\TileSize
Protected px, py, img, tilex,tiley, key.s, CacheFile.s Protected px, py, img, tilex,tiley, key.s, CacheFile.s
MyDebug("Drawing tiles") MyDebug("Drawing tiles")
*Drawing\Bounds\NorthWest\x = tx-nx-1
*Drawing\Bounds\NorthWest\y = ty-ny-1
*Drawing\Bounds\SouthEast\x = tx+nx+1
*Drawing\Bounds\SouthEast\y = ty+ny+1
For y = - ny - 1 To ny + 1 For y = - ny - 1 To ny + 1
For x = - nx - 1 To nx + 1 For x = - nx - 1 To nx + 1
; If PBMap\Moving ;If drawing was threaded, this would exit the loop when the user is moving ; If PBMap\Moving ;If drawing was threaded, this would exit the loop when the user is moving
@@ -714,35 +709,50 @@ Module PBMap
EndProcedure EndProcedure
Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192) Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192)
Protected 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
tx = Int(*Drawing\Position\x) ;Don't forget the Int() !
ty = Int(*Drawing\Position\y)
nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
ny = *Drawing\CenterY / PBMap\TileSize
*Drawing\Bounds\NorthWest\x = tx-nx-1
*Drawing\Bounds\NorthWest\y = ty-ny-1
*Drawing\Bounds\SouthEast\x = tx+nx+1
*Drawing\Bounds\SouthEast\y = ty+ny+1
;VectorFont(FontID(PBMap\Font), 10) ;VectorFont(FontID(PBMap\Font), 10)
VectorSourceColor(RGBA(0, 0, 0,Alpha)) VectorSourceColor(RGBA(0, 0, 0,Alpha))
;GetMapRegionDegrees(@Degrees1,@degrees2) ;GetMapRegionDegrees(@Degrees1,@degrees2)
XY2LatLon(*Drawing\Bounds\NorthWest,@Degrees1) XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
XY2LatLon(*Drawing\Bounds\SouthEast,@Degrees2) XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
ny = Round(Degrees1\Latitude,#PB_Round_Up)+1 nx = Round(Degrees1\Longitude, #PB_Round_Down)-1
ny1 = Round(degrees2\Latitude,#PB_Round_Down)-1 ny = Round(Degrees1\Latitude, #PB_Round_Up) +1
nx = Round(Degrees1\Longitude,#PB_Round_Down)-1 nx1 = Round(Degrees2\Longitude, #PB_Round_Up) +1
nx1 = Round(degrees2\Longitude,#PB_Round_Up) +1 ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1
For y = ny1 To ny GetPixelCoordFromLocation(@Degrees2, @pos2)
Degrees1\Latitude = y
degrees2\Latitude = y + 1 x = nx
For x = nx To nx1 For y = ny1 To ny
Degrees1\Longitude =x Degrees1\Longitude = x
Degrees2\Longitude =x+ 1 Degrees1\Latitude = y
GetPixelCoordFromLocation(@Degrees1,@pos1) GetPixelCoordFromLocation(@Degrees1, @pos1)
MovePathCursor(pos1\x,pos1\y) MovePathCursor(pos1\x, pos1\y)
AddPathLine(pos2\x,pos1\y) AddPathLine( pos2\x, pos1\y)
MovePathCursor(pos1\x,pos1\y) Next
AddPathLine(pos1\x,pos2\y) y = ny
For x = nx To nx1
Degrees1\Longitude = x
Degrees1\Latitude = y
GetPixelCoordFromLocation(@Degrees1, @pos1)
MovePathCursor(pos1\x, pos1\y)
AddPathLine( pos1\x, pos2\y)
Next Next
Next
StrokePath(1) StrokePath(1)
EndProcedure EndProcedure
@@ -818,7 +828,7 @@ Module PBMap
EndProcedure EndProcedure
; Draw all markers on the screen ! ; Draw all markers on the screen !
Procedure DrawMarker(*Drawing.DrawingParameters) Procedure DrawMarkers(*Drawing.DrawingParameters)
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
@@ -849,6 +859,7 @@ Module PBMap
*Drawing\DeltaY = Py * PBMap\TileSize - (Int(Py) * PBMap\TileSize) *Drawing\DeltaY = Py * PBMap\TileSize - (Int(Py) * PBMap\TileSize)
*Drawing\TargetLocation\Latitude = PBMap\TargetLocation\Latitude *Drawing\TargetLocation\Latitude = PBMap\TargetLocation\Latitude
*Drawing\TargetLocation\Longitude = PBMap\TargetLocation\Longitude *Drawing\TargetLocation\Longitude = PBMap\TargetLocation\Longitude
;Main drawing stuff ;Main drawing stuff
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget)) StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers ;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers
@@ -857,7 +868,7 @@ Module PBMap
DrawTiles(*Drawing, a) DrawTiles(*Drawing, a)
Next Next
DrawTrack(*Drawing) DrawTrack(*Drawing)
DrawMarker(*Drawing) DrawMarkers(*Drawing)
DrawPointer(*Drawing) DrawPointer(*Drawing)
;- Display how many images in cache ;- Display how many images in cache
VectorFont(FontID(PBMap\Font), 30) VectorFont(FontID(PBMap\Font), 30)
@@ -874,9 +885,9 @@ Module PBMap
EndIf EndIf
Next Next
DrawVectorText(Str(ThreadCounter)) DrawVectorText(Str(ThreadCounter))
DrawDegrees(*Drawing, 192)
;If PBMap\Options\ShowScale ;If PBMap\Options\ShowScale
DrawScale(*Drawing,10,GadgetHeight(PBMAP\Gadget)-20,192) DrawScale(*Drawing,10,GadgetHeight(PBMAP\Gadget)-20,192)
DrawDegrees(*Drawing, 192)
;EndIf ;EndIf
StopVectorDrawing() StopVectorDrawing()
;If there was a problem while drawing, redraw ;If there was a problem while drawing, redraw
@@ -1118,19 +1129,19 @@ Module PBMap
Debug "Reload" Debug "Reload"
PBMap\Redraw = #True PBMap\Redraw = #True
Case #PB_MAP_TILE_CLEANUP Case #PB_MAP_TILE_CLEANUP
*Tile = EventData() *Tile = EventData()
;If PBMap\MemCache\Images(*Tile\key)\Tile\RetryNb = -2 ;Check the end of the thread ;After a Web tile loading thread, clean the tile structure memory and set the image nb in the cache
;avoid to have threads accessing vars (and avoid mutex), see GetImageThread()
Protected timg = PBMap\MemCache\Images(*Tile\key)\Tile\nImage Protected timg = PBMap\MemCache\Images(*Tile\key)\Tile\nImage
PBMap\MemCache\Images(*Tile\key)\nImage = timg PBMap\MemCache\Images(*Tile\key)\nImage = timg
FreeMemory(PBMap\MemCache\Images(*Tile\key)\Tile) FreeMemory(PBMap\MemCache\Images(*Tile\key)\Tile)
PBMap\MemCache\Images(*Tile\key)\Tile = 0 PBMap\MemCache\Images(*Tile\key)\Tile = 0
PBMap\Redraw = #True PBMap\Redraw = #True
;EndIf
EndSelect EndSelect
EndProcedure EndProcedure
Procedure TimerEvents() Procedure TimerEvents()
;Redraw at regular intervals
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty) If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
Drawing() Drawing()
EndIf EndIf
@@ -1222,7 +1233,6 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::Refresh() PBMap::Refresh()
EndProcedure EndProcedure
OpenConsole()
;- MAIN TEST ;- MAIN TEST
If OpenWindow(#Window_0, 260, 225, 700, 571, "PBMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) If OpenWindow(#Window_0, 260, 225, 700, 571, "PBMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
@@ -1252,10 +1262,10 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::MapGadget(#Map, 10, 10, 512, 512) PBMap::MapGadget(#Map, 10, 10, 512, 512)
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::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, @MyPointer()) PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer())
Repeat Repeat
Event = WaitWindowEvent() Event = WaitWindowEvent()
@@ -1289,15 +1299,12 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::Quit() PBMap::Quit()
EndIf EndIf
CloseConsole()
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 622 ; CursorPosition = 751
; FirstLine = 608 ; FirstLine = 719
; Folding = --------- ; Folding = ---------
; EnableThread ; EnableThread
; EnableXP ; EnableXP
; DisableDebugger
; EnableUnicode ; EnableUnicode