Cache tree creation
This commit is contained in:
49
PBMap.pb
49
PBMap.pb
@@ -217,7 +217,7 @@ Module PBMap
|
|||||||
|
|
||||||
;Shows an error msg and terminates the program
|
;Shows an error msg and terminates the program
|
||||||
Procedure Error(msg.s)
|
Procedure Error(msg.s)
|
||||||
MessageRequester("MapGadget", msg, #PB_MessageRequester_Ok)
|
MessageRequester("PBMap", msg, #PB_MessageRequester_Ok)
|
||||||
End
|
End
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -408,9 +408,7 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
PreferenceGroup("URL")
|
PreferenceGroup("URL")
|
||||||
PBMap\Options\DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/")
|
PBMap\Options\DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/")
|
||||||
If PBMap\Options\DefaultOSMServer <> ""
|
|
||||||
AddMapServerLayer("OSM", 1, PBMap\Options\DefaultOSMServer)
|
|
||||||
EndIf
|
|
||||||
PreferenceGroup("PATHS")
|
PreferenceGroup("PATHS")
|
||||||
PBMap\Options\HDDCachePath = ReadPreferenceString("TilesCachePath", GetTemporaryDirectory())
|
PBMap\Options\HDDCachePath = ReadPreferenceString("TilesCachePath", GetTemporaryDirectory())
|
||||||
PreferenceGroup("OPTIONS")
|
PreferenceGroup("OPTIONS")
|
||||||
@@ -436,6 +434,9 @@ Module PBMap
|
|||||||
PBMap\Timer = 1
|
PBMap\Timer = 1
|
||||||
PBMap\Mode = #MODE_DEFAULT
|
PBMap\Mode = #MODE_DEFAULT
|
||||||
LoadOptions()
|
LoadOptions()
|
||||||
|
If PBMap\Options\DefaultOSMServer <> ""
|
||||||
|
AddMapServerLayer("OSM", 1, PBMap\Options\DefaultOSMServer)
|
||||||
|
EndIf
|
||||||
curl_global_init(#CURL_GLOBAL_WIN32)
|
curl_global_init(#CURL_GLOBAL_WIN32)
|
||||||
TechnicalImagesCreation()
|
TechnicalImagesCreation()
|
||||||
SetLocation(0, 0)
|
SetLocation(0, 0)
|
||||||
@@ -443,6 +444,14 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure.i AddMapServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
Procedure.i AddMapServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
||||||
Protected *Ptr = AddElement(PBMap\Layers())
|
Protected *Ptr = AddElement(PBMap\Layers())
|
||||||
|
Protected DirName.s = PBMap\Options\HDDCachePath + LayerName + "\"
|
||||||
|
If FileSize(DirName) <> -2
|
||||||
|
If CreateDirectory(DirName) = #False ; Creates a directory based on the layer name
|
||||||
|
Error("Can't create the following cache directory : " + DirName)
|
||||||
|
Else
|
||||||
|
MyDebug(DirName + " successfully created", 4)
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
If *Ptr
|
If *Ptr
|
||||||
PBMap\Layers()\Name = LayerName
|
PBMap\Layers()\Name = LayerName
|
||||||
PBMap\Layers()\Order = Order
|
PBMap\Layers()\Order = Order
|
||||||
@@ -651,20 +660,16 @@ Module PBMap
|
|||||||
Protected FileSize.i, timg
|
Protected FileSize.i, timg
|
||||||
If PBMap\Options\Proxy
|
If PBMap\Options\Proxy
|
||||||
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile, PBMap\Options\ProxyURL, PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile, PBMap\Options\ProxyURL, PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
||||||
If FileSize > 0
|
|
||||||
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
|
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
|
||||||
Else
|
|
||||||
MyDebug("Problem loading from web " + TileURL, 3)
|
|
||||||
EndIf
|
|
||||||
Else
|
Else
|
||||||
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile)
|
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile)
|
||||||
|
EndIf
|
||||||
If FileSize > 0
|
If FileSize > 0
|
||||||
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
|
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
nImage = GetTileFromHDD(CacheFile)
|
||||||
Else
|
Else
|
||||||
MyDebug("Problem loading from web " + TileURL, 3)
|
MyDebug("Problem loading from web " + TileURL, 3)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; **** PLEASE KEEP THIS CODE
|
; **** PLEASE KEEP THIS CODE
|
||||||
; I'm (djes) now using Curl only as the catchimage/saveimage is a double operation (uncompress/recompress PNG)
|
; I'm (djes) now using Curl only as the catchimage/saveimage is a double operation (uncompress/recompress PNG)
|
||||||
; and is modifying the original PNG image which could lead to PNG error (Idle has spent hours debunking the 2 bits PNG bug)
|
; and is modifying the original PNG image which could lead to PNG error (Idle has spent hours debunking the 2 bits PNG bug)
|
||||||
@@ -687,7 +692,6 @@ Module PBMap
|
|||||||
; MyDebug(" Problem loading from web " + TileURL, 3)
|
; MyDebug(" Problem loading from web " + TileURL, 3)
|
||||||
; EndIf
|
; EndIf
|
||||||
; ****
|
; ****
|
||||||
EndIf
|
|
||||||
ProcedureReturn nImage
|
ProcedureReturn nImage
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -780,9 +784,24 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
tiley = ty + y
|
tiley = ty + y
|
||||||
If tiley >= 0 And tiley < tilemax
|
If tiley >= 0 And tiley < tilemax
|
||||||
kq = (PBMap\zoom << 8) | (tilex << 16) | (tiley << 36)
|
kq = (PBMap\Zoom << 8) | (tilex << 16) | (tiley << 36)
|
||||||
key = PBMap\Layers()\Name + Str(kq)
|
key = PBMap\Layers()\Name + Str(kq)
|
||||||
CacheFile = PBMap\Options\HDDCachePath + key + ".png"
|
; Creates a directory based on the zoom
|
||||||
|
Protected DirName.s = PBMap\Options\HDDCachePath + PBMap\Layers()\Name + "\" + Str(PBMap\Zoom)
|
||||||
|
If FileSize(DirName) <> -2
|
||||||
|
If CreateDirectory(DirName) = #False
|
||||||
|
Error("Can't create the following cache directory : " + DirName)
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
; Creates a directory based on x
|
||||||
|
DirName.s + "\" + Str(tilex)
|
||||||
|
If FileSize(DirName) <> -2
|
||||||
|
If CreateDirectory(DirName) = #False
|
||||||
|
Error("Can't create the following cache directory : " + DirName)
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
; Tile cache name based on y
|
||||||
|
CacheFile = DirName + "\" + Str(tiley) + ".png"
|
||||||
img = GetTile(key, CacheFile, px, py, tilex, tiley, PBMap\Layers()\ServerURL)
|
img = GetTile(key, CacheFile, px, py, tilex, tiley, PBMap\Layers()\ServerURL)
|
||||||
If img <> -1
|
If img <> -1
|
||||||
MovePathCursor(px, py)
|
MovePathCursor(px, py)
|
||||||
@@ -1558,8 +1577,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
|
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 1515
|
; CursorPosition = 450
|
||||||
; FirstLine = 1485
|
; FirstLine = 419
|
||||||
; Folding = ------------
|
; Folding = ------------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user