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


JavaScript ArcGIS GroupLayer.tables用法及代碼示例

基本信息

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

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

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

類: esri/layers/GroupLayer

繼承: GroupLayer > Layer > Accessor

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

GroupLayer.tables函數(或屬性)的定義如下:

來自 Layer[]

layer 實例的集合,它們是保存在 Map 和/或 WebMap 中的表。為了使表被識別,FeatureLayer 的 isTable 屬性必須返回 true 。可以通過以下選項之一創建表:

  • 將 URL 引用到要素服務中的表。
  • 使用Layer.fromArcGISServerUrl 方法創建一個要素圖層,並使用要素圖層的isTable 屬性確認它是一個表。這可以是要素服務或要素集合。
  • 使用Layer.fromPortalItem 方法創建一個要素圖層,並使用要素圖層的isTable 屬性確認它是一個表。這可以是要素服務或要素集合。
  • 創建內存中的非空間客戶端要素圖層。

從 4.17 開始,可以將要素服務中的非空間表持久化到 WebMap,盡管尚不支持內存(要素集合)表。

尚不支持 GroupLayer 中的持久表。如果需要,請將它們添加到 Map 和/或 WebMap

目前,僅識別要素服務feature layers

要訪問空間層,請使用 MapWebMap 類中的 layers 屬性。

例子:

// This snippet shows how to add a table to a map's table collection.

// FeatureLayer.isTable = false
const featureLayer = new FeatureLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0"
});

// FeatureLayer.isTable = true
const table = new FeatureLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/1"
});

// Add featureLayer to the map
map.add(featureLayer);

// In order for the table to be stored within
// the map's table collection, load it and confirm it is the right type.

table.load().then(function() {
  // Add the table to the collection
  map.tables.add(table);
  console.log("Table is added to map's table collection");
});
// This snippet shows how to persist a table to an existing web map

// FeatureLayer.isTable = true
const table = new FeatureLayer({
  url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Crash_details_table/FeatureServer/0"
});

// Create Webmap instance
const webmap = new WebMap({
  portalItem: {
    id: webmapId
  }
});

// When web map is ready, load the table and add it to the web map
webmap.when(function() {
  table.load().then(function() {
    console.log("Adding table");
    // Add table to the webmap's table collection
    webmap.tables.add(table);
  });
});

// Call updateFrom on webmap and pass in the existing view
webmap.updateFrom(view).then(function() {
  // Call saveAs (or save) on the web map
  webmap.saveAs({
    // autocasts as new PortalItem()
    title: "New WebMap"
  });
});
// This snippet shows how to add an in-memory table to a map

// Create the array of objects containing field info
const fields = [{
  name: "ObjectID",
  alias: "ObjectID",
  type: "oid"
},
{
  name: "tree_type",
  alias: "Tree type",
  type: "string"
},
{
  name: "species",
  alias: "Species",
  type: "string"
}];

// Create the array of graphics holding attribute info
const graphics = [{
  attributes: {
    "tree_type": "deciduous",
    "species": "maple",
    "ObjectID": 2
  }
}, {
  attributes: {
    "tree_type": "coniferous",
    "species": "pine",
    "ObjectID": 3
  }
}];

// Create the feature layer (feature collection) table
const table = new FeatureLayer({
  fields: fields,
  objectIdField: "ObjectID",
  source: graphics
});

// Check when map is ready and load the table
map.when(function() {
  table.load().then(function() {
    console.log("Adding table");
    map.tables.add(table);
  });
});

相關用法


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