diff --git a/Assets/Scripts/CartesianTiles/WMSTileDataLayer.cs b/Assets/Scripts/CartesianTiles/WMSTileDataLayer.cs index 119ad3e6..36631abd 100644 --- a/Assets/Scripts/CartesianTiles/WMSTileDataLayer.cs +++ b/Assets/Scripts/CartesianTiles/WMSTileDataLayer.cs @@ -12,6 +12,9 @@ namespace Netherlands3D.Twin { public class WMSTileDataLayer : ImageProjectionLayer { + //this gives the requesting url the extra param to set transparancy enabled by default + public bool TransparencyEnabled = true; + private string wmsUrl = ""; public string WmsUrl { @@ -52,7 +55,6 @@ protected override IEnumerator DownloadDataAndGenerateTexture(TileChange tileCha var bboxValue = $"{tileChange.X},{tileChange.Y},{(tileChange.X + tileSize)},{(tileChange.Y + tileSize)}"; string url = wmsUrl.Replace("{0}", bboxValue); - //var webRequest = UnityWebRequest.Get(url); UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(url); tile.runningWebRequest = webRequest; yield return webRequest.SendWebRequest(); @@ -65,19 +67,8 @@ protected override IEnumerator DownloadDataAndGenerateTexture(TileChange tileCha } else { - //byte[] imageData = webRequest.downloadHandler.data; - //Texture2D tex = new Texture2D(2, 2, TextureFormat.RGBA32, false); - //tex.LoadImage(imageData); - ////tex.LoadRawTextureData(imageData); - //tex.Apply(); - Texture texture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture; - - ////Texture myTexture = DownloadHandlerTexture.GetContent(webRequest); Texture2D tex = texture as Texture2D; - - Color[] pixels = tex.GetPixels(); - if (tile.gameObject.TryGetComponent(out var projector)) { projector.SetSize(tileSize, tileSize, tileSize); @@ -90,8 +81,6 @@ protected override IEnumerator DownloadDataAndGenerateTexture(TileChange tileCha textureDecalProjector.SetSize(decalProjector.size.x, decalProjector.size.y, ProjectorMinDepth); } - - ClearPreviousTexture(tile); callback(tileChange); } diff --git a/Assets/Scripts/Layers/Adapters/DataTypeAdapters/WMSImportAdapter.cs b/Assets/Scripts/Layers/Adapters/DataTypeAdapters/WMSImportAdapter.cs index 1907d1b6..f7f83f17 100644 --- a/Assets/Scripts/Layers/Adapters/DataTypeAdapters/WMSImportAdapter.cs +++ b/Assets/Scripts/Layers/Adapters/DataTypeAdapters/WMSImportAdapter.cs @@ -71,16 +71,17 @@ public void Execute(LocalFile localFile) private void AddWMSLayer(WMS.WMSLayerQueryParams layer, string sourceUrl, FolderLayer folderLayer) { - Debug.Log("Adding WMS layer: " + layer.name); - // Create a layerType URL for the specific layerType - UriBuilder uriBuilder = CreateLayerUri(layer, sourceUrl); - var getLayerTypeUrl = uriBuilder.Uri.ToString(); - string finalUrl = Uri.UnescapeDataString(getLayerTypeUrl); - //Spawn a new WMS layer WMSLayerGameObject newLayer = Instantiate(layerPrefab); newLayer.LayerData.SetParent(folderLayer); newLayer.Name = layer.name; + + Debug.Log("Adding WMS layer: " + layer.name); + // Create a layerType URL for the specific layerType + UriBuilder uriBuilder = CreateLayerUri(layer, sourceUrl); + var getLayerTypeUrl = uriBuilder.Uri.ToString(); + string finalUrl = Uri.UnescapeDataString(getLayerTypeUrl); + newLayer.SetURL(finalUrl); } @@ -115,6 +116,8 @@ private UriBuilder CreateLayerUri(WMS.WMSLayerQueryParams layer, string sourceUr { uriBuilder.AddQueryParameter("format", "image/png"); } + if (!sourceUrl.Contains("transparent=")) + uriBuilder.AddQueryParameter("transparent", layerPrefab.TransparencyEnabled.ToString()); return uriBuilder; } diff --git a/Assets/Scripts/Layers/LayerTypes/WMSLayerGameObject.cs b/Assets/Scripts/Layers/LayerTypes/WMSLayerGameObject.cs index 8d35b45c..43aa309e 100644 --- a/Assets/Scripts/Layers/LayerTypes/WMSLayerGameObject.cs +++ b/Assets/Scripts/Layers/LayerTypes/WMSLayerGameObject.cs @@ -10,12 +10,21 @@ namespace Netherlands3D.Twin.Layers public class WMSLayerGameObject : CartesianTileLayerGameObject, ILayerWithPropertyData { private WMSTileDataLayer wmsProjectionLayer; - public WMSTileDataLayer WMSProjectionLayer { get => wmsProjectionLayer; } - + public WMSTileDataLayer WMSProjectionLayer + { + get + { + if (wmsProjectionLayer == null) + wmsProjectionLayer = GetComponent(); + return wmsProjectionLayer; + } + } protected LayerURLPropertyData urlPropertyData = new(); LayerPropertyData ILayerWithPropertyData.PropertyData => urlPropertyData; + public bool TransparencyEnabled { get => WMSProjectionLayer.TransparencyEnabled; } + protected override void Awake() { base.Awake();