Sublayer

AMD: require(["esri/layers/support/Sublayer"], (Sublayer) => { /* code goes here */ });
ESM: import Sublayer from "@arcgis/core/layers/support/Sublayer.js";
Class: esri/layers/support/Sublayer
Inheritance: SublayerAccessor
Since: ArcGIS Maps SDK for JavaScript 4.1

Represents a sublayer in a MapImageLayer or a TileLayer. MapImageLayer allows you to display, query, and analyze layers from data defined in a map service. Map services contain sublayers with properties such as renderer, labelingInfo, and definitionExpression, and others that are defined on the server. The properties of each MapImageLayer sublayer on the map service may be dynamically changed by the user or developer. The properties of each TileLayer sublayer are read-only, and cannot be modified.

Known Limitations

The following limitations apply to sublayers from all map services published with ArcMap, or published to ArcGIS Server 10.5.1 or earlier:

Dynamic layers

Sublayers may be rendered on the fly as dynamic layers. Dynamic layers are created using the source property of the sublayer. There are two types of dynamic layers: dynamic map layers and dynamic data layers.

Dynamic map layers allow you to override sublayers in the map service with new renderers, definition expressions, opacity, scale visibility, etc. Multiple dynamic map layers may exist for a single map service layer.

Dynamic data layers provide the ability to create sublayers on the fly from data inside registered workspaces. The data may be tables with or without geometries, feature classes, or rasters. These data sources are not directly visible to the services directory, but may be published and configured with the ArcGIS Server Manager. Data from tables may be joined to other tables or dynamic map layers.

See also
Example
// defines the properties of various sublayers in a map service
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [
    {  // sets a definition expression on sublayer 3
      id: 3,
      definitionExpression: "pop2000 > 40000000"
    },
    {  // sublayer 2 will be rendered as defined in the map service
      id: 2
    },
    {  // sublayer 1 will be included in the layer, with visibility off
      id: 1,
      visible: false
    },
    {  // sublayer 0 will have new renderer and label
       // expressions applied in the view on the fly
      id: 0,
       renderer: {
         type: "class-breaks"  // autocasts as new ClassBreaksRenderer()
         // set renderer properties here
       },
       labelingInfo: [ new LabelClass ( ... ) ]
     }
   ]
});

Constructors

Sublayer

Constructor
new Sublayer(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Example
// typical usage
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [  // autocasts as a Collection of Sublayers
    { // sets a definition expression on sublayer 0
      id: 0,
      definitionExpression: "pop2000 > 40000000"
    },
    {  // creates a dynamic data layer
      source: {
        type: dynamic-layer,
        dataSource: {
          type: "table",
          workspaceId: "MyDatabaseWorkspaceIDSSR2",
          dataSourceName: "ss6.gdb.Railroads"
        }
      }
    }
  ]
});

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class

Describes the layer's supported capabilities.

Sublayer

The name of the class.

Accessor

A SQL where clause used to filter features in the image.

Sublayer

An array of fields in the Sublayer.

Sublayer

A convenient property that can be used to make case-insensitive lookups for a field by name.

Sublayer

If a map image layer contains a sublayer which is meant to be floor-aware, then that sublayer must have a floorInfo property, containing a LayerFloorInfo object which has a string property to represent the floorField.

Sublayer

The full extent of the Sublayer.

Sublayer

The sublayer's layer ID.

Sublayer

Returns true if the sublayer is a non-spatial table in a map service.

Sublayer

The label definition for this layer, specified as an array of LabelClass objects.

Sublayer

Indicates if labels for the sublayer will be visible in the view.

Sublayer

The MapImageLayer or TileLayer to which the sublayer belongs.

Sublayer

Indicates whether the layer will be included in the legend.

Sublayer

Indicates how the layer should display in the LayerList widget.

Sublayer

The Error object returned if an error occurred while loading.

Sublayer

Represents the status of a load operation.

Sublayer

A list of warnings which occurred while loading.

Sublayer

The maximum scale (most zoomed in) at which the layer is visible in the view.

Sublayer

The minimum scale (most zoomed out) at which the layer is visible in the view.

Sublayer

The name of an oidfield containing a unique value or identifier for each feature in the Sublayer.

Sublayer

The level of opacity to set on the sublayer on a scale from 0.0 - 1.0 where 0 is fully transparent and 1.0 is fully opaque.

Sublayer

The parent layer to which the sublayer belongs.

Sublayer

Indicates whether to display popups when features in the layer are clicked.

Sublayer

The popup template for the sublayer.

Sublayer

An array of relationships associated with the sublayer.

Sublayer

The renderer to apply to the sublayer.

Sublayer

An object that allows you to create a dynamic layer with data either from the map service sublayers or data from a registered workspace.

Sublayer

The map service's metadata JSON exposed by the ArcGIS REST API.

Sublayer

The spatial reference of the sublayer as defined by the service.

Sublayer

If a sublayer contains sublayers, this property is a Collection of Sublayer objects belonging to the given sublayer with sublayers.

Sublayer

The title of the sublayer used to identify it in places such as the LayerList and Legend widgets.

Sublayer
For Sublayer the type is always "sublayer". Sublayer

The name of the field holding the type ID or subtypes for the features.

Sublayer

An array of types defined in the feature service exposed by ArcGIS REST API.

Sublayer

The URL to the REST endpoint of the sublayer.

Sublayer

Indicates if the layer is visible in the view.

Sublayer

Property Details

capabilities

Property
capabilities Objectreadonly
Since: ArcGIS Maps SDK for JavaScript 4.27 Sublayer since 4.1, capabilities added at 4.27.

Describes the layer's supported capabilities.

Properties
data Object

Describes characteristics of the data in the layer.

Specification
supportsAttachment Boolean

Indicates if attachments are enabled on the layer.

operations Object

Describes operations that can be performed on features in the layer.

Specification
supportsQuery Boolean

Indicates if features in the layer can be queried.

supportsQueryAttachments Boolean

Indicates if the layer supports REST API queryAttachments operation. If false, queryAttachments() method can only return attachments for one feature at a time. If true, queryAttachments() can return attachments for array of objectIds.

queryRelated Object

Indicates if the layer's query operation supports querying features or records related to features in the layer.

Specification
supportsCount Boolean

Indicates if the layer's query response includes the number of features or records related to features in the layer.

supportsOrderBy Boolean

Indicates if the related features or records returned in the query response can be ordered by one or more fields.

supportsPagination Boolean

Indicates if the query response supports pagination for related features or records.

Example
// Once the layer loads, check if `supportsAttachment`
// operation is enabled on the layer

layer.when(function(){
  if (layer.capabilities.data.supportsAttachment) {
    // if attachments are enabled on the layer
    setupAttachments();
  }
});

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.7 Accessor since 4.0, declaredClass added at 4.7.

The name of the class. The declared class name is formatted as esri.folder.className.

definitionExpression

Property
definitionExpression String

A SQL where clause used to filter features in the image. Only the features that satisfy the definition expression are displayed in the View. Definition expressions may be set when a sublayer is constructed prior to it loading in the view or after it has been added to the MapImageLayer. To see if you can use this property, check the supportsSublayerDefinitionExpression property of MapImageLayer.capabilities.

Examples
let countiesLyr = layer.sublayers.find(function(sublayer){
  return sublayer.title === "States";
});
countiesLyr.definitionExpression = "STATE = 'Nebraska'"
// add a definition expression to sublayer when
// it is created in MapImageLayer constructor
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0,
    definitionExpression: "STATE = 'Nebraska'"
  }]
});
// Set a definition expression on the sublayer with ID of 0
layer.findSublayerById(0).definitionExpression = "STATE = 'Nebraska'";

fields

Property
fields Field[]readonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, fields added at 4.15.

An array of fields in the Sublayer. Each field represents an attribute that may contain a value for each feature in the Sublayer. This property is only available after the Sublayer has been loaded.

See also
Example
// print the first Sublayer's first field to the console
console.log(mapImageLayer.sublayers.items[0].fields[0]);

// OUTPUT:
alias: "OBJECTID"
defaultValue: undefined
description: "the objectid"
domain: null
editable: false
name: "objectid"
nullable: false
type: "oid"
valueType: null

fieldsIndex

Property
fieldsIndex FieldsIndexreadonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, fieldsIndex added at 4.15.

A convenient property that can be used to make case-insensitive lookups for a field by name. It can also provide a list of the date fields in a Sublayer. This property is only available after the Sublayer has been loaded.

See also
Example
// lookup a field by name, name is case-insensitive
const fieldsIndex = mapImageLayer.sublayers.items[0].fieldsIndex.get("OBjecTID");

// if there's a field by that name, print it to the console
if (fieldsIndex) {
  console.log("fieldsIndex: ", fieldsIndex);
}

floorInfo

Property
floorInfo LayerFloorInfoautocast
Since: ArcGIS Maps SDK for JavaScript 4.21 Sublayer since 4.1, floorInfo added at 4.21.

If a map image layer contains a sublayer which is meant to be floor-aware, then that sublayer must have a floorInfo property, containing a LayerFloorInfo object which has a string property to represent the floorField.

fullExtent

Property
fullExtent Extentreadonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, fullExtent added at 4.15.

The full extent of the Sublayer. This property is only available after the Sublayer has been loaded.

See also

id

Property
id Number

The sublayer's layer ID. When a source is not defined on the layer, this value represents the id of the sublayer defined by the map service. If creating a DynamicDataLayer or a MapDataLayer and adding it to the source property of the sublayer, the value of this property can be anything set by the developer.

Examples
// Creates a MapImageLayer instance containing only the sublayers defined below.
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  // this service has four sublayers, but we're only going to include three.
  sublayers: [ { id: 2 }, { id: 1 }, { id: 0 } ]
});
// Creates a MapImageLayer instance containing only the sublayers defined below.
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{ // sets a new renderer on this sublayer
    id: 2,
    renderer: {
      type: "class-breaks"  // autocasts as new ClassBreaksRenderer()
      // set renderer properties here
    }
  }, { // sets new labelingInfo on the sublayer
    id: 1,
    labelingInfo: [ new LabelClass( ... ) ]
  }, { // retains properties defined by the service, but makes sublayer not visible
    id: 0,
    visible: false
  }]
});

isTable

Property
isTable Booleanreadonly
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, isTable added at 4.30.

Returns true if the sublayer is a non-spatial table in a map service.

Default Value:false
See also

labelingInfo

Property
labelingInfo LabelClass[] |null |undefined

The label definition for this layer, specified as an array of LabelClass objects. Use this property to specify labeling properties for the layer such as label expression, placement, and size.

Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 3,
    labelsVisible: true,
    // labelingInfo autocasts to an array of LabelClass objects
    labelingInfo: [{
      labelExpression: "[name]",
      labelPlacement: "always-horizontal",
      symbol: {
        type: "text",  // autocasts as new TextSymbol()
        color: [255, 255, 255, 0.7],
        haloColor: [0, 0, 0, 0.85],
        haloSize: 1,
        font: {
          size: 11
        }
      },
      minScale: 2400000,
      maxScale: 73000
    }]
  }]
});

labelsVisible

Property
labelsVisible Boolean

Indicates if labels for the sublayer will be visible in the view.

Example
// turns on labels defined for sublayer 0
layer.findSublayerById(0).labelsVisible = true;

layer

Property
layer MapImageLayer |TileLayer

The MapImageLayer or TileLayer to which the sublayer belongs.

legendEnabled

Property
legendEnabled Boolean

Indicates whether the layer will be included in the legend. When false, the layer will be excluded from the legend.

Default Value:true

listMode

Property
listMode String
Since: ArcGIS Maps SDK for JavaScript 4.11 Sublayer since 4.1, listMode added at 4.11.

Indicates how the layer should display in the LayerList widget. The possible values are listed below.

Value Description
show The layer is visible in the table of contents.
hide The layer is hidden in the table of contents.
hide-children Hide the children layers from the table of contents.

Possible Values:"show" |"hide" |"hide-children"

Default Value:"show"

loadError

Property
loadError Errorreadonly

The Error object returned if an error occurred while loading.

Default Value:null

loadStatus

Property
loadStatus Stringreadonly

Represents the status of a load operation.

Value Description
not-loaded The object's resources have not loaded.
loading The object's resources are currently loading.
loaded The object's resources have loaded without errors.
failed The object's resources failed to load. See loadError for more details.

Possible Values:"not-loaded" |"loading" |"failed" |"loaded"

Default Value:"not-loaded"

loadWarnings

Property
loadWarnings Object[]readonly

A list of warnings which occurred while loading.

maxScale

Property
maxScale Number

The maximum scale (most zoomed in) at which the layer is visible in the view. If the map is zoomed in beyond this scale, the layer will not be visible. A value of 0 means the layer does not have a maximum scale. The maxScale value should always be smaller than the minScale value, and greater than or equal to the service specification.

Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [
    {
      id: 0,
      minScale: 5000000,
      maxScale: 24000
    },
    {
      id: 1
      minScale: 24000,
      maxScale: 100
    }
  ]
});

minScale

Property
minScale Number

The minimum scale (most zoomed out) at which the layer is visible in the view. If the map is zoomed out beyond this scale, the layer will not be visible. A value of 0 means the layer does not have a minimum scale. The minScale value should always be larger than the maxScale value, and lesser than or equal to the service specification.

Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [
    {
      id: 0,
      minScale: 5000000,
      maxScale: 24000
    },
    {
      id: 1,
      minScale: 24000,
      maxScale: 100
    }
  ]
});

objectIdField

Property
objectIdField Stringreadonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, objectIdField added at 4.15.

The name of an oid field containing a unique value or identifier for each feature in the Sublayer.

See also

opacity

Property
opacity Number

The level of opacity to set on the sublayer on a scale from 0.0 - 1.0 where 0 is fully transparent and 1.0 is fully opaque. If the MapImageLayer.opacity is set, the actual opacity value of the sublayer will be the value of MapImageLayer.opacity multiplied by the sublayer's opacity.

Example
// Set the opacity of the layer to 0.5
layer.findSublayerById(0).opacity = 0.5;

parent

Property
parent Sublayer |MapImageLayer |TileLayer
Since: ArcGIS Maps SDK for JavaScript 4.27 Sublayer since 4.1, parent added at 4.27.

The parent layer to which the sublayer belongs.

popupEnabled

Property
popupEnabled Boolean
Since: ArcGIS Maps SDK for JavaScript 4.7 Sublayer since 4.1, popupEnabled added at 4.7.

Indicates whether to display popups when features in the layer are clicked. The layer needs to have a popupTemplate to define what information should be displayed in the popup. Alternatively, a default popup template may be automatically used if Popup.defaultPopupTemplateEnabled is set to true.

Default Value:true

popupTemplate

Property
popupTemplate PopupTemplate

The popup template for the sublayer. When set, the popupTemplate allows users to access attributes and display their values in the view's popup when the user clicks the image.

Sublayers with a RasterDataSource cannot be queried and therefore do not support PopupTemplate.

Alternatively, a default popup template may be automatically used if Popup.defaultPopupTemplateEnabled is set to true.

Known Limitations

  • Arcade expressions are not supported in PopupTemplates set on MapImageLayer sublayers or TileLayer sublayers unless they reference ArcGIS Enterprise 10.6 map services (or later) created from ArcGIS Pro.
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0,
    popupTemplate: {
      title: "{COUNTY}",
      content: "{POP2007} people lived in this county in 2007"
    }
  }]
});

relationships

Property
relationships Relationship[]readonly
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, relationships added at 4.30.

An array of relationships associated with the sublayer. Each relationship defines a relationship between this sublayer and another layer or table.

renderer

Property
renderer Rendererautocast

The renderer to apply to the sublayer. This value overrides the renderer read from the map service. To see if you can use this property, check the supportsDynamicLayers property of MapImageLayer.capabilities.

Known Limitations

  • 3D symbols are not currently supported in renderers set on sublayers.
  • Visual variables and Arcade expressions are not supported in renderers set on MapImageLayer sublayers unless they reference ArcGIS Enterprise 10.6 map services (or later) created from ArcGIS Pro.
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0,
    renderer: {
      type: "simple",  // autocasts as new SimpleRenderer()
      symbol: {
        type: "simple-marker",  // autocasts as new SimpleMarkerSymbol()
        color: "black",
        size: 8
      }
    }
  }]
});

source

Property
source DynamicMapLayer |DynamicDataLayer

An object that allows you to create a dynamic layer with data either from the map service sublayers or data from a registered workspace. See DynamicMapLayer for creating dynamic layers from map service layers for on the fly rendering, labeling, and filtering (definition expressions). To create dynamic layers from other sources in registered workspaces such as tables and table joins, see DynamicDataLayer.

Example
// Creates two sublayers that point to the same map service layer.
// Each layer presents different features in the data using
// definition expressions and renderers.
let mapImageLayer = new MapImageLayer({
  sublayers: [{
    id: 10,
    definitionExpression: "POP < 100000",
    renderer: {
      type: "simple",  // autocasts as new SimpleRenderer()
      symbol: smallMarker
    },
    source: {
      type: "map-layer",
      mapLayerId: 0
    }
  }, {
    id: 11,
    definitionExpression: "POP > 100001",
    renderer: {
      type: "simple",  // autocasts as new SimpleRenderer()
      symbol: largeMarker
    },
    source: {
      type: "map-layer",
      mapLayerId: 0
    }
  }]
});

sourceJSON

Property
sourceJSON Object
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, sourceJSON added at 4.15.

The map service's metadata JSON exposed by the ArcGIS REST API. While most commonly used properties are exposed on the Sublayer class directly, this property gives access to all information returned by the map service. This property is useful if working in an application built using an older version of the API which requires access to map service properties from a more recent version.

spatialReference

Property
spatialReference SpatialReferencereadonly
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, spatialReference added at 4.30.

The spatial reference of the sublayer as defined by the service.

sublayers

Property
sublayers Collection<Sublayer>

If a sublayer contains sublayers, this property is a Collection of Sublayer objects belonging to the given sublayer with sublayers.

Example
// test function for determining if a MapImageLayer's sublayers
// contain at least one dynamic data layer
function hasDynamicDataLayer (layer){
  if (layer.sublayers && layer.sublayers.sublayers){
    return layer.sublayers.sublayers.some(function(sublayer){
      return sublayer.source.type === "data-layer";
    });
  } else {
    console.log("layer does not have sublayers or nested sublayers");
    return false;
  }
}

title

Property
title String

The title of the sublayer used to identify it in places such as the LayerList and Legend widgets. This value can be defined in the map service or programmatically by the developer. It can also be useful for finding a specific sublayer.

Example
let radarSublayer = layer.sublayers.find(function(sublayer){
  return sublayer.title === "radar";
});

type

Property
type Stringreadonly

For Sublayer the type is always "sublayer".

typeIdField

Property
typeIdField Stringreadonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, typeIdField added at 4.15.

The name of the field holding the type ID or subtypes for the features. See ArcGIS Pro subtypes document. This property is only available after the Sublayer has been loaded.

See also

types

Property
types FeatureType[]readonly
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, types added at 4.15.

An array of types defined in the feature service exposed by ArcGIS REST API. Each item includes information about the type, such as the type ID, name, and definition expression. This property is only available after the Sublayer has been loaded.

See also

url

Property
url String

The URL to the REST endpoint of the sublayer. This allows you to view the schema of fields and query tables located in registered workspaces.

visible

Property
visible Boolean

Indicates if the layer is visible in the view. To see if you can use this property, check the supportsSublayerVisibility property of MapImageLayer.capabilities.

Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    // this sublayer is visible by default
    id: 0
  }, {
    // this sublayer will be added to the layer but not visible
    id: 1,
    visible: false
  }]
    // all other sublayers in the service are excluded from the layer
});

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor

Cancels a load() operation if it is already in progress.

Sublayer

Creates a deep clone of the sublayer.

Sublayer
Promise<FeatureLayer>

A convenient method for creating a FeatureLayer instance based on the Sublayer's configuration, including dynamic sources.

Sublayer

Creates a popup template for the sublayer, populated with all the fields of the sublayer.

Sublayer

Creates a Query object with default values representing the layer's state, including filters (definition expression) on the layer's features.

Sublayer

Returns a FeatureType describing the feature's type.

Sublayer

Returns the Domain associated with the given field name.

Sublayer

Returns true if a named group of handles exist.

Accessor

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected).

Sublayer

isRejected() may be used to verify if creating an instance of the class is rejected.

Sublayer

isResolved() may be used to verify if creating an instance of the class is resolved.

Sublayer
Promise

Loads the resources referenced by this class.

Sublayer

Query information about attachments associated with features.

Sublayer
Promise<Number>

Executes a Query against the sublayer and returns the number of features that satisfy the query.

Sublayer
Promise<FeatureSet>

Executes a query against features in the sublayer.

Sublayer
Promise<Number[]>

Executes a Query against the sublayer and returns an array of Object IDs for features that satisfy the input query.

Sublayer
Promise<Object>

Executes a RelationshipQuery against the sublayer and returns FeatureSets grouped by source layer or table objectIds.

Sublayer
Promise<Object>

Executes a RelationshipQuery against the sublayer and when resolved, it returns an object containing key value pairs.

Sublayer

Removes a group of handles owned by the object.

Accessor
Promise

when() may be leveraged once an instance of the class is created.

Sublayer

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

cancelLoad

Method
cancelLoad()

Cancels a load() operation if it is already in progress.

clone

Method
clone(){Sublayer}

Creates a deep clone of the sublayer.

Returns
Type Description
Sublayer A deep clone of the sublayer instance that invoked this method.

createFeatureLayer

Method
createFeatureLayer(){Promise<FeatureLayer>}
Since: ArcGIS Maps SDK for JavaScript 4.7 Sublayer since 4.1, createFeatureLayer added at 4.7.

A convenient method for creating a FeatureLayer instance based on the Sublayer's configuration, including dynamic sources. This allows you to take advantage of FeatureLayer capabilities not supported in Sublayer, such as the Smart Mapping creator functions.

Returns
Type Description
Promise<FeatureLayer> A promise resolving to a FeatureLayer matching the configuration of the Sublayer instance that called this method.
Example
let sublayer = mapImageLayer.findSublayerById(0);

// when the createFeatureLayer() promise resolves, load the FeatureLayer
// and pass it to the createParameters function
sublayer.createFeatureLayer()
  .then(function(featureLayer){
    return featureLayer.load();
  })
  .then(createParameters);

function createParameters (featureLayer) {
  let colorParams = {
    layer: featureLayer,
    basemap: map.basemap,
    field: "POPULATION",
    normalizationField: "SQ_MILES",
    legendOptions: {
      title: "Population density (sq. miles)"
    }
  };
}

// when the promise resolves, apply the renderer to the sublayer
colorRendererCreator.createContinuousRenderer(colorParams)
  .then(function(response){
    sublayer.renderer = response.renderer;
  });

createPopupTemplate

Method
createPopupTemplate(options){PopupTemplate}
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, createPopupTemplate added at 4.15.

Creates a popup template for the sublayer, populated with all the fields of the sublayer.

Starting with version 4.28, date fields are formatted using the short-date-short-time preset dateFormat rather than long-month-day-year in popup templates created with the createPopupTemplate() method. For example, previously a date that may have appeared as "December 30, 1997" will now appear as "12/30/1997 6:00 PM".

Parameter
optional

Options for creating the popup template.

Returns
Type Description
PopupTemplate The popup template, or null if the layer does not have any fields.

createQuery

Method
createQuery(){Query}

Creates a Query object with default values representing the layer's state, including filters (definition expression) on the layer's features.

Returns
Type Description
Query The default query object including the definitionExpression for the sublayer.

getFeatureType

Method
getFeatureType(feature){FeatureType}
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, getFeatureType added at 4.15.

Returns a FeatureType describing the feature's type. This is applicable if the layer containing the feature has a typeIdField.

Parameter
feature Graphic

A feature from this Sublayer.

Returns
Type Description
FeatureType The FeatureType describing the feature's type.

getFieldDomain

Method
getFieldDomain(fieldName, options){Domain}
Since: ArcGIS Maps SDK for JavaScript 4.15 Sublayer since 4.1, getFieldDomain added at 4.15.

Returns the Domain associated with the given field name. The domain can be either a CodedValueDomain or RangeDomain.

Parameters
fieldName String

Name of the field.

options Object
optional

An object specifying additional options. See the object specification table below for the required properties of this object.

Specification
feature Graphic

The feature to which the Domain is assigned.

Returns
Type Description
Domain The Domain object associated with the given field name for the given feature.
Example
// Get a range domain associated with the first feature
// returned from queryFeatures().
sublayer.queryFeatures(query).then(function(results){
  const domain = sublayer.getFieldDomain("Height", {feature: results.features[0]});
  console.log("domain", domain)
});

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

isFulfilled

Method
isFulfilled(){Boolean}

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).

isRejected

Method
isRejected(){Boolean}

isRejected() may be used to verify if creating an instance of the class is rejected. If it is rejected, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been rejected.

isResolved

Method
isResolved(){Boolean}

isResolved() may be used to verify if creating an instance of the class is resolved. If it is resolved, true will be returned.

Returns
Type Description
Boolean Indicates whether creating an instance of the class has been resolved.

load

Method
load(signal){Promise}

Loads the resources referenced by this class. This method automatically executes for a View and all of the resources it references in Map if the view is constructed with a map instance.

This method must be called by the developer when accessing a resource that will not be loaded in a View.

The load() method only triggers the loading of the resource the first time it is called. The subsequent calls return the same promise.

It's possible to provide a signal to stop being interested into a Loadable instance load status. When the signal is aborted, the instance does not stop its loading process, only cancelLoad can abort it.

Parameter
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise Resolves when the resources have loaded.

queryAttachments

Method
queryAttachments(attachmentQuery, options)
Since: ArcGIS Maps SDK for JavaScript 4.26 Sublayer since 4.1, queryAttachments added at 4.26.

Query information about attachments associated with features. It will return an error if the layer's capabilities.data.supportsAttachment property is false. Attachments for multiple features can be queried if the layer's capabilities.operations.supportsQueryAttachments is true.

Known Limitations

When the layer's capabilities.operations.supportsQueryAttachments property is false, AttachmentQuery.objectIds property only accepts a single objectId.

Parameters
attachmentQuery AttachmentQuery autocast
Autocasts from Object

Specifies the attachment parameters for query.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

queryFeatureCount

Method
queryFeatureCount(query, options){Promise<Number>}
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, queryFeatureCount added at 4.30.

Executes a Query against the sublayer and returns the number of features that satisfy the query. If no parameters are specified, the total number of features satisfying the layer's configuration/filters is returned.

Parameters
query Query autocast
optional
Autocasts from Object

Specifies the attributes and spatial filter of the query. If no parameters are specified, the total number of features satisfying the layer's configuration/filters is returned.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise<Number> When resolved, returns the number of features that satisfy the query.

queryFeatures

Method
queryFeatures(query, options){Promise<FeatureSet>}

Executes a query against features in the sublayer. To see if you can use this property, check the supportsQuery property of MapImageLayer.capabilities.

Parameters
query Query autocast
optional
Autocasts from Object

Specifies the attributes and spatial filter of the query. If no parameters are specified, then all features satisfying the layer's configuration/filters are returned.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise<FeatureSet> Returns a promise that resolves to a FeatureSet containing the features that satisfy the query.

queryObjectIds

Method
queryObjectIds(query, options){Promise<Number[]>}
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, queryObjectIds added at 4.30.

Executes a Query against the sublayer and returns an array of Object IDs for features that satisfy the input query. If no parameters are specified, then the Object IDs of all features satisfying the layer's configuration/filters are returned.

Parameters
query Query autocast
optional
Autocasts from Object

Specifies the attributes and spatial filter of the query. If no parameters are specified, then the Object IDs of all features satisfying the layer's configuration/filters are returned.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise<Number[]> When resolved, returns an array of numbers representing the object IDs of the features satisfying the query.

queryRelatedFeatures

Method
queryRelatedFeatures(relationshipQuery, options){Promise<Object>}
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, queryRelatedFeatures added at 4.30.

Executes a RelationshipQuery against the sublayer and returns FeatureSets grouped by source layer or table objectIds.

Parameters
relationshipQuery RelationshipQuery autocast
Autocasts from Object

Specifies relationship parameters for querying related features or records from a layer or a table.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise<Object> When resolved, returns FeatureSets grouped by source layer/table objectIds. Each FeatureSet contains an array of Graphic features including the values of the fields requested by the user.

queryRelatedFeaturesCount

Method
queryRelatedFeaturesCount(relationshipQuery, options){Promise<Object>}
Since: ArcGIS Maps SDK for JavaScript 4.30 Sublayer since 4.1, queryRelatedFeaturesCount added at 4.30.

Executes a RelationshipQuery against the sublayer and when resolved, it returns an object containing key value pairs. Key in this case is the objectId of the feature and value is the number of related features associated with the feature.

Parameters
relationshipQuery RelationshipQuery autocast
Autocasts from Object

Specifies relationship parameters for querying related features or records from a layer or a table.

options Object
optional

An object with the following properties.

Specification
signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named AbortError when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.

Returns
Type Description
Promise<Object> When resolved, returns an object containing key value pairs. Key in this case is the objectId of the feature and value is the number of related features.

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

when

Method
when(callback, errback){Promise}
Since: ArcGIS Maps SDK for JavaScript 4.6 Sublayer since 4.1, when added at 4.6.

when() may be leveraged once an instance of the class is created. This method takes two input parameters: a callback function and an errback function. The callback executes when the instance of the class loads. The errback executes if the instance of the class fails to load.

Parameters
callback Function
optional

The function to call when the promise resolves.

errback Function
optional

The function to execute when the promise fails.

Returns
Type Description
Promise Returns a new promise for the result of callback that may be used to chain additional functions.
Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same way
let view = new MapView();
view.when(function(){
  // This function will execute once the promise is resolved
}, function(error){
  // This function will execute if the promise is rejected due to an error
});

Type Definitions

DynamicDataLayer

Type Definition
DynamicDataLayer

A dynamic data layer is a layer created on-the-fly with data stored in a registered workspace. This is data that can be rendered and queried on the fly, but that isn't explicitly exposed as a service sublayer. Depending on the type of data source, these layers are classified as one of the following:

Data source Description
TableDataSource A feature class with geometries or table without geometries. When a table data source does not contain geometries, it may be used as one of the sources in a join operation. Feature class tables may be used on their own since they contain a geometry field.
QueryTableDataSource A feature class or table that may be queried on the fly with a SQL where clause. This data source is useful for scenarios where you have a table containing unique geometries and another table with multiple records that match to each geometry. You can use the QueryTableDataSource to select only a subset of those matching records (so records in both tables have a one-to-one relationship with each other) and join them to the table with geometries.
RasterDataSource A raster dataset used for visualization purposes only.
JoinTableDataSource This data source consists of two data sources joined by a common attribute or key. The left table data source typically contains geometries, while the right source may be a table or query table without geometries.
Properties
type String

This value is always data-layer and is inferred when the dataSource property is set.

The value is always "data-layer".

A table, feature class, or raster that resides in a registered workspace (either a folder or geodatabase). The data sources are not visible in the Services Directory by default. They may be viewed, published, and configured using the ArcGIS Server Manager.

fields Object[]

Controls field visibility in the layer. Only specified fields will be visible. If null, all fields are visible in the dynamic layer. The specification for a field object is provided below.

Specification
name String

The name of the field.

alias String

The alias of the field.

See also
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
  sublayers: [{
    id: 0,
    renderer: renderer,
      opacity: 0.9,
      source: {
        type: "data-layer",
        dataSource: {
          type: "join-table",
          leftTableSource: {
            type: "map-layer",
            mapLayerId: 3
          },
          rightTableSource: {
            type: "data-layer",
            // references a table in a registered workspace that doesn't have geometries
            dataSource: {
              type: "table",
              workspaceId: "CensusFileGDBWorkspaceID",
              dataSourceName: "ancestry"
            }
          },
          leftTableKey: "STATE_NAME",
          rightTableKey: "State",
          joinType: "left-outer-join"
        }
      }
    }
  ]
});

DynamicMapLayer

Type Definition
DynamicMapLayer

A dynamic map layer refers to a layer published in a map service that has dynamic layers enabled. This layer type may be used to create multiple sublayers that point to the same service layer, but are assigned different definition expressions, renderers, and other properties.

Properties
type String

This value is always map-layer and is inferred when the mapLayerId property is set.

The value is always "map-layer".

mapLayerId Number

The id of the service sublayer.

gdbVersion String

An optional property for specifying the GDB version.

See also
Example
// Creates two sublayers that point to the same map service layer.
// Each layer presents different features in the data using
// definition expressions and renderers.
let mapImageLayer = new MapImageLayer({
  sublayers: [{
    id: 10,
    definitionExpression: "POP < 50000",
    renderer: {
      type: "class-breaks"  // autocasts as new ClassBreaksRenderer()
      // set renderer properties here
    },
    source: {
      type: "map-layer",
      mapLayerId: 0
    }
  }, {
    id: 11,
    definitionExpression: "GRADUATED_HS > 0.449",
    renderer: {
      type: "class-breaks"  // autocasts as new ClassBreaksRenderer()
      // set renderer properties here
    },
    source: {
      type: "map-layer",
      mapLayerId: 0
    }
  }]
});

JoinTableDataSource

Type Definition
JoinTableDataSource

The result of an on-the-fly join operation at runtime. Nested joins are supported. To use nested joins, set either leftTableSource or rightTableSource to join-table.

Properties
type String

This value is always join-table and is inferred when other join table properties of this object are set.

The value is always "join-table".

leftTableKey String

The field name used for joining or matching records in the left table to records in the right table.

rightTableKey String

The field name used for joining or matching records in the right table to records in the left table.

The left table for joining to the right table source. This can either be a dynamic map layer or a dynamic data layer. The dynamic data layer may contain another join data source used for nested joining.

The right table for joining to the left table source. This can either be a dynamic map layer or a dynamic data layer. The dynamic data layer may contain another join data source used for nested joining.

joinType String

The type of join that will be performed.

Possible Value Description
left-outer-join Unmatched records in the left table source are preserved and joined with null values in the right table source.
left-inner-join Records in the left table source are discarded if they are unmatched with records in the right table source.

Possible Values:"left-outer-join"|"left-inner-join"

See also
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
  sublayers: [{
    id: 0,
    renderer: renderer,
    opacity: 0.9,
    source: {
      type: "data-layer",
      dataSource: {
        type: "join-table",
        leftTableSource: {
          type: "map-layer",
          mapLayerId: 3
        },
        rightTableSource: {
          type: "data-layer",
          dataSource: {
            type: "table",
            workspaceId: "CensusFileGDBWorkspaceID",
            dataSourceName: "ancestry"
          }
        },
        leftTableKey: "STATE_NAME",
        rightTableKey: "State",
        joinType: "left-outer-join"
      }
    }
  }]
});

QueryTableDataSource

Type Definition
QueryTableDataSource

A query table is a feature class or table defined by a SQL query on the fly. Query layers allow both spatial and nonspatial information stored in a database to be easily integrated into map service operations. Since a query table uses SQL to directly query database tables and views, spatial information used by a query table is not required to be in a geodatabase.

This data source is useful for scenarios where you have a table containing multiple records that match to a single geometry in either another table or a map service layer. You can use the QueryTableDataSource to select only a subset of those matching records and join them to the table with geometries so records in both tables have a one-to-one relationship with each other.

Properties
type String

This value is always query-table and is inferred when the query property of this object is set.

The value is always "query-table".

workspaceId String

The workspace where the data resides (defined in ArcGIS Server Manager).

query String

The SQL query used to filter records.

oidFields String

The field name(s) containing the unique IDs for each record in the table. This can be a comma separated list if the query table is used in a JoinTableDataSource.

spatialReference SpatialReference

The spatial reference of the geometry of each feature in the table source.

geometryType String

The geometry type of each record in the table.

Possible Values:"point"|"multipoint"|"polyline"|"polygon"|"multipatch"

See also
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    title: "Places",
    renderer: renderer,
    source: {
      type: "data-layer",
      dataSource: {
        type: "query-table",
        workspaceId: "MyDatabaseWorkspaceIDSSR2",
        query: "SELECT * FROM ss6.gdb.Places",
        oidFields: "objectid"
      }
    }
  }]
});

RasterDataSource

Type Definition
RasterDataSource

A file-based raster that resides in a registered raster workspace. The raster may only be displayed in the view, not queried or assigned a renderer.

Properties
type String

This value is always raster.

The value is always "raster".

workspaceId String

The workspace where the raster resides as defined in the ArcGIS Server Manager.

dataSourceName String

The name of the raster in the registered workspace.

See also
Example
let layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/GlacierBay/MapServer",
  sublayers: [{
    title: "slope",
    opacity: 0.75,
    source: {
      type: "data-layer",
      dataSource: {
        type: "raster",
        workspaceId: "MyDatabaseWorkspaceIDSSR2",
        dataSourceName: "slope.tiff"
      }
    }
  }]
});

TableDataSource

Type Definition
TableDataSource

A table or feature class that resides in a registered workspace (either a folder or geodatabase). In the case of a geodatabase, if versioned, use version to switch to an alternate geodatabase version.

Properties
type String

This value is always table.

workspaceId String

The workspace where the table resides as defined in the ArcGIS Server Manager.

dataSourceName String

The name of the table in the registered workspace.

gdbVersion String

References the geodatabase version if multiple versions exist in the geodatabase.

See also
Example
let layer = new MapImageLayer({
   url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
   sublayers: [{
     renderer: renderer,
     source: {
       type: "data-layer",
       dataSource: {
         type: "table",
         workspaceId: "MyDatabaseWorkspaceIDSSR2",
         dataSourceName: "ss6.gdb.Railroads"
       }
     }
   }]
 });

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.