djes merging and lat/long drawing
This commit is contained in:
213
PBMap.pb
213
PBMap.pb
@@ -1,4 +1,4 @@
|
|||||||
;;**************************************************************
|
;**************************************************************
|
||||||
; Program: PBMap
|
; Program: PBMap
|
||||||
; Description: Permits the use of tiled maps like
|
; Description: Permits the use of tiled maps like
|
||||||
; OpenStreetMap in a handy PureBASIC module
|
; OpenStreetMap in a handy PureBASIC module
|
||||||
@@ -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
|
||||||
@@ -164,13 +164,11 @@ Module PBMap
|
|||||||
HDDCachePath.S ; Path where to load and save tiles downloaded from server
|
HDDCachePath.S ; Path where to load and save tiles downloaded from server
|
||||||
MemCache.TileMemCach ; Images in memory cache
|
MemCache.TileMemCach ; Images in memory cache
|
||||||
;
|
;
|
||||||
OnStage.i
|
|
||||||
Redraw.i
|
Redraw.i
|
||||||
Moving.i
|
Moving.i
|
||||||
Dirty.i ; To signal that drawing need a refresh
|
Dirty.i ; To signal that drawing need a refresh
|
||||||
;
|
;
|
||||||
MainDrawingThread.i
|
MainDrawingThread.i
|
||||||
;List TilesThreads.TileThread()
|
|
||||||
TileThreadMutex.i; ;Mutex to protect resources
|
TileThreadMutex.i; ;Mutex to protect resources
|
||||||
List track.Location() ; To display a GPX track
|
List track.Location() ; To display a GPX track
|
||||||
List Marker.Marker() ; To diplay marker
|
List Marker.Marker() ; To diplay marker
|
||||||
@@ -183,6 +181,7 @@ Module PBMap
|
|||||||
|
|
||||||
#PB_MAP_REDRAW = #PB_EventType_FirstCustomValue + 1
|
#PB_MAP_REDRAW = #PB_EventType_FirstCustomValue + 1
|
||||||
#PB_MAP_RETRY = #PB_EventType_FirstCustomValue + 2
|
#PB_MAP_RETRY = #PB_EventType_FirstCustomValue + 2
|
||||||
|
#PB_MAP_TILE_CLEANUP = #PB_EventType_FirstCustomValue + 3
|
||||||
|
|
||||||
;-Global variables
|
;-Global variables
|
||||||
Global PBMap.PBMap, Null.i
|
Global PBMap.PBMap, Null.i
|
||||||
@@ -349,6 +348,9 @@ Module PBMap
|
|||||||
;Should not occur
|
;Should not occur
|
||||||
KillThread(PBMap\MemCache\Images()\Tile\GetImageThread)
|
KillThread(PBMap\MemCache\Images()\Tile\GetImageThread)
|
||||||
EndIf
|
EndIf
|
||||||
|
Else
|
||||||
|
FreeMemory(PBMap\MemCache\Images()\Tile)
|
||||||
|
PBMap\MemCache\Images()\Tile = 0
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
DeleteMapElement(PBMap\MemCache\Images())
|
DeleteMapElement(PBMap\MemCache\Images())
|
||||||
@@ -515,7 +517,7 @@ Module PBMap
|
|||||||
; SaveImage(timg, CacheFile, #PB_ImagePlugin_PNG)
|
; SaveImage(timg, CacheFile, #PB_ImagePlugin_PNG)
|
||||||
; FreeImage(timg)
|
; FreeImage(timg)
|
||||||
; Else
|
; Else
|
||||||
If SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG,0,32)
|
If SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG, 0, 32)
|
||||||
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
|
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
|
||||||
Else
|
Else
|
||||||
MyDebug("Loaded from web " + TileURL + " but cannot save to CacheFile " + CacheFile, 3)
|
MyDebug("Loaded from web " + TileURL + " but cannot save to CacheFile " + CacheFile, 3)
|
||||||
@@ -539,25 +541,17 @@ Module PBMap
|
|||||||
Repeat
|
Repeat
|
||||||
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile, *Tile\Layer)
|
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile, *Tile\Layer)
|
||||||
If nImage <> -1
|
If nImage <> -1
|
||||||
LockMutex(PBMap\TileThreadMutex)
|
|
||||||
PBMap\MemCache\Images(*Tile\key)\nImage = nImage
|
|
||||||
UnlockMutex(PBMap\TileThreadMutex)
|
|
||||||
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
|
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
|
||||||
PBMap\Dirty = #True
|
|
||||||
*Tile\RetryNb = 0
|
*Tile\RetryNb = 0
|
||||||
; PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_REDRAW, *Tile) ;If image is loaded from web, redraw
|
|
||||||
Else
|
Else
|
||||||
MyDebug("Image key : " + *Tile\key + " web image not correctly loaded", 3)
|
MyDebug("Image key : " + *Tile\key + " web image not correctly loaded", 3)
|
||||||
Delay(5000)
|
Delay(1000)
|
||||||
*Tile\RetryNb - 1
|
*Tile\RetryNb - 1
|
||||||
; PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_RETRY, *Tile) ;If image is not loaded, retry
|
|
||||||
EndIf
|
EndIf
|
||||||
Until *Tile\RetryNb <= 0
|
Until *Tile\RetryNb <= 0
|
||||||
;End of the thread
|
*Tile\nImage = nImage
|
||||||
LockMutex(PBMap\TileThreadMutex)
|
*Tile\RetryNb = -2 ;End of the thread
|
||||||
FreeMemory(PBMap\MemCache\Images(*Tile\key)\Tile)
|
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ;To free memory outside the thread
|
||||||
PBMap\MemCache\Images(*Tile\key)\Tile = 0
|
|
||||||
UnlockMutex(PBMap\TileThreadMutex)
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTile(key.s, CacheFile.s, px.i, py.i, tilex.i, tiley.i, Layer.i)
|
Procedure.i GetTile(key.s, CacheFile.s, px.i, py.i, tilex.i, tiley.i, Layer.i)
|
||||||
@@ -573,17 +567,16 @@ Module PBMap
|
|||||||
AddMapElement(PBMap\MemCache\Images(), key)
|
AddMapElement(PBMap\MemCache\Images(), key)
|
||||||
MyDebug("Key : " + key + " added in memory cache!", 3)
|
MyDebug("Key : " + key + " added in memory cache!", 3)
|
||||||
PBMap\MemCache\Images()\nImage = -1
|
PBMap\MemCache\Images()\nImage = -1
|
||||||
;UnlockMutex(PBMap\TileThreadMutex)
|
|
||||||
EndIf
|
EndIf
|
||||||
If PBMap\MemCache\Images()\Tile = 0 ;Check if a loading thread is not running
|
If PBMap\MemCache\Images()\Tile = 0 ;Check if a loading thread is not running
|
||||||
MyDebug("Trying to load from HDD " + CacheFile)
|
MyDebug("Trying to load from HDD " + CacheFile, 3)
|
||||||
timg = GetTileFromHDD(CacheFile.s)
|
timg = GetTileFromHDD(CacheFile.s)
|
||||||
If timg <> -1
|
If timg <> -1
|
||||||
MyDebug("Key : " + key + " found on HDD")
|
MyDebug("Key : " + key + " found on HDD", 3)
|
||||||
PBMap\MemCache\Images()\nImage = timg
|
PBMap\MemCache\Images()\nImage = timg
|
||||||
ProcedureReturn timg
|
ProcedureReturn timg
|
||||||
EndIf
|
EndIf
|
||||||
MyDebug("Key : " + key + " not found on HDD")
|
MyDebug("Key : " + key + " not found on HDD", 3)
|
||||||
;Launch a new thread
|
;Launch a new thread
|
||||||
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
|
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
|
||||||
If *NewTile
|
If *NewTile
|
||||||
@@ -599,33 +592,17 @@ Module PBMap
|
|||||||
\CacheFile = CacheFile
|
\CacheFile = CacheFile
|
||||||
\Layer = Layer
|
\Layer = Layer
|
||||||
\RetryNb = 5
|
\RetryNb = 5
|
||||||
|
\nImage = -1
|
||||||
|
MyDebug(" Creating get image thread nb " + Str(\GetImageThread) + " to get " + CacheFile, 3)
|
||||||
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
|
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
|
||||||
myDebug(" Creating get image thread nb " + Str(\GetImageThread))
|
|
||||||
EndWith
|
EndWith
|
||||||
Else
|
Else
|
||||||
MyDebug(" Error, can't create a new tile loading thread")
|
MyDebug(" Error, can't create a new tile loading thread", 3)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
ProcedureReturn timg
|
ProcedureReturn timg
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Procedure DrawTile(*Tile.Tile)
|
|
||||||
; Protected x = *Tile\Position\x
|
|
||||||
; Protected y = *Tile\Position\y
|
|
||||||
; MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX), 2)
|
|
||||||
; MyDebug(" at coords " + Str(x) + "," + Str(y), 2)
|
|
||||||
; MovePathCursor(x, y)
|
|
||||||
; DrawVectorImage(ImageID(*Tile\nImage))
|
|
||||||
; EndProcedure
|
|
||||||
;
|
|
||||||
; Procedure DrawLoading(*Tile.Tile)
|
|
||||||
; Protected x = *Tile\Position\x
|
|
||||||
; Protected y = *Tile\Position\y
|
|
||||||
; Protected Text$ = "Loading"
|
|
||||||
; MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX), 2)
|
|
||||||
; MyDebug(" at coords " + Str(x) + "," + Str(y))
|
|
||||||
; EndProcedure
|
|
||||||
|
|
||||||
Procedure DrawTiles(*Drawing.DrawingParameters, Layer.i, alpha.i=255)
|
Procedure DrawTiles(*Drawing.DrawingParameters, Layer.i, alpha.i=255)
|
||||||
;DisableDebugger
|
;DisableDebugger
|
||||||
Protected x.i, y.i,kq.q
|
Protected x.i, y.i,kq.q
|
||||||
@@ -635,12 +612,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
|
||||||
@@ -648,7 +620,7 @@ Module PBMap
|
|||||||
; EndIf
|
; EndIf
|
||||||
px = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX
|
px = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX
|
||||||
py = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY
|
py = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY
|
||||||
tilex = ((tx+x) % (1<< PBMap\Zoom))
|
tilex = ((tx+x) % (1<<PBMap\Zoom))
|
||||||
tiley = ty+y
|
tiley = ty+y
|
||||||
kq = Layer | (pbmap\zoom << 8) | (tilex << 16) | (tiley << 36)
|
kq = Layer | (pbmap\zoom << 8) | (tilex << 16) | (tiley << 36)
|
||||||
key = Str(kq)
|
key = Str(kq)
|
||||||
@@ -664,17 +636,6 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
Next
|
Next
|
||||||
|
|
||||||
; ;Free tile memory
|
|
||||||
; ;TODO : maybe get out this proc from drawtiles in a special "free ressources" task
|
|
||||||
; ForEach PBMap\TilesThreads()
|
|
||||||
; ;Check if there's no more loading thread
|
|
||||||
; If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
|
|
||||||
; FreeMemory(PBMap\TilesThreads()\Tile)
|
|
||||||
; DeleteElement(PBMap\TilesThreads())
|
|
||||||
; EndIf
|
|
||||||
; Next
|
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; ;-**** Clean Mem Cache
|
; ;-**** Clean Mem Cache
|
||||||
@@ -743,42 +704,59 @@ Module PBMap
|
|||||||
AddPathLine(x+128,y+10)
|
AddPathLine(x+128,y+10)
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
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
|
||||||
|
|
||||||
;VectorFont(FontID(PBMap\Font), 10)
|
|
||||||
VectorSourceColor(RGBA(0, 0, 0,Alpha))
|
|
||||||
|
|
||||||
;GetMapRegionDegrees(@Degrees1,@degrees2)
|
tx = *Drawing\Position\x
|
||||||
|
ty = *Drawing\Position\y
|
||||||
|
nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
|
||||||
|
ny = *Drawing\CenterY / PBMap\TileSize
|
||||||
|
|
||||||
XY2LatLon(*Drawing\Bounds\NorthWest,@Degrees1)
|
*Drawing\Bounds\NorthWest\x = tx-nx-1
|
||||||
XY2LatLon(*Drawing\Bounds\SouthEast,@Degrees2)
|
*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)
|
||||||
|
VectorSourceColor(RGBA(0, 0, 0,alpha))
|
||||||
|
|
||||||
ny = Round(Degrees1\Latitude,#PB_Round_Up)+1
|
XY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1)
|
||||||
ny1 = Round(degrees2\Latitude,#PB_Round_Down)-1
|
XY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2)
|
||||||
nx = Round(Degrees1\Longitude,#PB_Round_Down)-1
|
|
||||||
nx1 = Round(degrees2\Longitude,#PB_Round_Up) +1
|
nx = Round(Degrees1\Longitude, #PB_Round_Down)-1
|
||||||
|
ny = Round(Degrees1\Latitude, #PB_Round_Up) +1
|
||||||
For y = ny1 To ny
|
nx1 = Round(Degrees2\Longitude, #PB_Round_Up) +1
|
||||||
Degrees1\Latitude = y
|
ny1 = Round(Degrees2\Latitude, #PB_Round_Down)-1
|
||||||
degrees2\Latitude = y + 1
|
|
||||||
For x = nx To nx1
|
GetPixelCoordFromLocation(@Degrees2, @pos2)
|
||||||
Degrees1\Longitude =x
|
|
||||||
Degrees2\Longitude =x+ 1
|
x = nx
|
||||||
GetPixelCoordFromLocation(@Degrees1,@pos1)
|
For y = ny1 To ny
|
||||||
MovePathCursor(pos1\x,pos1\y)
|
Degrees1\Longitude = x
|
||||||
AddPathLine(pos2\x,pos1\y)
|
Degrees1\Latitude = y
|
||||||
MovePathCursor(pos1\x,pos1\y)
|
GetPixelCoordFromLocation(@Degrees1, @pos1)
|
||||||
AddPathLine(pos1\x,pos2\y)
|
MovePathCursor(pos1\x, pos1\y)
|
||||||
Next
|
AddPathLine( pos2\x, pos1\y)
|
||||||
Next
|
MovePathCursor(10,pos1\y)
|
||||||
|
DrawVectorText(StrD(0-(90-Mod((y+90),180)),1))
|
||||||
|
Next
|
||||||
|
|
||||||
|
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)
|
||||||
|
MovePathCursor(pos1\x,10)
|
||||||
|
DrawVectorText(StrD(0-(180-Mod((x+180),360)),1))
|
||||||
|
Next
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
Procedure TrackPointer(x.i, y.i,dist.l)
|
Procedure TrackPointer(x.i, y.i,dist.l)
|
||||||
Protected color.l
|
Protected color.l
|
||||||
color=RGBA(0, 0, 0, 255)
|
color=RGBA(0, 0, 0, 255)
|
||||||
@@ -850,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
|
||||||
@@ -870,7 +848,6 @@ Module PBMap
|
|||||||
Procedure Drawing()
|
Procedure Drawing()
|
||||||
Protected *Drawing.DrawingParameters = @PBMap\Drawing
|
Protected *Drawing.DrawingParameters = @PBMap\Drawing
|
||||||
Protected Px.d, Py.d,a
|
Protected Px.d, Py.d,a
|
||||||
PBMap\OnStage = #True
|
|
||||||
PBMap\Dirty = #False
|
PBMap\Dirty = #False
|
||||||
PBMap\Redraw = #False
|
PBMap\Redraw = #False
|
||||||
;Precalc some values
|
;Precalc some values
|
||||||
@@ -882,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
|
||||||
@@ -890,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)
|
||||||
@@ -901,23 +879,18 @@ Module PBMap
|
|||||||
Protected ThreadCounter = 0
|
Protected ThreadCounter = 0
|
||||||
ForEach PBMap\MemCache\Images()
|
ForEach PBMap\MemCache\Images()
|
||||||
If PBMap\MemCache\Images()\Tile <> 0
|
If PBMap\MemCache\Images()\Tile <> 0
|
||||||
If PBMap\MemCache\Images()\Tile\GetImageThread <> 0
|
If IsThread(PBMap\MemCache\Images()\Tile\GetImageThread)
|
||||||
ThreadCounter + 1
|
ThreadCounter + 1
|
||||||
EndIf
|
EndIf
|
||||||
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 PBMap\Dirty
|
|
||||||
; PBMap\Redraw = #True
|
|
||||||
; ;PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_REDRAW)
|
|
||||||
; EndIf
|
|
||||||
PBMap\OnStage = #False
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Refresh()
|
Procedure Refresh()
|
||||||
@@ -1058,15 +1031,11 @@ Module PBMap
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLatitude()
|
Procedure.d GetLatitude()
|
||||||
Protected Value.d
|
ProcedureReturn 0-(90-Mod((PBMap\TargetLocation\Latitude+90),180))
|
||||||
Value = PBMap\TargetLocation\Latitude
|
|
||||||
ProcedureReturn Value
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLongitude()
|
Procedure.d GetLongitude()
|
||||||
Protected Value.d
|
ProcedureReturn 0-(180-Mod((PBMap\TargetLocation\Longitude+180),360))
|
||||||
Value = PBMap\TargetLocation\Longitude
|
|
||||||
ProcedureReturn Value
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetZoom()
|
Procedure.i GetZoom()
|
||||||
@@ -1077,7 +1046,7 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure CanvasEvents()
|
Procedure CanvasEvents()
|
||||||
Protected MouseX.i, MouseY.i
|
Protected MouseX.i, MouseY.i
|
||||||
Protected Marker.Position
|
Protected Marker.Position, *Tile.Tile
|
||||||
PBMap\Moving = #False
|
PBMap\Moving = #False
|
||||||
Select EventType()
|
Select EventType()
|
||||||
Case #PB_EventType_MouseWheel
|
Case #PB_EventType_MouseWheel
|
||||||
@@ -1151,11 +1120,21 @@ Module PBMap
|
|||||||
Case #PB_MAP_RETRY
|
Case #PB_MAP_RETRY
|
||||||
Debug "Reload"
|
Debug "Reload"
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
|
Case #PB_MAP_TILE_CLEANUP
|
||||||
|
*Tile = EventData()
|
||||||
|
;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
|
||||||
|
PBMap\MemCache\Images(*Tile\key)\nImage = timg
|
||||||
|
FreeMemory(PBMap\MemCache\Images(*Tile\key)\Tile)
|
||||||
|
PBMap\MemCache\Images(*Tile\key)\Tile = 0
|
||||||
|
PBMap\Redraw = #True
|
||||||
EndSelect
|
EndSelect
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure TimerEvents()
|
Procedure TimerEvents()
|
||||||
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty) And PBMap\OnStage = #False
|
;Redraw at regular intervals
|
||||||
|
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
|
||||||
Drawing()
|
Drawing()
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -1205,8 +1184,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Procedure UpdateLocation(*Location.Location)
|
Procedure UpdateLocation(*Location.Location)
|
||||||
SetGadgetText(#String_0, StrD(*Location\Latitude))
|
SetGadgetText(#String_0, StrD(0-(90-Mod((*Location\Latitude+90),180))))
|
||||||
SetGadgetText(#String_1, StrD(*Location\Longitude))
|
SetGadgetText(#String_1, StrD(0-(180-Mod((*Location\Longitude+180),360))))
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -1246,7 +1225,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)
|
||||||
|
|
||||||
@@ -1279,7 +1257,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
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()
|
||||||
@@ -1312,14 +1290,11 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
Until Quit = #True
|
Until Quit = #True
|
||||||
|
|
||||||
PBMap::Quit()
|
PBMap::Quit()
|
||||||
EndIf
|
EndIf
|
||||||
|
CompilerEndIf
|
||||||
CloseConsole()
|
|
||||||
|
|
||||||
CompilerEndIf
|
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 1290
|
; CursorPosition = 1263
|
||||||
; FirstLine = 1275
|
; FirstLine = 1250
|
||||||
; Folding = ---------
|
; Folding = ---------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user