Merge remote-tracking branch 'refs/remotes/origin/idle' into djes

This commit is contained in:
djes
2016-08-29 10:02:56 +02:00

188
PBMap.pb
View File

@@ -2,7 +2,7 @@
; 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
; Author: Thyphoon And Djes ; Author: Thyphoon, Djes And Idle
; Date: Mai 17, 2016 ; Date: Mai 17, 2016
; License: Free, unrestricted, credit appreciated ; License: Free, unrestricted, credit appreciated
; but not required. ; but not required.
@@ -12,7 +12,7 @@
; (see also Proxy Details) ; (see also Proxy Details)
;************************************************************** ;**************************************************************
#Red = 255 ;#Red = 255
CompilerIf #PB_Compiler_Thread = #False CompilerIf #PB_Compiler_Thread = #False
MessageRequester("Warning !!","You must enable ThreadSafe support in compiler options",#PB_MessageRequester_Ok ) MessageRequester("Warning !!","You must enable ThreadSafe support in compiler options",#PB_MessageRequester_Ok )
@@ -28,10 +28,14 @@ UsePNGImageEncoder()
DeclareModule PBMap DeclareModule PBMap
#Red = 255 #Red = 255
;-Show debug infos ;-Show debug infos
Global Verbose = 0 Global Verbose = 1
Global MyDebugLevel = 3 Global MyDebugLevel = 3
;-Proxy ON/OFF ;-Proxy ON/OFF
Global Proxy = #False Global Proxy = #False
#SCALE_NAUTICAL = 1
#SCALE_KM = 0
Declare InitPBMap(window) Declare InitPBMap(window)
Declare SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18) Declare SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
@@ -42,6 +46,7 @@ DeclareModule PBMap
Declare ZoomToArea() Declare ZoomToArea()
Declare SetCallBackLocation(*CallBackLocation) Declare SetCallBackLocation(*CallBackLocation)
Declare SetCallBackMainPointer(CallBackMainPointer.i) Declare SetCallBackMainPointer(CallBackMainPointer.i)
Declare SetMapScaleUnit(ScaleUnit=PBMAP::#SCALE_KM)
Declare LoadGpxFile(file.s); Declare LoadGpxFile(file.s);
Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
Declare Quit() Declare Quit()
@@ -50,6 +55,7 @@ DeclareModule PBMap
Declare.d GetLatitude() Declare.d GetLatitude()
Declare.d GetLongitude() Declare.d GetLongitude()
Declare.i GetZoom() Declare.i GetZoom()
EndDeclareModule EndDeclareModule
Module PBMap Module PBMap
@@ -81,6 +87,7 @@ Module PBMap
key.s key.s
CacheFile.s CacheFile.s
GetImageThread.i GetImageThread.i
layer.i
EndStructure EndStructure
Structure DrawingParameters Structure DrawingParameters
@@ -111,7 +118,7 @@ Module PBMap
EndStructure EndStructure
Structure TileMemCach Structure TileMemCach
Map Images.ImgMemCach() Map Images.ImgMemCach(4096)
EndStructure EndStructure
Structure Marker Structure Marker
@@ -122,6 +129,7 @@ Module PBMap
Structure Option Structure Option
WheelMouseRelative.i WheelMouseRelative.i
ScaleUnit.i ; Scale unit to use for measurements
EndStructure EndStructure
;-PBMap Structure ;-PBMap Structure
@@ -138,7 +146,9 @@ Module PBMap
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/ Array ServerURL.s(0) ; Web URL ex: http://tile.openstreetmap.org/
NumberOfMapLayers.i ; The number of map tile layers;
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
@@ -266,7 +276,6 @@ Module PBMap
OpenConsole() OpenConsole()
EndIf EndIf
PBMap\HDDCachePath = GetTemporaryDirectory() PBMap\HDDCachePath = GetTemporaryDirectory()
PBMap\ServerURL = "http://tile.openstreetmap.org/"
PBMap\ZoomMin = 0 PBMap\ZoomMin = 0
PBMap\ZoomMax = 18 PBMap\ZoomMax = 18
PBMap\MoveStartingPoint\x = - 1 PBMap\MoveStartingPoint\x = - 1
@@ -277,6 +286,8 @@ Module PBMap
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
PBMap\Window = window PBMap\Window = window
PBMap\Options\WheelMouseRelative = #True PBMap\Options\WheelMouseRelative = #True
SetMapServer("http://tile.openstreetmap.org/")
;-Preferences ;-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") ; CreatePreferences(GetHomeDirectory() + "PBMap.prefs")
@@ -306,11 +317,14 @@ Module PBMap
EndProcedure EndProcedure
Procedure SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18) Procedure SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
PBMap\ServerURL = ServerURL PBMAP\NumberOfMapLayers + 1
ReDim PBMap\ServerURL(PBMAP\NumberOfMapLayers)
PBMap\ServerURL(PBMAP\NumberOfMapLayers-1) = ServerURL
PBMap\ZoomMin = ZoomMin PBMap\ZoomMin = ZoomMin
PBMap\ZoomMax = ZoomMax PBMap\ZoomMax = ZoomMax
PBMap\TileSize = TileSize PBMap\TileSize = TileSize
EndProcedure EndProcedure
Procedure Quit() Procedure Quit()
PBMap\Drawing\End = #True PBMap\Drawing\End = #True
@@ -448,40 +462,46 @@ Module PBMap
Procedure.i GetTileFromHDD(CacheFile.s) Procedure.i GetTileFromHDD(CacheFile.s)
Protected nImage.i Protected nImage.i
Debug "Loading image " + CacheFile + " ; Size : " + Str(FileSize(CacheFile)) ; Debug "Loading image " + CacheFile + " ; Size : " + Str(FileSize(CacheFile))
If FileSize(CacheFile) > 0 If FileSize(CacheFile) > 0
nImage = LoadImage(#PB_Any, CacheFile) nImage = LoadImage(#PB_Any, CacheFile)
If IsImage(nImage) If IsImage(nImage)
Debug "Success loading " + CacheFile + " as nImage " + Str(nImage) ;Debug "Success loading " + CacheFile + " as nImage " + Str(nImage)
MyDebug("Success loading " + CacheFile + " as nImage " + Str(nImage), 3) MyDebug("Success loading " + CacheFile + " as nImage " + Str(nImage), 3)
ProcedureReturn nImage ProcedureReturn nImage
Else Else
Debug "Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !" ; Debug "Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !"
MyDebug("Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !", 3) MyDebug("Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !", 3)
EndIf EndIf
Else Else
Debug "Failed loading " + CacheFile + " -> Size <= 0" ; Debug "Failed loading " + CacheFile + " -> Size <= 0"
MyDebug("Failed loading " + CacheFile + " -> Size <= 0", 3) MyDebug("Failed loading " + CacheFile + " -> Size <= 0", 3)
EndIf EndIf
ProcedureReturn -1 ProcedureReturn -1
EndProcedure EndProcedure
Procedure.i GetLocalTile(key.s, CacheFile.s) Procedure.i GetLocalTile(key.s, CacheFile.s)
Protected timg
MyDebug("Check if we have this image in memory", 3) MyDebug("Check if we have this image in memory", 3)
If FindMapElement(PBMap\MemCache\Images(), key) If FindMapElement(PBMap\MemCache\Images(), key)
MyDebug("Key : " + key + " found !", 3) MyDebug("Key : " + key + " found !", 3)
ProcedureReturn PBMap\MemCache\Images()\nImage ProcedureReturn PBMap\MemCache\Images()\nImage
Else Else
MyDebug("Key : " + key + " Try HDD!") MyDebug("Key : " + key + " Try HDD!")
ProcedureReturn GetTileFromHDD(CacheFile.s) timg = GetTileFromHDD(CacheFile.s)
If timg <> -1
AddMapElement(PBMap\MemCache\Images(),key)
PBMap\MemCache\Images()\nImage = timg
EndIf
ProcedureReturn timg
EndIf EndIf
EndProcedure EndProcedure
Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s) Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s,layer.i)
Protected *Buffer Protected *Buffer
Protected nImage.i = -1 Protected nImage.i = -1
Protected FileHandle.i Protected FileHandle.i,timg
Protected TileURL.s = PBMap\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected TileURL.s = PBMap\ServerURL(layer) + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
MyDebug("Check if we have this image on Web", 3) MyDebug("Check if we have this image on Web", 3)
If Proxy If Proxy
FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
@@ -496,17 +516,26 @@ Module PBMap
nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer))
If IsImage(nImage) If IsImage(nImage)
MyDebug("Load from web " + TileURL + " as Tile nb " + nImage, 3) MyDebug("Load from web " + TileURL + " as Tile nb " + nImage, 3)
Debug "url: " + TileURL ; Debug "url: " + TileURL
Debug "cache file: " + CacheFile ; Debug "cache file: " + CacheFile
SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG) ; timg = LoadImage(#PB_Any,CacheFile)
FreeMemory(*Buffer) ; If timg
; StartDrawing(ImageOutput(timg))
; DrawImage(ImageID(nimage))
; StopDrawing()
; SaveImage(timg, CacheFile, #PB_ImagePlugin_PNG)
; FreeImage(timg)
; Else
SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG)
FreeMemory(*Buffer)
; EndIf
Else Else
MyDebug("Can't catch image " + TileURL, 3) MyDebug("Can't catch image " + TileURL, 3)
nImage = -1 nImage = -1
;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer))
EndIf EndIf
Else Else
Debug("ReceiveHTTPMemory's buffer is empty") ; Debug("ReceiveHTTPMemory's buffer is empty")
MyDebug("ReceiveHTTPMemory's buffer is empty", 3) MyDebug("ReceiveHTTPMemory's buffer is empty", 3)
EndIf EndIf
EndIf EndIf
@@ -515,20 +544,20 @@ Module PBMap
Procedure GetImageThread(*Tile.Tile) Procedure GetImageThread(*Tile.Tile)
Protected nImage.i = -1 Protected nImage.i = -1
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile) nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile,*tile\layer)
If nImage <> -1 If nImage <> -1
LockMutex(PBMap\TileThreadMutex) LockMutex(PBMap\TileThreadMutex)
PBMap\MemCache\Images(*Tile\key)\nImage = nImage PBMap\MemCache\Images(*Tile\key)\nImage = nImage
UnlockMutex(PBMap\TileThreadMutex) UnlockMutex(PBMap\TileThreadMutex)
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 : " + *Tile\key) MyDebug("With the following key : " + *Tile\key)
Else *Tile\nImage = nImage
PostEvent(#PB_Event_Gadget, PBMap\window,PBmap\Gadget, #PB_MAP_REDRAW, *Tile)
Else
MyDebug("Error GetImageThread procedure, image not loaded - " + *Tile\key) MyDebug("Error GetImageThread procedure, image not loaded - " + *Tile\key)
nImage = -1 ;nImage = -1
EndIf EndIf
;Define this tile image nb
*Tile\nImage = nImage
PostEvent(#PB_Event_Gadget, PBMap\window,PBmap\Gadget, #PB_MAP_REDRAW, *Tile)
EndProcedure EndProcedure
Procedure DrawTile(*Tile.Tile) Procedure DrawTile(*Tile.Tile)
@@ -548,42 +577,52 @@ Module PBMap
MyDebug(" at coords " + Str(x) + "," + Str(y)) MyDebug(" at coords " + Str(x) + "," + Str(y))
EndProcedure EndProcedure
Procedure DrawTiles(*Drawing.DrawingParameters) Procedure DrawTiles(*Drawing.DrawingParameters,layer.i,alpha.i=255)
;DisableDebugger ;DisableDebugger
Protected x.i, y.i Protected x.i, y.i,kq.q
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 / PBMap\TileSize ;How many tiles around the point Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
Protected ny = *Drawing\CenterY / PBMap\TileSize Protected ny = *Drawing\CenterY / PBMap\TileSize
Protected px, py, img, key.s, CacheFile.s Protected px, py, img, tilex,tiley, key.s, CacheFile.s
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
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
CacheFile = PBMap\HDDCachePath + "PBMap_" + Str(PBMap\Zoom) + "_" + Str(tx + x) + "_" + Str(ty + y) + ".png" tilex = ((tx+x) % (1<< PBMap\Zoom))
key = "Z" + RSet(Str(PBMap\Zoom), 4, "0") + "X" + RSet(Str(tx + x), 8, "0") + "Y" + RSet(Str(ty + y), 8, "0") ;Unique identifier tiley = ty+y
kq = layer | (pbmap\zoom << 8) | (tilex << 16) | (tiley << 36)
key = Str(kq)
CacheFile = PBMap\HDDCachePath + key + ".png"
img = GetLocalTile(key, CacheFile) img = GetLocalTile(key, CacheFile)
If img <> -1 If img <> -1
MovePathCursor(px, py) MovePathCursor(px, py)
DrawVectorImage(ImageID(img)) DrawVectorImage(ImageID(img),alpha)
Else Else
MovePathCursor(px, py) MovePathCursor(px, py)
DrawVectorImage(ImageID(PBMap\ImgLoading)) DrawVectorImage(ImageID(PBMap\ImgLoading),alpha)
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)
;TODO : not sure if it really needs a mutex here, i'm still trying to find where the white tile issue is coming from
;a tile download is either getting clobbered or timing out or getting kicked and it results in a corrupted png file on linux
LockMutex(PBMap\TileThreadMutex)
AddElement(PBMap\TilesThreads()) AddElement(PBMap\TilesThreads())
PBMap\TilesThreads()\Tile = *NewTile PBMap\TilesThreads()\Tile = *NewTile
UnlockMutex(PBMap\TileThreadMutex)
;New tile parameters ;New tile parameters
\Position\x = px ;*Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX \Position\x = px
\Position\y = py ;*Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY \Position\y = py
\PBMapTileX = tx + x \PBMapTileX = tilex
\PBMapTileY = ty + y \PBMapTileY = tiley
\PBMapZoom = PBMap\Zoom \PBMapZoom = PBMap\Zoom
\key = key \key = key
\CacheFile = CacheFile \CacheFile = CacheFile
\layer = layer
LockMutex(PBMap\TileThreadMutex) LockMutex(PBMap\TileThreadMutex)
AddMapElement(PBMap\MemCache\Images(), \key) ;Add the image to the cache, once in this loop AddMapElement(PBMap\MemCache\Images(), \key) ;Add the image to the cache, once in this loop
PBMap\MemCache\Images()\nImage = PBMap\ImgLoading PBMap\MemCache\Images()\nImage = PBMap\ImgLoading
@@ -596,9 +635,13 @@ Module PBMap
MyDebug(" Error, can't create a new tile") MyDebug(" Error, can't create a new tile")
Break 2 Break 2
EndIf EndIf
EndIf EndIf
Next Next
Next
Next
;Free tile memory ;Free tile memory
;TODO : maybe get out this proc from drawtiles in a special "free ressources" task ;TODO : maybe get out this proc from drawtiles in a special "free ressources" task
ForEach PBMap\TilesThreads() ForEach PBMap\TilesThreads()
@@ -656,15 +699,29 @@ Module PBMap
EndIf EndIf
EndProcedure EndProcedure
Procedure DrawScale(*Drawing.DrawingParameters) Procedure DrawScale(*Drawing.DrawingParameters,x,y,alpha=80)
;TODO Add Option and function to display Scale on Map ;TODO Add Option and function to display Scale on Map
Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom) Protected sunit.s
VectorFont(FontID(PBMap\Font), 30) Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom) / 2
VectorSourceColor(RGBA(0, 0, 0, 80))
MovePathCursor(50,50) Select PBMap\Options\ScaleUnit
DrawVectorText(StrD(Scale)) Case #SCALE_Nautical
Scale * 0.539957
sunit = " Nm"
Case #SCALE_KM;
sunit = " Km"
EndSelect
VectorFont(FontID(PBMap\Font), 10)
VectorSourceColor(RGBA(0, 0, 0,alpha))
MovePathCursor(x,y)
DrawVectorText(StrD(Scale,3)+sunit)
MovePathCursor(x,y+12)
AddPathLine(x+128,y+10)
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)
@@ -755,7 +812,7 @@ Module PBMap
;-*** Main drawing ;-*** Main drawing
Procedure Drawing() Procedure Drawing()
Protected *Drawing.DrawingParameters = @PBMap\Drawing Protected *Drawing.DrawingParameters = @PBMap\Drawing
Protected Px.d, Py.d Protected Px.d, Py.d,a
;Precalc some values ;Precalc some values
*Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2 *Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2
*Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2 *Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2
@@ -767,7 +824,11 @@ Module PBMap
*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))
DrawTiles(*Drawing) ;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers
;such as for openseamap tiles which are overlaid. not that efficent from here though.
For a = 0 To PBMap\NumberOfMapLayers-1
DrawTiles(*Drawing,a)
Next
DrawTrack(*Drawing) DrawTrack(*Drawing)
DrawMarker(*Drawing) DrawMarker(*Drawing)
DrawPointer(*Drawing) DrawPointer(*Drawing)
@@ -778,6 +839,10 @@ Module PBMap
DrawVectorText(Str(MapSize(PBMap\MemCache\Images()))) DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
MovePathCursor(50,80) MovePathCursor(50,80)
DrawVectorText(Str(ListSize(PBMap\TilesThreads()))) DrawVectorText(Str(ListSize(PBMap\TilesThreads())))
;If PBMap\Options\ShowScale
DrawScale(*Drawing,10,GadgetHeight(PBMAP\Gadget)-20,192)
;EndIf
StopVectorDrawing() StopVectorDrawing()
EndProcedure EndProcedure
@@ -854,7 +919,7 @@ Module PBMap
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
PBMap\Zoom = PBMap\Zoom + zoom PBMap\Zoom = PBMap\Zoom + zoom
Case #PB_Absolute Case #PB_Absolute
PBMap\Zoom = zoom PBMap\Zoom = zoom
EndSelect EndSelect
@@ -879,6 +944,11 @@ Module PBMap
PBMap\CallBackMainPointer = CallBackMainPointer PBMap\CallBackMainPointer = CallBackMainPointer
EndProcedure EndProcedure
Procedure SetMapScaleUnit(ScaleUnit.i = PBMAP::#SCALE_KM)
PBMap\Options\ScaleUnit = ScaleUnit
Drawing()
EndProcedure
;Zoom on x, y position relative to the canvas gadget ;Zoom on x, y position relative to the canvas gadget
Procedure SetZoomOnPosition(x, y, zoom) Procedure SetZoomOnPosition(x, y, zoom)
Protected MouseX.d, MouseY.d Protected MouseX.d, MouseY.d
@@ -1094,6 +1164,7 @@ 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)
@@ -1123,7 +1194,9 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::MapGadget(#Map, 10, 10, 512, 512) PBMap::MapGadget(#Map, 10, 10, 512, 512)
PBMap::SetCallBackMainPointer(@MainPointer()) ;To change the Main Pointer PBMap::SetCallBackMainPointer(@MainPointer()) ;To change the Main Pointer
PBMap::SetCallBackLocation(@UpdateLocation()) PBMap::SetCallBackLocation(@UpdateLocation())
PBMap::SetLocation(-36.8485,174.7633,10) PBMap::SetLocation(-36.81148,175.08634,12)
PBMap::SetMapServer("http://t1.openseamap.org/seamark/") ;add a special osm overlay map
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL)
;PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer()) ;PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer())
Repeat Repeat
@@ -1163,12 +1236,11 @@ CompilerIf #PB_Compiler_IsMainFile
CloseConsole() CloseConsole()
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64)
; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; CursorPosition = 1219
; CursorPosition = 362 ; FirstLine = 1193
; FirstLine = 339 ; Folding = ----------
; Folding = ---------
; EnableUnicode
; EnableThread ; EnableThread
; EnableXP ; EnableXP
; DisableDebugger ; DisableDebugger
; EnableUnicode