Renamed OSM to PBMap
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
;**************************************************************
|
;**************************************************************
|
||||||
; Program: OSM (OpenStreetMap Module)
|
; Program: PBMap
|
||||||
|
; Description: Permits the use of tiled maps like
|
||||||
|
; OpenStreetMap in a handy PureBASIC module
|
||||||
; Author: Thyphoon And Djes
|
; Author: Thyphoon And Djes
|
||||||
; Date: Mai 17, 2016
|
; Date: Mai 17, 2016
|
||||||
; License: Free, unrestricted, credit appreciated
|
; License: Free, unrestricted, credit appreciated
|
||||||
; but not required.
|
; but not required.
|
||||||
; Note: Please share improvement !
|
; Note: Please share improvement !
|
||||||
; Thanks: Progi1984,
|
; Thanks: Progi1984
|
||||||
;**************************************************************
|
;**************************************************************
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_Thread = #False
|
CompilerIf #PB_Compiler_Thread = #False
|
||||||
@@ -19,12 +21,12 @@ InitNetwork()
|
|||||||
UsePNGImageDecoder()
|
UsePNGImageDecoder()
|
||||||
UsePNGImageEncoder()
|
UsePNGImageEncoder()
|
||||||
|
|
||||||
DeclareModule OSM
|
DeclareModule PBMap
|
||||||
;-Show debug infos
|
;-Show debug infos
|
||||||
Global Verbose = #True
|
Global Verbose = #True
|
||||||
;-Proxy ON/OFF
|
;-Proxy ON/OFF
|
||||||
Global Proxy = #True
|
Global Proxy = #True
|
||||||
Declare InitOSM()
|
Declare InitPBMap()
|
||||||
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
||||||
Declare Event(Event.l)
|
Declare Event(Event.l)
|
||||||
Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute)
|
Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute)
|
||||||
@@ -42,7 +44,7 @@ DeclareModule OSM
|
|||||||
Declare.i GetZoom()
|
Declare.i GetZoom()
|
||||||
EndDeclareModule
|
EndDeclareModule
|
||||||
|
|
||||||
Module OSM
|
Module PBMap
|
||||||
|
|
||||||
EnableExplicit
|
EnableExplicit
|
||||||
|
|
||||||
@@ -64,9 +66,9 @@ Module OSM
|
|||||||
;- Tile Structure
|
;- Tile Structure
|
||||||
Structure Tile
|
Structure Tile
|
||||||
Position.Position
|
Position.Position
|
||||||
OSMTileX.i
|
PBMapTileX.i
|
||||||
OSMTileY.i
|
PBMapTileY.i
|
||||||
OSMZoom.i
|
PBMapZoom.i
|
||||||
nImage.i
|
nImage.i
|
||||||
GetImageThread.i
|
GetImageThread.i
|
||||||
EndStructure
|
EndStructure
|
||||||
@@ -74,9 +76,9 @@ Module OSM
|
|||||||
Structure DrawingParameters
|
Structure DrawingParameters
|
||||||
Position.Position
|
Position.Position
|
||||||
Canvas.i
|
Canvas.i
|
||||||
OSMTileX.i
|
PBMapTileX.i
|
||||||
OSMTileY.i
|
PBMapTileY.i
|
||||||
OSMZoom.i
|
PBMapZoom.i
|
||||||
Mutex.i
|
Mutex.i
|
||||||
TargetLocation.Location
|
TargetLocation.Location
|
||||||
CenterX.i
|
CenterX.i
|
||||||
@@ -109,8 +111,8 @@ Module OSM
|
|||||||
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
|
||||||
|
|
||||||
;-OSM Structure
|
;-PBMap Structure
|
||||||
Structure OSM
|
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
|
||||||
@@ -141,7 +143,7 @@ Module OSM
|
|||||||
EditMarkerIndex.l
|
EditMarkerIndex.l
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Global OSM.OSM, Null.i
|
Global PBMap.PBMap, Null.i
|
||||||
|
|
||||||
;Shows an error msg and terminates the program
|
;Shows an error msg and terminates the program
|
||||||
Procedure Error(msg.s)
|
Procedure Error(msg.s)
|
||||||
@@ -216,25 +218,25 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
;- ***
|
;- ***
|
||||||
|
|
||||||
Procedure InitOSM()
|
Procedure InitPBMap()
|
||||||
Protected Result.i
|
Protected Result.i
|
||||||
If Verbose
|
If Verbose
|
||||||
OpenConsole()
|
OpenConsole()
|
||||||
EndIf
|
EndIf
|
||||||
OSM\HDDCachePath = GetTemporaryDirectory()
|
PBMap\HDDCachePath = GetTemporaryDirectory()
|
||||||
OSM\ServerURL = "http://tile.openstreetmap.org/"
|
PBMap\ServerURL = "http://tile.openstreetmap.org/"
|
||||||
OSM\ZoomMin = 0
|
PBMap\ZoomMin = 0
|
||||||
OSM\ZoomMax = 18
|
PBMap\ZoomMax = 18
|
||||||
OSM\MoveStartingPoint\x = - 1
|
PBMap\MoveStartingPoint\x = - 1
|
||||||
OSM\TileSize = 256
|
PBMap\TileSize = 256
|
||||||
OSM\Dirty = #False
|
PBMap\Dirty = #False
|
||||||
OSM\Drawing\Mutex = CreateMutex()
|
PBMap\Drawing\Mutex = CreateMutex()
|
||||||
OSM\Drawing\Semaphore = CreateSemaphore()
|
PBMap\Drawing\Semaphore = CreateSemaphore()
|
||||||
OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected
|
PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected
|
||||||
OSM\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
||||||
;- Proxy details
|
;- Proxy details
|
||||||
;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
|
||||||
; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs")
|
; Result = CreatePreferences(GetHomeDirectory() + "PBMap.prefs")
|
||||||
; If Proxy
|
; If Proxy
|
||||||
; PreferenceGroup("PROXY")
|
; PreferenceGroup("PROXY")
|
||||||
; WritePreferenceString("ProxyURL", "myproxy.fr")
|
; WritePreferenceString("ProxyURL", "myproxy.fr")
|
||||||
@@ -244,7 +246,7 @@ Module OSM
|
|||||||
; If Result
|
; If Result
|
||||||
; ClosePreferences()
|
; ClosePreferences()
|
||||||
; EndIf
|
; EndIf
|
||||||
Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs")
|
Result = OpenPreferences(GetHomeDirectory() + "PBMap.prefs")
|
||||||
If Proxy
|
If Proxy
|
||||||
PreferenceGroup("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:", "")
|
||||||
@@ -257,24 +259,24 @@ Module OSM
|
|||||||
EndIf
|
EndIf
|
||||||
curl_global_init(#CURL_GLOBAL_WIN32);
|
curl_global_init(#CURL_GLOBAL_WIN32);
|
||||||
;- Main drawing thread launching
|
;- Main drawing thread launching
|
||||||
OSM\MainDrawingThread = CreateThread(@DrawingThread(), @OSM\Drawing)
|
PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing)
|
||||||
If OSM\MainDrawingThread = 0
|
If PBMap\MainDrawingThread = 0
|
||||||
Error("MapGadget : can't create main drawing thread.")
|
Error("MapGadget : can't create main drawing thread.")
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Quit()
|
Procedure Quit()
|
||||||
;kill main drawing thread (nicer than KillThread(OSM\MainDrawingThread))
|
;kill main drawing thread (nicer than KillThread(PBMap\MainDrawingThread))
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
OSM\Drawing\End = #True
|
PBMap\Drawing\End = #True
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
;wait for loading threads to finish nicely
|
;wait for loading threads to finish nicely
|
||||||
ResetList( OSM\TilesThreads())
|
ResetList(PBMap\TilesThreads())
|
||||||
While NextElement(OSM\TilesThreads())
|
While NextElement(PBMap\TilesThreads())
|
||||||
If IsThread(OSM\TilesThreads()\GetImageThread) = 0
|
If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
|
||||||
FreeMemory(OSM\TilesThreads()\Tile)
|
FreeMemory(PBMap\TilesThreads()\Tile)
|
||||||
DeleteElement(OSM\TilesThreads())
|
DeleteElement(PBMap\TilesThreads())
|
||||||
ResetList( OSM\TilesThreads())
|
ResetList( PBMap\TilesThreads())
|
||||||
EndIf
|
EndIf
|
||||||
Wend
|
Wend
|
||||||
curl_global_cleanup()
|
curl_global_cleanup()
|
||||||
@@ -296,17 +298,17 @@ Module OSM
|
|||||||
|
|
||||||
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
|
||||||
OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height)
|
PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
|
||||||
Else
|
Else
|
||||||
OSM\Gadget = Gadget
|
PBMap\Gadget = Gadget
|
||||||
CanvasGadget(OSM\Gadget, X, Y, Width, Height)
|
CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;*** Converts coords to tile.decimal
|
;*** Converts coords to tile.decimal
|
||||||
;Warning, structures used in parameters are not tested
|
;Warning, structures used in parameters are not tested
|
||||||
Procedure LatLon2XY(*Location.Location, *Coords.Position)
|
Procedure LatLon2XY(*Location.Location, *Coords.Position)
|
||||||
Protected n.d = Pow(2.0, OSM\Zoom)
|
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||||
Protected LatRad.d = Radian(*Location\Latitude)
|
Protected LatRad.d = Radian(*Location\Latitude)
|
||||||
*Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0)
|
*Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0)
|
||||||
*Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
|
*Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
|
||||||
@@ -317,7 +319,7 @@ Module OSM
|
|||||||
;*** Converts tile.decimal to coords
|
;*** Converts tile.decimal to coords
|
||||||
;Warning, structures used in parameters are not tested
|
;Warning, structures used in parameters are not tested
|
||||||
Procedure XY2LatLon(*Coords.Position, *Location.Location)
|
Procedure XY2LatLon(*Coords.Position, *Location.Location)
|
||||||
Protected n.d = Pow(2.0, OSM\Zoom)
|
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||||
Protected LatitudeRad.d
|
Protected LatitudeRad.d
|
||||||
*Location\Longitude = *Coords\x / n * 360.0 - 180.0
|
*Location\Longitude = *Coords\x / n * 360.0 - 180.0
|
||||||
LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n)))
|
LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n)))
|
||||||
@@ -343,8 +345,8 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize
|
Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize
|
||||||
Protected mapWidth.l = Pow(2, OSM\Zoom + 8)
|
Protected mapWidth.l = Pow(2, PBMap\Zoom + 8)
|
||||||
Protected mapHeight.l = Pow(2, OSM\Zoom + 8)
|
Protected mapHeight.l = Pow(2, PBMap\Zoom + 8)
|
||||||
Protected x1.l,y1.l
|
Protected x1.l,y1.l
|
||||||
; get x value
|
; get x value
|
||||||
x1 = (*Location\Longitude+180)*(mapWidth/360)
|
x1 = (*Location\Longitude+180)*(mapWidth/360)
|
||||||
@@ -354,14 +356,14 @@ Module OSM
|
|||||||
y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
||||||
Protected x2.l, y2.l
|
Protected x2.l, y2.l
|
||||||
; get x value
|
; get x value
|
||||||
x2 = (OSM\TargetLocation\Longitude+180)*(mapWidth/360)
|
x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360)
|
||||||
; convert from degrees To radians
|
; convert from degrees To radians
|
||||||
latRad = OSM\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(OSM\Gadget)/2 - (x2-x1)
|
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
||||||
*Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1)
|
*Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure LoadGpxFile(file.s)
|
Procedure LoadGpxFile(file.s)
|
||||||
@@ -376,17 +378,17 @@ Module OSM
|
|||||||
Protected *MainNode,*subNode,*child,child.l
|
Protected *MainNode,*subNode,*child,child.l
|
||||||
*MainNode=MainXMLNode(0)
|
*MainNode=MainXMLNode(0)
|
||||||
*MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg")
|
*MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg")
|
||||||
ClearList(OSM\track())
|
ClearList(PBMap\track())
|
||||||
For child = 1 To XMLChildCount(*MainNode)
|
For child = 1 To XMLChildCount(*MainNode)
|
||||||
*child = ChildXMLNode(*MainNode, child)
|
*child = ChildXMLNode(*MainNode, child)
|
||||||
AddElement(OSM\track())
|
AddElement(PBMap\track())
|
||||||
If ExamineXMLAttributes(*child)
|
If ExamineXMLAttributes(*child)
|
||||||
While NextXMLAttribute(*child)
|
While NextXMLAttribute(*child)
|
||||||
Select XMLAttributeName(*child)
|
Select XMLAttributeName(*child)
|
||||||
Case "lat"
|
Case "lat"
|
||||||
OSM\track()\Latitude=ValD(XMLAttributeValue(*child))
|
PBMap\track()\Latitude=ValD(XMLAttributeValue(*child))
|
||||||
Case "lon"
|
Case "lon"
|
||||||
OSM\track()\Longitude=ValD(XMLAttributeValue(*child))
|
PBMap\track()\Longitude=ValD(XMLAttributeValue(*child))
|
||||||
EndSelect
|
EndSelect
|
||||||
Wend
|
Wend
|
||||||
EndIf
|
EndIf
|
||||||
@@ -397,9 +399,9 @@ Module OSM
|
|||||||
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")
|
||||||
MyDebug("Check if we have this image in memory")
|
MyDebug("Check if we have this image in memory")
|
||||||
If FindMapElement(OSM\MemCache\Images(), key)
|
If FindMapElement(PBMap\MemCache\Images(), key)
|
||||||
MyDebug("Key : " + key + " found !")
|
MyDebug("Key : " + key + " found !")
|
||||||
ProcedureReturn OSM\MemCache\Images()\nImage
|
ProcedureReturn PBMap\MemCache\Images()\nImage
|
||||||
Else
|
Else
|
||||||
MyDebug("Key : " + key + " not found !")
|
MyDebug("Key : " + key + " not found !")
|
||||||
ProcedureReturn -1
|
ProcedureReturn -1
|
||||||
@@ -423,7 +425,7 @@ Module OSM
|
|||||||
Protected *Buffer
|
Protected *Buffer
|
||||||
Protected nImage.i = -1
|
Protected nImage.i = -1
|
||||||
Protected FileHandle.i
|
Protected FileHandle.i
|
||||||
Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
|
Protected TileURL.s = PBMap\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
|
||||||
MyDebug("Check if we have this image on Web")
|
MyDebug("Check if we have this image on Web")
|
||||||
If Proxy
|
If Proxy
|
||||||
FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
||||||
@@ -454,16 +456,16 @@ Module OSM
|
|||||||
|
|
||||||
Procedure GetImageThread(*Tile.Tile)
|
Procedure GetImageThread(*Tile.Tile)
|
||||||
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\PBMapZoom), 4, "0") + "X" + RSet(Str(*Tile\PBMapTileX), 8, "0") + "Y" + RSet(Str(*Tile\PBMapTileY), 8, "0")
|
||||||
Protected CacheFile.s = OSM\HDDCachePath + "OSM_" + Str(*Tile\OSMZoom) + "_" + Str(*Tile\OSMTileX) + "_" + Str(*Tile\OSMTileY) + ".png"
|
Protected CacheFile.s = PBMap\HDDCachePath + "PBMap_" + Str(*Tile\PBMapZoom) + "_" + Str(*Tile\PBMapTileX) + "_" + Str(*Tile\PBMapTileY) + ".png"
|
||||||
;Adding the image to the cache if possible
|
;Adding the image to the cache if possible
|
||||||
AddMapElement(OSM\MemCache\Images(), key)
|
AddMapElement(PBMap\MemCache\Images(), key)
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
nImage = GetTileFromHDD(CacheFile)
|
||||||
If nImage = -1
|
If nImage = -1
|
||||||
nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY, CacheFile)
|
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile)
|
||||||
EndIf
|
EndIf
|
||||||
If nImage <> -1
|
If nImage <> -1
|
||||||
OSM\MemCache\Images(key)\nImage = nImage
|
PBMap\MemCache\Images(key)\nImage = nImage
|
||||||
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
|
||||||
@@ -477,7 +479,7 @@ Module OSM
|
|||||||
Procedure DrawTile(*Tile.Tile)
|
Procedure DrawTile(*Tile.Tile)
|
||||||
Protected x = *Tile\Position\x
|
Protected x = *Tile\Position\x
|
||||||
Protected y = *Tile\Position\y
|
Protected y = *Tile\Position\y
|
||||||
MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX))
|
MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX))
|
||||||
MyDebug(" at coords " + Str(x) + "," + Str(y))
|
MyDebug(" at coords " + Str(x) + "," + Str(y))
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
DrawVectorImage(ImageID(*Tile\nImage))
|
DrawVectorImage(ImageID(*Tile\nImage))
|
||||||
@@ -487,17 +489,17 @@ Module OSM
|
|||||||
Protected x = *Tile\Position\x
|
Protected x = *Tile\Position\x
|
||||||
Protected y = *Tile\Position\y
|
Protected y = *Tile\Position\y
|
||||||
Protected Text$ = "Loading"
|
Protected Text$ = "Loading"
|
||||||
MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX))
|
MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX))
|
||||||
MyDebug(" at coords " + Str(x) + "," + Str(y))
|
MyDebug(" at coords " + Str(x) + "," + Str(y))
|
||||||
BeginVectorLayer()
|
BeginVectorLayer()
|
||||||
;MovePathCursor(x, y)
|
;MovePathCursor(x, y)
|
||||||
VectorSourceColor(RGBA(255, 255, 255, 128))
|
VectorSourceColor(RGBA(255, 255, 255, 128))
|
||||||
AddPathBox(x, y, OSM\TileSize, OSM\TileSize)
|
AddPathBox(x, y, PBMap\TileSize, PBMap\TileSize)
|
||||||
FillPath()
|
FillPath()
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
VectorFont(FontID(OSM\Font), OSM\TileSize / 20)
|
VectorFont(FontID(PBMap\Font), PBMap\TileSize / 20)
|
||||||
VectorSourceColor(RGBA(150, 150, 150, 255))
|
VectorSourceColor(RGBA(150, 150, 150, 255))
|
||||||
MovePathCursor(x + (OSM\TileSize - VectorTextWidth(Text$)) / 2, y + (OSM\TileSize - VectorTextHeight(Text$)) / 2)
|
MovePathCursor(x + (PBMap\TileSize - VectorTextWidth(Text$)) / 2, y + (PBMap\TileSize - VectorTextHeight(Text$)) / 2)
|
||||||
DrawVectorText(Text$)
|
DrawVectorText(Text$)
|
||||||
EndVectorLayer()
|
EndVectorLayer()
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -506,33 +508,33 @@ Module OSM
|
|||||||
Protected x.i, y.i
|
Protected x.i, y.i
|
||||||
Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() !
|
Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() !
|
||||||
Protected ty = Int(*Drawing\Position\y)
|
Protected ty = Int(*Drawing\Position\y)
|
||||||
Protected nx = *Drawing\CenterX / OSM\TileSize ;How many tiles around the point
|
Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
|
||||||
Protected ny = *Drawing\CenterY / OSM\TileSize
|
Protected ny = *Drawing\CenterY / PBMap\TileSize
|
||||||
MyDebug("Drawing tiles")
|
MyDebug("Drawing tiles")
|
||||||
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
|
||||||
;Was quiting the loop if a move occured, giving maybe smoother movement
|
;Was quiting the loop if a move occured, giving maybe smoother movement
|
||||||
;If OSM\Moving
|
;If PBMap\Moving
|
||||||
; Break 2
|
; Break 2
|
||||||
;EndIf
|
;EndIf
|
||||||
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
|
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
|
||||||
If *NewTile
|
If *NewTile
|
||||||
With *NewTile
|
With *NewTile
|
||||||
;Keep a track of tiles (especially to free memory)
|
;Keep a track of tiles (especially to free memory)
|
||||||
AddElement(OSM\TilesThreads())
|
AddElement(PBMap\TilesThreads())
|
||||||
OSM\TilesThreads()\Tile = *NewTile
|
PBMap\TilesThreads()\Tile = *NewTile
|
||||||
;New tile parameters
|
;New tile parameters
|
||||||
\Position\x = *Drawing\CenterX + x * OSM\TileSize - *Drawing\DeltaX
|
\Position\x = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX
|
||||||
\Position\y = *Drawing\CenterY + y * OSM\TileSize - *Drawing\DeltaY
|
\Position\y = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY
|
||||||
\OSMTileX = tx + x
|
\PBMapTileX = tx + x
|
||||||
\OSMTileY = ty + y
|
\PBMapTileY = ty + y
|
||||||
\OSMZoom = OSM\Zoom
|
\PBMapZoom = PBMap\Zoom
|
||||||
;Check if the image exists
|
;Check if the image exists
|
||||||
\nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY)
|
\nImage = GetTileFromMem(\PBMapZoom, \PBMapTileX, \PBMapTileY)
|
||||||
If \nImage = -1
|
If \nImage = -1
|
||||||
;If not, load it in the background
|
;If not, load it in the background
|
||||||
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
|
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
|
||||||
OSM\TilesThreads()\GetImageThread = \GetImageThread
|
PBMap\TilesThreads()\GetImageThread = \GetImageThread
|
||||||
MyDebug(" Creating get image thread nb " + Str(\GetImageThread))
|
MyDebug(" Creating get image thread nb " + Str(\GetImageThread))
|
||||||
EndIf
|
EndIf
|
||||||
If IsImage(\nImage)
|
If IsImage(\nImage)
|
||||||
@@ -551,10 +553,10 @@ Module OSM
|
|||||||
Next
|
Next
|
||||||
;Free tile memory when the loading thread has finished
|
;Free tile memory when the loading thread has finished
|
||||||
;TODO : get out this proc from drawtiles in a special "free ressources" task
|
;TODO : get out this proc from drawtiles in a special "free ressources" task
|
||||||
ForEach OSM\TilesThreads()
|
ForEach PBMap\TilesThreads()
|
||||||
If IsThread(OSM\TilesThreads()\GetImageThread) = 0
|
If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
|
||||||
FreeMemory(OSM\TilesThreads()\Tile)
|
FreeMemory(PBMap\TilesThreads()\Tile)
|
||||||
DeleteElement(OSM\TilesThreads())
|
DeleteElement(PBMap\TilesThreads())
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -586,7 +588,7 @@ Module OSM
|
|||||||
VectorSourceColor(RGBA(255, 255, 255, 255))
|
VectorSourceColor(RGBA(255, 255, 255, 255))
|
||||||
AddPathCircle(x,y-20,12)
|
AddPathCircle(x,y-20,12)
|
||||||
FillPath()
|
FillPath()
|
||||||
VectorFont(FontID(OSM\Font), 13)
|
VectorFont(FontID(PBMap\Font), 13)
|
||||||
MovePathCursor(x-VectorTextWidth(Str(dist))/2, y-20-VectorTextHeight(Str(dist))/2)
|
MovePathCursor(x-VectorTextWidth(Str(dist))/2, y-20-VectorTextHeight(Str(dist))/2)
|
||||||
VectorSourceColor(RGBA(0, 0, 0, 255))
|
VectorSourceColor(RGBA(0, 0, 0, 255))
|
||||||
DrawVectorText(Str(dist))
|
DrawVectorText(Str(dist))
|
||||||
@@ -596,13 +598,13 @@ Module OSM
|
|||||||
Protected Pixel.PixelPosition
|
Protected Pixel.PixelPosition
|
||||||
Protected Location.Location
|
Protected Location.Location
|
||||||
Protected km.f, memKm.i
|
Protected km.f, memKm.i
|
||||||
If ListSize(OSM\track())>0
|
If ListSize(PBMap\track())>0
|
||||||
;Trace Track
|
;Trace Track
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
ForEach OSM\track()
|
ForEach PBMap\track()
|
||||||
If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0
|
If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0
|
||||||
GetPixelCoordFromLocation(@OSM\track(),@Pixel)
|
GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
||||||
If ListIndex(OSM\track())=0
|
If ListIndex(PBMap\track())=0
|
||||||
MovePathCursor(Pixel\X, Pixel\Y)
|
MovePathCursor(Pixel\X, Pixel\Y)
|
||||||
Else
|
Else
|
||||||
AddPathLine(Pixel\X, Pixel\Y)
|
AddPathLine(Pixel\X, Pixel\Y)
|
||||||
@@ -612,50 +614,50 @@ Module OSM
|
|||||||
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)
|
||||||
;Draw Distance
|
;Draw Distance
|
||||||
ForEach OSM\track()
|
ForEach PBMap\track()
|
||||||
;-Test Distance
|
;-Test Distance
|
||||||
If ListIndex(OSM\track())=0
|
If ListIndex(PBMap\track())=0
|
||||||
Location\Latitude=OSM\track()\Latitude
|
Location\Latitude=PBMap\track()\Latitude
|
||||||
Location\Longitude=OSM\track()\Longitude
|
Location\Longitude=PBMap\track()\Longitude
|
||||||
Else
|
Else
|
||||||
km=km+HaversineInKM(@Location,@OSM\track()) ;<- display Distance
|
km=km+HaversineInKM(@Location,@PBMap\track()) ;<- display Distance
|
||||||
Location\Latitude=OSM\track()\Latitude
|
Location\Latitude=PBMap\track()\Latitude
|
||||||
Location\Longitude=OSM\track()\Longitude
|
Location\Longitude=PBMap\track()\Longitude
|
||||||
EndIf
|
EndIf
|
||||||
GetPixelCoordFromLocation(@OSM\track(),@Pixel)
|
GetPixelCoordFromLocation(@PBMap\track(),@Pixel)
|
||||||
If Int(km)<>memKm
|
If Int(km)<>memKm
|
||||||
memKm=Int(km)
|
memKm=Int(km)
|
||||||
If OSM\Zoom>10
|
If PBMap\Zoom>10
|
||||||
BeginVectorLayer()
|
BeginVectorLayer()
|
||||||
TrackPointer(Pixel\X , Pixel\Y,Int(km))
|
TrackPointer(Pixel\X , Pixel\Y,Int(km))
|
||||||
EndVectorLayer()
|
EndVectorLayer()
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Add a Marker To the Map
|
; Add a Marker To the Map
|
||||||
Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
||||||
AddElement(OSM\Marker())
|
AddElement(PBMap\Marker())
|
||||||
OSM\Marker()\Location\Latitude=Latitude
|
PBMap\Marker()\Location\Latitude=Latitude
|
||||||
OSM\Marker()\Location\Longitude=Longitude
|
PBMap\Marker()\Location\Longitude=Longitude
|
||||||
OSM\Marker()\color=color
|
PBMap\Marker()\color=color
|
||||||
OSM\Marker()\CallBackPointer = CallBackPointer
|
PBMap\Marker()\CallBackPointer = CallBackPointer
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Draw all markers on the screen !
|
; Draw all markers on the screen !
|
||||||
Procedure DrawMarker(*Drawing.DrawingParameters)
|
Procedure DrawMarker(*Drawing.DrawingParameters)
|
||||||
Protected Pixel.PixelPosition
|
Protected Pixel.PixelPosition
|
||||||
ForEach OSM\Marker()
|
ForEach PBMap\Marker()
|
||||||
If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0
|
If PBMap\Marker()\Location\Latitude <> 0 And PBMap\Marker()\Location\Longitude <> 0
|
||||||
GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel)
|
GetPixelCoordFromLocation(PBMap\Marker()\Location, @Pixel)
|
||||||
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^
|
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^
|
||||||
If OSM\Marker()\CallBackPointer > 0
|
If PBMap\Marker()\CallBackPointer > 0
|
||||||
CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
||||||
Else
|
Else
|
||||||
Pointer(Pixel\X, Pixel\Y, OSM\Marker()\color)
|
Pointer(Pixel\X, Pixel\Y, PBMap\Marker()\color)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
@@ -675,17 +677,17 @@ Module OSM
|
|||||||
CopyStructure(*SharedDrawing, @Drawing, DrawingParameters)
|
CopyStructure(*SharedDrawing, @Drawing, DrawingParameters)
|
||||||
UnlockMutex(*SharedDrawing\Mutex)
|
UnlockMutex(*SharedDrawing\Mutex)
|
||||||
;Precalc some values
|
;Precalc some values
|
||||||
Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2
|
Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||||
Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2
|
Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2
|
||||||
;Pixel shift, aka position in the tile
|
;Pixel shift, aka position in the tile
|
||||||
Px = Drawing\Position\x : Py = Drawing\Position\y
|
Px = Drawing\Position\x : Py = Drawing\Position\y
|
||||||
Drawing\DeltaX = Px * OSM\TileSize - (Int(Px) * OSM\TileSize) ;Don't forget the Int() !
|
Drawing\DeltaX = Px * PBMap\TileSize - (Int(Px) * PBMap\TileSize) ;Don't forget the Int() !
|
||||||
Drawing\DeltaY = Py * OSM\TileSize - (Int(Py) * OSM\TileSize)
|
Drawing\DeltaY = Py * PBMap\TileSize - (Int(Py) * PBMap\TileSize)
|
||||||
Drawing\TargetLocation\Latitude = OSM\TargetLocation\Latitude
|
Drawing\TargetLocation\Latitude = PBMap\TargetLocation\Latitude
|
||||||
Drawing\TargetLocation\Longitude = OSM\TargetLocation\Longitude
|
Drawing\TargetLocation\Longitude = PBMap\TargetLocation\Longitude
|
||||||
Drawing\Dirty = #False
|
Drawing\Dirty = #False
|
||||||
;Main drawing stuff
|
;Main drawing stuff
|
||||||
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
|
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||||
DrawTiles(@Drawing)
|
DrawTiles(@Drawing)
|
||||||
DrawTrack(@Drawing)
|
DrawTrack(@Drawing)
|
||||||
DrawMarker(@Drawing)
|
DrawMarker(@Drawing)
|
||||||
@@ -707,32 +709,32 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Refresh()
|
Procedure Refresh()
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure SetLocation(latitude.d, longitude.d, zoom = 15, Mode.i = #PB_Absolute)
|
Procedure SetLocation(latitude.d, longitude.d, zoom = 15, Mode.i = #PB_Absolute)
|
||||||
Select Mode
|
Select Mode
|
||||||
Case #PB_Absolute
|
Case #PB_Absolute
|
||||||
OSM\TargetLocation\Latitude = latitude
|
PBMap\TargetLocation\Latitude = latitude
|
||||||
OSM\TargetLocation\Longitude = longitude
|
PBMap\TargetLocation\Longitude = longitude
|
||||||
OSM\Zoom = zoom
|
PBMap\Zoom = zoom
|
||||||
Case #PB_Relative
|
Case #PB_Relative
|
||||||
OSM\TargetLocation\Latitude + latitude
|
PBMap\TargetLocation\Latitude + latitude
|
||||||
OSM\TargetLocation\Longitude + longitude
|
PBMap\TargetLocation\Longitude + longitude
|
||||||
OSM\Zoom + zoom
|
PBMap\Zoom + zoom
|
||||||
EndSelect
|
EndSelect
|
||||||
If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf
|
If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf
|
||||||
If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf
|
If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf
|
||||||
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing)
|
||||||
;Convert X, Y in tile.decimal into real pixels
|
;Convert X, Y in tile.decimal into real pixels
|
||||||
OSM\Position\x = OSM\Drawing\Position\x * OSM\TileSize
|
PBMap\Position\x = PBMap\Drawing\Position\x * PBMap\TileSize
|
||||||
OSM\Position\y = OSM\Drawing\Position\y * OSM\TileSize
|
PBMap\Position\y = PBMap\Drawing\Position\y * PBMap\TileSize
|
||||||
OSM\Drawing\PassNb = 1
|
PBMap\Drawing\PassNb = 1
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||||
;***
|
;***
|
||||||
If OSM\CallBackLocation > 0
|
If PBMap\CallBackLocation > 0
|
||||||
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
|
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -740,18 +742,18 @@ Module OSM
|
|||||||
;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
|
||||||
ForEach OSM\track()
|
ForEach PBMap\track()
|
||||||
If ListIndex(OSM\track())=0 Or OSM\track()\Longitude<MinX
|
If ListIndex(PBMap\track())=0 Or PBMap\track()\Longitude<MinX
|
||||||
MinX=OSM\track()\Longitude
|
MinX=PBMap\track()\Longitude
|
||||||
EndIf
|
EndIf
|
||||||
If ListIndex(OSM\track())=0 Or OSM\track()\Longitude>MaxX
|
If ListIndex(PBMap\track())=0 Or PBMap\track()\Longitude>MaxX
|
||||||
MaxX=OSM\track()\Longitude
|
MaxX=PBMap\track()\Longitude
|
||||||
EndIf
|
EndIf
|
||||||
If ListIndex(OSM\track())=0 Or OSM\track()\Latitude<MinY
|
If ListIndex(PBMap\track())=0 Or PBMap\track()\Latitude<MinY
|
||||||
MinY=OSM\track()\Latitude
|
MinY=PBMap\track()\Latitude
|
||||||
EndIf
|
EndIf
|
||||||
If ListIndex(OSM\track())=0 Or OSM\track()\Latitude>MaxY
|
If ListIndex(PBMap\track())=0 Or PBMap\track()\Latitude>MaxY
|
||||||
MaxY=OSM\track()\Latitude
|
MaxY=PBMap\track()\Latitude
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source
|
Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source
|
||||||
@@ -761,71 +763,71 @@ Module OSM
|
|||||||
Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY)))
|
Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY)))
|
||||||
Protected ryc.d = (ry1 + ry2) / 2
|
Protected ryc.d = (ry1 + ry2) / 2
|
||||||
Protected centerY.d = Degree(ATan(SinH(ryc)))
|
Protected centerY.d = Degree(ATan(SinH(ryc)))
|
||||||
Protected resolutionHorizontal.d = DeltaX / GadgetWidth(OSM\Gadget)
|
Protected resolutionHorizontal.d = DeltaX / GadgetWidth(PBMap\Gadget)
|
||||||
Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360)));
|
Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360)));
|
||||||
Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ;
|
Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ;
|
||||||
Protected viewHeightHalf.d = GadgetHeight(OSM\Gadget)/2;
|
Protected viewHeightHalf.d = GadgetHeight(PBMap\Gadget)/2;
|
||||||
Protected zoomFactorPowered.d = viewHeightHalf / (40.7436654315252*(vy1 - vy0))
|
Protected zoomFactorPowered.d = viewHeightHalf / (40.7436654315252*(vy1 - vy0))
|
||||||
Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * OSM\TileSize)
|
Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * PBMap\TileSize)
|
||||||
If resolutionHorizontal<>0 And resolutionVertical<>0
|
If resolutionHorizontal<>0 And resolutionVertical<>0
|
||||||
Protected resolution.d = Max(resolutionHorizontal, resolutionVertical)* paddingFactor
|
Protected resolution.d = Max(resolutionHorizontal, resolutionVertical)* paddingFactor
|
||||||
Protected zoom.d = Log(360 / (resolution * OSM\TileSize))/Log(2)
|
Protected zoom.d = Log(360 / (resolution * PBMap\TileSize))/Log(2)
|
||||||
Protected lon.d = centerX;
|
Protected lon.d = centerX;
|
||||||
Protected lat.d = centerY;
|
Protected lat.d = centerY;
|
||||||
SetLocation(lat,lon, Round(zoom,#PB_Round_Down))
|
SetLocation(lat,lon, Round(zoom,#PB_Round_Down))
|
||||||
Else
|
Else
|
||||||
SetLocation(OSM\TargetLocation\Latitude,OSM\TargetLocation\Longitude, 15)
|
SetLocation(PBMap\TargetLocation\Latitude,PBMap\TargetLocation\Longitude, 15)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure SetZoom(Zoom.i, mode.i = #PB_Relative)
|
Procedure SetZoom(Zoom.i, mode.i = #PB_Relative)
|
||||||
Select mode
|
Select mode
|
||||||
Case #PB_Relative
|
Case #PB_Relative
|
||||||
OSM\Zoom = OSM\Zoom + zoom
|
PBMap\Zoom = PBMap\Zoom + zoom
|
||||||
Case #PB_Absolute
|
Case #PB_Absolute
|
||||||
OSM\Zoom = zoom
|
PBMap\Zoom = zoom
|
||||||
EndSelect
|
EndSelect
|
||||||
If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf
|
If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf
|
||||||
If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf
|
If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf
|
||||||
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing)
|
||||||
;Convert X, Y in tile.decimal into real pixels
|
;Convert X, Y in tile.decimal into real pixels
|
||||||
OSM\Position\X = OSM\Drawing\Position\x * OSM\TileSize
|
PBMap\Position\X = PBMap\Drawing\Position\x * PBMap\TileSize
|
||||||
OSM\Position\Y = OSM\Drawing\Position\y * OSM\TileSize
|
PBMap\Position\Y = PBMap\Drawing\Position\y * PBMap\TileSize
|
||||||
;*** Creates a drawing thread and fill parameters
|
;*** Creates a drawing thread and fill parameters
|
||||||
OSM\Drawing\PassNb = 1
|
PBMap\Drawing\PassNb = 1
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||||
;***
|
;***
|
||||||
If OSM\CallBackLocation > 0
|
If PBMap\CallBackLocation > 0
|
||||||
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
|
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure SetCallBackLocation(CallBackLocation.i)
|
Procedure SetCallBackLocation(CallBackLocation.i)
|
||||||
OSM\CallBackLocation = CallBackLocation
|
PBMap\CallBackLocation = CallBackLocation
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLatitude()
|
Procedure.d GetLatitude()
|
||||||
Protected Value.d
|
Protected Value.d
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
Value = OSM\TargetLocation\Latitude
|
Value = PBMap\TargetLocation\Latitude
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
ProcedureReturn Value
|
ProcedureReturn Value
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLongitude()
|
Procedure.d GetLongitude()
|
||||||
Protected Value.d
|
Protected Value.d
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
Value = OSM\TargetLocation\Longitude
|
Value = PBMap\TargetLocation\Longitude
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
ProcedureReturn Value
|
ProcedureReturn Value
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetZoom()
|
Procedure.i GetZoom()
|
||||||
Protected Value.d
|
Protected Value.d
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
Value = OSM\Zoom
|
Value = PBMap\Zoom
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
ProcedureReturn Value
|
ProcedureReturn Value
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -834,82 +836,82 @@ Module OSM
|
|||||||
Protected MouseX.i, MouseY.i
|
Protected MouseX.i, MouseY.i
|
||||||
Protected Marker.Position
|
Protected Marker.Position
|
||||||
Protected *Drawing.DrawingParameters
|
Protected *Drawing.DrawingParameters
|
||||||
If IsGadget(OSM\Gadget) And GadgetType(OSM\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 ;{
|
||||||
Gadget = EventGadget()
|
Gadget = EventGadget()
|
||||||
Select Gadget
|
Select Gadget
|
||||||
Case OSM\Gadget
|
Case PBMap\Gadget
|
||||||
Select EventType()
|
Select EventType()
|
||||||
Case #PB_EventType_LeftButtonDown
|
Case #PB_EventType_LeftButtonDown
|
||||||
;Check if we select a marker
|
;Check if we select a marker
|
||||||
MouseX = OSM\Position\x - GadgetWidth(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
|
MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||||
MouseY = OSM\Position\y - GadgetHeight(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
|
MouseY = PBMap\Position\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||||
ForEach OSM\Marker()
|
ForEach PBMap\Marker()
|
||||||
LatLon2XY(@OSM\Marker()\Location, @Marker)
|
LatLon2XY(@PBMap\Marker()\Location, @Marker)
|
||||||
Marker\x * OSM\TileSize
|
Marker\x * PBMap\TileSize
|
||||||
Marker\y * OSM\TileSize
|
Marker\y * PBMap\TileSize
|
||||||
If Distance(Marker\x, Marker\y, MouseX, MouseY) < 8
|
If Distance(Marker\x, Marker\y, MouseX, MouseY) < 8
|
||||||
OSM\EditMarkerIndex = ListIndex(OSM\Marker())
|
PBMap\EditMarkerIndex = ListIndex(PBMap\Marker())
|
||||||
Break
|
Break
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
;Mem cursor Coord
|
;Mem cursor Coord
|
||||||
OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
|
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||||
OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
|
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||||
Case #PB_EventType_MouseMove
|
Case #PB_EventType_MouseMove
|
||||||
If OSM\MoveStartingPoint\x <> - 1
|
If PBMap\MoveStartingPoint\x <> - 1
|
||||||
MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x
|
MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x
|
||||||
MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y
|
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y
|
||||||
OSM\Moving = #True
|
PBMap\Moving = #True
|
||||||
;move Marker
|
;move Marker
|
||||||
If OSM\EditMarkerIndex > -1
|
If PBMap\EditMarkerIndex > -1
|
||||||
SelectElement(OSM\Marker(), OSM\EditMarkerIndex)
|
SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex)
|
||||||
LatLon2XY(@OSM\Marker()\Location, @Marker)
|
LatLon2XY(@PBMap\Marker()\Location, @Marker)
|
||||||
Marker\x + MouseX / OSM\TileSize
|
Marker\x + MouseX / PBMap\TileSize
|
||||||
Marker\y + MouseY / OSM\TileSize
|
Marker\y + MouseY / PBMap\TileSize
|
||||||
XY2LatLon(@Marker, @OSM\Marker()\Location)
|
XY2LatLon(@Marker, @PBMap\Marker()\Location)
|
||||||
Else
|
Else
|
||||||
;New move values
|
;New move values
|
||||||
OSM\Position\x - MouseX
|
PBMap\Position\x - MouseX
|
||||||
OSM\Position\y - MouseY
|
PBMap\Position\y - MouseY
|
||||||
;-*** Fill parameters and signal the drawing thread
|
;-*** Fill parameters and signal the drawing thread
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
;OSM tile position in tile.decimal
|
;PBMap tile position in tile.decimal
|
||||||
OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize
|
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
|
||||||
OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize
|
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
|
||||||
OSM\Drawing\PassNb = 1
|
PBMap\Drawing\PassNb = 1
|
||||||
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
|
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||||
;If CallBackLocation send Location to function
|
;If CallBackLocation send Location to function
|
||||||
If OSM\CallBackLocation > 0
|
If PBMap\CallBackLocation > 0
|
||||||
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
|
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||||
EndIf
|
EndIf
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
EndIf
|
EndIf
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||||
;- ***
|
;- ***
|
||||||
OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
|
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||||
OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
|
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||||
EndIf
|
EndIf
|
||||||
Case #PB_EventType_LeftButtonUp
|
Case #PB_EventType_LeftButtonUp
|
||||||
OSM\Moving = #False
|
PBMap\Moving = #False
|
||||||
OSM\MoveStartingPoint\x = - 1
|
PBMap\MoveStartingPoint\x = - 1
|
||||||
If OSM\EditMarkerIndex > -1
|
If PBMap\EditMarkerIndex > -1
|
||||||
OSM\EditMarkerIndex = -1
|
PBMap\EditMarkerIndex = -1
|
||||||
Else ;Move Map
|
Else ;Move Map
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize
|
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
|
||||||
OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize
|
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
|
||||||
MyDebug("OSM\Drawing\Position\x " + Str(OSM\Drawing\Position\x) + " ; OSM\Drawing\Position\y " + Str(OSM\Drawing\Position\y) )
|
MyDebug("PBMap\Drawing\Position\x " + Str(PBMap\Drawing\Position\x) + " ; PBMap\Drawing\Position\y " + Str(PBMap\Drawing\Position\y) )
|
||||||
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
|
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
EndIf
|
EndIf
|
||||||
EndSelect
|
EndSelect
|
||||||
EndSelect
|
EndSelect
|
||||||
EndSelect
|
EndSelect
|
||||||
Else
|
Else
|
||||||
MessageRequester("Module OSM", "You must use OSMGadget before", #PB_MessageRequester_Ok )
|
MessageRequester("Module PBMap", "You must use PBMapGadget before", #PB_MessageRequester_Ok )
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
@@ -980,7 +982,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
OSM::Refresh()
|
PBMap::Refresh()
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;- MAIN TEST
|
;- MAIN TEST
|
||||||
@@ -1008,49 +1010,49 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
Define pfValue.d
|
Define pfValue.d
|
||||||
|
|
||||||
;Our main gadget
|
;Our main gadget
|
||||||
OSM::InitOSM()
|
PBMap::InitPBMap()
|
||||||
OSM::MapGadget(#Map, 10, 10, 512, 512)
|
PBMap::MapGadget(#Map, 10, 10, 512, 512)
|
||||||
OSM::SetCallBackLocation(@UpdateLocation())
|
PBMap::SetCallBackLocation(@UpdateLocation())
|
||||||
OSM::SetLocation(49.04599, 2.03347, 17)
|
PBMap::SetLocation(49.04599, 2.03347, 17)
|
||||||
OSM::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer())
|
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer())
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
Event = WaitWindowEvent()
|
Event = WaitWindowEvent()
|
||||||
OSM::Event(Event)
|
PBMap::Event(Event)
|
||||||
Select Event
|
Select Event
|
||||||
Case #PB_Event_CloseWindow : Quit = 1
|
Case #PB_Event_CloseWindow : Quit = 1
|
||||||
Case #PB_Event_Gadget ;{
|
Case #PB_Event_Gadget ;{
|
||||||
Gadget = EventGadget()
|
Gadget = EventGadget()
|
||||||
Select Gadget
|
Select Gadget
|
||||||
Case #Gdt_Up
|
Case #Gdt_Up
|
||||||
OSM::SetLocation(10* 360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative)
|
PBMap::SetLocation(10* 360 / Pow(2, PBMap::GetZoom() + 8), 0, 0, #PB_Relative)
|
||||||
Case #Gdt_Down
|
Case #Gdt_Down
|
||||||
OSM::SetLocation(10* -360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative)
|
PBMap::SetLocation(10* -360 / Pow(2, PBMap::GetZoom() + 8), 0, 0, #PB_Relative)
|
||||||
Case #Gdt_Left
|
Case #Gdt_Left
|
||||||
OSM::SetLocation(0, 10* -360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative)
|
PBMap::SetLocation(0, 10* -360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative)
|
||||||
Case #Gdt_Right
|
Case #Gdt_Right
|
||||||
OSM::SetLocation(0, 10* 360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative)
|
PBMap::SetLocation(0, 10* 360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative)
|
||||||
Case #Button_4
|
Case #Button_4
|
||||||
OSM::SetZoom(1)
|
PBMap::SetZoom(1)
|
||||||
Case #Button_5
|
Case #Button_5
|
||||||
OSM::SetZoom( - 1)
|
PBMap::SetZoom( - 1)
|
||||||
Case #Gdt_LoadGpx
|
Case #Gdt_LoadGpx
|
||||||
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0))
|
PBMap::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0))
|
||||||
OSM::ZoomToArea() ; <-To center the view, and to viex all the track
|
PBMap::ZoomToArea() ; <-To center the view, and to viex all the track
|
||||||
Case #Gdt_AddMarker
|
Case #Gdt_AddMarker
|
||||||
OSM:: 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()
|
||||||
EndSelect
|
EndSelect
|
||||||
Until Quit = #True
|
Until Quit = #True
|
||||||
|
|
||||||
OSM::Quit()
|
PBMap::Quit()
|
||||||
EndIf
|
EndIf
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
||||||
; CursorPosition = 458
|
; CursorPosition = 8
|
||||||
; Folding = --------
|
; Folding = --------
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableThread
|
; EnableThread
|
Reference in New Issue
Block a user