// 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.Drawing;
using System.Linq;
using Core.Components.Gis.Features;
using Core.Components.Gis.Style;
using Core.Components.Gis.Theme;
namespace Core.Components.Gis.Data
{
///
/// This class represents features that are visible as points.
///
public class MapPointData : FeatureBasedMapData
{
///
/// Creates a new instance of with default styling.
///
/// The name of the .
/// Thrown when is
/// null or only whitespace.
public MapPointData(string name) : this(name, CreateDefaultPointStyle()) {}
///
/// Creates a new instance of .
///
/// The name of the .
/// The style of the data.
/// Thrown when is
/// null or only whitespace.
/// Thrown when
/// is null.
public MapPointData(string name, PointStyle style) : base(name)
{
if (style == null)
{
throw new ArgumentNullException(nameof(style));
}
Style = style;
}
///
/// Creates a new instance of .
///
/// The name of the .
/// The default style of the data that is not categorized by the categories
/// defined in .
/// The map theme belong to the data.
/// Thrown when is
/// null or only whitespace.
/// Thrown when
/// is null.
public MapPointData(string name, PointStyle style, MapTheme mapTheme)
: base(name, mapTheme)
{
if (style == null)
{
throw new ArgumentNullException(nameof(style));
}
Style = style;
}
///
/// Gets the style of the points.
///
public PointStyle Style { get; }
///
/// This method validates newly set features.
///
/// The new features to validate.
/// Thrown when is null.
/// Thrown when any feature in
/// contains multiple point-collections.
///
protected override void ValidateFeatures(IEnumerable featuresToValidate)
{
base.ValidateFeatures(featuresToValidate);
if (HasFeatureWithMultiplePointCollections(featuresToValidate))
{
throw new ArgumentException("MapPointData only accepts MapFeature instances whose MapGeometries contain a single point-collection.");
}
}
private static PointStyle CreateDefaultPointStyle()
{
return new PointStyle
{
Color = Color.Black,
Size = 2,
Symbol = PointSymbol.Square,
StrokeColor = Color.Black,
StrokeThickness = 1
};
}
private static bool HasFeatureWithMultiplePointCollections(IEnumerable pointFeatures)
{
return pointFeatures.Where(feature => feature != null)
.SelectMany(feature => feature.MapGeometries)
.Any(geometry => geometry.PointCollections.Count() != 1);
}
}
}