Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/MapMainDemo/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/MapMainDemo/Modules/DataSource.cs

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using DevExpress.Utils;
using System.Xml.Linq;
using System.Globalization;

namespace DevExpress.XtraMap.Demos {

    public partial class DataSource : MapTutorialControl {
        ImageTilesLayer TilesLayer { get { return (ImageTilesLayer)(mapControl1.Layers[0]); } }
        VectorItemsLayer ItemsLayer { get { return (VectorItemsLayer)(mapControl1.Layers[1]); } }
        Font toolTipFont;
        public DataSource() {
            InitializeComponent();
            TilesLayer.DataProvider = CreateBingDataProvider(BingMapKind.Hybrid);
            ItemsLayer.DataSource = LoadShipsFromXML();
            this.toolTipFont = new Font(AppearanceObject.DefaultFont.FontFamily, 12, FontStyle.Bold);
        }
        List<ShipInfo> LoadShipsFromXML() {
            List<ShipInfo> ships = new List<ShipInfo>();
            XDocument document = DemoUtils.LoadXml("Ships.xml");
            if(document != null) {
                foreach(XElement element in document.Element("Ships").Elements()) {
                    double latitude = Convert.ToDouble(element.Element("Latitude").Value, CultureInfo.InvariantCulture);
                    double longitude = Convert.ToDouble(element.Element("Longitude").Value, CultureInfo.InvariantCulture);
                    string name = element.Element("Name").Value;
                    string description = element.Element("Description").Value;
                    string year = element.Element("Year").Value;
                    ships.Add(new ShipInfo() { Latitude = latitude, Longitude = longitude, Description = description, Name = name, Year = year });
                }
            }
            return ships;
        }
        void toolTipController1_BeforeShow(object sender, ToolTipControllerShowEventArgs e) {
            MapCustomElement customElement = (MapCustomElement)(e.SelectedObject);
            ShipInfo shipInfo = (ShipInfo)ItemsLayer.GetItemSourceObject(customElement);

            ToolTipTitleItem titleItem1 = new ToolTipTitleItem() { Text = shipInfo.Header };
            titleItem1.Appearance.ForeColor = SystemColors.GrayText;
            titleItem1.Appearance.Font = toolTipFont;

            SuperToolTip superToolTip = new SuperToolTip();
            superToolTip.Items.Add(titleItem1);

            ToolTipSeparatorItem sepItem = new ToolTipSeparatorItem();
            superToolTip.Items.Add(sepItem);

            ToolTipItem textItem = new ToolTipItem() { Text = e.ToolTip };
            superToolTip.Items.Add(textItem);
            e.SuperTip = superToolTip;
        }
    }

    public class ShipInfo {
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public string Name { get; set; }
        public string Year { get; set; }
        public string Description { get; set; }
        public string Header { get { return Name + " (" + Year + ")"; } }
    }
}