ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlToFeatureDefinition.GetStyleMapAsync C# (CSharp) Method

GetStyleMapAsync() private method

Gets the 'normal' style of a style map. Getting this style may need recursive download. When the style is ready -> execute the callback.
The 'highlight' style is not used by the KmlLayer.
private GetStyleMapAsync ( System.Xml.Linq.XElement styleMap, System.Xml.Linq.XDocument xDoc, ICredentials credentials, Action callback, X509Certificate clientCertificate = null ) : void
styleMap System.Xml.Linq.XElement The style map element to parse.
xDoc System.Xml.Linq.XDocument The xDocument the style map is part of.
credentials ICredentials The credentials.
callback Action The callback to call when the style is downloaded (if needed).
clientCertificate System.Security.Cryptography.X509Certificates.X509Certificate The client certificate.
return void
        private void GetStyleMapAsync(XElement styleMap, XDocument xDoc, ICredentials credentials, Action<KMLStyle> callback, X509Certificate clientCertificate = null)
        {
            XNamespace kmlNS = styleMap.Name.Namespace;
            KMLStyle kmlStyle = null;
            foreach (XElement pair in styleMap.Descendants(kmlNS + "Pair"))
            {
                XElement key = pair.Element(kmlNS + "key");
                if (key != null)
                {
                    if (key.Value == "normal")
                    {
                        XElement style = pair.Element(kmlNS + "Style");
                        if (style != null)
                        {
                            kmlStyle = new KMLStyle();
                            GetStyle(style, kmlStyle);
                        }
                        else
                        {
                            XElement styleUrl = pair.Element(kmlNS + "styleUrl");
                            if (styleUrl != null)
                            {
                                XAttribute styleIdAttribute = styleMap.Attribute("id");
                                string styleId = styleIdAttribute == null ? null : styleIdAttribute.Value;

                                // Get the style from the styleUrl. This may need to downloading an external KML file
                                GetStyleUrlAsync(styleUrl.Value, xDoc, credentials
                                    , kmlstyle =>
                                        {
                                            //// After obtaining the style (which may have involved recursion and downloading external KML files
                                            //// to resolve style URLs) be sure to always overwrite the styleId with the name given to this StyleMap.
                                            if (styleId != null && kmlstyle != null)
                                                kmlstyle.StyleId = styleId;
                                            callback(kmlstyle);
                                        }, clientCertificate);
                                return;
                            }
                        }
                    }
                }
            }

            // execute the callback with the found style (or null if not found)
            callback(kmlStyle);
        }