private void ReadImageryMetadata(XmlElement imageryMetadata)
        {
            string imageUrl = null;

            string[] imageUrlSubdomains = null;
            int?     zoomMin            = null;
            int?     zoomMax            = null;

            foreach (var element in imageryMetadata.ChildNodes.OfType <XmlElement>())
            {
                switch ((string)element.LocalName)
                {
                case "ImageUrl":
                    imageUrl = element.InnerText;
                    break;

                case "ImageUrlSubdomains":
                    imageUrlSubdomains = element.ChildNodes
                                         .OfType <XmlElement>()
                                         .Where(e => (string)e.LocalName == "string")
                                         .Select(e => e.InnerText)
                                         .ToArray();
                    break;

                case "ZoomMin":
                    zoomMin = int.Parse(element.InnerText);
                    break;

                case "ZoomMax":
                    zoomMax = int.Parse(element.InnerText);
                    break;

                default:
                    break;
                }
            }

            if (!string.IsNullOrEmpty(imageUrl) && imageUrlSubdomains != null && imageUrlSubdomains.Length > 0)
            {
                if (zoomMin.HasValue && zoomMin.Value > MinZoomLevel)
                {
                    MinZoomLevel = zoomMin.Value;
                }

                if (zoomMax.HasValue && zoomMax.Value < MaxZoomLevel)
                {
                    MaxZoomLevel = zoomMax.Value;
                }

                if (string.IsNullOrEmpty(Culture))
                {
                    Culture = CultureInfo.CurrentUICulture.Name;
                }

                TileSource = new BingMapsTileSource(imageUrl.Replace("{culture}", Culture), imageUrlSubdomains);
            }
        }
Esempio n. 2
0
        private void ReadImageryMetadata(XElement metadataResponse)
        {
            var ns       = metadataResponse.Name.Namespace;
            var metadata = metadataResponse.Descendants(ns + "ImageryMetadata").FirstOrDefault();

            if (metadata != null)
            {
                var imageUrl   = metadata.Element(ns + "ImageUrl")?.Value;
                var subdomains = metadata.Element(ns + "ImageUrlSubdomains")?.Elements(ns + "string").Select(e => e.Value).ToArray();

                if (!string.IsNullOrEmpty(imageUrl) && subdomains != null && subdomains.Length > 0)
                {
                    var zoomMin = metadata.Element(ns + "ZoomMin")?.Value;
                    var zoomMax = metadata.Element(ns + "ZoomMax")?.Value;

                    if (zoomMin != null && int.TryParse(zoomMin, out int zoomLevel) && MinZoomLevel < zoomLevel)
                    {
                        MinZoomLevel = zoomLevel;
                    }

                    if (zoomMax != null && int.TryParse(zoomMax, out zoomLevel) && MaxZoomLevel > zoomLevel)
                    {
                        MaxZoomLevel = zoomLevel;
                    }

                    if (string.IsNullOrEmpty(Culture))
                    {
                        Culture = CultureInfo.CurrentUICulture.Name;
                    }

                    TileSource = new BingMapsTileSource
                    {
                        UriFormat  = imageUrl.Replace("{culture}", Culture),
                        Subdomains = subdomains
                    };
                }
            }

            var logoUri = metadataResponse.Element(ns + "BrandLogoUri");

            if (logoUri != null)
            {
                LogoImageUri = new Uri(logoUri.Value);
            }
        }
Esempio n. 3
0
        private void ReadImageryMetadataResponse(XmlReader xmlReader)
        {
            string logoUri  = null;
            string imageUrl = null;

            string[] imageUrlSubdomains = null;
            int?     zoomMin            = null;
            int?     zoomMax            = null;

            do
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                    case "BrandLogoUri":
                        logoUri = xmlReader.ReadElementContentAsString();
                        break;

                    case "ImageUrl":
                        imageUrl = xmlReader.ReadElementContentAsString();
                        break;

                    case "ImageUrlSubdomains":
                        imageUrlSubdomains = ReadStrings(xmlReader.ReadSubtree());
                        break;

                    case "ZoomMin":
                        zoomMin = xmlReader.ReadElementContentAsInt();
                        break;

                    case "ZoomMax":
                        zoomMax = xmlReader.ReadElementContentAsInt();
                        break;

                    default:
                        xmlReader.Read();
                        break;
                    }
                }
                else
                {
                    xmlReader.Read();
                }
            }while (xmlReader.NodeType != XmlNodeType.None);

            if (!string.IsNullOrEmpty(imageUrl) && imageUrlSubdomains != null && imageUrlSubdomains.Length > 0)
            {
                var _ = Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (string.IsNullOrEmpty(Culture))
                    {
                        Culture = CultureInfo.CurrentUICulture.Name;
                    }

                    TileSource = new BingMapsTileSource(imageUrl.Replace("{culture}", Culture), imageUrlSubdomains);

                    if (zoomMin.HasValue && zoomMin.Value > MinZoomLevel)
                    {
                        MinZoomLevel = zoomMin.Value;
                    }

                    if (zoomMax.HasValue && zoomMax.Value < MaxZoomLevel)
                    {
                        MaxZoomLevel = zoomMax.Value;
                    }

                    if (!string.IsNullOrEmpty(logoUri))
                    {
                        LogoImage = new BitmapImage(new Uri(logoUri));
                    }
                }));
            }
        }