Skip to content

Commit

Permalink
Merge pull request #258 from Netherlands3D/feature/bij-heropenen-proj…
Browse files Browse the repository at this point in the history
…ect-met-vectorlagen-worden-geen-kleuren-getoond

Feature/bij heropenen project met vectorlagen worden geen kleuren getoond
  • Loading branch information
mvriel authored Sep 23, 2024
2 parents 06a45cc + 6215e2c commit 5cce2aa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
26 changes: 25 additions & 1 deletion Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public partial class GeoJSONLineLayer : LayerGameObject
{
public List<FeatureLineVisualisations> SpawnedVisualisations = new();

private bool randomizeColorPerFeature = false;
public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; }

[SerializeField] private LineRenderer3D lineRenderer3D;

public LineRenderer3D LineRenderer3D
Expand All @@ -30,7 +33,7 @@ public LineRenderer3D LineRenderer3D
// Destroy(lineRenderer3D.gameObject);
lineRenderer3D = value;
}
}
}

public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy)
{
Expand All @@ -46,6 +49,9 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original

var newFeatureVisualisation = new FeatureLineVisualisations() { feature = feature };

// Create visual with random color if enabled
lineRenderer3D.LineMaterial = GetMaterialInstance();

if (feature.Geometry is MultiLineString multiLineString)
{
var newLines = GeoJSONGeometryVisualizerUtility.VisualizeMultiLineString(multiLineString, originalCoordinateSystem, lineRenderer3D);
Expand All @@ -60,6 +66,24 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original
SpawnedVisualisations.Add(newFeatureVisualisation);
}

private Material GetMaterialInstance()
{
Material featureMaterialInstance;
// Create material with random color if randomize per feature is enabled
if (RandomizeColorPerFeature)
{
var randomColor = UnityEngine.Random.ColorHSV();
randomColor.a = LayerData.Color.a;

featureMaterialInstance = new Material(lineRenderer3D.LineMaterial) { color = randomColor };
return featureMaterialInstance;
}

// Default to material with layer color
featureMaterialInstance = new Material(lineRenderer3D.LineMaterial) { color = LayerData.Color };
return featureMaterialInstance;
}

/// <summary>
/// Checks the Bounds of the visualisations and checks them against the camera frustum
/// to remove visualisations that are out of view
Expand Down
30 changes: 27 additions & 3 deletions Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public partial class GeoJSONPointLayer : LayerGameObject
{
public List<FeaturePointVisualisations> SpawnedVisualisations = new();

private bool randomizeColorPerFeature = false;
public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; }

[SerializeField] private BatchedMeshInstanceRenderer pointRenderer3D;

public BatchedMeshInstanceRenderer PointRenderer3D
Expand All @@ -28,7 +31,7 @@ public BatchedMeshInstanceRenderer PointRenderer3D
pointRenderer3D = value;
}
}

public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy)
{
pointRenderer3D.gameObject.SetActive(activeInHierarchy);
Expand All @@ -42,7 +45,10 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original
return;

var newFeatureVisualisation = new FeaturePointVisualisations() { feature = feature };


// Create visual with random color if enabled
pointRenderer3D.Material = GetMaterialInstance();

if (feature.Geometry is MultiPoint multiPoint)
{
var newPointCollection = GeoJSONGeometryVisualizerUtility.VisualizeMultiPoint(multiPoint, originalCoordinateSystem, PointRenderer3D);
Expand All @@ -57,7 +63,25 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original
SpawnedVisualisations.Add(newFeatureVisualisation);
}

/// <summary>
private Material GetMaterialInstance()
{
Material featureMaterialInstance;
// Create material with random color if randomize per feature is enabled
if (RandomizeColorPerFeature)
{
var randomColor = UnityEngine.Random.ColorHSV();
randomColor.a = LayerData.Color.a;

featureMaterialInstance = new Material(pointRenderer3D.Material) { color = randomColor };
return featureMaterialInstance;
}

// Default to material with layer color
featureMaterialInstance = new Material(pointRenderer3D.Material) { color = LayerData.Color };
return featureMaterialInstance;
}

/// <summary>
/// Checks the Bounds of the visualisations and checks them against the camera frustum
/// to remove visualisations that are out of view
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ public class GeoJsonLayerGameObject : LayerGameObject, ILayerWithPropertyData
LayerPropertyData ILayerWithPropertyData.PropertyData => urlPropertyData;

protected virtual void Awake()
{
LoadDefaultValues();
}

protected virtual void LoadDefaultValues()
{
//GeoJSON layer+visual colors are set to random colors until user can pick colors in UI
var randomLayerColor = Color.HSVToRGB(UnityEngine.Random.value, UnityEngine.Random.Range(0.5f, 1f), 1);
randomLayerColor.a = 0.5f;
LayerData.Color = randomLayerColor;

}

/// <summary>
Expand Down

0 comments on commit 5cce2aa

Please sign in to comment.