Cleaning
This commit is contained in:
49
osm.pb
49
osm.pb
@@ -82,14 +82,13 @@ Module OSM
|
|||||||
|
|
||||||
Structure TileMemCach
|
Structure TileMemCach
|
||||||
Map Images.ImgMemCach()
|
Map Images.ImgMemCach()
|
||||||
Mutex.i
|
|
||||||
Semaphore.i
|
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure Marker
|
Structure Marker
|
||||||
Location.Location
|
Location.Location
|
||||||
color.l
|
color.l
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
;-OSM Structure
|
;-OSM Structure
|
||||||
Structure OSM
|
Structure OSM
|
||||||
Gadget.i ; Canvas Gadget Id
|
Gadget.i ; Canvas Gadget Id
|
||||||
@@ -109,16 +108,13 @@ Module OSM
|
|||||||
TileSize.i ; Tile size downloaded on the server ex : 256
|
TileSize.i ; Tile size downloaded on the server ex : 256
|
||||||
|
|
||||||
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 ; Image in memory cache
|
MemCache.TileMemCach ; Images in memory cache
|
||||||
List MapImageIndex.ImgMemCach() ; Index from MemCache\Image() to construct map
|
|
||||||
|
|
||||||
Moving.i
|
Moving.i
|
||||||
Dirty.i ;To signal that drawing need a refresh
|
Dirty.i ;To signal that drawing need a refresh
|
||||||
;CurlMutex.i ;seems that I can't thread curl ! :(((((
|
;CurlMutex.i ;seems that I can't thread curl ! :(((((
|
||||||
List TilesThreads.TileThread()
|
List TilesThreads.TileThread()
|
||||||
|
|
||||||
MapImageMutex.i ; Mutex to lock
|
|
||||||
|
|
||||||
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
|
||||||
EditMarkerIndex.l
|
EditMarkerIndex.l
|
||||||
@@ -363,9 +359,9 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i)
|
Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i)
|
||||||
|
|
||||||
Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0")
|
Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0")
|
||||||
|
|
||||||
Debug "Check if we have this image in memory"
|
Debug "Check if we have this image in memory"
|
||||||
|
|
||||||
If FindMapElement(OSM\MemCache\Images(), key)
|
If FindMapElement(OSM\MemCache\Images(), key)
|
||||||
@@ -443,7 +439,7 @@ Module OSM
|
|||||||
|
|
||||||
Protected nImage.i = -1
|
Protected nImage.i = -1
|
||||||
Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0")
|
Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0")
|
||||||
|
|
||||||
;Adding the image to the cache if possible
|
;Adding the image to the cache if possible
|
||||||
AddMapElement(OSM\MemCache\Images(), key)
|
AddMapElement(OSM\MemCache\Images(), key)
|
||||||
nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
|
nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
|
||||||
@@ -556,7 +552,7 @@ Module OSM
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Pointer(x.i, y.i, color.l = #Red)
|
Procedure Pointer(x.i, y.i, color.l = #Red)
|
||||||
|
|
||||||
color=RGBA(255, 0, 0, 255)
|
color=RGBA(255, 0, 0, 255)
|
||||||
VectorSourceColor(color)
|
VectorSourceColor(color)
|
||||||
@@ -578,7 +574,7 @@ Module OSM
|
|||||||
Protected Location.Location
|
Protected Location.Location
|
||||||
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize)
|
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize)
|
||||||
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
|
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
|
||||||
|
|
||||||
If ListSize(OSM\track())>0
|
If ListSize(OSM\track())>0
|
||||||
|
|
||||||
ForEach OSM\track()
|
ForEach OSM\track()
|
||||||
@@ -615,7 +611,7 @@ Module OSM
|
|||||||
|
|
||||||
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize)
|
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize)
|
||||||
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
|
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
|
||||||
|
|
||||||
ForEach OSM\Marker()
|
ForEach OSM\Marker()
|
||||||
If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0
|
If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0
|
||||||
GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel)
|
GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel)
|
||||||
@@ -633,11 +629,12 @@ Module OSM
|
|||||||
WaitSemaphore(*Drawing\Semaphore)
|
WaitSemaphore(*Drawing\Semaphore)
|
||||||
|
|
||||||
Debug "--------- Main drawing thread ------------"
|
Debug "--------- Main drawing thread ------------"
|
||||||
|
|
||||||
*Drawing\Dirty = #False
|
|
||||||
Protected CenterX = GadgetWidth(OSM\Gadget) / 2
|
Protected CenterX = GadgetWidth(OSM\Gadget) / 2
|
||||||
Protected CenterY = GadgetHeight(OSM\Gadget) / 2
|
Protected CenterY = GadgetHeight(OSM\Gadget) / 2
|
||||||
|
|
||||||
|
*Drawing\Dirty = #False
|
||||||
|
|
||||||
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
|
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
|
||||||
DrawTiles(*Drawing)
|
DrawTiles(*Drawing)
|
||||||
DrawTrack(*Drawing)
|
DrawTrack(*Drawing)
|
||||||
@@ -647,8 +644,7 @@ Module OSM
|
|||||||
|
|
||||||
;- Redraw
|
;- Redraw
|
||||||
;If something was not correctly drawn, redraw after a while
|
;If something was not correctly drawn, redraw after a while
|
||||||
;Be sure that we're not modifying while moving
|
LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore)
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
|
||||||
If *Drawing\Dirty
|
If *Drawing\Dirty
|
||||||
Debug "Something was dirty ! We try again to redraw"
|
Debug "Something was dirty ! We try again to redraw"
|
||||||
;Delay(250)
|
;Delay(250)
|
||||||
@@ -656,10 +652,10 @@ Module OSM
|
|||||||
SignalSemaphore(*Drawing\Semaphore)
|
SignalSemaphore(*Drawing\Semaphore)
|
||||||
Else
|
Else
|
||||||
;Clean the semaphore to avoid multiple unuseful redraws
|
;Clean the semaphore to avoid multiple unuseful redraws
|
||||||
Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0
|
Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0
|
||||||
EndIf
|
EndIf
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(OSM\Drawing\Mutex)
|
||||||
|
|
||||||
Until *Drawing\End
|
Until *Drawing\End
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -685,16 +681,15 @@ Module OSM
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Macro Min(a,b)
|
Macro Min(a,b)
|
||||||
(Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b))
|
(Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b))
|
||||||
EndMacro
|
EndMacro
|
||||||
|
|
||||||
Macro Max(a,b)
|
Macro Max(a,b)
|
||||||
(Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b))
|
(Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b))
|
||||||
EndMacro
|
EndMacro
|
||||||
|
|
||||||
|
Procedure ZoomToArea()
|
||||||
Procedure ZoomToArea()
|
|
||||||
;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map
|
;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map
|
||||||
;bounding box in long/lat coords (x=long, y=lat)
|
;bounding box in long/lat coords (x=long, y=lat)
|
||||||
Protected MinY.d,MaxY.d,MinX.d,MaxX.d
|
Protected MinY.d,MaxY.d,MinX.d,MaxX.d
|
||||||
@@ -766,10 +761,10 @@ Module OSM
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
Procedure SetCallBackLocation(CallBackLocation.i)
|
Procedure SetCallBackLocation(CallBackLocation.i)
|
||||||
OSM\CallBackLocation=CallBackLocation
|
OSM\CallBackLocation = CallBackLocation
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Event(Event.l)
|
Procedure Event(Event.l)
|
||||||
|
|
||||||
Protected Gadget.i
|
Protected Gadget.i
|
||||||
@@ -958,8 +953,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x64)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x64)
|
||||||
; CursorPosition = 481
|
; CursorPosition = 757
|
||||||
; FirstLine = 455
|
; FirstLine = 705
|
||||||
; Folding = ------
|
; Folding = ------
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableThread
|
; EnableThread
|
||||||
|
Reference in New Issue
Block a user