From afc271278a6375ee8fafe62ad4c01781844833cf Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 4 Jul 2017 12:20:07 +0200 Subject: [PATCH] CallBackDrawTile + misc cleaning + useragent Allows a customised tile drawing --- PBMap.pb | 138 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 54 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index 92330a1..a07fcde 100644 --- a/PBMap.pb +++ b/PBMap.pb @@ -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 @@ -81,7 +85,10 @@ DeclareModule PBMap Declare.d GetLayerAlpha(Name.s) Declare BindMapGadget(Gadget.i) Declare SetCallBackLocation(*CallBackLocation) - Declare SetCallBackMainPointer(CallBackMainPointer.i) + 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() @@ -113,9 +120,8 @@ DeclareModule PBMap Declare FatalError(msg.s) Declare Error(msg.s) Declare Refresh() - Declare.i ClearDiskCache() - Declare SetCallBackMarker(*CallBackLocation) - Declare SetCallBackLeftClic(*CallBackLocation) + Declare.i ClearDiskCache() + 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 @@ -904,8 +915,8 @@ Module PBMap \Proxy = ReadPreferenceInteger("Proxy", #False) If \Proxy \ProxyURL = ReadPreferenceString("ProxyURL", "") ; = InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") - \ProxyPort = ReadPreferenceString("ProxyPort", "") ; = InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "") - \ProxyUser = ReadPreferenceString("ProxyUser", "") ; = InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "") + \ProxyPort = ReadPreferenceString("ProxyPort", "") ; = InputRequester("ProxyPort", "Do you use a specific port? Then enter it", "") + \ProxyUser = ReadPreferenceString("ProxyUser", "") ; = InputRequester("ProxyUser", "Do you use a user name? Then enter it", "") \ProxyPassword = ReadPreferenceString("ProxyPass", "") ; = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") ; TODO EndIf PreferenceGroup("HERE") @@ -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) @@ -1328,14 +1339,14 @@ Module PBMap EndProcedure 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 x.i, y.i, kq.q + 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<