import type { TablesMixin } from "@arcgis/core/support/TablesMixin.js";- Subclasses
- Map, GroupLayer
- Since
- ArcGIS Maps SDK for JavaScript 4.17
A mixin that provides properties to access tables.
Properties
| Property | Type | Class |
|---|---|---|
| |
tables
- Type
- Collection<Layer>
A collection of Layer instances that are tables
saved in a Map and/or a WebMap.
In order for the table(s) to be recognized as such, the FeatureLayer's FeatureLayer.isTable
property must return true. A table can be created via one of the options below:
- Referencing the URL to a table in a feature service.
- Create a feature layer using the Layer.fromArcGISServerUrl() method and confirm that it is a table using feature layer's FeatureLayer.isTable property. This can be either a feature service or feature collection.
- Create a feature layer using the Layer.fromPortalItem() method and confirm that it is a table using feature layer's FeatureLayer.isTable property. This can be either a feature service or feature collection.
- Create an in-memory, non-spatial, client-side feature layer.
Beginning with 4.17, it is possible to persist non-spatial, tables in a feature service to a WebMap, although in-memory (feature collection) tables are not yet supported.
Persisting tables within a GroupLayer.tables is not yet supported. If this is needed, add them to the Map.tables and/or WebMap.tables.
Currently, only feature service feature layers are recognized.
To access spatial layers, use the layers property in either Map.layers
or WebMap.layers classes
- Examples
- // This snippet shows how to add a table to a map's table collection.// FeatureLayer.isTable = falseconst featureLayer = new FeatureLayer({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0"});// Add featureLayer to the mapmap.add(featureLayer);// FeatureLayer.isTable = trueconst table = new FeatureLayer({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/1"});// 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(() => {// Add the table to the collectionmap.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 = trueconst table = new FeatureLayer({url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Crash_details_table/FeatureServer/0"});// Create Webmap instanceconst webmap = new WebMap({portalItem: {id: webmapId}});// When web map is ready, load the table and add it to the web mapwebmap.when(() => {table.load().then(() => {console.log("Adding table");// Add table to the webmap's table collectionwebmap.tables.add(table);});});// Call updateFrom on webmap and pass in the existing viewwebmap.updateFrom(view).then(() => {// Call saveAs (or save) on the web mapwebmap.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 infoconst 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 infoconst graphics = [{attributes: {"tree_type": "deciduous","species": "maple","ObjectID": 2}}, {attributes: {"tree_type": "coniferous","species": "pine","ObjectID": 3}}];// Create the feature layer (feature collection) tableconst table = new FeatureLayer({fields: fields,objectIdField: "ObjectID",source: graphics});// Check when map is ready and load the tablemap.when(() => {table.load().then(() => {console.log("Adding table");map.tables.add(table);});});