標籤:
1、Map
Map 是 ArcGIS API for Silverlight 中的核心組件,主要用於呈現地圖服務、影像服務中的空間資料,此外還可以展示 WMS 服務、熱點圖(HeatMap)、Bing 地圖、OpenStreetMap、GeoRSS、KML 資料等,並且 Map 可以與使用者互動,接受使用者輸入。
屬性:
Extent:地圖外包矩形的範圍,即四個角點座標範圍。
IsLogoVisible:是否顯示esri的logo。
Layers:地圖中的圖層集合,先加入的圖層在底部,最後加入的圖層在最上層顯示。
PanDuration/ZoomDuration:平移/縮放時動畫期間。
SpatialReference:空間參考,通過WKID(空間參考編號)或WKT(空間參考名稱)指定,預設為加入地圖中的第一個具有空間參考的圖層的空間參考。
WrapAround:設定地圖是否經向迴圈,即通過平移工具,一直向左或向右移動地圖,類比球體旋轉。
方法:
MapToScreen/ScreenToMap:地圖與螢幕之間的座標轉換。
PanTo/ZoomTo:平移/縮放到指定範圍。
事件:
ExtentChanged:地圖範圍改變事件。
MouseClick:地圖上的單擊事件。
Progress:地圖資料載入進度事件。
PropertyChanged:地圖屬性變化事件。
2、載入地圖資料
<UserControl x:Class="HelloWorld.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <esri:Map x:Name="myMap"> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"InitializationFailed="Layer_InitializationFailed"/> </esri:Map> </Grid></UserControl>
添加後台代碼(C#):
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using ESRI.ArcGIS.Client;namespace HelloWorld{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void Layer_InitializationFailed(object sender,EventArgs e) { //擷取圖層對象 Layer layer = sender as Layer; //顯示圖層載入失敗原因的提示 MessageBox.Show("載入圖層失敗:" + layer.InitializationFailure.Message); } }}
3、後台代碼方式
通過在後台代碼(如 C#)中建立 ArcGISDynamicMapServiceLayer 並將其添加到Map 對象中,實現向地圖中添加動態服務圖層的功能,代碼如下所示:
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using ESRI.ArcGIS.Client;namespace HelloWorld{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); // 建立動態服務圖層 ArcGISDynamicMapServiceLayer usaMapLayer = new ArcGISDynamicMapServiceLayer(); usaMapLayer.ID = "usaMap";// 指定圖層ID // 指定圖層URL usaMapLayer.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"; // 將圖層添加到地圖中 myMap.Layers.Add(usaMapLayer); } }}
Silverlight載入第一個Map