Compare commits
5 Commits
MasterRevi
...
tilewip
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7c32502fe3 | ||
![]() |
6a91b81bc7 | ||
![]() |
287bd29104 | ||
![]() |
926b2c5c16 | ||
![]() |
29c1b39507 |
545
PBMap.pb
545
PBMap.pb
@@ -3,7 +3,7 @@
|
||||
; Description: Permits the use of tiled maps like
|
||||
; OpenStreetMap in a handy PureBASIC module
|
||||
; Author: Thyphoon, djes And Idle
|
||||
; Date: March, 2017
|
||||
; Date: Mai 17, 2016
|
||||
; License: PBMap : Free, unrestricted, credit
|
||||
; appreciated but not required.
|
||||
; OSM : see http://www.openstreetmap.org/copyright
|
||||
@@ -23,21 +23,11 @@ UsePNGImageDecoder()
|
||||
UsePNGImageEncoder()
|
||||
|
||||
DeclareModule PBMap
|
||||
;-Show debug infos
|
||||
Global MyDebugLevel = 0
|
||||
|
||||
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
|
||||
#Red = 255
|
||||
CompilerEndIf
|
||||
|
||||
Global slash.s
|
||||
|
||||
CompilerSelect #PB_Compiler_OS
|
||||
CompilerCase #PB_OS_Windows
|
||||
slash = "\"
|
||||
CompilerDefault
|
||||
slash = "/"
|
||||
CompilerEndSelect
|
||||
;-Show debug infos
|
||||
Global Verbose = 0
|
||||
Global MyDebugLevel = 0
|
||||
|
||||
#SCALE_NAUTICAL = 1
|
||||
#SCALE_KM = 0
|
||||
@@ -49,6 +39,11 @@ DeclareModule PBMap
|
||||
|
||||
#MARKER_EDIT_EVENT = #PB_Event_FirstCustomValue
|
||||
|
||||
Structure GeographicCoordinates
|
||||
Longitude.d
|
||||
Latitude.d
|
||||
EndStructure
|
||||
|
||||
;-Declarations
|
||||
Declare InitPBMap(window)
|
||||
Declare SetOption(Option.s, Value.s)
|
||||
@@ -87,19 +82,13 @@ DeclareModule PBMap
|
||||
Declare.i GetZoom()
|
||||
Declare.i GetMode()
|
||||
Declare SetMode(Mode.i = #MODE_DEFAULT)
|
||||
Declare NominatimGeoLocationQuery(Address.s, *ReturnPosition= 0) ;Send back the position *ptr.GeographicCoordinates
|
||||
Declare.i ClearDiskCache()
|
||||
Declare NominatimGeoLocationQuery(Address.s, *ReturnPosition.GeographicCoordinates = 0) ;Send back the position *ptr.GeographicCoordinates
|
||||
EndDeclareModule
|
||||
|
||||
Module PBMap
|
||||
|
||||
EnableExplicit
|
||||
|
||||
Structure GeographicCoordinates
|
||||
Longitude.d
|
||||
Latitude.d
|
||||
EndStructure
|
||||
|
||||
Structure PixelCoordinates
|
||||
x.d
|
||||
y.d
|
||||
@@ -123,19 +112,19 @@ Module PBMap
|
||||
Structure BoundingBox
|
||||
NorthWest.GeographicCoordinates
|
||||
SouthEast.GeographicCoordinates
|
||||
BottomRight.PixelCoordinates
|
||||
TopLeft.PixelCoordinates
|
||||
BottomLeft.PixelCoordinates
|
||||
TopRight.PixelCoordinates
|
||||
EndStructure
|
||||
|
||||
Structure DrawingParameters
|
||||
Canvas.i
|
||||
RadiusX.d ; Canvas radius, or center in pixels
|
||||
RadiusY.d
|
||||
GeographicCoordinates.GeographicCoordinates ; Real center in lat/lon
|
||||
CenterX.d ; Gadget center in screen relative pixels
|
||||
CenterY.d
|
||||
GeographicCoordinates.GeographicCoordinates ; Real center
|
||||
TileCoordinates.Coordinates ; Center coordinates in tile.decimal
|
||||
Bounds.BoundingBox ; Drawing boundaries in lat/lon
|
||||
Width.d ; Drawing width in degrees
|
||||
Height.d ; Drawing height in degrees
|
||||
Width.d ; Drawing width in degrees
|
||||
PBMapZoom.i
|
||||
DeltaX.i ; Screen relative pixels tile shift
|
||||
DeltaY.i
|
||||
@@ -190,8 +179,6 @@ Module PBMap
|
||||
ShowPointer.i
|
||||
TimerInterval.i
|
||||
MaxMemCache.i ; in MiB
|
||||
Verbose.i ; Maximum debug informations
|
||||
Warning.i ; Warning requesters
|
||||
ShowMarkersNb.i
|
||||
ShowMarkersLegend.i
|
||||
;Drawing stuff
|
||||
@@ -256,7 +243,7 @@ Module PBMap
|
||||
Moving.i
|
||||
Dirty.i ; To signal that drawing need a refresh
|
||||
|
||||
List TracksList.Tracks() ; To display a GPX track
|
||||
List TracksList.Tracks()
|
||||
List Markers.Marker() ; To diplay marker
|
||||
EditMarker.l
|
||||
|
||||
@@ -282,16 +269,163 @@ Module PBMap
|
||||
|
||||
;Send debug infos to stdout (allowing mixed debug infos with curl or other libs)
|
||||
Procedure MyDebug(msg.s, DbgLevel = 0)
|
||||
If PBMap\Options\Verbose And DbgLevel >= MyDebugLevel
|
||||
If Verbose And DbgLevel >= MyDebugLevel
|
||||
PrintN(msg)
|
||||
;Debug msg
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
;- *** GetText - Translation purpose
|
||||
;TODO use this for all text
|
||||
IncludeFile "gettext.pbi"
|
||||
|
||||
;- *** CURL specific
|
||||
; (program has To be compiled in console format for curl debug infos)
|
||||
|
||||
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
|
||||
|
||||
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
|
||||
|
||||
ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream)
|
||||
Protected SizeProper.i = Size & 255
|
||||
Protected NMemBProper.i = NMemB
|
||||
If *ReceiveHTTPToMemoryBuffer = 0
|
||||
*ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
|
||||
If *ReceiveHTTPToMemoryBuffer = 0
|
||||
Error("Curl : Problem allocating memory")
|
||||
EndIf
|
||||
Else
|
||||
*ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
|
||||
If *ReceiveHTTPToMemoryBuffer = 0
|
||||
Error("Curl : Problem reallocating memory")
|
||||
EndIf
|
||||
EndIf
|
||||
CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper)
|
||||
ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper
|
||||
ProcedureReturn SizeProper * NMemBProper
|
||||
EndProcedure
|
||||
|
||||
Procedure.i CurlReceiveHTTPToMemory(URL$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="")
|
||||
Protected *Buffer, curl.i, Timeout.i, res.i, respcode.l
|
||||
If Len(URL$)
|
||||
curl = curl_easy_init()
|
||||
If curl
|
||||
Timeout = 3
|
||||
curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$))
|
||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_HEADER, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1)
|
||||
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
|
||||
If Verbose
|
||||
curl_easy_setopt(curl, #CURLOPT_VERBOSE, 1)
|
||||
EndIf
|
||||
curl_easy_setopt(curl, #CURLOPT_FAILONERROR, 1)
|
||||
If Len(ProxyURL$)
|
||||
;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True)
|
||||
If Len(ProxyPort$)
|
||||
ProxyURL$ + ":" + ProxyPort$
|
||||
EndIf
|
||||
; Debug ProxyURL$
|
||||
curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$))
|
||||
If Len(ProxyUser$)
|
||||
If Len(ProxyPassword$)
|
||||
ProxyUser$ + ":" + ProxyPassword$
|
||||
EndIf
|
||||
;Debug ProxyUser$
|
||||
curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$))
|
||||
EndIf
|
||||
EndIf
|
||||
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction())
|
||||
res = curl_easy_perform(curl)
|
||||
If res = #CURLE_OK
|
||||
*Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr)
|
||||
If *Buffer
|
||||
CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr)
|
||||
FreeMemory(*ReceiveHTTPToMemoryBuffer)
|
||||
*ReceiveHTTPToMemoryBuffer = #Null
|
||||
ReceiveHTTPToMemoryBufferPtr = 0
|
||||
Else
|
||||
MyDebug("Problem allocating buffer", 4)
|
||||
EndIf
|
||||
;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me.
|
||||
Else
|
||||
curl_easy_getinfo(curl, #CURLINFO_HTTP_CODE, @respcode)
|
||||
MyDebug("CURL : HTTP ERROR " + Str(respcode) , 8)
|
||||
curl_easy_cleanup(curl)
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
curl_easy_cleanup(curl)
|
||||
Else
|
||||
MyDebug("Can't Init CURL", 4)
|
||||
EndIf
|
||||
EndIf
|
||||
; Debug "Curl Buffer : " + Str(*Buffer)
|
||||
ProcedureReturn *Buffer
|
||||
EndProcedure
|
||||
|
||||
;Curl write callback (needed for win32 dll)
|
||||
ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i)
|
||||
ProcedureReturn WriteData(FileHandle, *ptr, Size * NMemB)
|
||||
EndProcedure
|
||||
|
||||
Procedure.i CurlReceiveHTTPToFile(URL$, DestFileName$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="")
|
||||
Protected *Buffer, curl.i, Timeout.i, res.i, respcode.l
|
||||
Protected FileHandle.i
|
||||
MyDebug("CurlReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + " " + ProxyPort$ + " " + ProxyUser$, 8)
|
||||
MyDebug(" to file : " + DestFileName$, 8)
|
||||
FileHandle = CreateFile(#PB_Any, DestFileName$)
|
||||
If FileHandle And Len(URL$)
|
||||
curl = curl_easy_init()
|
||||
If curl
|
||||
Timeout = 120
|
||||
curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$))
|
||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_HEADER, 0)
|
||||
curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1)
|
||||
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
|
||||
If Verbose
|
||||
curl_easy_setopt(curl, #CURLOPT_VERBOSE, 1)
|
||||
EndIf
|
||||
curl_easy_setopt(curl, #CURLOPT_FAILONERROR, 1)
|
||||
;curl_easy_setopt(curl, #CURLOPT_CONNECTTIMEOUT, 60)
|
||||
If Len(ProxyURL$)
|
||||
;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True)
|
||||
If Len(ProxyPort$)
|
||||
ProxyURL$ + ":" + ProxyPort$
|
||||
EndIf
|
||||
MyDebug(ProxyURL$, 8)
|
||||
curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$))
|
||||
If Len(ProxyUser$)
|
||||
If Len(ProxyPassword$)
|
||||
ProxyUser$ + ":" + ProxyPassword$
|
||||
EndIf
|
||||
MyDebug(ProxyUser$, 8)
|
||||
curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$))
|
||||
EndIf
|
||||
EndIf
|
||||
curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle)
|
||||
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction())
|
||||
res = curl_easy_perform(curl)
|
||||
If res <> #CURLE_OK
|
||||
curl_easy_getinfo(curl, #CURLINFO_HTTP_CODE, @respcode)
|
||||
MyDebug("CURL : HTTP ERROR " + Str(respcode) , 8)
|
||||
CloseFile(FileHandle)
|
||||
curl_easy_cleanup(curl)
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
curl_easy_cleanup(curl)
|
||||
Else
|
||||
MyDebug("Can't init CURL", 8)
|
||||
EndIf
|
||||
CloseFile(FileHandle)
|
||||
ProcedureReturn FileSize(DestFileName$)
|
||||
EndIf
|
||||
ProcedureReturn #False
|
||||
EndProcedure
|
||||
|
||||
;- ***
|
||||
|
||||
Procedure TechnicalImagesCreation()
|
||||
;"Loading" image
|
||||
Protected LoadingText$ = "Loading"
|
||||
@@ -379,10 +513,6 @@ Module PBMap
|
||||
PBMap\Options\HDDCachePath = Value
|
||||
Case "maxmemcache"
|
||||
PBMap\Options\MaxMemCache = Val(Value)
|
||||
Case "verbose"
|
||||
SelBool(Verbose)
|
||||
Case "warning"
|
||||
SelBool(Warning)
|
||||
Case "wheelmouserelative"
|
||||
SelBool(WheelMouseRelative)
|
||||
Case "showdegrees"
|
||||
@@ -434,8 +564,6 @@ Module PBMap
|
||||
PreferenceGroup("OPTIONS")
|
||||
WritePreferenceInteger("WheelMouseRelative", \WheelMouseRelative)
|
||||
WritePreferenceInteger("MaxMemCache", \MaxMemCache)
|
||||
WritePreferenceInteger("Verbose", \Verbose)
|
||||
WritePreferenceInteger("Warning", \Warning)
|
||||
WritePreferenceInteger("ShowDegrees", \ShowDegrees)
|
||||
WritePreferenceInteger("ShowDebugInfos", \ShowDebugInfos)
|
||||
WritePreferenceInteger("ShowScale", \ShowScale)
|
||||
@@ -487,12 +615,10 @@ Module PBMap
|
||||
\DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/")
|
||||
|
||||
PreferenceGroup("PATHS")
|
||||
\HDDCachePath = ReadPreferenceString("TilesCachePath", GetTemporaryDirectory() + "PBMap" + slash)
|
||||
\HDDCachePath = ReadPreferenceString("TilesCachePath", GetTemporaryDirectory())
|
||||
PreferenceGroup("OPTIONS")
|
||||
\WheelMouseRelative = ReadPreferenceInteger("WheelMouseRelative", #True)
|
||||
\MaxMemCache = ReadPreferenceInteger("MaxMemCache", 20480) ;20 MiB, about 80 tiles in memory
|
||||
\Verbose = ReadPreferenceInteger("Verbose", #True)
|
||||
\Warning = ReadPreferenceInteger("Warning", #False)
|
||||
\ShowDegrees = ReadPreferenceInteger("ShowDegrees", #False)
|
||||
\ShowDebugInfos = ReadPreferenceInteger("ShowDebugInfos", #False)
|
||||
\ShowScale = ReadPreferenceInteger("ShowScale", #False)
|
||||
@@ -515,6 +641,14 @@ Module PBMap
|
||||
|
||||
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 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
|
||||
PBMap\Layers()\Name = LayerName
|
||||
PBMap\Layers()\Order = Order
|
||||
@@ -556,6 +690,7 @@ Module PBMap
|
||||
Next
|
||||
Delay(10)
|
||||
Until MapSize(PBMap\MemCache\Images()) = 0
|
||||
curl_global_cleanup()
|
||||
EndProcedure
|
||||
|
||||
Macro Min(a,b)
|
||||
@@ -627,7 +762,7 @@ Module PBMap
|
||||
;Lat Lon coordinates 2 pixel relative to the center of view
|
||||
Procedure LatLon2PixelRel(*Location.GeographicCoordinates, *Pixel.PixelCoordinates, Zoom)
|
||||
Protected tilemax = Pow(2.0, Zoom) * PBMap\TileSize
|
||||
Protected cx.d = PBMap\Drawing\RadiusX
|
||||
Protected cx.d = PBMap\Drawing\CenterX
|
||||
Protected dpx.d = PBMap\PixelCoordinates\x
|
||||
Protected LatRad.d = Radian(*Location\Latitude)
|
||||
Protected px.d = tilemax * (Mod( *Location\Longitude + 180.0, 360) / 360.0 )
|
||||
@@ -646,7 +781,7 @@ Module PBMap
|
||||
;Debug "c0"
|
||||
*Pixel\x = cx + (px - dpx)
|
||||
EndIf
|
||||
*Pixel\y = PBMap\Drawing\RadiusY + (py - PBMap\PixelCoordinates\y)
|
||||
*Pixel\y = PBMap\Drawing\CenterY + (py - PBMap\PixelCoordinates\y)
|
||||
EndProcedure
|
||||
|
||||
; HaversineAlgorithm
|
||||
@@ -683,20 +818,21 @@ Module PBMap
|
||||
latRad = PBMap\GeographicCoordinates\Latitude*#PI/180;
|
||||
mercN = Log(Tan((#PI/4)+(latRad/2)))
|
||||
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
||||
*Pixel\x=PBMap\Drawing\RadiusX - (x2-x1)
|
||||
*Pixel\y=PBMap\Drawing\RadiusY - (y2-y1)
|
||||
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
||||
*Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
||||
EndProcedure
|
||||
|
||||
Procedure IsInDrawingPixelBoundaries(*Drawing.DrawingParameters, *Position.GeographicCoordinates)
|
||||
Protected Pixel.PixelCoordinates
|
||||
LatLon2PixelRel(*Position, @Pixel, PBMap\Zoom)
|
||||
If Pixel\x >= 0 And Pixel\y >= 0 And Pixel\x < *Drawing\RadiusX * 2 And Pixel\y < *Drawing\RadiusY * 2
|
||||
LatLon2Pixel(*Position, @Pixel, PBMap\Zoom)
|
||||
If Pixel\x >= *Drawing\Bounds\BottomLeft\x And Pixel\y <= *Drawing\Bounds\BottomLeft\y And Pixel\x <= *Drawing\Bounds\TopRight\x And Pixel\y >= *Drawing\Bounds\TopRight\y
|
||||
ProcedureReturn #True
|
||||
Else
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
;TODO : rotation fix
|
||||
Procedure IsInDrawingBoundaries(*Drawing.DrawingParameters, *Position.GeographicCoordinates)
|
||||
Protected Lat.d = *Position\Latitude, Lon.d = *Position\Longitude
|
||||
Protected LatNW.d = *Drawing\Bounds\NorthWest\Latitude, LonNW.d = *Drawing\Bounds\NorthWest\Longitude
|
||||
@@ -745,16 +881,15 @@ Module PBMap
|
||||
Protected *Buffer
|
||||
Protected nImage.i = -1
|
||||
Protected FileSize.i, timg
|
||||
HTTPProxy(PBMap\Options\ProxyURL + ":" + PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
||||
FileSize = ReceiveHTTPFile(TileURL, CacheFile)
|
||||
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
|
||||
; **** IMPORTANT NOTICE (please not remove)
|
||||
; I'm (djes) now using Curl (actually, just normal pb) only, as this original catchimage/saveimage method is a double operation (uncompress/recompress PNG)
|
||||
; **** IMPORTANT NOTICE
|
||||
; I'm (djes) now using Curl only, as this original catchimage/saveimage method 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 1 bit PNG bug)
|
||||
; More than that, the original Purebasic Receive library is still not Proxy enabled.
|
||||
; *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
|
||||
@@ -787,7 +922,7 @@ Module PBMap
|
||||
*Tile\RetryNb = 0
|
||||
Else
|
||||
MyDebug("Image key : " + *Tile\key + " web image not correctly loaded", 3)
|
||||
Delay(2000)
|
||||
Delay(5000)
|
||||
*Tile\RetryNb - 1
|
||||
EndIf
|
||||
Until *Tile\RetryNb <= 0
|
||||
@@ -881,8 +1016,8 @@ Module PBMap
|
||||
Protected x.i, y.i,kq.q
|
||||
Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() !
|
||||
Protected ty = Int(*Drawing\TileCoordinates\y)
|
||||
Protected nx = *Drawing\RadiusX / PBMap\TileSize ;How many tiles around the point
|
||||
Protected ny = *Drawing\RadiusY / PBMap\TileSize
|
||||
Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
|
||||
Protected ny = *Drawing\CenterY / PBMap\TileSize
|
||||
Protected px, py, *timg.ImgMemCach, tilex, tiley, key.s
|
||||
Protected URL.s, CacheFile.s
|
||||
Protected tilemax = 1<<PBMap\Zoom
|
||||
@@ -890,8 +1025,8 @@ Module PBMap
|
||||
MyDebug("Drawing tiles")
|
||||
For y = - ny - 1 To ny + 1
|
||||
For x = - nx - 1 To nx + 1
|
||||
px = *Drawing\RadiusX + x * PBMap\TileSize - *Drawing\DeltaX
|
||||
py = *Drawing\RadiusY + y * PBMap\TileSize - *Drawing\DeltaY
|
||||
px = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX
|
||||
py = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY
|
||||
tilex = (tx + x) % tilemax
|
||||
If tilex < 0
|
||||
tilex + tilemax
|
||||
@@ -901,35 +1036,23 @@ Module PBMap
|
||||
kq = (PBMap\Zoom << 8) | (tilex << 16) | (tiley << 36)
|
||||
key = PBMap\Layers()\Name + Str(kq)
|
||||
; Creates the cache tree based on the OSM tree+Layer : layer/zoom/x/y.png
|
||||
Protected DirName.s = PBMap\Options\HDDCachePath + PBMap\Layers()\Name
|
||||
If FileSize(DirName) <> -2
|
||||
If CreateDirectory(DirName) = #False ; Creates a directory based on the layer name
|
||||
Error("Can't create the following layer directory : " + DirName)
|
||||
Else
|
||||
MyDebug(DirName + " successfully created", 4)
|
||||
EndIf
|
||||
EndIf
|
||||
; Creates the sub-directory based on the zoom
|
||||
DirName + slash + Str(PBMap\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 zoom directory : " + DirName)
|
||||
Else
|
||||
MyDebug(DirName + " successfully created", 4)
|
||||
Error("Can't create the following cache directory : " + DirName)
|
||||
EndIf
|
||||
EndIf
|
||||
; Creates the sub-directory based on x
|
||||
DirName.s + slash + Str(tilex)
|
||||
DirName.s + "\" + Str(tilex)
|
||||
If FileSize(DirName) <> -2
|
||||
If CreateDirectory(DirName) = #False
|
||||
Error("Can't create the following x directory : " + DirName)
|
||||
Else
|
||||
MyDebug(DirName + " successfully created", 4)
|
||||
Error("Can't create the following cache directory : " + DirName)
|
||||
EndIf
|
||||
EndIf
|
||||
; Tile cache name based on y
|
||||
URL = PBMap\Layers()\ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png"
|
||||
CacheFile = DirName + slash + Str(tiley) + ".png"
|
||||
CacheFile = DirName + "\" + Str(tiley) + ".png"
|
||||
*timg = GetTile(key, URL, CacheFile)
|
||||
If *timg\nImage <> -1
|
||||
MovePathCursor(px, py)
|
||||
@@ -966,10 +1089,10 @@ Module PBMap
|
||||
Procedure DrawPointer(*Drawing.DrawingParameters)
|
||||
If PBMap\CallBackMainPointer > 0
|
||||
; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
|
||||
CallFunctionFast(PBMap\CallBackMainPointer, *Drawing\RadiusX, *Drawing\RadiusY)
|
||||
CallFunctionFast(PBMap\CallBackMainPointer, *Drawing\CenterX, *Drawing\CenterY)
|
||||
Else
|
||||
VectorSourceColor(RGBA($FF, 0, 0, $FF))
|
||||
MovePathCursor(*Drawing\RadiusX, *Drawing\RadiusY)
|
||||
MovePathCursor(*Drawing\CenterX, *Drawing\CenterY)
|
||||
AddPathLine(-8, -16, #PB_Path_Relative)
|
||||
AddPathCircle(8, 0, 8, 180, 0, #PB_Path_Relative)
|
||||
AddPathLine(-8, 16, #PB_Path_Relative)
|
||||
@@ -1003,27 +1126,21 @@ Module PBMap
|
||||
Protected tx, ty, nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d
|
||||
Protected pos1.PixelCoordinates,pos2.PixelCoordinates,Degrees1.GeographicCoordinates,degrees2.GeographicCoordinates
|
||||
Protected realx
|
||||
|
||||
;TODO to find why it doesn't work
|
||||
; tx = Int(*Drawing\TileCoordinates\x)
|
||||
; ty = Int(*Drawing\TileCoordinates\y)
|
||||
; tx = *Drawing\TileCoordinates\x
|
||||
; ty = *Drawing\TileCoordinates\y
|
||||
; nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
|
||||
; ny = *Drawing\CenterY / PBMap\TileSize
|
||||
; *Drawing\Bounds\NorthWest\x = tx-nx-1
|
||||
; *Drawing\Bounds\NorthWest\y = ty-ny-1
|
||||
; *Drawing\Bounds\SouthEast\x = tx+nx+2
|
||||
; *Drawing\Bounds\SouthEast\y = ty+ny+2
|
||||
; Debug "------------------"
|
||||
;TileXY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1, PBMap\Zoom)
|
||||
;TileXY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2, PBMap\Zoom)
|
||||
CopyStructure(*Drawing\Bounds\NorthWest, @Degrees1, GeographicCoordinates)
|
||||
Debug "----"
|
||||
Debug Degrees1\Longitude-1
|
||||
CopyStructure(*Drawing\Bounds\SouthEast, @Degrees2, GeographicCoordinates)
|
||||
;tx = Int(*Drawing\TileCoordinates\x)
|
||||
;ty = Int(*Drawing\TileCoordinates\y)
|
||||
tx = *Drawing\TileCoordinates\x
|
||||
ty = *Drawing\TileCoordinates\y
|
||||
nx = *Drawing\RadiusX / PBMap\TileSize ;How many tiles around the point
|
||||
ny = *Drawing\RadiusY / PBMap\TileSize
|
||||
*Drawing\Bounds\TopLeft\x = tx-nx-1
|
||||
*Drawing\Bounds\TopLeft\y = ty-ny-1
|
||||
*Drawing\Bounds\BottomRight\x = tx+nx+2
|
||||
*Drawing\Bounds\BottomRight\y = ty+ny+2
|
||||
TileXY2LatLon(*Drawing\Bounds\TopLeft, @Degrees1, PBMap\Zoom)
|
||||
TileXY2LatLon(*Drawing\Bounds\BottomRight, @Degrees2, PBMap\Zoom)
|
||||
Debug Degrees1\Longitude
|
||||
;***
|
||||
|
||||
;ensure we stay positive for the drawing
|
||||
nx = Mod(Mod(Round(Degrees1\Longitude, #PB_Round_Down)-1, 360) + 360, 360)
|
||||
ny = Round(Degrees1\Latitude, #PB_Round_Up) +1
|
||||
@@ -1193,11 +1310,13 @@ Module PBMap
|
||||
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
|
||||
If Int(km) <> memKm
|
||||
memKm = Int(km)
|
||||
RotateCoordinates(Pixel\x, Pixel\y, -PBMap\Angle)
|
||||
If Int(km) = 0
|
||||
DrawTrackPointerFirst(Pixel\x , Pixel\y, Int(km))
|
||||
Else
|
||||
DrawTrackPointer(Pixel\x , Pixel\y, Int(km))
|
||||
EndIf
|
||||
RotateCoordinates(Pixel\x, Pixel\y, PBMap\Angle)
|
||||
EndIf
|
||||
Next
|
||||
EndIf
|
||||
@@ -1379,11 +1498,13 @@ Module PBMap
|
||||
ForEach PBMap\Markers()
|
||||
If IsInDrawingPixelBoundaries(*Drawing, @PBMap\Markers()\GeographicCoordinates)
|
||||
LatLon2PixelRel(@PBMap\Markers()\GeographicCoordinates, @Pixel, PBMap\Zoom)
|
||||
RotateCoordinates(Pixel\x, Pixel\y, -PBMap\Angle)
|
||||
If PBMap\Markers()\CallBackPointer > 0
|
||||
CallFunctionFast(PBMap\Markers()\CallBackPointer, Pixel\x, Pixel\y, PBMap\Markers()\Focus, PBMap\Markers()\Selected)
|
||||
Else
|
||||
DrawMarker(Pixel\x, Pixel\y, ListIndex(PBMap\Markers()), @PBMap\Markers())
|
||||
EndIf
|
||||
RotateCoordinates(Pixel\x, Pixel\y, PBMap\Angle)
|
||||
EndIf
|
||||
Next
|
||||
EndProcedure
|
||||
@@ -1392,9 +1513,9 @@ Module PBMap
|
||||
; Display how many images in cache
|
||||
VectorFont(FontID(PBMap\Font), 16)
|
||||
VectorSourceColor(RGBA(0, 0, 0, 80))
|
||||
MovePathCursor(50, 50)
|
||||
MovePathCursor(50,50)
|
||||
DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
|
||||
MovePathCursor(50, 70)
|
||||
MovePathCursor(50,70)
|
||||
Protected ThreadCounter = 0
|
||||
ForEach PBMap\MemCache\Images()
|
||||
If PBMap\MemCache\Images()\Tile <> 0
|
||||
@@ -1404,11 +1525,11 @@ Module PBMap
|
||||
EndIf
|
||||
Next
|
||||
DrawVectorText(Str(ThreadCounter))
|
||||
MovePathCursor(50, 90)
|
||||
MovePathCursor(50,90)
|
||||
DrawVectorText(Str(PBMap\Zoom))
|
||||
MovePathCursor(50, 110)
|
||||
MovePathCursor(50,110)
|
||||
DrawVectorText(StrD(*Drawing\Bounds\NorthWest\Latitude) + "," + StrD(*Drawing\Bounds\NorthWest\Longitude))
|
||||
MovePathCursor(50, 130)
|
||||
MovePathCursor(50,130)
|
||||
DrawVectorText(StrD(*Drawing\Bounds\SouthEast\Latitude) + "," + StrD(*Drawing\Bounds\SouthEast\Longitude))
|
||||
EndProcedure
|
||||
|
||||
@@ -1429,8 +1550,8 @@ Module PBMap
|
||||
PBMap\Dirty = #False
|
||||
PBMap\Redraw = #False
|
||||
;*** Precalc some values
|
||||
*Drawing\RadiusX = GadgetWidth(PBMap\Gadget) / 2
|
||||
*Drawing\RadiusY = GadgetHeight(PBMap\Gadget) / 2
|
||||
*Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||
*Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2
|
||||
*Drawing\GeographicCoordinates\Latitude = PBMap\GeographicCoordinates\Latitude
|
||||
*Drawing\GeographicCoordinates\Longitude = PBMap\GeographicCoordinates\Longitude
|
||||
LatLon2TileXY(*Drawing\GeographicCoordinates, *Drawing\TileCoordinates, PBMap\Zoom)
|
||||
@@ -1441,19 +1562,39 @@ Module PBMap
|
||||
*Drawing\DeltaX = Px * ts - (Int(Px) * ts) ;Don't forget the Int() !
|
||||
*Drawing\DeltaY = Py * ts - (Int(Py) * ts)
|
||||
;Drawing boundaries
|
||||
nx = *Drawing\RadiusX / ts ;How many tiles around the point
|
||||
ny = *Drawing\RadiusY / ts
|
||||
NW\x = Px - nx - 1
|
||||
NW\y = Py - ny - 1
|
||||
SE\x = Px + nx + 2
|
||||
SE\y = Py + ny + 2
|
||||
TileXY2LatLon(@NW, *Drawing\Bounds\NorthWest, PBMap\Zoom)
|
||||
TileXY2LatLon(@SE, *Drawing\Bounds\SouthEast, PBMap\Zoom)
|
||||
; nx = *Drawing\CenterX / ts ;How many tiles around the point
|
||||
; ny = *Drawing\CenterY / ts
|
||||
; NW\x = Px - nx - 1
|
||||
; NW\y = Py - ny - 1
|
||||
; SE\x = Px + nx + 2
|
||||
; SE\y = Py + ny + 2
|
||||
; TileXY2LatLon(@NW, *Drawing\Bounds\NorthWest, PBMap\Zoom)
|
||||
; TileXY2LatLon(@SE, *Drawing\Bounds\SouthEast, PBMap\Zoom)
|
||||
;TODO : rotation fix
|
||||
nx = PixelCenter\x - *Drawing\CenterX
|
||||
ny = PixelCenter\y + *Drawing\CenterY
|
||||
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||
RotateCoordinates(PixelCenter\x, PixelCenter\y, PBMap\Angle)
|
||||
*Drawing\Bounds\BottomLeft\x = ConvertCoordinateX(nx, ny, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
*Drawing\Bounds\BottomLeft\y = ConvertCoordinateY(nx, ny, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
nx + GadgetWidth(PBMap\Gadget)
|
||||
ny - GadgetHeight(PBMap\Gadget)
|
||||
*Drawing\Bounds\TopRight\x = ConvertCoordinateX(nx, ny, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
*Drawing\Bounds\TopRight\y = ConvertCoordinateY(nx, ny, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
StopVectorDrawing()
|
||||
Pixel2LatLon(*Drawing\Bounds\BottomLeft, *Drawing\Bounds\SouthEast, PBMap\Zoom)
|
||||
Pixel2LatLon(*Drawing\Bounds\TopRight, *Drawing\Bounds\NorthWest, PBMap\Zoom)
|
||||
; Debug *Drawing\Bounds\NorthWest\Latitude
|
||||
; Debug *Drawing\Bounds\NorthWest\Longitude
|
||||
; Debug *Drawing\Bounds\SouthEast\Latitude
|
||||
; Debug *Drawing\Bounds\SouthEast\Longitude
|
||||
;*Drawing\Width = (SE\x / Pow(2, PBMap\Zoom) * 360.0) - (NW\x / Pow(2, PBMap\Zoom) * 360.0) ;Calculus without clipping
|
||||
;*Drawing\Height = *Drawing\Bounds\NorthWest\Latitude - *Drawing\Bounds\SouthEast\Latitude
|
||||
;***
|
||||
; Main drawing stuff
|
||||
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||
;Main rotation
|
||||
RotateCoordinates(*Drawing\CenterX, *Drawing\CenterY, PBMap\Angle)
|
||||
;Clearscreen
|
||||
VectorSourceColor(RGBA(150, 150, 150, 255))
|
||||
FillVectorOutput()
|
||||
@@ -1462,15 +1603,16 @@ Module PBMap
|
||||
ForEach PBMap\Layers()
|
||||
DrawTiles(*Drawing, ListIndex(PBMap\Layers()))
|
||||
Next
|
||||
If PBMap\Options\ShowDegrees And PBMap\Zoom > 2
|
||||
DrawDegrees(*Drawing, 192)
|
||||
EndIf
|
||||
If PBMap\Options\ShowTrack
|
||||
DrawTracks(*Drawing)
|
||||
EndIf
|
||||
If PBMap\Options\ShowMarkers
|
||||
DrawMarkers(*Drawing)
|
||||
EndIf
|
||||
If PBMap\Options\ShowDegrees And PBMap\Zoom > 2
|
||||
DrawDegrees(*Drawing, 192)
|
||||
EndIf
|
||||
ResetCoordinates()
|
||||
If PBMap\Options\ShowPointer
|
||||
DrawPointer(*Drawing)
|
||||
EndIf
|
||||
@@ -1490,27 +1632,27 @@ Module PBMap
|
||||
EndProcedure
|
||||
|
||||
Procedure.d Pixel2Lon(x)
|
||||
Protected NewX.d = (PBMap\PixelCoordinates\x - PBMap\Drawing\RadiusX + x) / PBMap\TileSize
|
||||
Protected NewX.d = (PBMap\PixelCoordinates\x - GadgetWidth(PBMap\Gadget) / 2 + x) / PBMap\TileSize
|
||||
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||
; double mod is to ensure the longitude to be in the range [-180;180[
|
||||
ProcedureReturn Mod(Mod(NewX / n * 360.0, 360.0) + 360.0, 360.0) - 180
|
||||
EndProcedure
|
||||
|
||||
Procedure.d Pixel2Lat(y)
|
||||
Protected NewY.d = (PBMap\PixelCoordinates\y - PBMap\Drawing\RadiusY + y) / PBMap\TileSize
|
||||
Protected NewY.d = (PBMap\PixelCoordinates\y - GadgetHeight(PBMap\Gadget) / 2 + y) / PBMap\TileSize
|
||||
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||
ProcedureReturn Degree(ATan(SinH(#PI * (1.0 - 2.0 * NewY / n))))
|
||||
EndProcedure
|
||||
|
||||
Procedure.d MouseLongitude()
|
||||
Protected MouseX.d = (PBMap\PixelCoordinates\x - PBMap\Drawing\RadiusX + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)) / PBMap\TileSize
|
||||
Protected MouseX.d = (PBMap\PixelCoordinates\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)) / PBMap\TileSize
|
||||
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||
; double mod is to ensure the longitude to be in the range [-180;180[
|
||||
ProcedureReturn Mod(Mod(MouseX / n * 360.0, 360.0) + 360.0, 360.0) - 180
|
||||
EndProcedure
|
||||
|
||||
Procedure.d MouseLatitude()
|
||||
Protected MouseY.d = (PBMap\PixelCoordinates\y - PBMap\Drawing\RadiusY + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)) / PBMap\TileSize
|
||||
Protected MouseY.d = (PBMap\PixelCoordinates\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)) / PBMap\TileSize
|
||||
Protected n.d = Pow(2.0, PBMap\Zoom)
|
||||
ProcedureReturn Degree(ATan(SinH(#PI * (1.0 - 2.0 * MouseY / n))))
|
||||
EndProcedure
|
||||
@@ -1552,17 +1694,17 @@ Module PBMap
|
||||
Procedure ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
|
||||
;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)
|
||||
Protected DeltaX.d = MaxX - MinX ;assumption ! In original code DeltaX have no source
|
||||
Protected centerX.d = MinX + DeltaX / 2 ; assumption ! In original code CenterX have no source
|
||||
Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source
|
||||
Protected centerX.d=MinX+DeltaX/2 ; assumption ! In original code CenterX have no source
|
||||
Protected paddingFactor.f= 1.2 ;paddingFactor: this can be used to get the "120%" effect ThomM refers to. Value of 1.2 would get you the 120%.
|
||||
Protected ry1.d = Log((Sin(Radian(MinY)) + 1) / Cos(Radian(MinY)))
|
||||
Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY)))
|
||||
Protected ryc.d = (ry1 + ry2) / 2
|
||||
Protected centerY.d = Degree(ATan(SinH(ryc)))
|
||||
Protected resolutionHorizontal.d = DeltaX / (PBMap\Drawing\RadiusX * 2)
|
||||
Protected resolutionHorizontal.d = DeltaX / GadgetWidth(PBMap\Gadget)
|
||||
Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360)));
|
||||
Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ;
|
||||
Protected viewHeightHalf.d = PBMap\Drawing\RadiusY ;
|
||||
Protected viewHeightHalf.d = GadgetHeight(PBMap\Gadget)/2;
|
||||
Protected zoomFactorPowered.d = viewHeightHalf / (40.7436654315252*(vy1 - vy0))
|
||||
Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * PBMap\TileSize)
|
||||
If resolutionHorizontal<>0 And resolutionVertical<>0
|
||||
@@ -1683,14 +1825,22 @@ Module PBMap
|
||||
|
||||
;Zoom on x, y position relative to the canvas gadget
|
||||
Procedure ZoomOnPixelRel(x, y, zoom)
|
||||
ZoomOnPixel(x - PBMap\Drawing\RadiusX, y - PBMap\Drawing\RadiusY, zoom)
|
||||
Protected CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||
Protected CenterY = GadgetHeight(PBMap\Gadget) / 2
|
||||
x - CenterX
|
||||
y - CenterY
|
||||
ZoomOnPixel(x, y, zoom)
|
||||
EndProcedure
|
||||
|
||||
;Go to x, y position relative to the canvas gadget left up
|
||||
Procedure GotoPixelRel(x, y)
|
||||
Protected CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||
Protected CenterY = GadgetHeight(PBMap\Gadget) / 2
|
||||
x - CenterX
|
||||
y - CenterY
|
||||
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom)
|
||||
PBMap\PixelCoordinates\x + x - PBMap\Drawing\RadiusX
|
||||
PBMap\PixelCoordinates\y + y - PBMap\Drawing\RadiusY
|
||||
PBMap\PixelCoordinates\x + x
|
||||
PBMap\PixelCoordinates\y + y
|
||||
Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
|
||||
; Start drawing
|
||||
PBMap\Redraw = #True
|
||||
@@ -1730,17 +1880,16 @@ Module PBMap
|
||||
EndProcedure
|
||||
|
||||
Procedure NominatimGeoLocationQuery(Address.s, *ReturnPosition.GeographicCoordinates = 0)
|
||||
Protected Size.i
|
||||
Protected Query.s = "http://nominatim.openstreetmap.org/search/" +
|
||||
URLEncoder(Address) +
|
||||
;"Unter%20den%20Linden%201%20Berlin" +
|
||||
"?format=json&addressdetails=0&polygon=0&limit=1"
|
||||
Protected JSONFileName.s = PBMap\Options\HDDCachePath + "nominatimresponse.json"
|
||||
; Protected *Buffer = CurlReceiveHTTPToMemory("http://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1", PBMap\Options\ProxyURL, PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
||||
; Debug *Buffer
|
||||
; Debug MemorySize(*Buffer)
|
||||
; Protected JSon.s = PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8)
|
||||
HTTPProxy(PBMap\Options\ProxyURL + ":" + PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
||||
Size = ReceiveHTTPFile(Query, JSONFileName)
|
||||
Protected Size.i = CurlReceiveHTTPToFile(Query, JSONFileName, PBMap\Options\ProxyURL, PBMap\Options\ProxyPort, PBMap\Options\ProxyUser, PBMap\Options\ProxyPassword)
|
||||
If LoadJSON(0, JSONFileName) = 0
|
||||
;Demivec's code
|
||||
MyDebug( JSONErrorMessage() + " at position " +
|
||||
@@ -1767,67 +1916,6 @@ Module PBMap
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
;(c) ts-soft http://www.purebasic.fr/english/viewtopic.php?f=12&t=58657&hilit=createdirectory&view=unread#unread
|
||||
CompilerSelect #PB_Compiler_OS
|
||||
CompilerCase #PB_OS_Windows
|
||||
#FILE_ATTRIBUTE_DEVICE = 64 ;(0x40)
|
||||
#FILE_ATTRIBUTE_INTEGRITY_STREAM = 32768 ;(0x8000)
|
||||
#FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192;(0x2000)
|
||||
#FILE_ATTRIBUTE_NO_SCRUB_DATA = 131072;(0x20000)
|
||||
#FILE_ATTRIBUTE_VIRTUAL = 65536;(0x10000)
|
||||
#FILE_ATTRIBUTE_DONTSETFLAGS = ~(#FILE_ATTRIBUTE_DIRECTORY|
|
||||
#FILE_ATTRIBUTE_SPARSE_FILE|
|
||||
#FILE_ATTRIBUTE_OFFLINE|
|
||||
#FILE_ATTRIBUTE_NOT_CONTENT_INDEXED|
|
||||
#FILE_ATTRIBUTE_VIRTUAL|
|
||||
0)
|
||||
Macro SetFileAttributesEx(Name, Attribs)
|
||||
SetFileAttributes(Name, Attribs & #FILE_ATTRIBUTE_DONTSETFLAGS)
|
||||
EndMacro
|
||||
CompilerDefault
|
||||
Macro SetFileAttributesEx(Name, Attribs)
|
||||
SetFileAttributes(Name, Attribs)
|
||||
EndMacro
|
||||
CompilerEndSelect
|
||||
|
||||
Procedure CreateDirectoryEx(DirectoryName.s, FileAttribute = #PB_Default)
|
||||
Protected i, c, tmp.s
|
||||
If Right(DirectoryName, 1) = slash
|
||||
DirectoryName = Left(DirectoryName, Len(DirectoryName) -1)
|
||||
EndIf
|
||||
c = CountString(DirectoryName, slash) + 1
|
||||
For i = 1 To c
|
||||
tmp + StringField(DirectoryName, i, slash)
|
||||
If FileSize(tmp) <> -2
|
||||
CreateDirectory(tmp)
|
||||
EndIf
|
||||
tmp + slash
|
||||
Next
|
||||
If FileAttribute <> #PB_Default
|
||||
SetFileAttributesEx(DirectoryName, FileAttribute)
|
||||
EndIf
|
||||
If FileSize(DirectoryName) = -2
|
||||
ProcedureReturn #True
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure.i ClearDiskCache()
|
||||
If PBMap\Options\Warning
|
||||
Protected Result.i = MessageRequester("Warning", "You will clear all cache content in " + PBMap\Options\HDDCachePath + ". Are you sure ?",#PB_MessageRequester_YesNo)
|
||||
If Result = #PB_MessageRequester_No ; Quit if "no" selected
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
EndIf
|
||||
If DeleteDirectory(PBMap\Options\HDDCachePath, "", #PB_FileSystem_Recursive)
|
||||
MyDebug("Cache in : " + PBMap\Options\HDDCachePath + " cleared")
|
||||
CreateDirectoryEx(PBMap\Options\HDDCachePath)
|
||||
ProcedureReturn #True
|
||||
Else
|
||||
MyDebug("Can't clear cache in " + PBMap\Options\HDDCachePath)
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure CanvasEvents()
|
||||
Protected CanvasMouseX.d, CanvasMouseY.d, MouseX.d, MouseY.d
|
||||
Protected MarkerCoords.PixelCoordinates, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize
|
||||
@@ -1835,18 +1923,17 @@ Module PBMap
|
||||
Protected Pixel.PixelCoordinates
|
||||
Static CtrlKey
|
||||
PBMap\Moving = #False
|
||||
CanvasMouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\Drawing\RadiusX
|
||||
CanvasMouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\Drawing\RadiusY
|
||||
; rotation wip
|
||||
; StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||
; RotateCoordinates(0, 0, PBMap\Angle)
|
||||
; CanvasMouseX = ConvertCoordinateX(MouseX, MouseY, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
; CanvasMouseY = ConvertCoordinateY(MouseX, MouseY, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
; StopVectorDrawing()
|
||||
MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\Drawing\CenterX
|
||||
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\Drawing\CenterY
|
||||
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||
RotateCoordinates(0, 0, PBMap\Angle)
|
||||
CanvasMouseX = ConvertCoordinateX(MouseX, MouseY, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
CanvasMouseY = ConvertCoordinateY(MouseX, MouseY, #PB_Coordinate_Device, #PB_Coordinate_User)
|
||||
StopVectorDrawing()
|
||||
Select EventType()
|
||||
Case #PB_EventType_Focus
|
||||
PBMap\Drawing\RadiusX = GadgetWidth(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\RadiusY = GadgetHeight(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2
|
||||
Case #PB_EventType_KeyUp
|
||||
Select GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_Key)
|
||||
Case #PB_Shortcut_Delete
|
||||
@@ -2014,6 +2101,7 @@ Module PBMap
|
||||
If ListSize(\Track()) > 0
|
||||
If \Visible
|
||||
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||
RotateCoordinates(PBMap\Drawing\CenterX, PBMap\Drawing\CenterY, PBMap\Angle)
|
||||
;Simulate tracks drawing
|
||||
ForEach \Track()
|
||||
LatLon2Pixel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
|
||||
@@ -2060,8 +2148,8 @@ Module PBMap
|
||||
EndSelect
|
||||
EndProcedure
|
||||
|
||||
; Redraws at regular intervals
|
||||
Procedure TimerEvents()
|
||||
;Redraw at regular intervals
|
||||
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
|
||||
Drawing()
|
||||
EndIf
|
||||
@@ -2073,8 +2161,8 @@ Module PBMap
|
||||
BindGadgetEvent(PBMap\Gadget, @CanvasEvents())
|
||||
AddWindowTimer(PBMap\Window, PBMap\Timer, PBMap\Options\TimerInterval)
|
||||
BindEvent(#PB_Event_Timer, @TimerEvents())
|
||||
PBMap\Drawing\RadiusX = GadgetWidth(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\RadiusY = GadgetHeight(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2
|
||||
PBMap\Drawing\CenterX = GadgetHeight(PBMap\Gadget) / 2
|
||||
EndProcedure
|
||||
|
||||
; Creates a canvas and attach our map
|
||||
@@ -2090,6 +2178,9 @@ Module PBMap
|
||||
|
||||
Procedure InitPBMap(Window)
|
||||
Protected Result.i
|
||||
If Verbose
|
||||
OpenConsole()
|
||||
EndIf
|
||||
PBMap\ZoomMin = 0
|
||||
PBMap\ZoomMax = 18
|
||||
PBMap\MoveStartingPoint\x = - 1
|
||||
@@ -2101,25 +2192,17 @@ Module PBMap
|
||||
PBMap\Timer = 1
|
||||
PBMap\Mode = #MODE_DEFAULT
|
||||
LoadOptions()
|
||||
If PBMap\Options\Verbose
|
||||
OpenConsole()
|
||||
EndIf
|
||||
CreateDirectoryEx(PBMap\Options\HDDCachePath)
|
||||
If PBMap\Options\DefaultOSMServer <> ""
|
||||
AddMapServerLayer("OSM", 1, PBMap\Options\DefaultOSMServer)
|
||||
EndIf
|
||||
curl_global_init(#CURL_GLOBAL_WIN32)
|
||||
TechnicalImagesCreation()
|
||||
SetLocation(0, 0)
|
||||
EndProcedure
|
||||
|
||||
EndModule
|
||||
|
||||
;****************************************************************
|
||||
;
|
||||
;- Example of application
|
||||
;
|
||||
;****************************************************************
|
||||
|
||||
;-**** Example of application ****
|
||||
CompilerIf #PB_Compiler_IsMainFile
|
||||
InitNetwork()
|
||||
|
||||
@@ -2130,8 +2213,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
#Gdt_Right
|
||||
#Gdt_Up
|
||||
#Gdt_Down
|
||||
;#Gdt_RotateLeft
|
||||
;#Gdt_RotateRight
|
||||
#Gdt_RotateLeft
|
||||
#Gdt_RotateRight
|
||||
#Button_4
|
||||
#Button_5
|
||||
#Combo_0
|
||||
@@ -2147,7 +2230,6 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
#Gdt_AddOpenseaMap
|
||||
#Gdt_Degrees
|
||||
#Gdt_EditMode
|
||||
#Gdt_ClearDiskCache
|
||||
#TextGeoLocationQuery
|
||||
#StringGeoLocationQuery
|
||||
EndEnumeration
|
||||
@@ -2200,8 +2282,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_Left, WindowWidth(#Window_0) - 150 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_Right,WindowWidth(#Window_0) - 90 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
;ResizeGadget(#Gdt_RotateLeft, WindowWidth(#Window_0) - 150 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
;ResizeGadget(#Gdt_RotateRight,WindowWidth(#Window_0) - 90 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_RotateLeft, WindowWidth(#Window_0) - 150 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_RotateRight,WindowWidth(#Window_0) - 90 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_Up, WindowWidth(#Window_0) - 120 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_Down, WindowWidth(#Window_0) - 120 ,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Text_2,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
@@ -2216,7 +2298,6 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
ResizeGadget(#Gdt_AddOpenseaMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_Degrees,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_EditMode,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#Gdt_ClearDiskCache,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#TextGeoLocationQuery,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
ResizeGadget(#StringGeoLocationQuery,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||
PBMap::Refresh()
|
||||
@@ -2230,8 +2311,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
LoadFont(2, "Arial", 8)
|
||||
|
||||
TextGadget(#Text_1, 530, 50, 60, 15, "Movements")
|
||||
;ButtonGadget(#Gdt_RotateLeft, 550, 070, 30, 30, "LRot") : SetGadgetFont(#Gdt_RotateLeft, FontID(2))
|
||||
;ButtonGadget(#Gdt_RotateRight, 610, 070, 30, 30, "RRot") : SetGadgetFont(#Gdt_RotateRight, FontID(2))
|
||||
ButtonGadget(#Gdt_RotateLeft, 550, 070, 30, 30, "LRot") : SetGadgetFont(#Gdt_RotateLeft, FontID(2))
|
||||
ButtonGadget(#Gdt_RotateRight, 610, 070, 30, 30, "RRot") : SetGadgetFont(#Gdt_RotateRight, FontID(2))
|
||||
ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($25C4)) : SetGadgetFont(#Gdt_Left, FontID(0))
|
||||
ButtonGadget(#Gdt_Right, 610, 100, 30, 30, Chr($25BA)) : SetGadgetFont(#Gdt_Right, FontID(0))
|
||||
ButtonGadget(#Gdt_Up, 580, 070, 30, 30, Chr($25B2)) : SetGadgetFont(#Gdt_Up, FontID(0))
|
||||
@@ -2248,9 +2329,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
ButtonGadget(#Gdt_AddOpenseaMap, 530, 340, 150, 30, "Show/Hide OpenSeaMap", #PB_Button_Toggle)
|
||||
ButtonGadget(#Gdt_Degrees, 530, 370, 150, 30, "Show/Hide Degrees", #PB_Button_Toggle)
|
||||
ButtonGadget(#Gdt_EditMode, 530, 400, 150, 30, "Edit mode ON/OFF", #PB_Button_Toggle)
|
||||
ButtonGadget(#Gdt_ClearDiskCache, 530, 430, 150, 30, "Clear disk cache", #PB_Button_Toggle)
|
||||
TextGadget(#TextGeoLocationQuery, 530, 465, 150, 15, "Enter an address")
|
||||
StringGadget(#StringGeoLocationQuery, 530, 480, 150, 20, "")
|
||||
TextGadget(#TextGeoLocationQuery, 530, 435, 150, 15, "Enter an address")
|
||||
StringGadget(#StringGeoLocationQuery, 530, 450, 150, 20, "")
|
||||
SetActiveGadget(#StringGeoLocationQuery)
|
||||
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
|
||||
;*** TODO : code to remove when the SetActiveGadget(-1) will be fixed
|
||||
@@ -2271,7 +2351,6 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
PBMap::SetOption("ShowDegrees", "0") : Degrees = 0
|
||||
PBMap::SetOption("ShowDebugInfos", "0")
|
||||
PBMap::SetOption("ShowScale", "1")
|
||||
PBMap::SetOption("Warning", "1")
|
||||
PBMap::SetOption("ShowMarkersLegend", "1")
|
||||
PBMap::SetOption("ShowTrackKms", "1")
|
||||
PBMap::SetOption("ColourFocus", "$FFFF00AA")
|
||||
@@ -2297,12 +2376,12 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
PBMap::SetLocation(0, 10* -360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative)
|
||||
Case #Gdt_Right
|
||||
PBMap::SetLocation(0, 10* 360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative)
|
||||
;Case #Gdt_RotateLeft
|
||||
; PBMAP::SetAngle(-5,#PB_Relative)
|
||||
; PBMap::Refresh()
|
||||
;Case #Gdt_RotateRight
|
||||
; PBMAP::SetAngle(5,#PB_Relative)
|
||||
; PBMap::Refresh()
|
||||
Case #Gdt_RotateLeft
|
||||
PBMAP::SetAngle(-5,#PB_Relative)
|
||||
PBMap::Refresh()
|
||||
Case #Gdt_RotateRight
|
||||
PBMAP::SetAngle(5,#PB_Relative)
|
||||
PBMap::Refresh()
|
||||
Case #Button_4
|
||||
PBMap::SetZoom(1)
|
||||
Case #Button_5
|
||||
@@ -2342,8 +2421,6 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
PBMap::SetMode(PBMap::#MODE_DEFAULT)
|
||||
SetGadgetState(#Gdt_EditMode, 0)
|
||||
EndIf
|
||||
Case #Gdt_ClearDiskCache
|
||||
PBMap::ClearDiskCache()
|
||||
Case #StringGeoLocationQuery
|
||||
Select EventType()
|
||||
Case #PB_EventType_Focus
|
||||
@@ -2378,10 +2455,10 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
CompilerEndIf
|
||||
|
||||
|
||||
; IDE Options = PureBasic 5.60 beta 7 (Windows - x64)
|
||||
; CursorPosition = 2250
|
||||
; FirstLine = 2260
|
||||
; IDE Options = PureBasic 5.42 LTS (Windows - x64)
|
||||
; CursorPosition = 2430
|
||||
; FirstLine = 2401
|
||||
; Folding = -----------------
|
||||
; EnableUnicode
|
||||
; EnableThread
|
||||
; EnableXP
|
||||
; EnableUnicode
|
1070
libcurl.pbi
Normal file
1070
libcurl.pbi
Normal file
File diff suppressed because it is too large
Load Diff
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 286 KiB After Width: | Height: | Size: 374 KiB |
Reference in New Issue
Block a user