#region Disclaimer / License // Copyright (C) 2010, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library 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 2.1 of the License, or (at your option) any later version. // // This library 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 library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.Text; using OSGeo.MapGuide.ObjectModels.Common; using OSGeo.MapGuide.ObjectModels; using System.Drawing; using OSGeo.MapGuide.MaestroAPI.Schema; using System.Xml; namespace OSGeo.MapGuide.MaestroAPI.SchemaOverrides { /// /// A WMS Raster configuration element /// public class RasterWmsItem : IFdoSerializable { /// /// Represents all valid WMS image formats /// public class WmsImageFormat { /// /// Portable Network Graphics (PNG) /// public const string PNG = "PNG"; /// /// Tagged Image File (TIF) /// public const string TIF = "TIF"; /// /// Joint Photographic Experts Group (JPEG) /// public const string JPG = "JPG"; /// /// Graphics Interchange Format (GIF) /// public const string GIF = "GIF"; } internal RasterWmsItem() { } /// /// Initializes a new instance of the class. /// /// Name of the schema /// Name of the class. /// Name of the raster property. public RasterWmsItem(string schemaName, string className, string rasterPropertyName) { this.SchemaName = schemaName; this.FeatureClass = className; this.RasterPropertyName = rasterPropertyName; } /// /// Gets the name of the FDO logical schema this particular override applies to /// public string SchemaName { get; internal set; } /// /// Gets or sets the feature class. /// /// /// The feature class. /// public string FeatureClass { get; set; } /// /// Gets or sets the name of the raster property. /// /// /// The name of the raster property. /// public string RasterPropertyName { get; set; } /// /// Gets or sets the elevation dimension. /// /// /// The elevation dimension. /// public string ElevationDimension { get; set; } /// /// Gets or sets the image format. /// /// /// The image format. /// public string ImageFormat { get; set; } private List _layers = new List(); /// /// Gets the array of WMS layer configuration elements /// public WmsLayerDefinition[] Layers { get { return _layers.ToArray(); } } /// /// Adds a WMS layer configuration element. /// /// The layer. public void AddLayer(WmsLayerDefinition layer) { _layers.Add(layer); } /// /// Removes the given WMS layer configuration element /// /// The layer. public void RemoveLayer(WmsLayerDefinition layer) { _layers.Remove(layer); } /// /// Gets or sets a value indicating whether tile caching is used /// /// /// true if tile caching is used; otherwise, false. /// public bool UseTileCache { get; set; } /// /// Gets or sets the time. /// /// /// The time. /// public string Time { get; set; } /// /// Gets or sets the name of the spatial context. /// /// /// The name of the spatial context. /// public string SpatialContextName { get; set; } /// /// Gets or sets a value indicating whether this instance is transparent. /// /// /// true if this instance is transparent; otherwise, false. /// public bool IsTransparent { get; set; } /// /// Gets or sets the color of the background. /// /// /// The color of the background. /// public Color BackgroundColor { get; set; } /// /// Writes the current element's content /// /// /// public void WriteXml(System.Xml.XmlDocument doc, System.Xml.XmlNode currentNode) { var rasterDef = doc.CreateElement("RasterDefinition"); var n = doc.CreateAttribute("name"); n.Value = this.RasterPropertyName; rasterDef.Attributes.Append(n); { var format = doc.CreateElement("Format"); format.InnerText = this.ImageFormat; var mimeType = doc.CreateElement("FormatType"); if (!string.IsNullOrEmpty(this.ImageFormat)) { switch (this.ImageFormat) { case WmsImageFormat.GIF: mimeType.InnerText = "image/gif"; break; case WmsImageFormat.JPG: mimeType.InnerText = "image/jpeg"; //NOXLATE break; case WmsImageFormat.PNG: mimeType.InnerText = "image/png"; break; case WmsImageFormat.TIF: mimeType.InnerText = "image/tiff"; //NOXLATE break; } } var transparent = doc.CreateElement("Transparent"); transparent.InnerText = this.IsTransparent ? "true" : "false"; var bgcolor = doc.CreateElement("BackgroundColor"); bgcolor.InnerText = "0x" + Utility.SerializeHTMLColor(this.BackgroundColor, false); var useTileCache = doc.CreateElement("UseTileCache"); useTileCache.InnerText = this.UseTileCache ? "true" : "false"; var time = doc.CreateElement("Time"); time.InnerText = this.Time; var elevation = doc.CreateElement("Elevation"); elevation.InnerText = this.ElevationDimension; var sc = doc.CreateElement("SpatialContext"); sc.InnerText = this.SpatialContextName; rasterDef.AppendChild(format); rasterDef.AppendChild(mimeType); rasterDef.AppendChild(transparent); rasterDef.AppendChild(useTileCache); rasterDef.AppendChild(bgcolor); rasterDef.AppendChild(time); rasterDef.AppendChild(elevation); rasterDef.AppendChild(sc); foreach (var layer in this.Layers) { layer.WriteXml(doc, rasterDef); } }; currentNode.AppendChild(rasterDef); } /// /// Set the current element's content from the current XML node /// /// /// public void ReadXml(System.Xml.XmlNode node, System.Xml.XmlNamespaceManager mgr) { if (node.Name != "RasterDefinition") throw new Exception("Bad document. Expected element: RasterDefinition"); var fc = node.ParentNode.Attributes["name"].Value; //NOXLATE this.FeatureClass = Utility.DecodeFDOName(fc.Substring(0, fc.Length - "Type".Length)); //NOXLATE this.RasterPropertyName = node.Attributes["name"].Value; //NOXLATE var format = node["Format"]; var transparent = node["Transparent"]; var useTileCache = node["UseTileCache"]; var bgcolor = node["BackgroundColor"]; var time = node["Time"]; var elevation = node["Elevation"]; var sc = node["SpatialContext"]; if (format != null) this.ImageFormat = format.InnerText; if (transparent != null) this.IsTransparent = (transparent.InnerText.ToLower() == "true"); if (useTileCache != null) this.UseTileCache = (useTileCache.InnerText.ToLower() == "true"); if (bgcolor != null) { if (!string.IsNullOrEmpty(bgcolor.InnerText)) { if (bgcolor.InnerText.StartsWith("0x")) this.BackgroundColor = ColorTranslator.FromHtml("#" + bgcolor.InnerText.Substring(2)); else this.BackgroundColor = ColorTranslator.FromHtml("#" + bgcolor.InnerText); } else { this.BackgroundColor = default(Color); } } if (time != null) this.Time = time.InnerText; if (elevation != null) this.ElevationDimension = elevation.InnerText; if (sc != null) this.SpatialContextName = sc.InnerText; foreach (XmlNode ln in node.ChildNodes) { if (ln.Name == "Layer") { var layer = new WmsLayerDefinition(); layer.ReadXml(ln, mgr); this.AddLayer(layer); } } } /// /// Removes all WMS layer configuration elements /// public void RemoveAllLayers() { _layers.Clear(); } } }