ArcGIS Runtime API for .NET——Layers
Layers图层
图层
地图和场景使用图层的集合来显示来自各种来源和格式的地理数据。 这些可以包括来自在线或本地来源的多个底图图层和数据层。
地图中的每个图层都引用来自在线服务或本地数据集的地理数据。 可以将多种图层添加到地图,每个图层都设计为显示特定类型的数据。 一些图层显示图像,例如卫星照片或航拍照片,其他图层则由一组特征组成,这些特征使用点,线或面的几何形状表示真实世界的实体。 除几何图形外,要素还具有提供有关其表示的实体的详细信息的属性。
一.底图图层
底图图层是为地图或场景提供整体视觉内容的图层。它通常包含地理特征,例如大陆,湖泊,行政边界,街道,城市和地名。这些要素用底图图层服务提供的不同样式表示,例如街道,地形和图像。您选择的样式取决于应用程序的类型和要创建的可视化。
底图图层为地图绘制应用程序提供了视觉基础。它通常包含具有全球覆盖范围的数据,并且是添加到地图或场景中的第一层。底图图层的主要数据源是底图图层服务。当视图显示地图时,底图图层是要绘制的第一层,其次是数据层,然后是图形。
底图图层服务提供了许多矢量图块和图像图块底图图层,可用于构建不同类型的地图绘制应用程序。每个底图图层样式均在枚举中定义。例如,您可以使用“导航”样式创建支持行车路线的应用程序,也可以使用“图像”创建显示地球的真实视图的应用程序。
//添加矢量切片地图
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_API_KEY";
var map = new Map(BasemapStyle.ArcGISNavigation);
//var map = new Map(BasemapStyle.ArcGISTopographic);
//var map = new Map(BasemapStyle.ArcGISLightGray);
//var map = new Map(BasemapStyle.OSMLightGray);
//添加图像切片地图
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_API_KEY";
var map = new Map(BasemapStyle.ArcGISImagery);
//var map = new Map(BasemapStyle.ArcGISHillshadeLight);
//var map = new Map(BasemapStyle.ArcGISHillshadeDark);
二.数据层
数据层,也称为操作层,是可以从数据源访问地理数据的层。可以使用数据层在地图或场景的底图图层之上显示地理数据。图层的数据源可以是数据服务或文件,例如shapefile或GeoPackage。
数据层提供对在地图或场景中显示的地理数据的访问。每个层都引用一个文件或服务数据源。数据源包含为矢量数据(点,线,多边形和属性)或栅格数据(图像)。不同类型的层可以访问和显示不同类型的数据。
数据层的数据通常作为数据服务存储在ArcGIS Platform中。可以使用要素服务,矢量切片服务和图像切片服务来托管数据。在数据托管中了解更多信息。
也可以从设备上存储的数据集创建数据层。例如,存储在shapefile,移动地图包或地理数据库中的数据。了解有关在离线地图,场景和数据中使用离线数据的更多信息。
要将数据层添加到地图或场景,通常通常先添加图像或图块层,然后再添加多边形,线和点层。地图或场景控制图层的顺序,地图或场景视图组合图层以创建最终显示。
//在地图中添加数据层
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_API_KEY";
var map = new Map(BasemapStyle.ArcGISTopographic);
var trailheadsTable = new ServiceFeatureTable(new Uri("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0"));
var trailsTable = new ServiceFeatureTable(new Uri("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails_Styled/FeatureServer/0"));
var openSpacesTable = new ServiceFeatureTable(new Uri("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space_Styled/FeatureServer/0"));
map.OperationalLayers.Add(new FeatureLayer(trailheadsTable));
map.OperationalLayers.Add(new FeatureLayer(trailsTable));
map.OperationalLayers.Add(new FeatureLayer(openSpacesTable));
MainMapView.Map = map;
三.图层类型
可以使用不同类型的数据层来访问和显示应用程序中不同类型的数据。数据层可以访问ArcGIS数据源和其他类型的数据源,例如OGC数据和文件。
不同的数据层提供不同类型的功能。可用的功能在很大程度上取决于数据源的功能。例如,要素层可以访问要素服务并执行查询,编辑和数据导出,而矢量图块层只能访问来自矢量图块服务的图块。
图层类是ArcGIS Runtime中使用的所有类型的图层的基类。创建的图层类型取决于要显示的数据类型。例如,要显示要素数据(点,线或面的几何图形),可以创建一个FeatureLayer来指向在线服务(例如要素服务)或受支持的本地数据集。下表总结了可用于ArcGIS Runtime应用程序的常见图层类型。
ArcGIS数据源
OGC数据源
其他数据源
四.示例
1.添加一个要素图层
地图包含地理数据层。 地图包含底图图层以及一个或多个数据图层(可选)。 本示例展示如何访问和显示中的要素图层。 可以使用ID或URL访问要素图层。
要素图层是ArcGIS中托管的要素服务中的数据集。 每个要素图层均包含具有单个几何类型(点,线或面)和一组属性的要素。 可以使用要素图层来存储,访问和管理应用程序的大量地理数据。 可以通过访问要素图层的URL从要素图层获取要素。
在本示例中,将使用URL来访问和显示ArcGIS Online中托管的三个不同要素图层。
步骤:
创建一个新的Visual Studio项目。
2.设置API密钥
在Visual Studio的“解决方案资源管理器”中,单击App.xaml.cs。
在App类中,为OnStartup()函数添加一个替代,以在ArcGISRuntimeEnvironment上设置ApiKey属性。
// Copyright 2021 Esri
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace DisplayAMap
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Note: it is not best practice to store API keys in source code.
// The API key is referenced here for the convenience of this tutorial.
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_API_KEY";
}
}
}
3.创建一个视图模型来存储应用程序逻辑
修改MapViewModel.cs中的内容。
using System;
using System.Collections.Generic;
using System.Text;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace feature_layer
{
class MapViewModel : INotifyPropertyChanged
{
public MapViewModel()
{
SetupMap();
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private Map _map;
public Map Map
{
get { return _map; }
set
{
_map = value;
OnPropertyChanged();
}
}
private void SetupMap()
{
Map = new Map(BasemapStyle.ArcGISTopographic);
var parksUri = new Uri(
"https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0"
);
var trailsUri = new Uri(
"https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0"
);
var trailheadsUri = new Uri(
"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
);
var parksLayer = new FeatureLayer(parksUri);
var trailsLayer = new FeatureLayer(trailsUri);
var trailheadsLayer = new FeatureLayer(trailheadsUri);
Map.OperationalLayers.Add(parksLayer);
Map.OperationalLayers.Add(trailsLayer);
Map.OperationalLayers.Add(trailheadsLayer);
}
}
}