當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS Layer.fromArcGISServerUrl用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/layers/Layer"], (Layer) => { /* code goes here */ });

ESM: import Layer from "@arcgis/core/layers/Layer";

類: esri/layers/Layer

繼承: Layer > Accessor

子類: BaseDynamicLayer , BaseElevationLayer , BaseTileLayer , BuildingSceneLayer , CSVLayer , ElevationLayer , FeatureLayer , GeoJSONLayer , GeoRSSLayer , GraphicsLayer , GroupLayer , ImageryLayer , ImageryTileLayer , IntegratedMeshLayer , KMLLayer , MapImageLayer , MapNotesLayer , OGCFeatureLayer , PointCloudLayer , RouteLayer , SceneLayer , StreamLayer , SubtypeGroupLayer , TileLayer , UnknownLayer , UnsupportedLayer , VectorTileLayer , VoxelLayer , WCSLayer , WFSLayer , WMSLayer , WMTSLayer , WebTileLayer

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

Layer.fromArcGISServerUrl函數(或屬性)的定義如下:

fromArcGISServerUrl (params) {Promise<Layer>} static


從 ArcGIS 服務器 URL 創建一個新圖層實例。根據 URL,返回的圖層類型可能是: FeatureLayer, TileLayer, MapImageLayer, ImageryLayer, ImageryTileLayer, SceneLayer, StreamLayer, IntegratedMeshLayer, PointCloudLayer, BuildingSceneLayer, ElevationLayer or GroupLayer.

這在您使用各種 ArcGIS 服務器 URL 時很有用,但您不一定知道它們創建的圖層類型。此方法為您創建適當的圖層類型。對於要素服務或場景服務,當 URL 指向服務並且服務具有多個圖層時,返回的承諾將解析為 GroupLayer

從版本 4.17 開始,可以從托管要素服務加載表。這僅適用於 feature layers ,如果 FeatureLayer.isTable 返回 true 將成功加載。

下表詳細說明了加載特定 URL 類型時返回的內容。

URL 返回
具有一層的要素服務 FeatureLayer 其中 isTable 返回 false
一桌特色服務 FeatureLayer 其中 isTable 返回 true
具有多個層/表的要素服務 GroupLayer 帶有圖層和表格。
類型不是 "Feature Layer" 的圖層將被丟棄,例如公共設施網絡圖層 不適用

參數:

規格:
類型說明
params Object

用於創建圖層的輸入參數。

規格:
url

String

用於創建圖層的ArcGIS 服務器 URL。

properties

Object

可選的

在此處設置任何層的屬性以構建層實例(例如 popupTemplate、渲染器等)。

返回:

類型 說明
Promise<Layer> 返回一個解析為新的 Layer 實例的 Promise。

例子:

// This snippet shows how to add a feature layer from an ArcGIS Server URL
// Get an ArcGIS Server URL from a custom function
const arcgisUrl = getLayerUrl();

Layer.fromArcGISServerUrl({
  url: arcgisUrl,
  properties: {
    // set any layer properties here
    popupTemplate: new PopupTemplate()
  }
}).then(function(layer){
  // add the layer to the map
  map.add(layer);
});
// This snippet shows how to add a table from an ArcGIS Server URL
// Get an ArcGIS Server URL from a custom function
const arcgisUrl = getLayerUrl();

Layer.fromArcGISServerUrl({
  url: arcgisUrl
}).then(function(layer){
  // Load the table before it can be used
  layer.load().then(function() {
    // Check that it is the right type
    if (layer.isTable) {
      // Add table to map's tables collection
      map.tables.add(layer);
    }
  });
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 Layer.fromArcGISServerUrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。