From 757af8c19cea3e87ed0843b09afd361ad83d8e10 Mon Sep 17 00:00:00 2001 From: Gen Braga Date: Thu, 14 Feb 2019 22:26:05 +0000 Subject: [PATCH] Map.Proxy is a new property that allows to define the proxy used by all HTTP requests made to retrieve the map tiles. [GB.MAP] * NEW: Map.Proxy is a new property that allows to define the proxy used by all HTTP requests made to retrieve the map tiles. --- comp/src/gb.map/.src/Map.class | 13 +++++++++++-- comp/src/gb.map/.src/MapView.class | 6 ++---- comp/src/gb.map/.src/Tests/Form4.class | 8 ++++++++ comp/src/gb.map/.src/Tools/_MapProxy.class | 20 ++++++++++++++++++++ comp/src/gb.map/.src/_MapTile.class | 16 +++++++++++++--- 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 comp/src/gb.map/.src/Tools/_MapProxy.class diff --git a/comp/src/gb.map/.src/Map.class b/comp/src/gb.map/.src/Map.class index f3653fa6b..91b4d1945 100644 --- a/comp/src/gb.map/.src/Map.class +++ b/comp/src/gb.map/.src/Map.class @@ -12,6 +12,8 @@ Property Read PixelBox As Rect Property Read Bounds As MapBounds Property Read Count As Integer Property MaxZoom As Integer +Public _Proxy As _MapProxy +Property Read Proxy As _MapProxy ''Returns a object used for defining proxy parameters. Private $iMaxZoom As Integer = 18 Private $iZoom As Integer = 1 Private $mpCenter As New MapPoint @@ -184,14 +186,14 @@ End Public Sub AddTile(Name As String, Pattern As String, Optional Args As Collection, Optional CacheName As String) As _MapTile - Dim hLayer As New _MapTile(CacheName) + Dim hLayer As New _MapTile(CacheName, Me) hLayer.Name = Name 'hLayer.Pattern = Pattern hLayer.SetPattern(Pattern, Args) $aLayers.Add(hLayer) $aLayerNames.Add(Name) - Object.Attach(hLayer, Me, "Layer") + 'Object.Attach(hLayer, Me, "Layer") Return hLayer End @@ -373,3 +375,10 @@ Private Sub MaxZoom_Write(Value As Integer) $iMaxZoom = Value End + +Private Function Proxy_Read() As _MapProxy + + If Not _Proxy Then _Proxy = New _MapProxy + Return _Proxy + +End \ No newline at end of file diff --git a/comp/src/gb.map/.src/MapView.class b/comp/src/gb.map/.src/MapView.class index 98f842017..4c3452065 100644 --- a/comp/src/gb.map/.src/MapView.class +++ b/comp/src/gb.map/.src/MapView.class @@ -6,17 +6,15 @@ Inherits UserControl Public Const _Properties As String = "*,Border{Border.*},AllowEffect=true,ShowControls=true" Public Const _Group As String = "View" - Property Lock As Boolean Property Border As Integer Property Read {Map} As Map Property AllowEffect As Boolean Property ShowControls As Boolean Property Mode As Integer + Private $iMode As Integer Private $bShowControls As Boolean = True - - Private $hCenter As MapPoint Private $hMap As New Map As "Map" Private $hView As DrawingArea @@ -364,4 +362,4 @@ Private Sub Mode_Write(Value As Integer) -End +End \ No newline at end of file diff --git a/comp/src/gb.map/.src/Tests/Form4.class b/comp/src/gb.map/.src/Tests/Form4.class index f2c222166..ddf84bd9c 100644 --- a/comp/src/gb.map/.src/Tests/Form4.class +++ b/comp/src/gb.map/.src/Tests/Form4.class @@ -8,6 +8,14 @@ Dim hbound As MapBounds 'hImg = Scanners["hpaio:/net/HP_LaserJet_MFP_M426fdn?ip=192.168.1.25"].Scan() 'MapView1.Map.AddTile("gmap", "https://khms0.google.com/kh/v={version}?x={x}&y={y}&z={z}", ["version": "821"]).Copyright = "google" + + 'Authenticated proxy settings bellow + MapView1.Map.Proxy.Auth = Net.AuthBasic + MapView1.Map.Proxy.Type = Net.ProxyHTTP + MapView1.Map.Proxy.Host = "your-proxy-server" + MapView1.Map.Proxy.User = "your-proxy-user" + MapView1.Map.Proxy.Password = "your-proxy-password" + MapView1.Map.AddTile("OpenStreetMap", "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", Null).Copyright = "© OpenStreetMap contributors" MapView1.Map.Center = MapPoint(48.866667, 2.333333) diff --git a/comp/src/gb.map/.src/Tools/_MapProxy.class b/comp/src/gb.map/.src/Tools/_MapProxy.class new file mode 100644 index 000000000..f01e89874 --- /dev/null +++ b/comp/src/gb.map/.src/Tools/_MapProxy.class @@ -0,0 +1,20 @@ +' Gambas class file + +''' This virtual class allows to define proxy parameters. + +Export + +'' Return or set the HTTP authentication mode to use. +'' It can be one of the following constants +'' - Net.AuthNone (the Default) +'' - Net.AuthBasic +'' - Net.AuthNtlm +Public Auth As Integer +'' Return or set the proxy type. +'' It can be one Of the following constant: +'' - Net.ProxyHTTP (the Default) +'' - Net.ProxySocks5 +Public Type As Integer +Public Host As String '' Return or set the proxy host name. +Public User As String '' Return or set the proxy user name. +Public Password As String '' Return or set the proxy password. \ No newline at end of file diff --git a/comp/src/gb.map/.src/_MapTile.class b/comp/src/gb.map/.src/_MapTile.class index e46ff0b44..6e8d41107 100644 --- a/comp/src/gb.map/.src/_MapTile.class +++ b/comp/src/gb.map/.src/_MapTile.class @@ -9,9 +9,9 @@ Property Read Loading As Boolean Property UseWebMapService As Boolean Property WMSArgs As Collection Property MaxBounds As MapBounds -''Delay before refreshing an image in the cache. (By default 30 day) +'' Delay before refreshing an image in the cache. (By default 30 day) Property CacheRefreshDelay As Integer -''Set the projection used by the WMS server. +'' Set the projection used by the WMS server. Property WMSProjection As String Private $aStack As New String[] @@ -51,7 +51,7 @@ Private $bCacheRefresh As Boolean = True ' Private $bHaveCache As Boolean Event Refresh -Public Sub _new(Optional CacheName As String) +Public Sub _new(Optional CacheName As String, Parent As Object) Dim sTempPath As String Dim hClient As HttpClient @@ -59,6 +59,7 @@ Public Sub _new(Optional CacheName As String) 'Dim hTable As Table 'db.Debug = True + Object.Attach(Me, Parent, "Layer") $prjLatLon = New Proj("epsg:4326") If CacheName Then sTempPath = $sCachePath &/ CacheName @@ -77,6 +78,15 @@ Public Sub _new(Optional CacheName As String) For i = 0 To $aClients.Max hClient = New HttpClient As "Client" hClient.Async = True + With GetMap() + If ._Proxy Then + hClient.Proxy.Auth = ._Proxy.Auth + hClient.Proxy.Type = ._Proxy.Type + hClient.Proxy.Host = ._Proxy.Host + hClient.Proxy.User = ._Proxy.User + hClient.Proxy.Password = ._Proxy.Password + Endif + End With $aClients[i] = hClient hClient.Timeout = 10 Next