From 3a3b382dd44af9362377f23248d160e4d2576e10 Mon Sep 17 00:00:00 2001 From: Fabien Bodard Date: Tue, 18 Dec 2012 21:10:41 +0000 Subject: [PATCH] [GB.MAP] * NEW: Now Layers have an opacity property * NEW: Tiles are showed with an opacity effect in the MapView. git-svn-id: svn://localhost/gambas/trunk@5444 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- comp/src/gb.map/.info | 4 +++ comp/src/gb.map/.src/Map.class | 1 + comp/src/gb.map/.src/MapView.class | 1 + comp/src/gb.map/.src/Tests/FMain.class | 2 ++ comp/src/gb.map/.src/Types/_Tile.class | 2 +- comp/src/gb.map/.src/_MapTile.class | 36 +++++++++++++++++++++++--- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/comp/src/gb.map/.info b/comp/src/gb.map/.info index b8f584a0c..bab592268 100644 --- a/comp/src/gb.map/.info +++ b/comp/src/gb.map/.info @@ -70,6 +70,10 @@ Preload p b +_ShowWithEffect +v +b + :Refresh : diff --git a/comp/src/gb.map/.src/Map.class b/comp/src/gb.map/.src/Map.class index 3eb9c327b..75529b534 100644 --- a/comp/src/gb.map/.src/Map.class +++ b/comp/src/gb.map/.src/Map.class @@ -25,6 +25,7 @@ Private $aLayers As New _MapLayer[] Private $aLayerNames As New String[] Property Preload As Boolean Private $bPreload As Boolean +Public _ShowWithEffect As Boolean Event Refresh Private Function Top_Read() As Integer diff --git a/comp/src/gb.map/.src/MapView.class b/comp/src/gb.map/.src/MapView.class index e5a41f80c..ff6dcfa9a 100644 --- a/comp/src/gb.map/.src/MapView.class +++ b/comp/src/gb.map/.src/MapView.class @@ -28,6 +28,7 @@ Public Sub _new() $hView = New DrawingArea($hPan) As "View" Me.Proxy = $hView $hMap.resize($hView.ClientW, $hView.ClientH) + $hmap._ShowWithEffect = True $hView.Tracking = True $hView.Padding = True $hView.Background = Color.DarkGray diff --git a/comp/src/gb.map/.src/Tests/FMain.class b/comp/src/gb.map/.src/Tests/FMain.class index 1d2360ea2..8d6eba81a 100644 --- a/comp/src/gb.map/.src/Tests/FMain.class +++ b/comp/src/gb.map/.src/Tests/FMain.class @@ -19,7 +19,9 @@ Public Sub _new() MapView1.Map.AddTile("GoogleMap", "https://khms{s}.google.fr/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "121"]).SubDomains = ["0", "1", "2"] MapView1.Map["GoogleMap"].Visible = False + With MapView1.Map.AddTile("OpenStreet", "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", Null) + .Opacity = 0.5 .Copyright = "OpenStreetMap contributors" End With 'MapView1.Map.AddShape("test") diff --git a/comp/src/gb.map/.src/Types/_Tile.class b/comp/src/gb.map/.src/Types/_Tile.class index c9e5d9f3c..421302ce0 100644 --- a/comp/src/gb.map/.src/Types/_Tile.class +++ b/comp/src/gb.map/.src/Types/_Tile.class @@ -13,5 +13,5 @@ Public Status As Integer Public Image As Image Public TryCount As Integer Public Name As String -Public Alpha As Integer +Public Opacity As Float diff --git a/comp/src/gb.map/.src/_MapTile.class b/comp/src/gb.map/.src/_MapTile.class index ab6df91a7..02529ff1e 100644 --- a/comp/src/gb.map/.src/_MapTile.class +++ b/comp/src/gb.map/.src/_MapTile.class @@ -11,19 +11,21 @@ Public $aStack As New String[] Private $sPattern As String Private $aSubDomains As String[] = ["a", "b", "c"] Property SubDomains As String[] +Property Opacity As Float +Private $fOpacity As Float = 1 Private $aPreload As New String[] Private $bPreloadMode As Boolean -Private tmrShowGrade As New Timer As "ShowGrade" +Private $fGradStep As Float = 0.1 Private $bIsQuadKey As Boolean Event Refresh - +Private tmrShow As New Timer As "tmrShow" Public Sub _new(Optional CacheName As String) Dim sTempPath As String Dim hClient As HttpClient Dim i As Integer - tmrShowGrade.Delay = 30 + tmrShow.Delay = 30 If CacheName Then sTempPath = $sCachePath &/ CacheName @@ -44,6 +46,7 @@ Public Sub _new(Optional CacheName As String) 'hClient.Timeout = 1 Next + End ' svn checkout --username=gambix svn+ssh://gambas@svn.code.sf.net/p/gambas/code/gambas/trunk ' @@ -58,7 +61,17 @@ Public Sub Draw() hTile = $coltiles[s] Select Case hTile.Status Case _Tile.Normal - Try Draw.Image(hTile.Image, hTile.X * 256 - hMap.PixelBox.X, hTile.Y * 256 - hMap.PixelBox.Y) + If hmap._ShowWithEffect Then + Try Paint.DrawImage(hTile.Image, hTile.X * 256 - hMap.PixelBox.X, hTile.Y * 256 - hMap.PixelBox.Y,,, Min(hTile.Opacity, $fOpacity)) + + If hTile.Opacity < $fOpacity Then + hTile.Opacity += $fGradStep + Raise Refresh + Endif + Else + Try Paint.DrawImage(hTile.Image, hTile.X * 256 - hMap.PixelBox.X, hTile.Y * 256 - hMap.PixelBox.Y,,, $fOpacity) + Endif + 'Draw.Foreground = Color.Green 'Draw.Text("TileOK", hTile.X * 256 - hMap.PixelBox.X, hTile.Y * 256 - hMap.PixelBox.Y) Case _Tile.Error @@ -127,6 +140,8 @@ Public Sub Load() If Error Then 'Error "Image illisible -> " & hTile.Name ReLoadTile(hTile) + Else + hTile.Opacity = $fOpacity Endif Else hTile.Status = _Tile.Loading @@ -410,3 +425,16 @@ Private Function TileToQuadKey(X As Integer, Y As Integer, Z As Integer) As Stri Return quadKey End + +Private Function Opacity_Read() As Float + + Return $fOpacity + +End + +Private Sub Opacity_Write(Value As Float) + + $fOpacity = Min(1, Max(0, Value)) + $fGradStep = $fOpacity / 10 + +End