// Copyright (C) Stichting Deltares 2017. 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.Components.Gis.Properties;
namespace Core.Components.Gis.Data
{
///
/// Class representing a mapdata coming from a Web Map Tile Service (WMTS).
///
public class WmtsMapData : ImageBasedMapData
{
///
/// Creates a new instance of .
///
/// The name of the map data.
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// The type of image format. It should be for formatted
/// in MIME.
/// Thrown when
///
/// - is null or only whitespace.
/// - is not stated as a MIME-type.
///
/// Thrown when ,
/// or is null.
public WmtsMapData(string name, string sourceCapabilitiesUrl, string selectedCapabilityName,
string preferredFormat) : this(name)
{
Configure(sourceCapabilitiesUrl, selectedCapabilityName, preferredFormat);
}
///
/// Creates a new instance of that hasn't been configured.
///
/// The name of the map data.
/// Thrown when is null or only whitespace.
public WmtsMapData(string name) : base(name)
{
IsVisible = false;
}
///
/// 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 SelectedCapabilityIdentifier { get; private set; }
///
/// Gets the MIME-type specification of the preferred tile image format.
///
public string PreferredFormat { get; private set; }
///
/// Configures this instance to use a particular WMTS.
///
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// The type of image format. It should be for formatted
/// in MIME.
/// Thrown when any input argument is null.
/// Thrown when
/// is not stated as a MIME-type.
public void Configure(string sourceCapabilitiesUrl, string selectedCapabilityName,
string preferredFormat)
{
if (sourceCapabilitiesUrl == null)
{
throw new ArgumentNullException(nameof(sourceCapabilitiesUrl));
}
if (selectedCapabilityName == null)
{
throw new ArgumentNullException(nameof(selectedCapabilityName));
}
if (preferredFormat == null)
{
throw new ArgumentNullException(nameof(preferredFormat));
}
if (!preferredFormat.StartsWith("image/"))
{
throw new ArgumentException(@"Specified image format is not a MIME type.", nameof(preferredFormat));
}
SourceCapabilitiesUrl = sourceCapabilitiesUrl;
SelectedCapabilityIdentifier = selectedCapabilityName;
PreferredFormat = preferredFormat;
IsConfigured = true;
IsVisible = true;
}
///
/// Removes the configuration to the connected WMTS.
///
public void RemoveConfiguration()
{
SourceCapabilitiesUrl = null;
SelectedCapabilityIdentifier = null;
PreferredFormat = null;
IsConfigured = false;
IsVisible = false;
Name = Resources.WmtsMapData_Unconfigured_name;
}
}
}