// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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.Common.Base.Data;
using Core.Components.Gis.Properties;
namespace Core.Components.Gis.Data
{
///
/// Class representing a mapdata coming from a Web Map Tile Service (WMTS).
///
public class WmtsMapData : MapData
{
private RoundedDouble transparency;
///
/// Creates a new instance of .
///
/// The name of the source.
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// Thrown when is null or only whitespace.
/// Thrown when
/// or is null.
public WmtsMapData(string name, string sourceCapabilitiesUrl, string selectedCapabilityName) : this(name)
{
Configure(sourceCapabilitiesUrl, selectedCapabilityName);
}
///
/// Creates a new instance of that hasn't been configured.
///
/// The name of the source.
/// Thrown when is null or only whitespace.
private WmtsMapData(string name) : base(name)
{
transparency = new RoundedDouble(2, 0.0);
}
///
/// Gets the URL of the source.
///
public string SourceCapabilitiesUrl { get; private set; }
///
/// Gets the name of the specific capability that is exposed by
/// that has been connected to for this map data.
///
public string SelectedCapabilityName { get; private set; }
///
/// Gets or sets the transparency of the map data.
///
public RoundedDouble Transparency
{
get
{
return transparency;
}
set
{
var newValue = new RoundedDouble(transparency.NumberOfDecimalPlaces, value);
if (double.IsNaN(newValue) || newValue < 0.0 || newValue > 1.0)
{
throw new ArgumentOutOfRangeException(nameof(value),
Resources.WmtsMapData_Transparency_Value_must_be_in_zero_to_one_range);
}
transparency = newValue;
}
}
///
/// Gets a value indicating if the map data is configured to use a particular WMTS.
///
public bool IsConfigured { get; private set; }
///
/// Creates a new instance of configured to the 'brtachtergrondkaart'
/// of PDOK.
///
public static WmtsMapData CreateDefaultPdokMapData()
{
return new WmtsMapData(Resources.WmtsMapData_CreateDefaultPdokMapData_Name,
"https://geodata.nationaalgeoregister.nl/tiles/service/wmts/bgtachtergrond?request=GetCapabilities",
"brtachtergrondkaart");
}
///
/// Creates a new instance of that hasn't been configured.
///
///
public static WmtsMapData CreateUnconnectedMapData()
{
return new WmtsMapData(Resources.WmtsMapData_Unconfigured_name);
}
///
/// Configures this instance to use a particular WMTS.
///
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// Thrown when
/// or is null.
public void Configure(string sourceCapabilitiesUrl, string selectedCapabilityName)
{
if (sourceCapabilitiesUrl == null)
{
throw new ArgumentNullException(nameof(sourceCapabilitiesUrl));
}
if (selectedCapabilityName == null)
{
throw new ArgumentNullException(nameof(selectedCapabilityName));
}
SourceCapabilitiesUrl = sourceCapabilitiesUrl;
SelectedCapabilityName = selectedCapabilityName;
IsConfigured = true;
}
///
/// Removes the configuration to the connected WMTS.
///
public void RemoveConfiguration()
{
SourceCapabilitiesUrl = null;
SelectedCapabilityName = null;
IsConfigured = false;
}
}
}