// 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 Core.Components.DotSpatial.Layer.BruTile; using Core.Components.Gis.Data; namespace Core.Components.DotSpatial.Forms { /// /// Abstract class for keeping track of various status information related to the /// used to create a background layer in a map view. /// internal abstract class BackgroundLayerStatus : IDisposable { /// /// Gets a value indicating that the most recent attempt to create the background /// layer failed (returning true) or was successful (returning false). /// public virtual bool PreviousBackgroundLayerCreationFailed { get; protected set; } /// /// Gets the initialized background layer. /// public virtual BruTileLayer BackgroundLayer { get; protected set; } /// /// Marks that a (new) background layer has successfully been initialized. /// /// The constructed layer. /// The data used to construct . /// Thrown when any of the input parameters is null. public void LayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) { if (backgroundLayer == null) { throw new ArgumentNullException(nameof(backgroundLayer)); } if (dataSource == null) { throw new ArgumentNullException(nameof(dataSource)); } OnLayerInitializationSuccessful(backgroundLayer, dataSource); } /// /// Mark that the attempt to create a new background layer failed. /// public void LayerInitializationFailed() { ClearConfiguration(); PreviousBackgroundLayerCreationFailed = true; } /// /// Clears the status information for the background layer and disposes /// as well. /// /// Optional: A flag to indicate /// if recreation of with the same parameters is expected /// (true) or is expected to be replaced (false). public abstract void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false); /// /// Indicates if a corresponds with the . /// /// The map data. /// Returns true if corresponds with /// , false otherwise. /// Thrown when is null. public bool HasSameConfiguration(ImageBasedMapData mapData) { if (mapData == null) { throw new ArgumentNullException(nameof(mapData)); } return OnHasSameConfiguration(mapData); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { BackgroundLayer?.Dispose(); } } /// /// Marks that a (new) background layer has successfully been initialized. /// /// The constructed layer. /// The data used to construct . protected abstract void OnLayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource); /// /// Indicates if a corresponds with the . /// /// The map data. /// Returns true if corresponds with /// , false otherwise. protected abstract bool OnHasSameConfiguration(ImageBasedMapData mapData); } }