当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。