WEB开发网
开发学院图形图像Flash Microsoft Virtual Earth Silverlight Map Contro... 阅读

Microsoft Virtual Earth Silverlight Map Control (CTP)快速上手

 2009-03-29 11:59:04 来源:WEB开发网   
核心提示: 第五步:写后台代码,using System;using System.Windows;using System.Windows.Controls;using System.Globalization;using Microsoft.VirtualEarth.MapControl;usin

第五步:写后台代码。

using System;
using System.Windows;
using System.Windows.Controls;
using System.Globalization;
using Microsoft.VirtualEarth.MapControl;
using Microsoft.VirtualEarth.MapControl.Design;
using System.Windows.Media;
using System.Windows.Media.Imaging;


namespace SLLiveEarthControl
{
    public partial class MainPage : UserControl
    {
         LocationConverter locConverter = new LocationConverter();
        // Converts the Button's location Tag to a map view..
        MapViewSpecificationConverter viewConverter = new MapViewSpecificationConverter();
        private MapLayer imageLayer = new MapLayer();

        public   MainPage()
        {
            InitializeComponent();
            viewMap.AddChild(imageLayer);
            viewMap.ViewChangeOnFrame += new EventHandler<MapEventArgs>(viewMap_ViewChangeOnFrame);
            viewMap.AnimationLevel = AnimationLevel.Full;
        }

        private void viewMap_ViewChangeOnFrame(object sender, MapEventArgs e)
        {
            Map map = sender as Map;
            if (map != null)
            {
                MapViewSpecification mapViewSpec = map.View;

                // 根据地图当前的状态动态改变txtLatitude和txtLongitude的值
                txtLatitude.Text = string.Format(CultureInfo.InvariantCulture,
                    "{0:F5}", mapViewSpec.Center.Latitude);
                txtLongitude.Text = string.Format(CultureInfo.InvariantCulture,
                    "{0:F5}", mapViewSpec.Center.Longitude);
            }
        }

        private void ChangeMapView_Click(object sender, RoutedEventArgs e)
        {
            viewMap.View = (MapViewSpecification)viewConverter.ConvertFrom(((Button)sender).Tag);
        }
        private void MapWithImages_MouseDoubleClick(object sender, MapMouseEventArgs e)
        {
            e.Handled = true;
            Location pinLocation =  viewMap.ViewportPointToLocation(e.ViewportPoint);
            Image pin = new Image();
            Random r = new Random();
            pin.Source = new BitmapImage(new Uri(r.Next() % 2==0 ? "female.png" : "male.png", UriKind.RelativeOrAbsolute));
            pin.Stretch = Stretch.None;
            imageLayer.AddChild(pin, pinLocation, PositionMethod.BottomCenter);
        }

        private void btnFlyto_Click(object sender, RoutedEventArgs e)
        {
            viewMap.View = new MapViewSpecification(new Location(Double.Parse(txtLatitude.Text), Double.Parse(txtLongitude.Text)), 14);
        }
    }
}

你可能已经注意到,我们在编程时已经完全脱离了Javascript;Virtual Earth在我们的手中,已经变得和TextBox,DataGrid一样,只是一个控制非常方便的控件了。

上一页  1 2 3 4 

Tags:Microsoft Virtual Earth

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接