Revert "Cache cleaning"

This reverts commit 035b26d9db.
This commit is contained in:
djes
2016-08-23 09:51:27 +02:00
parent 035b26d9db
commit 4d3c3ffffc

207
PBMap.pb
View File

@@ -26,6 +26,7 @@ UsePNGImageEncoder()
DeclareModule PBMap DeclareModule PBMap
;-Show debug infos ;-Show debug infos
Global Verbose = #False Global Verbose = #False
;-Proxy ON/OFF
Global Proxy = #False Global Proxy = #False
Declare InitPBMap() Declare InitPBMap()
Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18) Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18)
@@ -101,7 +102,7 @@ Module PBMap
Structure ImgMemCach Structure ImgMemCach
nImage.i nImage.i
Location.Location Usage.i
EndStructure EndStructure
Structure TileMemCach Structure TileMemCach
@@ -114,43 +115,37 @@ Module PBMap
CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
EndStructure EndStructure
Structure Option
WheelMouseRelative.i
EndStructure
;-PBMap Structure ;-PBMap Structure
Structure PBMap Structure PBMap
Gadget.i ; Canvas Gadget Id Gadget.i ; Canvas Gadget Id
Font.i ; Font to uses when write on the map Font.i ; Font to uses when write on the map
TargetLocation.Location ; Latitude and Longitude from focus point TargetLocation.Location ; Latitude and Longitude from focus point
Drawing.DrawingParameters ; Drawing parameters based on focus point Drawing.DrawingParameters ; Drawing parameters based on focus point
; ;
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
; ;
Position.PixelPosition ; Actual focus point coords in pixels (global) Position.PixelPosition ; Actual focus point coords in pixels (global)
MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map
; ;
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
ZoomMin.i ; Min Zoom supported by server ZoomMin.i ; Min Zoom supported by server
ZoomMax.i ; Max Zoom supported by server ZoomMax.i ; Max Zoom supported by server
Zoom.i ; Current zoom Zoom.i ; Current zoom
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 ; Images in memory cache MemCache.TileMemCach ; Images in memory cache
; ;
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() ; List TilesThreads.TileThread()
; ;
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
;
Options.option ;
EndStructure EndStructure
Global PBMap.PBMap, Null.i Global PBMap.PBMap, Null.i
@@ -168,7 +163,7 @@ Module PBMap
EndIf EndIf
EndProcedure EndProcedure
;- *** CURL specific ;- *** CURL specific ***
; (program has To be compiled in console format for curl debug infos) ; (program has To be compiled in console format for curl debug infos)
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
@@ -244,33 +239,30 @@ Module PBMap
PBMap\Drawing\Semaphore = CreateSemaphore() PBMap\Drawing\Semaphore = CreateSemaphore()
PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
;-Options ;- Proxy details
PBMap\Options\WheelMouseRelative = #True
;-Preferences
;Use this to create and customize your preferences file for the first time ;Use this to create and customize your preferences file for the first time
; CreatePreferences(GetHomeDirectory() + "PBMap.prefs") ; Result = CreatePreferences(GetHomeDirectory() + "PBMap.prefs")
; ;Or this to modify ; If Proxy
; ;OpenPreferences(GetHomeDirectory() + "PBMap.prefs") ; PreferenceGroup("PROXY")
; ;Or this ; WritePreferenceString("ProxyURL", "myproxy.fr")
; ;RunProgram("notepad.exe", GetHomeDirectory() + "PBMap.prefs", GetHomeDirectory()) ; WritePreferenceString("ProxyPort", "myproxyport")
; PreferenceGroup("PROXY") ; WritePreferenceString("ProxyUser", "myproxyname")
; WritePreferenceInteger("Proxy", #True) ; EndIf
; WritePreferenceString("ProxyURL", "myproxy.fr") ; If Result
; WritePreferenceString("ProxyPort", "myproxyport") ; ClosePreferences()
; WritePreferenceString("ProxyUser", "myproxyname") ; EndIf
; WritePreferenceString("ProxyPass", "myproxypass") ;TODO !Warning! !not encoded! Result = OpenPreferences(GetHomeDirectory() + "PBMap.prefs")
; ClosePreferences()
OpenPreferences(GetHomeDirectory() + "PBMap.prefs")
PreferenceGroup("PROXY")
Proxy = ReadPreferenceInteger("Proxy", #False)
If Proxy If Proxy
PreferenceGroup("PROXY")
Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "")
Global ProxyPort$ = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "") Global ProxyPort$ = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "")
Global ProxyUser$ = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "") Global ProxyUser$ = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "")
Global ProxyPassword$ = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") ;TODO Global ProxyPassword$ = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "")
EndIf EndIf
ClosePreferences() If Result
curl_global_init(#CURL_GLOBAL_WIN32) ClosePreferences()
EndIf
curl_global_init(#CURL_GLOBAL_WIN32);
;- Main drawing thread launching ;- Main drawing thread launching
PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing) PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing)
If PBMap\MainDrawingThread = 0 If PBMap\MainDrawingThread = 0
@@ -318,10 +310,10 @@ Module PBMap
Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
If Gadget = #PB_Any If Gadget = #PB_Any
PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height, #PB_Canvas_Keyboard) ;#PB_Canvas_Keyboard has to be set for mousewheel to work on windows PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
Else Else
PBMap\Gadget = Gadget PBMap\Gadget = Gadget
CanvasGadget(PBMap\Gadget, X, Y, Width, Height, #PB_Canvas_Keyboard) CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
EndIf EndIf
EndProcedure EndProcedure
@@ -379,7 +371,7 @@ Module PBMap
x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360) x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360)
; convert from degrees To radians ; convert from degrees To radians
latRad = PBMap\TargetLocation\Latitude*#PI/180; latRad = PBMap\TargetLocation\Latitude*#PI/180;
; get y value ; get y value
mercN = Log(Tan((#PI/4)+(latRad/2))) mercN = Log(Tan((#PI/4)+(latRad/2)))
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1) *Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
@@ -478,7 +470,6 @@ Module PBMap
Protected nImage.i = -1 Protected nImage.i = -1
Protected key.s = "Z" + RSet(Str(*Tile\PBMapZoom), 4, "0") + "X" + RSet(Str(*Tile\PBMapTileX), 8, "0") + "Y" + RSet(Str(*Tile\PBMapTileY), 8, "0") Protected key.s = "Z" + RSet(Str(*Tile\PBMapZoom), 4, "0") + "X" + RSet(Str(*Tile\PBMapTileX), 8, "0") + "Y" + RSet(Str(*Tile\PBMapTileY), 8, "0")
Protected CacheFile.s = PBMap\HDDCachePath + "PBMap_" + Str(*Tile\PBMapZoom) + "_" + Str(*Tile\PBMapTileX) + "_" + Str(*Tile\PBMapTileY) + ".png" Protected CacheFile.s = PBMap\HDDCachePath + "PBMap_" + Str(*Tile\PBMapZoom) + "_" + Str(*Tile\PBMapTileX) + "_" + Str(*Tile\PBMapTileY) + ".png"
Protected Tile.position
;Adding the image to the cache if possible ;Adding the image to the cache if possible
AddMapElement(PBMap\MemCache\Images(), key) AddMapElement(PBMap\MemCache\Images(), key)
nImage = GetTileFromHDD(CacheFile) nImage = GetTileFromHDD(CacheFile)
@@ -487,9 +478,6 @@ Module PBMap
EndIf EndIf
If nImage <> -1 If nImage <> -1
PBMap\MemCache\Images(key)\nImage = nImage PBMap\MemCache\Images(key)\nImage = nImage
Tile\x=*Tile\PBMapTileX
Tile\y=*Tile\PBMapTiley
XY2LatLon(@Tile,@PBMap\MemCache\Images(key)\Location)
MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache") MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache")
MyDebug("With the following key : " + key) MyDebug("With the following key : " + key)
Else Else
@@ -583,39 +571,20 @@ Module PBMap
DeleteElement(PBMap\TilesThreads()) DeleteElement(PBMap\TilesThreads())
EndIf EndIf
Next Next
;-****Clean Mem Cache
ForEach PBMap\MemCache\Images()
;GadgetWidth(PBMap\Gadget)/PBMap\TileSize
Protected MaxNbTile.l
If GadgetWidth(PBMap\Gadget)>GadgetHeight(PBMap\Gadget)
MaxNbTile=GadgetWidth(PBMap\Gadget)/PBMap\TileSize
Else
MaxNbTile=GadgetHeight(PBMap\Gadget)/PBMap\TileSize
EndIf
Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom)
Protected Limit.d=Scale*(MaxNbTile)*1.5
Protected Distance.d=HaversineInKM(@PBMap\MemCache\Images()\Location, @PBMap\TargetLocation)
Debug "Limit:"+StrD(Limit)+" Distance:"+StrD(Distance)
If Distance>Limit
Debug "delete"
DeleteMapElement(PBMap\MemCache\Images())
EndIf
Next
EndProcedure EndProcedure
Procedure Pointer(x.i, y.i, color.l = 0) Procedure Pointer(x.i, y.i, color.l = #Red)
color=RGBA(255, 0, 0, 255)
VectorSourceColor(color) VectorSourceColor(color)
MovePathCursor(x, y) MovePathCursor(x, y)
AddPathLine(-8, -16, #PB_Path_Relative) AddPathLine(-8,-16,#PB_Path_Relative)
AddPathCircle(8, 0, 8, 180, 0, #PB_Path_Relative) AddPathCircle(8,0,8,180,0,#PB_Path_Relative)
AddPathLine(-8, 16, #PB_Path_Relative) AddPathLine(-8,16,#PB_Path_Relative)
;FillPath(#PB_Path_Preserve) ;FillPath(#PB_Path_Preserve)
;ClipPath(#PB_Path_Preserve) ;ClipPath(#PB_Path_Preserve)
AddPathCircle(0, -16, 5, 0, 360, #PB_Path_Relative) AddPathCircle(0,-16,5,0,360,#PB_Path_Relative)
VectorSourceColor(color) VectorSourceColor(color)
FillPath(#PB_Path_Preserve):VectorSourceColor(color);RGBA(0, 0, 0, 255)) FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1)
StrokePath(1)
EndProcedure EndProcedure
Procedure TrackPointer(x.i, y.i,dist.l) Procedure TrackPointer(x.i, y.i,dist.l)
@@ -658,7 +627,7 @@ Module PBMap
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
;Draw Distance ;Draw Distance
ForEach PBMap\track() ForEach PBMap\track()
;Distance test ;-Test Distance
If ListIndex(PBMap\track())=0 If ListIndex(PBMap\track())=0
Location\Latitude=PBMap\track()\Latitude Location\Latitude=PBMap\track()\Latitude
Location\Longitude=PBMap\track()\Longitude Location\Longitude=PBMap\track()\Longitude
@@ -738,20 +707,8 @@ Module PBMap
If PBMap\CallBackMainPointer > 0 If PBMap\CallBackMainPointer > 0
CallFunctionFast(PBMap\CallBackMainPointer, Drawing\CenterX, Drawing\CenterY) CallFunctionFast(PBMap\CallBackMainPointer, Drawing\CenterX, Drawing\CenterY)
Else Else
Pointer(Drawing\CenterX, Drawing\CenterY, RGBA($FF, 0, 0, $FF)) Pointer(Drawing\CenterX, Drawing\CenterY, #Red)
EndIf EndIf
;TODO Add Option and function to display Scale on Map
;Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom)
;VectorFont(FontID(PBMap\Font), 30)
;VectorSourceColor(RGBA(0, 0, 0, 80))
;MovePathCursor(50,50)
;DrawVectorText(StrD(Scale))
;- Display How Many Image in Cache
VectorFont(FontID(PBMap\Font), 30)
VectorSourceColor(RGBA(0, 0, 0, 80))
MovePathCursor(50,50)
DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
StopVectorDrawing() StopVectorDrawing()
;Redraw ;Redraw
; If something was not correctly drawn, redraw after a while ; If something was not correctly drawn, redraw after a while
@@ -863,42 +820,6 @@ Module PBMap
EndIf EndIf
EndProcedure EndProcedure
;Zoom on x, y position relative to the canvas gadget
Procedure SetZoomOnPosition(x, y, zoom)
Protected MouseX.d, MouseY.d
Protected OldPx.d, OldPy.d, OldMx.d, OldMy.d
;Fast and dirty code
OldPx = PBMap\Position\x : OldPy = PBMap\Position\y
OldMx = OldPx + GadgetWidth(PBMap\Gadget) / 2 - x
OldMy = OldPy + GadgetHeight(PBMap\Gadget) / 2 - y
PBMap\Zoom = PBMap\Zoom + zoom
If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf
If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf
;Centered Zoom
LockMutex(PBMap\Drawing\Mutex)
LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing)
;Convert X, Y in tile.decimal into real pixels
PBMap\Position\x = PBMap\Drawing\Position\x * PBMap\TileSize
PBMap\Position\y = PBMap\Drawing\Position\y * PBMap\TileSize
MouseX = PBMap\Position\x + GadgetWidth(PBMap\Gadget) / 2 - x
MouseY = PBMap\Position\y + GadgetHeight(PBMap\Gadget) / 2 - y
;Cross-multiply to get the new center
PBMap\Position\x = (OldPx * MouseX) / OldMx
PBMap\Position\y = (OldPy * MouseY) / OldMy
;PBMap tile position in tile.decimal
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
PBMap\Drawing\PassNb = 1
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
UnlockMutex(PBMap\Drawing\Mutex)
;Start drawing
SignalSemaphore(PBMap\Drawing\Semaphore)
;If CallBackLocation send Location to function
If PBMap\CallBackLocation > 0
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
EndIf
EndProcedure
Procedure SetCallBackLocation(CallBackLocation.i) Procedure SetCallBackLocation(CallBackLocation.i)
PBMap\CallBackLocation = CallBackLocation PBMap\CallBackLocation = CallBackLocation
EndProcedure EndProcedure
@@ -936,6 +857,7 @@ Module PBMap
Protected Gadget.i Protected Gadget.i
Protected MouseX.i, MouseY.i Protected MouseX.i, MouseY.i
Protected Marker.Position Protected Marker.Position
Protected *Drawing.DrawingParameters
If IsGadget(PBMap\Gadget) And GadgetType(PBMap\Gadget) = #PB_GadgetType_Canvas If IsGadget(PBMap\Gadget) And GadgetType(PBMap\Gadget) = #PB_GadgetType_Canvas
Select Event Select Event
Case #PB_Event_Gadget ;{ Case #PB_Event_Gadget ;{
@@ -944,13 +866,7 @@ Module PBMap
Case PBMap\Gadget Case PBMap\Gadget
Select EventType() Select EventType()
Case #PB_EventType_MouseWheel Case #PB_EventType_MouseWheel
If PBMap\Options\WheelMouseRelative SetZoom(GetGadgetAttribute(PBMap\Gadget,#PB_Canvas_WheelDelta),#PB_Relative)
;Relative zoom (centered on the mouse)
SetZoomOnPosition(GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_WheelDelta))
Else
;Absolute zoom (centered on the center of the map)
SetZoom(GetGadgetAttribute(PBMap\Gadget,#PB_Canvas_WheelDelta), #PB_Relative)
EndIf
Case #PB_EventType_LeftButtonDown Case #PB_EventType_LeftButtonDown
;Check if we select a marker ;Check if we select a marker
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)
@@ -968,12 +884,11 @@ Module PBMap
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
Case #PB_EventType_MouseMove Case #PB_EventType_MouseMove
;If a move has been initiated by a left click
If PBMap\MoveStartingPoint\x <> - 1 If PBMap\MoveStartingPoint\x <> - 1
MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y
PBMap\Moving = #True PBMap\Moving = #True
;If it's marker move ;move Marker
If PBMap\EditMarkerIndex > -1 If PBMap\EditMarkerIndex > -1
SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex) SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex)
LatLon2XY(@PBMap\Marker()\Location, @Marker) LatLon2XY(@PBMap\Marker()\Location, @Marker)
@@ -984,32 +899,31 @@ Module PBMap
;New move values ;New move values
PBMap\Position\x - MouseX PBMap\Position\x - MouseX
PBMap\Position\y - MouseY PBMap\Position\y - MouseY
;Fill parameters and signal the drawing thread ;-*** Fill parameters and signal the drawing thread
LockMutex(PBMap\Drawing\Mutex) LockMutex(PBMap\Drawing\Mutex)
;PBMap tile position in tile.decimal ;PBMap tile position in tile.decimal
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
PBMap\Drawing\PassNb = 1 PBMap\Drawing\PassNb = 1
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation) XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
;If CallBackLocation send Location to function
If PBMap\CallBackLocation > 0
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
EndIf
UnlockMutex(PBMap\Drawing\Mutex) UnlockMutex(PBMap\Drawing\Mutex)
EndIf EndIf
;Start drawing ;Start drawing
SignalSemaphore(PBMap\Drawing\Semaphore) SignalSemaphore(PBMap\Drawing\Semaphore)
;If CallBackLocation send Location to function ;- ***
If PBMap\CallBackLocation > 0
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
EndIf
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
EndIf EndIf
Case #PB_EventType_LeftButtonUp Case #PB_EventType_LeftButtonUp
PBMap\Moving = #False PBMap\Moving = #False
PBMap\MoveStartingPoint\x = - 1 PBMap\MoveStartingPoint\x = - 1
;Stop marker move
If PBMap\EditMarkerIndex > -1 If PBMap\EditMarkerIndex > -1
PBMap\EditMarkerIndex = -1 PBMap\EditMarkerIndex = -1
Else Else ;Move Map
;Stop map move
LockMutex(PBMap\Drawing\Mutex) LockMutex(PBMap\Drawing\Mutex)
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
@@ -1153,10 +1067,10 @@ CompilerIf #PB_Compiler_IsMainFile
Case #Button_5 Case #Button_5
PBMap::SetZoom( - 1) PBMap::SetZoom( - 1)
Case #Gdt_LoadGpx Case #Gdt_LoadGpx
PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "*.gpx", 0)) PBMap::LoadGpxFile(OpenFileRequester("Choisissez un fichier <20> charger", "", "*.gpx", 0))
PBMap::ZoomToArea() ; <-To center the view, and zoom on the tracks PBMap::ZoomToArea() ; <-To center the view, and to viex all the track
Case #Gdt_AddMarker Case #Gdt_AddMarker
PBMap:: AddMarker(ValD(GetGadgetText(#String_0)), ValD(GetGadgetText(#String_1)), RGBA(Random(255), Random(255), Random(255),255)) PBMap:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255))
EndSelect EndSelect
Case #PB_Event_SizeWindow Case #PB_Event_SizeWindow
ResizeAll() ResizeAll()
@@ -1166,9 +1080,10 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::Quit() PBMap::Quit()
EndIf EndIf
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 1167 ; IDE Options = PureBasic 5.50 (Windows - x86)
; FirstLine = 1123 ; CursorPosition = 994
; FirstLine = 969
; Folding = --------- ; Folding = ---------
; EnableThread ; EnableThread
; EnableXP ; EnableXP