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;
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一样,只是一个控制非常方便的控件了。
- ››Microsoft Outlook 2010 邮箱客户端中常用邮件设置...
- ››Microsoft Office2007Open XML 格式的术语表
- ››Microsoft PowerPoint 2010介绍
- ››Microsoft ReportViewer(微软报表)项目中的应用...
- ››Microsoft APP-V 4.5使用经验之序列化工具
- ››Microsoft Access 2010的十大优势详解
- ››VirtualBox虚拟机安装CentOS系统
- ››Microsoft数据访问技术简介
- ››Microsoft My Phone for Windows Mobile 6+ 新版发...
- ››Microsoft Security Essentials 1.0.1959.0
- ››Microsoft Office Access 2007年中选项组控件中您...
- ››Microsoft Office Communications Server 2007 R2...
更多精彩
赞助商链接