Skip to content

Commit

Permalink
added default transparency unless predefined in sourceurl & little re…
Browse files Browse the repository at this point in the history
…factoring
  • Loading branch information
bozmir committed Oct 9, 2024
1 parent 885aaa3 commit 8bf2962
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
17 changes: 3 additions & 14 deletions Assets/Scripts/CartesianTiles/WMSTileDataLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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<TextureProjectorBase>(out var projector))
{
projector.SetSize(tileSize, tileSize, tileSize);
Expand All @@ -90,8 +81,6 @@ protected override IEnumerator DownloadDataAndGenerateTexture(TileChange tileCha
textureDecalProjector.SetSize(decalProjector.size.x, decalProjector.size.y, ProjectorMinDepth);

}


ClearPreviousTexture(tile);
callback(tileChange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 11 additions & 2 deletions Assets/Scripts/Layers/LayerTypes/WMSLayerGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WMSTileDataLayer>();
return wmsProjectionLayer;
}
}

protected LayerURLPropertyData urlPropertyData = new();
LayerPropertyData ILayerWithPropertyData.PropertyData => urlPropertyData;

public bool TransparencyEnabled { get => WMSProjectionLayer.TransparencyEnabled; }

protected override void Awake()
{
base.Awake();
Expand Down

0 comments on commit 8bf2962

Please sign in to comment.