public IconStyle(IconElement icon) { Icon = icon; }
/// <summary> /// Modifies a style with Style tags loaded from an XmlNode /// </summary> /// <param name="style">The XmlNode containing override information</param> /// <param name="oldStyle">The style to override</param> /// <param name="KmlPath">The path to the KML file that is being loaded</param> /// <returns>The style with overridden values</returns> private Style GetStyle(XmlNode style, Style oldStyle, string KmlPath) { try { Style overStyle = oldStyle; bool bPalette = false; // Determine the scale, if any, for this style XmlNode scaleNode = style.SelectSingleNode("IconStyle/scale"); if (scaleNode != null) overStyle.NormalScale = Convert.ToDouble(scaleNode.InnerText, CultureInfo.InvariantCulture); // Search for style tags in location 1 XmlNode hrefNode = style.SelectSingleNode("IconStyle/Icon/href"); if (hrefNode != null) { string filename = hrefNode.InnerText; if (filename.StartsWith("root://")) // Use palette bitmap { filename = Path.Combine(KmlDirectory, filename.Remove(0, 7)); if (File.Exists(filename)) { bPalette = true; overStyle.NormalIcon = GetDiskImage(filename); } } else if (filename.StartsWith("http://")) // Use bitmap from the internet { overStyle.NormalIcon = GetWebImage(filename); } else if (File.Exists(Path.Combine(Path.GetDirectoryName(KmlPath), filename))) // Use a file from disk { overStyle.NormalIcon = GetDiskImage(Path.Combine(Path.GetDirectoryName(KmlPath), filename)); } else if (File.Exists(Path.Combine(KmlDirectory, filename))) // Use a file from disk { overStyle.NormalIcon = GetDiskImage(Path.Combine(KmlDirectory, filename)); } } // See if we need to cut this style to a substyle XmlNode wNode = style.SelectSingleNode("IconStyle/Icon/w"); XmlNode hNode = style.SelectSingleNode("IconStyle/Icon/h"); if (wNode != null && hNode != null) { int w = Convert.ToInt32(wNode.InnerText, CultureInfo.InvariantCulture); int h = Convert.ToInt32(hNode.InnerText, CultureInfo.InvariantCulture); int x = 0, y = 0; XmlNode xNode = style.SelectSingleNode("IconStyle/Icon/x"); if (xNode != null) x = Convert.ToInt32(xNode.InnerText, CultureInfo.InvariantCulture); XmlNode yNode = style.SelectSingleNode("IconStyle/Icon/y"); if (yNode != null) y = Convert.ToInt32(yNode.InnerText, CultureInfo.InvariantCulture); if (bPalette) overStyle.NormalIcon = GetSubImage(overStyle, x*2, y*2, w*2, h*2); else overStyle.NormalIcon = GetSubImage(overStyle, x, y, w, h); } // Search for style tags in a possible secondary location XmlNode iconNode = style.SelectSingleNode("icon"); if (iconNode != null) { string filename = iconNode.InnerText; if (!filename.StartsWith("http://")) return null; overStyle.NormalIcon = GetWebImage(filename); } XmlNode balloonStyleNode = style.SelectSingleNode("BalloonStyle"); if(balloonStyleNode != null) { BalloonStyle balloonStyle = new BalloonStyle(); XmlNode balloonTextNode = balloonStyleNode.SelectSingleNode("text"); if(balloonTextNode != null) { TextElement textElement = new TextElement(); textElement.Text = balloonTextNode.InnerText; XmlNode textNodeColor = balloonTextNode.SelectSingleNode("textColor"); if(textNodeColor != null) textElement.TextColor = new ColorElement(ParseColor(textNodeColor.InnerText)); balloonStyle.Text = textElement; } XmlNode balloonTextColorNode = balloonStyleNode.SelectSingleNode("textColor"); if(balloonTextColorNode != null) balloonStyle.TextColor = new ColorElement(ParseColor(balloonTextColorNode.InnerText)); XmlNode balloonColorNode = balloonStyleNode.SelectSingleNode("color"); if(balloonColorNode != null) balloonStyle.Color = new ColorElement(ParseColor(balloonColorNode.InnerText)); overStyle.BalloonStyle = balloonStyle; } XmlNode iconStyleNode = style.SelectSingleNode("IconStyle"); if(iconStyleNode != null) { XmlNode iconElementNode = iconStyleNode.SelectSingleNode("Icon"); IconElement iconElement = new IconElement(); if(iconElementNode != null) { XmlNode iconElementHrefNode = iconElementNode.SelectSingleNode("href"); if (iconElementHrefNode != null) { string filename = iconElementHrefNode.InnerText; if (filename.StartsWith("root://")) // Use palette bitmap { filename = Path.Combine(KmlDirectory, filename.Remove(0, 7)); if (File.Exists(filename)) { bPalette = true; iconElement.href = GetDiskImage(filename); } } else if (filename.StartsWith("http://")) // Use bitmap from the internet { iconElement.href = GetWebImage(filename); } else if (File.Exists(Path.Combine(Path.GetDirectoryName(KmlPath), filename))) // Use a file from disk { iconElement.href = GetDiskImage(Path.Combine(Path.GetDirectoryName(KmlPath), filename)); } else if (File.Exists(Path.Combine(KmlDirectory, filename))) // Use a file from disk { iconElement.href = GetDiskImage(Path.Combine(KmlDirectory, filename)); } } // See if we need to cut this style to a substyle XmlNode iconElementWNode = iconElementNode.SelectSingleNode("w"); XmlNode iconElementHNode = iconElementNode.SelectSingleNode("h"); if (iconElementWNode != null && iconElementHNode != null) { int w = Convert.ToInt32(wNode.InnerText, CultureInfo.InvariantCulture); int h = Convert.ToInt32(hNode.InnerText, CultureInfo.InvariantCulture); int x = 0, y = 0; XmlNode xNode = iconElementNode.SelectSingleNode("x"); if (xNode != null) x = Convert.ToInt32(xNode.InnerText, CultureInfo.InvariantCulture); XmlNode yNode = iconElementNode.SelectSingleNode("y"); if (yNode != null) y = Convert.ToInt32(yNode.InnerText, CultureInfo.InvariantCulture); if (bPalette) iconElement.href = GetSubImage(overStyle, x*2, y*2, w*2, h*2); else iconElement.href = GetSubImage(overStyle, x, y, w, h); } IconStyle iconStyle = new IconStyle(iconElement); XmlNode iconStyleColorNode = iconStyleNode.SelectSingleNode("color"); if(iconStyleColorNode != null) iconStyle.Color = new ColorElement(ParseColor(iconStyleColorNode.InnerText)); XmlNode iconStyleColorModeNode = iconStyleNode.SelectSingleNode("colorMode"); if(iconStyleColorModeNode != null) { iconStyle.ColorMode = (iconStyleColorModeNode.InnerText.ToLower() == "random" ? ColorMode.Random : ColorMode.Normal); } XmlNode iconStyleHeadingNode = iconStyleNode.SelectSingleNode("heading"); if(iconStyleHeadingNode != null) iconStyle.Heading = new DecimalElement(double.Parse(iconStyleHeadingNode.InnerText, CultureInfo.InvariantCulture)); XmlNode iconStyleScaleNode = iconStyleNode.SelectSingleNode("scale"); if(iconStyleScaleNode != null) iconStyle.Scale = new DecimalElement(double.Parse(iconStyleScaleNode.InnerText, CultureInfo.InvariantCulture)); overStyle.IconStyle = iconStyle; } } XmlNode labelStyleNode = style.SelectSingleNode("LabelStyle"); if(labelStyleNode != null) { LabelStyle labelStyle = new LabelStyle(); XmlNode labelColorNode = labelStyleNode.SelectSingleNode("color"); if(labelColorNode != null) labelStyle.Color = new ColorElement(ParseColor(labelColorNode.InnerText)); XmlNode labelColorModeNode = labelStyleNode.SelectSingleNode("colorMode"); if(labelColorModeNode != null) labelStyle.ColorMode = (labelColorModeNode.InnerText.ToLower() == "random" ? ColorMode.Random : ColorMode.Normal); XmlNode labelScaleNode = labelStyleNode.SelectSingleNode("scale"); if(labelScaleNode != null) labelStyle.Scale = new DecimalElement(double.Parse(labelScaleNode.InnerText, CultureInfo.InvariantCulture)); overStyle.LabelStyle = labelStyle; } XmlNode lineStyleNode = style.SelectSingleNode("LineStyle"); if(lineStyleNode != null) { LineStyle lineStyle = new LineStyle(); XmlNode lineColorNode = lineStyleNode.SelectSingleNode("color"); if(lineColorNode != null) lineStyle.Color = new ColorElement(ParseColor(lineColorNode.InnerText)); XmlNode lineColorModeNode = lineStyleNode.SelectSingleNode("colorMode"); if(lineColorModeNode != null) lineStyle.ColorMode = (lineColorModeNode.InnerText.ToLower() == "random" ? ColorMode.Random : ColorMode.Normal); XmlNode lineWidthNode = lineStyleNode.SelectSingleNode("width"); if(lineWidthNode != null) lineStyle.Width = new DecimalElement(double.Parse(lineWidthNode.InnerText, CultureInfo.InvariantCulture)); overStyle.LineStyle = lineStyle; } XmlNode polyStyleNode = style.SelectSingleNode("PolyStyle"); if(polyStyleNode != null) { PolyStyle polyStyle = new PolyStyle(); XmlNode polyColorNode = polyStyleNode.SelectSingleNode("color"); if(polyColorNode != null) polyStyle.Color = new ColorElement(ParseColor(polyColorNode.InnerText)); XmlNode polyColorModeNode = polyStyleNode.SelectSingleNode("colorMode"); if(polyColorModeNode != null) polyStyle.ColorMode = (polyColorModeNode.InnerText.ToLower() == "random" ? ColorMode.Random : ColorMode.Normal); XmlNode polyFillNode = polyStyleNode.SelectSingleNode("fill"); if(polyFillNode != null) polyStyle.Fill = (polyFillNode.InnerText == "1" ? true : false); XmlNode polyOutlineNode = polyStyleNode.SelectSingleNode("outline"); if(polyOutlineNode != null) polyStyle.Outline = (polyOutlineNode.InnerText == "1" ? true : false); overStyle.PolyStyle = polyStyle; } return overStyle; } catch (System.Net.WebException ex) { Log.Write(Log.Levels.Error, "KMLImporter: " + ex.ToString()); } return null; }