This project has moved. For the latest updates, please go here.

Elements Specific to LineStyle

Mar 26, 2012 at 1:00 AM

Hi. Is it possible to use <gx:outerColor>, <gx:outerWidth>, etc. with LineStyle?

https://developers.google.com/kml/documentation/kmlreference?hl=lt#gxoutercolor

Coordinator
Apr 15, 2012 at 10:24 PM

First let me appologise for the long delay in getting back to you.

Those elements look like they were introduced in Google Earth 6.0 At the moment the library doesn't support creating them (though neither does libkml by the looks of things). I don't really know what to suggest to you to do at the moment; I will open an issue and try to take a look at it over the next couple of weeks.

As a temporary hack, you could use the AddOrphan method of Element to attach any custom Element to the LineStyle (either change the access modifier in Element.cs to public or use reflection like below). Here is a very quick example on how to add it (though you'll probably want to add the GX22 namespace to the root Kml - see this documentation for more details):

using System.Reflection;
using SharpKml.Base;
using SharpKml.Dom;

namespace Examples
{
    public class OuterColor : Element, ICustomElement
    {
        public Color32 Value { get; set; }

        public bool ProcessChildren
        {
            get { return false; }
        }

        public void CreateStartElement(System.Xml.XmlWriter writer)
        {
            writer.WriteElementString(
                KmlNamespaces.GX22Prefix,
                "outerColor",
                KmlNamespaces.GX22Namespace,
                this.Value.ToString());
        }
    }

    internal static class Program
    {
        public static void Main(string[] args)
        {
            LineStyle lineStyle = new LineStyle();
            AddOrphan(lineStyle, new OuterColor { Value = new Color32(255, 0, 255, 0) });

            // Show the example output.
            var serializer = new Serializer();
            serializer.Serialize(lineStyle);
            System.Console.WriteLine(serializer.Xml);
        }

        private static void AddOrphan(Element parent, Element orphan)
        {
            // TODO: Prehaps cache the MethodInfo?
            var method = parent.GetType().GetMethod("AddOrphan", BindingFlags.Instance | BindingFlags.NonPublic);
            method.Invoke(parent, new object[] { orphan });
        }
    }
}

Aug 16, 2012 at 1:18 PM

This worked well, I was able to add a 6.1 feature for line label visibility with relative ease.