Cleaning and add

This commit is contained in:
djes
2016-07-25 12:30:33 +02:00
parent f7c7f0c02b
commit 90ce841007
2 changed files with 9821 additions and 113 deletions

9706
Roller.gpx Normal file

File diff suppressed because it is too large Load Diff

228
osm.pb
View File

@@ -90,12 +90,12 @@ Module OSM
Gadget.i ; Canvas Gadget Id Gadget.i ; Canvas Gadget Id
TargetLocation.Location ; Latitude and Longitude from focus point TargetLocation.Location ; Latitude and Longitude from focus point
*Drawing.DrawingParameters ; Focus Tile coord *Drawing.DrawingParameters ; Drawing parameters based on focus point
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
Position.Pixel ; Actual focus Point coords in pixels Position.Pixel ; Actual focus Point coords in pixels
MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map MoveStartingPoint.Pixel ; 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
@@ -123,7 +123,7 @@ Module OSM
Global OSM.OSM, Null.i Global OSM.OSM, Null.i
;- *** CURL specific *** ;- *** CURL specific ***
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
@@ -222,7 +222,7 @@ Module OSM
EndProcedure EndProcedure
;- *** ;- ***
Procedure InitOSM() Procedure InitOSM()
Protected Result.i Protected Result.i
@@ -245,17 +245,17 @@ Module OSM
Global Proxy = #True Global Proxy = #True
;- => Use this to customise your preferences ;- => Use this to customise your preferences
; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs")
; If Proxy ; If Proxy
; PreferenceGroup("PROXY") ; PreferenceGroup("PROXY")
; WritePreferenceString("ProxyURL", "myproxy.fr") ; WritePreferenceString("ProxyURL", "myproxy.fr")
; WritePreferenceString("ProxyPort", "myproxyport") ; WritePreferenceString("ProxyPort", "myproxyport")
; WritePreferenceString("ProxyUser", "myproxyname") ; WritePreferenceString("ProxyUser", "myproxyname")
; EndIf ; EndIf
; If Result ; If Result
; ClosePreferences() ; ClosePreferences()
; EndIf ; EndIf
Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs")
If Proxy If Proxy
@@ -498,10 +498,10 @@ Module OSM
If OSM\EmergencyQuit = 0 ;Quit before drawing If OSM\EmergencyQuit = 0 ;Quit before drawing
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
If IsImage(*Tile\nImage) If IsImage(*Tile\nImage)
MovePathCursor(x,y) MovePathCursor(x,y)
DrawVectorImage(ImageID(*Tile\nImage)) DrawVectorImage(ImageID(*Tile\nImage))
MovePathCursor(x,y) MovePathCursor(x,y)
DrawVectorText(Str(x) + ", " + Str(y)) DrawVectorText(Str(x) + ", " + Str(y))
Else Else
Debug "Image missing" Debug "Image missing"
OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw
@@ -512,7 +512,7 @@ Module OSM
EndProcedure EndProcedure
Procedure DrawTiles() Procedure DrawTiles(*Drawing.DrawingParameters)
Protected x.i, y.i Protected x.i, y.i
@@ -538,22 +538,25 @@ Module OSM
If *NewTile If *NewTile
With *NewTile With *NewTile
;Keep a track of tiles (especially to free memory)
AddElement(OSM\TilesThreads()) AddElement(OSM\TilesThreads())
OSM\TilesThreads()\Tile = *NewTile OSM\TilesThreads()\Tile = *NewTile
;New tile parameters
\x = CenterX + x * OSM\TileSize \x = CenterX + x * OSM\TileSize
\y = CenterY + y * OSM\TileSize \y = CenterY + y * OSM\TileSize
\OSMTileX = tx + x \OSMTileX = tx + x
\OSMTileY = ty + y \OSMTileY = ty + y
\OSMZoom = OSM\Zoom \OSMZoom = OSM\Zoom
;Check if the image exists, if not, load it in the background ;Check if the image exists
\nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY)
If \nImage = -1 If \nImage = -1
;If not, load it in the background
\GetImageThread = CreateThread(@GetImageThread(), *NewTile) \GetImageThread = CreateThread(@GetImageThread(), *NewTile)
OSM\TilesThreads()\GetImageThread = \GetImageThread OSM\TilesThreads()\GetImageThread = \GetImageThread
Debug " Creating get image thread nb " + Str(\GetImageThread)
EndIf EndIf
Debug " Creating get image thread nb " + Str(\GetImageThread)
DrawTile(*NewTile) DrawTile(*NewTile)
EndWith EndWith
@@ -565,6 +568,8 @@ Module OSM
Next Next
Next Next
;Free tile memory when the loading thread has finished
;TODO : exit this proc from drawtiles in a special "free ressources" task
ForEach OSM\TilesThreads() ForEach OSM\TilesThreads()
If IsThread(OSM\TilesThreads()\GetImageThread) = 0 If IsThread(OSM\TilesThreads()\GetImageThread) = 0
FreeMemory(OSM\TilesThreads()\Tile) FreeMemory(OSM\TilesThreads()\Tile)
@@ -574,10 +579,10 @@ Module OSM
EndProcedure EndProcedure
Procedure DrawTrack() Procedure DrawTrack()
Protected Pixel.Pixel Protected Pixel.Pixel
Protected Location.Location Protected Location.Location
If ListSize(OSM\track())>0 If ListSize(OSM\track())>0
ForEach OSM\track() ForEach OSM\track()
If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0
@@ -587,14 +592,14 @@ Module OSM
Else Else
AddPathLine(Pixel\X,Pixel\Y) AddPathLine(Pixel\X,Pixel\Y)
EndIf EndIf
EndIf EndIf
Next Next
VectorSourceColor(RGBA(0, 255, 0, 150)) VectorSourceColor(RGBA(0, 255, 0, 150))
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
EndIf EndIf
EndProcedure EndProcedure
Procedure Pointer(x.l,y.l,color.l=#Red) Procedure Pointer(x.l,y.l,color.l=#Red)
@@ -621,7 +626,7 @@ Module OSM
Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterX = GadgetWidth(OSM\Gadget) / 2
Protected CenterY = GadgetHeight(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2
DrawTiles() DrawTiles(*Drawing)
LockMutex(OSM\DrawingMutex) LockMutex(OSM\DrawingMutex)
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
@@ -634,7 +639,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
If OSM\Dirty If OSM\Dirty And OSM\EmergencyQuit = #False
Debug "Something was dirty ! We try again to redraw" Debug "Something was dirty ! We try again to redraw"
;Delay(250) ;Delay(250)
@@ -770,91 +775,88 @@ EndModule
;Demonstration ;Demonstration
CompilerIf #PB_Compiler_IsMainFile CompilerIf #PB_Compiler_IsMainFile
Enumeration Enumeration
#Window_0 #Window_0
#Map #Map
#Button_0 #Button_0
#Button_1 #Button_1
#Button_2 #Button_2
#Button_3 #Button_3
#Button_4 #Button_4
#Button_5 #Button_5
#Combo_0 #Combo_0
#Text_0 #Text_0
#Text_1 #Text_1
#Text_2 #Text_2
#Text_3 #Text_3
#Text_4 #Text_4
#String_0 #String_0
#String_1 #String_1
#Gdt_LoadGpx #Gdt_LoadGpx
EndEnumeration EndEnumeration
Structure Location Structure Location
Longitude.d Longitude.d
Latitude.d Latitude.d
EndStructure EndStructure
Procedure UpdateLocation(*Location.Location)
SetGadgetText(#String_0,StrD(*Location\Latitude))
SetGadgetText(#String_1,StrD(*Location\Longitude))
ProcedureReturn 0
EndProcedure
;- Main
If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
OSM::InitOSM() Procedure UpdateLocation(*Location.Location)
LoadFont(0, "Wingdings", 12) SetGadgetText(#String_0,StrD(*Location\Latitude))
LoadFont(1, "Arial", 12, #PB_Font_Bold) SetGadgetText(#String_1,StrD(*Location\Longitude))
ProcedureReturn 0
OSM::OSMGadget(#Map, 10, 10, 512, 512) EndProcedure
;- Main
TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0))
ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0))
ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0))
ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0))
TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ")
ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ")
StringGadget(#String_0, 600, 230, 90, 20, "")
TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
StringGadget(#String_1, 600, 250, 90, 20, "")
ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX")
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation())
Repeat
Event = WaitWindowEvent()
OSM::Event(Event) OSM::InitOSM()
Select Event LoadFont(0, "Wingdings", 12)
Case #PB_Event_CloseWindow : Quit = 1 LoadFont(1, "Arial", 12, #PB_Font_Bold)
Case #PB_Event_Gadget ;{
Gadget = EventGadget() OSM::OSMGadget(#Map, 10, 10, 512, 512)
Select Gadget
Case #Button_4 TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ")
OSM::SetZoom(1) ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0))
Case #Button_5 ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0))
OSM::SetZoom( - 1) ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0))
Case #Gdt_LoadGpx ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0))
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ")
EndSelect ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
EndSelect ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
Until Quit = #True TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ")
EndIf StringGadget(#String_0, 600, 230, 90, 20, "")
<<<<<<< HEAD TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
======= StringGadget(#String_1, 600, 250, 90, 20, "")
ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX")
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation())
Repeat
Event = WaitWindowEvent()
OSM::Event(Event)
Select Event
Case #PB_Event_CloseWindow : Quit = 1
Case #PB_Event_Gadget ;{
Gadget = EventGadget()
Select Gadget
Case #Button_4
OSM::SetZoom(1)
Case #Button_5
OSM::SetZoom( - 1)
Case #Gdt_LoadGpx
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0))
EndSelect
EndSelect
Until Quit = #True
EndIf
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
; CursorPosition = 726 ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; FirstLine = 683 ; CursorPosition = 831
; FirstLine = 803
; Folding = ----- ; Folding = -----
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableXP
; EnableXP
>>>>>>> refs/remotes/origin/master