⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locationimageservice.cs

📁 Some time ago, I stated in another article that I d take the idea of location broadcasting and devel
💻 CS
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.Collections.Specialized;
using System.Xml;
using DeepCast;
using System.IO;
using DeepCast.Location;

namespace DeepCast.Services
{
    internal delegate void MapImageChangedDelegate(string mapUrl);

    /// <summary>
    /// Gets a Yahoo map image based on the current lat/long.
    /// </summary>
    internal class LocationImageService : GeoService
    {
        internal event MapImageChangedDelegate MapChanged;
        private GeoLocation _currentLocation;

        private const string Yahoo_Maps_Uri = "http://local.yahooapis.com/MapsService/V1/mapImage?";

        /// <summary>
        /// Updates the image.
        /// </summary>
        internal void Update()
        {
            if (_currentLocation != null)
            {
                Update(_currentLocation);
            }
        }
        /// <summary>
        /// Updates the image.
        /// </summary>
        /// <param name="location">The location.</param>
        internal override void Update(GeoLocation location)
        {
            if(Zoom == 0)
            { 
                // Default to a zoom level of 6 (valid values are 1 - 12).
                Zoom = 6;
            }

            _currentLocation = location;

            // Build a map api query
            Dictionary<string, string> parameters = new Dictionary<string, string>() 
            { 
                {"appid", Settings.YahooMapsApiKey},
                {"latitude", location.Latitude.ToStringNumeric()},
                {"longitude", location.Longitude.ToStringNumeric()},
                {"image_type", "gif"},
                {"image_height", "195"},
                {"image_width", "195"},
                {"zoom", Zoom.ToString()}
            };

            XDocument doc = XDocument.Load(Yahoo_Maps_Uri + Utility.BuildQueryString(parameters));

            // Get the image text from the xml
            foreach (var element in doc.Descendants())
            {
                if (!string.IsNullOrEmpty(element.Value))
                {
                    if (MapChanged != null)
                    {
                        MapChanged(element.Value);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Gets the service's friendly name.
        /// </summary>
        /// <value>The name.</value>
        internal override string Name
        {
            get { return "Maps"; }
        }
        /// <summary>
        /// Gets or sets the zoom level.
        /// </summary>
        /// <value>The zoom.</value>
        internal int Zoom { get; set; }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -