CallBackDrawTile + misc cleaning + useragent

Allows a customised tile drawing
This commit is contained in:
djes
2017-07-04 12:20:07 +02:00
parent a98f658287
commit afc271278a

View File

@@ -28,6 +28,10 @@ UseJPEGImageEncoder()
DeclareModule PBMap
#PBMAPNAME = "PBMap"
#PBMAPVERSION = "0.9"
#USERAGENT = #PBMAPNAME + "/" + #PBMAPVERSION + " (https://github.com/djes/PBMap)"
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
#Red = 255
CompilerEndIf
@@ -82,6 +86,9 @@ DeclareModule PBMap
Declare BindMapGadget(Gadget.i)
Declare SetCallBackLocation(*CallBackLocation)
Declare SetCallBackMainPointer(CallBackMainPointer.i)
Declare SetCallBackDrawTile(*CallBackLocation)
Declare SetCallBackMarker(*CallBackLocation)
Declare SetCallBackLeftClic(*CallBackLocation)
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
Declare.d GetLatitude()
Declare.d GetLongitude()
@@ -114,8 +121,7 @@ DeclareModule PBMap
Declare Error(msg.s)
Declare Refresh()
Declare.i ClearDiskCache()
Declare SetCallBackMarker(*CallBackLocation)
Declare SetCallBackLeftClic(*CallBackLocation)
EndDeclareModule
@@ -123,6 +129,10 @@ Module PBMap
EnableExplicit
;-*** Callback Prototypes
Prototype ProtoDrawTile(x.i, y.i, image.i, alpha.d = 1)
;-*** Internal Structures
Structure PixelCoordinates
@@ -278,10 +288,11 @@ Module PBMap
GeographicCoordinates.GeographicCoordinates ; Latitude and Longitude from focus point
Drawing.DrawingParameters ; Drawing parameters based on focus point
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
CallBackLocation.i ; @Procedure(latitude.d, longitude.d)
CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
CallBackMarker.i ; @Procedure (latitude.d,lontitude.d) pour connaitre la nouvelle position du marqueur (YA)
CallBackLeftClic.i ; @Procdeure (latitude.d,lontitude.d) pour connaitre la position lors du clic gauche (YA)
CallBackMarker.i ; @Procedure (latitude.d, lontitude.d) to know the marker position (YA)
CallBackLeftClic.i ; @Procedure (latitude.d, lontitude.d) to know the position on left click (YA)
CallBackDrawTile.ProtoDrawTile ; @Procedure (x.i, y.i, nImage.i) to customise tile drawing
PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global)
MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map
@@ -1174,7 +1185,7 @@ Module PBMap
; We're accessing MemoryCache
UnlockMutex(PBMap\MemoryCacheAccessMutex)
*Tile\Size = 0
*Tile\Download = ReceiveHTTPFile(*Tile\URL, *Tile\CacheFile, #PB_HTTP_Asynchronous)
*Tile\Download = ReceiveHTTPFile(*Tile\URL, *Tile\CacheFile, #PB_HTTP_Asynchronous, #USERAGENT)
If *Tile\Download
Repeat
Progress = HTTPProgress(*Tile\Download)
@@ -1329,13 +1340,13 @@ Module PBMap
Procedure DrawTiles(*Drawing.DrawingParameters, LayerName.s)
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 px, py, *timg.ImgMemCach, tilex, tiley, key.s
Protected tx.i = Int(*Drawing\TileCoordinates\x) ; Don't forget the Int() !
Protected ty.i = Int(*Drawing\TileCoordinates\y)
Protected nx.i = *Drawing\RadiusX / PBMap\TileSize ; How many tiles around the point
Protected ny.i = *Drawing\RadiusY / PBMap\TileSize
Protected px.i, py.i, *timg.ImgMemCach, tilex.i, tiley.i, key.s
Protected URL.s, CacheFile.s
Protected tilemax = 1<<PBMap\Zoom
Protected tilemax.i = 1<<PBMap\Zoom
Protected HereLoadBalancing.b ; Here is providing a load balancing system
FindMapElement(PBMap\Layers(), LayerName)
MyDebug("Drawing tiles")
@@ -1405,6 +1416,11 @@ Module PBMap
EndWith
*timg = GetTile(key, URL, CacheFile)
If *timg And *timg\nImage
If PBMap\CallBackDrawTile
;CallFunctionFast(PBMap\CallBackDrawTile, px, py, *timg\nImage)
PBMap\CallBackDrawTile(px, py, *timg\nImage, PBMap\Layers()\Alpha)
PBMap\Redraw = #True
Else
MovePathCursor(px, py)
If *timg\Alpha <= 224
DrawVectorImage(ImageID(*timg\nImage), *timg\Alpha * PBMap\Layers()\Alpha)
@@ -1414,6 +1430,7 @@ Module PBMap
DrawVectorImage(ImageID(*timg\nImage), 255 * PBMap\Layers()\Alpha)
*timg\Alpha = 256
EndIf
EndIf
Else
MovePathCursor(px, py)
DrawVectorImage(ImageID(PBMap\ImgLoading), 255 * PBMap\Layers()\Alpha)
@@ -2132,6 +2149,7 @@ Module PBMap
PBMap\Redraw = #True
EndProcedure
;-*** Callbacks
Procedure SetCallBackLocation(CallBackLocation.i)
PBMap\CallBackLocation = CallBackLocation
EndProcedure
@@ -2148,6 +2166,10 @@ Module PBMap
PBMap\CallBackLeftClic = CallBackLocation
EndProcedure
Procedure SetCallBackDrawTile(CallBackLocation.i)
PBMap\CallBackDrawTile = CallBackLocation
EndProcedure
Procedure SetMapScaleUnit(ScaleUnit.i = PBMAP::#SCALE_KM)
PBMap\Options\ScaleUnit = ScaleUnit
PBMap\Redraw = #True
@@ -2550,6 +2572,8 @@ Module PBMap
PBMap\MemCache\Images(key)\Tile = *Tile\Size
If *Tile\Size
PBMap\MemCache\Images(key)\Tile = -1 ; Web loading thread has finished successfully
;n = LoadImage(#PB_Any, *Tile\CacheFile)
Else
PBMap\MemCache\Images(key)\Tile = 0
EndIf
@@ -2724,6 +2748,11 @@ CompilerIf #PB_Compiler_IsMainFile
Debug "Identifier : " + *Marker\Identifier + "(" + StrD(*Marker\GeographicCoordinates\Latitude) + ", " + StrD(*Marker\GeographicCoordinates\Longitude) + ")"
EndProcedure
Procedure DrawTileCallBack(x.i, y.i, image.i, alpha.d)
MovePathCursor(x, y)
DrawVectorImage(ImageID(image), 255 * alpha)
EndProcedure
Procedure MainPointer(x.i, y.i)
VectorSourceColor(RGBA(255, 255,255, 255)) : AddPathCircle(x, y,32) : StrokePath(1)
VectorSourceColor(RGBA(0, 0, 0, 255)) : AddPathCircle(x, y, 29):StrokePath(2)
@@ -2824,6 +2853,7 @@ CompilerIf #PB_Compiler_IsMainFile
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(49.0446828398, 2.0349812508, "", "", -1, @MyMarker()) ; To add a marker with a customised GFX
PBMap::SetCallBackMarker(@MarkerMoveCallBack())
PBMap::SetCallBackDrawTile(@DrawTileCallBack())
Repeat
Event = WaitWindowEvent()
@@ -2956,8 +2986,8 @@ CompilerEndIf
; IDE Options = PureBasic 5.60 (Windows - x64)
; CursorPosition = 2727
; FirstLine = 2720
; CursorPosition = 291
; FirstLine = 279
; Folding = --------------------
; EnableThread
; EnableXP