// Copyright (C) Stichting Deltares and State of the Netherlands 2025. All rights reserved. // // This file is part of Riskeer. // // Riskeer is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using Core.Components.Gis.Features; using Core.Components.Gis.Theme; namespace Core.Components.Gis.Data { /// /// Base class for which is based on an array of features. /// The features are defined in the RD-new coordinate system. /// public abstract class FeatureBasedMapData : MapData { private IEnumerable features; /// /// Creates a new instance of . /// /// The name of the . /// Thrown when is /// null or only whitespace. protected FeatureBasedMapData(string name) : base(name) { features = new MapFeature[0]; ShowLabels = false; } /// /// Gets or sets an array of features defined in the RD-new coordinate system. /// /// Calls when setting a new array and so /// can throw all corresponding exceptions. This collection will not contain null /// elements. public IEnumerable Features { get { return features; } set { ValidateFeatures(value); features = value; } } /// /// Gets or sets a value indicating whether the labels of the should be shown. /// public bool ShowLabels { get; set; } /// /// Gets or sets the selected attribute of the meta data to show as label. /// public string SelectedMetaDataAttribute { get; set; } /// /// Gets the meta data associated with the map data. /// public IEnumerable MetaData { get { return features.SelectMany(f => f.MetaData) .Select(md => md.Key) .Distinct(); } } /// /// This method validates newly set features. /// /// The new features to validate. /// Thrown when /// is null or contains null. /// protected virtual void ValidateFeatures(IEnumerable featuresToValidate) { if (featuresToValidate == null || featuresToValidate.Any(e => e == null)) { throw new ArgumentNullException(nameof(featuresToValidate), @"The array of features cannot be null or contain null."); } } } /// /// Base class for which is based on an array of features /// and has categorical theming. The features are defined in the RD-new coordinate system. /// /// The type of category theme. public abstract class FeatureBasedMapData : FeatureBasedMapData where TCategoryTheme : CategoryTheme { /// /// Creates a new instance of . /// /// The name of the . /// Thrown when is /// null or only whitespace. protected FeatureBasedMapData(string name) : base(name) {} /// /// Creates a new instance of . /// /// The name of the . /// The /// belonging to the . /// Thrown when /// is null. /// Thrown when is /// null or only whitespace. protected FeatureBasedMapData(string name, MapTheme theme) : this(name) { if (theme == null) { throw new ArgumentNullException(nameof(theme)); } Theme = theme; } /// /// Gets the that belongs to the map data. /// public MapTheme Theme { get; } } }