UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

800 lines (797 loc) 132 kB
import type Graphic from "../Graphic.js"; import type PopupTemplate from "../PopupTemplate.js"; import type Collection from "../core/Collection.js"; import type FormTemplate from "../form/FormTemplate.js"; import type Extent from "../geometry/Extent.js"; import type Layer from "./Layer.js"; import type FeatureTemplate from "./support/FeatureTemplate.js"; import type FeatureType from "./support/FeatureType.js"; import type Field from "./support/Field.js"; import type FieldConfiguration from "./support/FieldConfiguration.js"; import type LabelClass from "./support/LabelClass.js"; import type PortalItem from "../portal/PortalItem.js"; import type DynamicDataLayer from "../rest/layerSources/DynamicDataLayer.js"; import type AttachmentInfo from "../rest/query/support/AttachmentInfo.js"; import type AttributeBinsFeatureSet from "../rest/support/AttributeBinsFeatureSet.js"; import type FeatureSet from "../rest/support/FeatureSet.js"; import type Query from "../rest/support/Query.js"; import type AttributeTableTemplate from "../tables/AttributeTableTemplate.js"; import type { ClonableMixin } from "../core/Clonable.js"; import type { ReadonlyArrayOrCollection } from "../core/Collection.js"; import type { MultiOriginJSONSupportMixin } from "../core/MultiOriginJSONSupport.js"; import type { EditOptions, Edits, EditsResult, FeatureEditResult } from "../editing/types.js"; import type { LayerEvents, LayerProperties } from "./Layer.js"; import type { LayerSaveAsOptions, LayerSaveOptions, FeatureTitleOptions } from "./types.js"; import type { APIKeyMixin, APIKeyMixinProperties } from "./mixins/APIKeyMixin.js"; import type { BlendLayer, BlendLayerProperties } from "./mixins/BlendLayer.js"; import type { CustomParametersMixin, CustomParametersMixinProperties } from "./mixins/CustomParametersMixin.js"; import type { DisplayFilteredLayer, DisplayFilteredLayerProperties } from "./mixins/DisplayFilteredLayer.js"; import type { EditBusLayer, EditBusLayerEvents } from "./mixins/EditBusLayer.js"; import type { FeatureEffectLayer, FeatureEffectLayerProperties } from "./mixins/FeatureEffectLayer.js"; import type { FeatureLayerBase, FeatureLayerBaseProperties } from "./mixins/FeatureLayerBase.js"; import type { FeatureReductionLayer, FeatureReductionLayerProperties } from "./mixins/FeatureReductionLayer.js"; import type { OperationalLayer, OperationalLayerProperties } from "./mixins/OperationalLayer.js"; import type { OrderedLayer, OrderedLayerProperties } from "./mixins/OrderedLayer.js"; import type { PortalLayer, PortalLayerProperties } from "./mixins/PortalLayer.js"; import type { PublishableLayer, PublishableLayerProperties } from "./mixins/PublishableLayer.js"; import type { RefreshableLayerEvents, RefreshableLayer, RefreshableLayerProperties } from "./mixins/RefreshableLayer.js"; import type { ScaleRangeLayer, ScaleRangeLayerProperties } from "./mixins/ScaleRangeLayer.js"; import type { TemporalLayer, TemporalLayerProperties } from "./mixins/TemporalLayer.js"; import type { TrackableLayer, TrackableLayerProperties } from "./mixins/TrackableLayer.js"; import type { PortalItemProperties } from "../portal/PortalItem.js"; import type { RendererUnion } from "../renderers/types.js"; import type { RequestOptions } from "../request/types.js"; import type { AttachmentQueryProperties } from "../rest/support/AttachmentQuery.js"; import type { AttributeBinsQueryProperties } from "../rest/support/AttributeBinsQuery.js"; import type { QueryProperties } from "../rest/support/Query.js"; import type { RelationshipQueryProperties } from "../rest/support/RelationshipQuery.js"; import type { TopFeaturesQueryProperties } from "../rest/support/TopFeaturesQuery.js"; import type { CreatePopupTemplateOptions } from "../support/popupUtils.js"; import type { ObjectId } from "../views/types.js"; import type { AttributeTableTemplateProperties } from "../tables/AttributeTableTemplate.js"; import type { DynamicDataLayerProperties } from "../rest/layerSources/DynamicDataLayer.js"; import type { FieldConfigurationProperties } from "./support/FieldConfiguration.js"; import type { FieldProperties } from "./support/Field.js"; import type { FormTemplateProperties } from "../form/FormTemplate.js"; import type { LabelClassProperties } from "./support/LabelClass.js"; import type { PopupTemplateProperties } from "../PopupTemplate.js"; import type { HeatmapRendererProperties } from "../renderers/HeatmapRenderer.js"; import type { PieChartRendererProperties } from "../renderers/PieChartRenderer.js"; import type { DictionaryRendererProperties } from "../renderers/DictionaryRenderer.js"; import type { DotDensityRendererProperties } from "../renderers/DotDensityRenderer.js"; import type { UniqueValueRendererProperties } from "../renderers/UniqueValueRenderer.js"; import type { ClassBreaksRendererProperties } from "../renderers/ClassBreaksRenderer.js"; import type { SimpleRendererProperties } from "../renderers/SimpleRenderer.js"; import type { FeatureTemplateProperties } from "./support/FeatureTemplate.js"; import type { FeatureTypeProperties } from "./support/FeatureType.js"; export interface FeatureLayerProperties extends LayerProperties, APIKeyMixinProperties, CustomParametersMixinProperties, PortalLayerProperties, OperationalLayerProperties, RefreshableLayerProperties, ScaleRangeLayerProperties, TrackableLayerProperties, TemporalLayerProperties, OrderedLayerProperties, BlendLayerProperties, DisplayFilteredLayerProperties, PublishableLayerProperties, FeatureEffectLayerProperties, FeatureReductionLayerProperties, FeatureLayerBaseProperties, Partial<Pick<FeatureLayer, "charts" | "editingEnabled" | "labelsVisible" | "legendEnabled" | "outFields" | "popupEnabled" | "screenSizePerspectiveEnabled" | "typeIdField">> { /** * This property is used to configure the associated layer's [Feature Table](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-feature-table/). It is meant to configure how the columns display within the table in regard to visibility, column order, and sorting. * * > [!WARNING] * > * > This property differs from a [FeatureTable's tableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/support/TableTemplate/) property. The `TableTemplate` provides more fine-grained control over how the table is rendered within the application by offering more advanced configurations such as custom cell rendering, column formatting, and more. `TableTemplate` is useful for application-level development that remains within an application. Use the `attributeTableTemplate` property to access the table's settings across different applications. By using this property, the settings can be saved within a webmap or layer. Please refer to the [AttributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/tables/AttributeTableTemplate/) and [TableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/support/TableTemplate/) documentation for more information. * * @since 4.31 * @see [Sample - FeatureTable Component](https://developers.arcgis.com/javascript/latest/sample-code/feature-table/) */ attributeTableTemplate?: AttributeTableTemplateProperties | null; /** * An object that allows you to create a dynamic layer with data * either from map service sublayers or data from a registered workspace. * See [DynamicMapLayer](https://developers.arcgis.com/javascript/latest/references/core/rest/layerSources/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](https://developers.arcgis.com/javascript/latest/references/core/rest/layerSources/DynamicDataLayer/). * * If you already have a [Sublayer](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Sublayer/) instance, you * can call the [Sublayer.createFeatureLayer()](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Sublayer/#createFeatureLayer) * method on the Sublayer to construct the layer for you. * * This only applies to map services with * [dynamic layers](https://enterprise.arcgis.com/en/server/latest/publish-services/linux/about-dynamic-layers.htm) enabled. * * > [!WARNING] * > * > **Known Limitations** * > * > FeatureLayers with a `dynamicDataSource` cannot be persisted to web maps, web scenes, and portal items. * * @since 4.7 * @see [Sublayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Sublayer/#source) * @see [Sublayer.createFeatureLayer()](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Sublayer/#createFeatureLayer) * @example * const layer = new FeatureLayer({ * url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/AGP/Census/MapServer", * title: "United States Population", * popupTemplate: { * title: "{states.STATE_NAME}", * content: "{expression/per_ancestry}% of the {states.POP2007} people in {states.STATE_NAME} have " * + "Norwegian ancestry.", * expressionInfos: [{ * name: "per_ancestry", * expression: "Round( ( $feature['ancestry.norwegian'] / $feature['states.POP2007'] ) * 100, 1)" * }], * fieldInfos: [{ * fieldName: "states.POP2007", * fieldFormat: { * type: "number", * useGrouping: "always", * maximumFractionDigits: 0 * } * }] * }, * dynamicDataSource: { * 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" * } * } * }); */ dynamicDataSource?: DynamicDataLayerProperties | null; /** * An array of [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) objects that control how fields are displayed in popups and other UI elements. Each object specifies options for an individual field, such as its display name, via `alias`, and formatting rules, via `fieldFormat`. Assign this property before the layer loads to ensure the configurations take effect. For more information, see the [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) documentation. * * If no field configurations are provided, they are automatically created when a [popupTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#popupTemplate) is assigned to the layer. If no [popupTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#popupTemplate) is set, you can manually define field configurations to customize how fields are shown. * * > [!WARNING] * > * > Support is limited in version 4.34. For details, see the [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) documentation. * * To modify field configurations, clone [fieldConfigurations](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations), make the changes, and then reassign the updated clone back to `FeatureLayer.fieldConfigurations`. * * @since 4.34 * @see [getFieldConfiguration()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#getFieldConfiguration) * @see [getFieldAlias()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#getFieldAlias) * @see [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) * @example * // Adding a new field configuration * const addNewConfig = (layer, fieldName, alias, * fieldFormat) => { * // Check if there is already an existing configuration for fieldName * const existingConfig = layer.getFieldConfiguration(fieldName); * if (!existingConfig) { * const newConfig = new FieldConfiguration({ name: fieldName, alias, fieldFormat }); * const newConfigs = clone(layer.fieldConfigurations); * newConfigs.push(newConfig); * layer.fieldConfigurations = newConfigs; * } * }; * @example * // Updating an existing field configuration * const updateConfig = (layer, fieldName, alias, * fieldFormat) => { * const existingConfig = layer.getFieldConfiguration(fieldName); * if (existingConfig) { * const newConfig = existingConfig.clone(); * newConfig.alias = alias; * newConfig.fieldFormat = fieldFormat; * * const index = layer.fieldConfigurations.indexOf(existingConfig); * const newConfigs = clone(layer.fieldConfigurations); * newConfigs[index] = newConfig; * layer.fieldConfigurations = newConfigs; * } * }; * @example * // Deleting an existing field configuration * const deleteConfig = (layer, fieldName) => { * const existingConfig = layer.getFieldConfiguration(fieldName); * if (existingConfig) { * const index = layer.fieldConfigurations.indexOf(existingConfig); * var newConfigs = clone(layer.fieldConfigurations); * newConfigs.splice(index, 1); * layer.fieldConfigurations = newConfigs; * } * }; */ fieldConfigurations?: FieldConfigurationProperties[] | null; /** * An array of fields in the layer. Each field represents an attribute * that may contain a value for each feature in the layer. For example, * a field named `POP_2015`, stores information about total population as a * numeric value for each feature; this value represents the total number * of people living within the geographic bounds of the feature. * * When creating a FeatureLayer from [client-side features](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#client-side), this property * should be set in the constructor along with the [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source) property. The `objectId` * field also must be set either in this array or in the [objectIdField](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#objectIdField) property. * * @see [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source) * @see [objectIdField](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#objectIdField) * @see [Add an array of client-side features](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#client-side) * @example * // define each field's schema * const fields = [ * new Field({ * name: "ObjectID", * alias: "ObjectID", * type: "oid" * }), new Field({ * name: "description", * alias: "Description", * type: "string" * }), new Field ({ * name: "title", * alias: "Title", * type: "string" * }) * ]; * * // See the sample snippet for the source and renderer properties * const layer = new FeatureLayer({ * // geometryType and spatialReference are inferred * // from the input source features * source: features, * // Object ID field is inferred from the fields array * fields: fields, * renderer: renderer * }); */ fields?: FieldProperties[]; /** * The [template](https://developers.arcgis.com/javascript/latest/references/core/form/FormTemplate/) used in an associated layer's [FeatureForm](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureForm/). All of the properties and field configurations set on the layer's [Feature Form](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-feature-form/) are handled via the [FormTemplate](https://developers.arcgis.com/javascript/latest/references/core/form/FormTemplate/). * * @since 4.16 * @see [Sample - Update Feature Attributes](https://developers.arcgis.com/javascript/latest/sample-code/editing-groupedfeatureform/) * @example * // Create the Field Elements to pass into the template * const fieldElement1 = new FieldElement({ * fieldName: "firstname", * label: "First name", * description: "First name of emergency contact" * }); * * const fieldElement2 = new FieldElement({ * fieldName: "lastname", * label: "Last name", * description: "Last name of emergency contact" * }); * * // Create the form's template * const formTemplate = new FormTemplate({ * title: "Emergency information", * description: "In case of emergency, update any additional information needed", * elements: [fieldElement1, fieldElement2] // pass in array of field elements from above * }); * * // Pass the template to the layer * featureLayer.formTemplate = formTemplate; * * // Pass the layer to the FeatureForm * const form = new FeatureForm({ * container: "form", // html div referencing the form * layer: featureLayer * }); */ formTemplate?: FormTemplateProperties | null; /** * The label definition for this layer, specified as an array of * [LabelClass](https://developers.arcgis.com/javascript/latest/references/core/layers/support/LabelClass/). Use this property to specify * labeling properties for the layer such as label expression, placement, and size. * * Multiple Label classes with different `where` clauses can be used to define several * labels with varying styles on the same feature. Likewise, multiple label classes * may be used to label different types of features (for example blue labels * for lakes and green labels for parks). * * See the [Labeling guide page](https://developers.arcgis.com/javascript/latest/labeling/) for more information and known limitations. * * > [!WARNING] * > * > **Known Limitations** * > * > 3D [SceneViews](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/) only support displaying one [LabelClass](https://developers.arcgis.com/javascript/latest/references/core/layers/support/LabelClass/) per feature. * * @see [Sample: Add multiple label classes to a layer](https://developers.arcgis.com/javascript/latest/sample-code/labels-multiple-classes/) * @see [Sample: Multi-line labels](https://developers.arcgis.com/javascript/latest/sample-code/labels-multiline/) * @see [Sample: Flat vs. volumetric 3D symbol layers](https://developers.arcgis.com/javascript/latest/sample-code/symbols-points-3d/) * @example * const statesLabelClass = new LabelClass({ * labelExpressionInfo: { expression: "$feature.NAME" }, * symbol: { * type: "text", // autocasts as new TextSymbol() * color: "black", * haloSize: 1, * haloColor: "white" * } * }); * * featureLayer.labelingInfo = [ statesLabelClass ]; */ labelingInfo?: LabelClassProperties[] | null; /** * The popup template for the layer. When set on the layer, the `popupTemplate` * allows users to access attributes and display their values in the * view's Popup when a feature is selected * using text and/or charts. See the [PopupTemplate sample](https://developers.arcgis.com/javascript/latest/sample-code/intro-popuptemplate/) * for an example of how [PopupTemplate](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/) interacts with a * [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/). * * A default popup template is automatically used if no `popupTemplate` has been defined when * [Popup.defaultPopupTemplateEnabled](https://developers.arcgis.com/javascript/latest/references/core/widgets/Popup/#defaultPopupTemplateEnabled) * is set to `true`. * * @see [createPopupTemplate()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#createPopupTemplate) * @see [SceneView.popup](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/#popup) * @see [View2D.popup](https://developers.arcgis.com/javascript/latest/references/core/views/View2D/#popup) */ popupTemplate?: PopupTemplateProperties | null; /** * Refresh interval of the layer in minutes. Value of `0` indicates no refresh. * At each refresh interval, the data is only updated if the `lastEditDate` in the layer's metadata is different from the `lastEditDate` field. * If the `lastEditDate` metadata info is not available, the FeatureLayer refreshes unconditionally. * * @default 0 * @since 4.6 * @see [refresh()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#refresh) * @see [refresh event](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#event-refresh) * @example * // the layer will be refreshed every 1 minute. * layer.refreshInterval = 1; * @see [RefreshableLayer.refresh()](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/RefreshableLayer/#refresh) * @see [refresh event](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/RefreshableLayer/#event-refresh) * @example * // the layer will be refreshed every minute. * layer.refreshInterval = 1; */ refreshInterval?: number; /** * The renderer assigned to the layer. The renderer defines how to * visualize each feature in the layer. Depending on the renderer type, * features may be visualized with the same symbol, or with varying symbols * based on the values of provided attribute fields or functions. * * However, when creating a FeatureLayer from client-side features, this property must * be specified in the layer's constructor along with the * [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source), * [fields](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fields), [objectIdField](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#objectIdField) properties. * * @see [Styles and data visualization](https://developers.arcgis.com/javascript/latest/visualization/) * @example * // all features in the layer will be visualized with * // a 6pt black marker symbol and a thin, white outline * layer.renderer = { * type: "simple", // autocasts as new SimpleRenderer() * symbol: { * type: "simple-marker", // autocasts as new SimpleMarkerSymbol() * size: 6, * color: "black", * outline: { // autocasts as new SimpleLineSymbol() * width: 0.5, * color: "white" * } * } * }; */ renderer?: (((SimpleRendererProperties & { type: "simple" }) | (ClassBreaksRendererProperties & { type: "class-breaks" }) | (UniqueValueRendererProperties & { type: "unique-value" }) | (DotDensityRendererProperties & { type: "dot-density" }) | (DictionaryRendererProperties & { type: "dictionary" }) | (PieChartRendererProperties & { type: "pie-chart" })) | (HeatmapRendererProperties & { type: "heatmap" })) | null; /** * A collection of [Graphic](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) objects used to create a FeatureLayer. * The geometry of each feature all must have a matching [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType). * This property must be set when creating a FeatureLayer from [client-side features](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#client-side). * When creating a FeatureLayer from client-side features, the `objectId` field must be set * either in the [fields](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fields) array or via [objectIdField](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#objectIdField). * * The [spatialReference](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#spatialReference) and [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) properties * are determined based on the features provided to this property. If the `source` is an empty * array at the time of layer initialization, then [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) must be set. * * The source is not updated after the FeatureLayer is initialized. Use [applyEdits()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#applyEdits) method to add, remove, and update features * from a client-side feature layer at runtime. Once `applyEdits()` resolves successfully, use [queryFeatures()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#queryFeatures) * to return updated features. * * @see [Add an array of client-side features](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#client-side) * @see [Sample - Add 100,000 features to feature collection](https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-large-collection/) * @example * let features = [ * { * geometry: { * type: "point", * x: -100, * y: 38 * }, * attributes: { * ObjectID: 1, * DepArpt: "KATL", * MsgTime: Date.now(), * FltId: "UAL1" * } * }, * ... * ]; * * // geometryType and spatialReference of the layer * // will be inferred from the first feature in the array * // if it has a geometry. * let layer = new FeatureLayer({ * source: features, // autocast as a Collection of new Graphic() * objectIdField: "ObjectID" * }); * @example * // Create an empty non-spatial feature layer * // Set geometryType property to null when creating non-spatial feature layer * const layer = new FeatureLayer({ * source: [], * objectIdField: "OBJECTID", * fields: [{ * name: "OBJECTID", * type: "oid" * }], * geometryType: null * }); * layer.load().then(() => console.log(layer.isTable)) */ source?: ReadonlyArrayOrCollection<Graphic>; /** * An array of feature templates defined in the feature layer. * See [ArcGIS Pro subtypes document](https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-subtypes.htm). * * @since 4.4 */ templates?: FeatureTemplateProperties[] | null; /** * An array of [types](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FeatureType/) 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. * * @since 4.4 */ types?: FeatureTypeProperties[] | null; } export interface FeatureLayerEvents extends EditBusLayerEvents, RefreshableLayerEvents, LayerEvents {} /** * * [Overview](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#overview) * * [Creating a FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#creating-a-featurelayer) * * [Querying](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#querying) * * [Data Visualization](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#data-visualization) * * [Known limitations](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#limits) * * <span id="overview"></span> * ## Overview * * A FeatureLayer is a single layer that can be created from a * [Map Service](https://enterprise.arcgis.com/en/server/latest/publish-services/windows/what-is-a-map-service.htm) * or [Feature Service](https://enterprise.arcgis.com/en/server/latest/publish-services/windows/what-is-a-feature-service-.htm); * ArcGIS Online or ArcGIS Enterprise portal items; or from an array of client-side features. The layer can be either a * spatial (has geographic features) or non-spatial (table). * * Spatial layer is composed of discrete features, each of which has a [Geometry](https://developers.arcgis.com/javascript/latest/references/core/geometry/Geometry/) * that allows it to be rendered in either a 2D [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/) or * 3D [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/) as a * [Graphic](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) with spatial context. Features also contain data * [Graphic.attributes](https://developers.arcgis.com/javascript/latest/references/core/Graphic/#attributes) that provide additional information about * the real-world feature it represents; attributes may be viewed in [popup](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#popupTemplate) windows * and used for [rendering](https://developers.arcgis.com/javascript/latest/references/core/renderers/Renderer/) the layer. * FeatureLayers may be [queried](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#queryFeatures), [analyzed](https://developers.arcgis.com/javascript/latest/spatial-analysis/intro-geometry-operators/), * and [rendered](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#renderer) to visualize data in a spatial context. * * Non-spatial layer is a table which does not have a spatial column representing geographic features. * * * <span id="creating-a-featurelayer"></span> * ## Creating a FeatureLayer * * FeatureLayers may be created in one of three ways: from a [service URL](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#url), an ArcGIS portal [item ID](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#portalItem), * or from an [array of client-side features](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source). * * <details> * <summary>Read More</summary> * * ### Reference a service URL * * To create a FeatureLayer instance from a service, you must set the [url](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#url) property * to the REST endpoint of a layer in either a Feature Service * or a Map Service. For a layer to be visible in a view, it must be added to the [Map](https://developers.arcgis.com/javascript/latest/references/core/Map/) * referenced by the view. See [Map.add()](https://developers.arcgis.com/javascript/latest/references/core/Map/#add) for information about adding layers to a map. * * ```js * const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); * // points to the states layer in a service storing U.S. census data * const fl = new FeatureLayer({ * url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3" * }); * map.add(fl); // adds the layer to the map * ``` * * Non-spatial table instance can be created from the table [url](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#url) in a service and the table must be loaded by calling [load()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#load) * method. * * ```js * // Add a non-spatial table. * const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); * // points to the non-spatial table in a service storing San Francisco crime incidents. * const table = new FeatureLayer({ * url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/1" * }); * table.load().then(function() { * // table is loaded. ready to be queried on the server. * }); * ``` * * If the service is requested from a different domain, a [CORS enabled server](https://developers.arcgis.com/javascript/latest/cors/) or a [proxy](https://developers.arcgis.com/javascript/latest/proxies/) is required. * * ### Reference an ArcGIS portal Item ID * * You can also create a FeatureLayer from its ID if it exists as an item in ArcGIS Online or ArcGIS Enterprise. * For example, the following snippet shows how to add a new FeatureLayer instance to a map using the * [portalItem](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#portalItem) property. * * ```js * // points to a hosted Feature Layer in ArcGIS Online * const fl = new FeatureLayer({ * portalItem: { // autocasts as esri/portal/PortalItem * id: "8444e275037549c1acab02d2626daaee" * } * }); * map.add(fl); // adds the layer to the map * ``` * * The following snippet shows how to create a FeatureLayer referencing a table using the * [portalItem](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#portalItem) property. * * ```js * // points to a hosted table in ArcGIS Online * const table = new FeatureLayer({ * portalItem: { // autocasts as esri/portal/PortalItem * id: "123f4410054b43d7a0bacc1533ceb8dc" * } * }); * * // Before adding the table to the map, it must first be loaded and confirm it is the right type. * table.load().then(function() { * if (table.isTable) { * map.tables.add(table); * } * }); * ``` * * <span id="client-side"></span> * ### Add an array of client-side features * * A FeatureLayer can be created from client-side features such as an array of [graphics](https://developers.arcgis.com/javascript/latest/references/core/Graphic/). * These graphics may have [geometries](https://developers.arcgis.com/javascript/latest/references/core/Graphic/#geometry) for spatial layers or may be non-spatial. * If the graphics do not include geometries and the [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) is `null`, the resulting layer will be a non-spatial FeatureLayer. * Since a FeatureLayer requires a defined schema, several properties must be specified when initializing a layer with client-side data. * * **Automatic property inference:** If required properties are not explicitly set, the API attempts to infer values from the provided parameters or features * in the [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source). For example, the [spatialReference](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#spatialReference), [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType), [hasZ](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#hasZ) * and [hasM](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#hasM) properties can be derived from the features provided in the [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source). However, if the source is an empty array at the time of * initialization, the [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) cannot be inferred, and the layer will fail to initialize when the layer is added to the map. * * **Geometry type and spatial reference:** For spatial data, the [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) must be defined explicitly, if the [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source) * is empty at the time layer's initialization. A valid [spatialReference](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#spatialReference) is also required. * * **Field schema:** Both spatial and non-spatial feature collections must include an [objectIdField](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#objectIdField), which provides a unique identifier * for each feature. This must be indicated along with an array of [field](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fields) objects, providing the schema of each field. * Certain characters are not supported in field names. See [field naming guidelines](https://support.esri.com/en-us/knowledge-base/what-characters-should-not-be-used-in-arcgis-for-field--000005588) * for details. If the data includes date fields with values recorded in a time zone other than `UTC`, the [dateFieldsTimeZone](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#dateFieldsTimeZone) property should be set to * ensure correct results in [date-based queries](https://developers.arcgis.com/javascript/latest/references/core/rest/support/Query/#date-query). * * Once all required properties are configured, the array of features must be assigned to the [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source) property. See * [create a FeatureLayer with client-side graphics sample](https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/). * * **Runtime updates:** FeatureLayer's [source](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#source) is not updated after the FeatureLayer is initialized. If features are added, removed or updated at runtime, * then use [applyEdits()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#applyEdits) to update the features then use [queryFeatures()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#queryFeatures) to return updated features. Check out * [Working with large feature collections](https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-large-collection/) * to see this in action. * * Attribute values used in attribute queries executed against client-side feature layer, and layer views are case sensitive. * * ```js * const layer = new FeatureLayer({ * // create an instance of esri/layers/support/Field for each field object * fields: [ * { * name: "ObjectID", * alias: "ObjectID", * type: "oid" * }, { * name: "type", * alias: "Type", * type: "string" * }, { * name: "place", * alias: "Place", * type: "string" * },{ * name: "recordedDate", * alias: "recordedDate", * type: "date" * }], * dateFieldsTimeZone: "America/New_York", // date field values in are eastern time zone * objectIdField: "ObjectID", // inferred from fields array if not specified * geometryType: "point", // geometryType and spatialReference are inferred from the first feature * // in the source array if they are not specified. * spatialReference: { wkid: 4326 }, * source: graphics, // an array of graphics with geometry and attributes * // popupTemplate and symbol are not required in each feature * // since those are handled with the popupTemplate and * // renderer properties of the layer * popupTemplate: popupTemplate, * // a default simple renderer will be applied if not set. * renderer: uvRenderer // UniqueValueRenderer based on `type` attribute * }); * map.add(layer); * ``` * * A client-side non-spatial table can be created by setting the layer's [geometryType](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#geometryType) property to `null`, * then the table must be loaded by calling the [load()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#load) method. * * ```js * // Create an empty non-spatial feature layer * // Set geometryType property to null when creating non-spatial feature layer * const layer = new FeatureLayer({ * source: [], * objectIdField: "OBJECTID", * fields: [{ * name: "OBJECTID", * type: "oid" * }, * { * name: "type", * type: "string", * }], * geometryType: null * }); * layer.load().then(() => console.log(layer.isTable)) * ``` * * </details> * * <span id="querying"></span> * ## Querying * * Features within a FeatureLayer are rendered as [features](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) inside a * [FeatureLayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/). A FeatureLayerView may or may not have all features from the associated FeatureLayer. * To determine this, check the [FeatureLayerView.hasAllFeatures](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#hasAllFeatures) property on the FeatureLayerView. * If `hasAllFeatures` is `true`, the FeatureLayerView has all features from the layer, not just those visible in the view extent. * * When `hasAllFeatures` is `true`, calling [FeatureLayerView.queryFeatures()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#queryFeatures) on the FeatureLayerView * runs against all features in the layer. Otherwise, the `FeatureLayerView.queryFeatures()` runs only against features available for drawing in the FeatureLayerView. * To limit the query to features currently visible in the view when `hasAllFeatures` is `true`, set the query’s [Query.geometry](https://developers.arcgis.com/javascript/latest/references/core/rest/support/Query/#geometry) * property to the View's [View2D.extent](https://developers.arcgis.com/javascript/latest/references/core/views/View2D/#extent). * * <details> * <summary>Read More</summary> * * ```js * // returns all the graphics from the layer view * view.whenLayerView(layer).then((layerView) => { * reactiveUtils.when( * () => !layerView.updating, * (val) => { * const query = layerView.createQuery(); * // check if layerView has all features in the layer * // if true, set query.geoemtry to view.extent to run * // the query against features visible in the view * if (layerView.hasAllFeatures) { * query.geometry = view.extent; * } * * layerView.queryFeatures(query).then((results) =>{ * console.log(results); * }); * } * ); * }); * ``` * * When accessing features from a query on the [FeatureLayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/), note that * features are returned as they are displayed in the view, including any generalization that may have been * applied to the features to enhance performance. To obtain feature geometries at full resolution, first check the FeatureLayerView’s * [FeatureLayerView.hasFullGeometries](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#hasFullGeometries) property; if it is `true`, use the * [FeatureLayerView.queryFeatures()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#queryFeatures) method on the FeatureLayerView; * otherwise, use the [queryFeatures()](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#queryFeatures) method on the FeatureLayer. * * The [query methods](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#queryFeatures) in the FeatureLayer class query features directly from the service. * For example, the following snippet returns all features from the service, not just the features drawn in the * [FeatureLayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/). * * ```js * // Queries for all the features in the service (not the graphics in the view) * layer.queryFeatures().then((results) => { * // prints an array of all the features in the service to the console * console.log(results.features); * }); * ``` * * For information regarding how to create a LayerView * for a particular layer, see [View.whenLayerView()](https://developers.arcgis.com/javascript/latest/references/core/views/View/#whenLayerView). * * </details> * * <span id="data-visualization"></span> * ## Data Visualization * * Features in a FeatureLayer are visualized by setting a [Renderer](https://developers.arcgis.com/javascript/latest/references/core/renderers/Renderer/) to the * [renderer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#renderer) property of the layer. See the [Styles and data visualization](https://developers.arcgis.com/javascript/latest/visualization/) guide for * a comprehensive set of examples of how to visualize data in a FeatureLayer. * * FeatureLayer supports [FeatureLayerView.highlight()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#highlight), which is enabled by default when users click or tap features to view the popup. You can also call the * [FeatureLayerView.highlight()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/#highlight) method on the * [FeatureLayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/) to highlight features in other workflows. * * > [!WARNING] * > * > <span id="limits"></span> * > **Known Limitations** * > * > Locations with a very high density of features may not display all available features at small scales. * > Very large datasets may require potentially long initial load times, particularly at small scales. * > FeatureLayers are not optimized for high-frequency, dynamic data, or real-time streaming use cases. As a result, they may not perform efficiently with rapidly updating data streams. * > For real-time or dynamic data updates, use [StreamLayers](https://developers.arcgis.com/javascript/latest/references/core/layers/StreamLayer/), which are designed for efficient handling of high-frequency streaming data and dynamic features. * > Server-side and client-side feature tile caching allow features to load much faster after the initial data download. * > We are continuously improving our feature fetching strategy and load time efficiency in each release. * > The [big-integer](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Field/#type) field type is still in beta and may not be fully supported in the JavaScript SDK. Console * > warnings will be thrown when a layer has a `big-integer` field. To disable the warnings use the following flag: * > ```js * > <script> * > var esriConfig = { * > has: { * > "big-integer-warning-enabled": false * > } * > } * > </script> * > ``` * * @since 4.0 * @see [Sample - Add FeatureLayer to your Map](https://developers.arcgis.com/javascript/latest/sample-code/intro-layers/) * @see [Sample - Create a FeatureLayer with client-side graphics](https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/) * @see [Sample - Query features from a FeatureLayer](https://developers.arcgis.com/javascript/latest/sample-code/featurelayer-query/) * @see [FeatureLayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/FeatureLayerView/) */ export default class FeatureLayer extends __FeatureLayerSansType { /** The layer type provides a convenient way to check the type of the layer without the need to import specific layer modules. */ get type(): "feature"; } export abstract class __FeatureLayerSansType extends FeatureLayerSuperclass { /** * @deprecated * Do not directly reference this property. * Use EventNames and EventTypes helpers from \@arcgis/core/Evented */ "@eventTypes": FeatureLayerEvents; /** * @see [Client-side FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#client-side) * @example * // Typical usage * // Create featurelayer from feature service * const layer = new FeatureLayer({ * // URL to the service * url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0" * }); * * // Typical usage * // Create featurelayer from client-side graphics * const layer = new FeatureLayer({ * source: graphics, * fields: [{ * name: "ObjectID", * alias: "ObjectID", * type: "oid" * }, { * name: "place", * alias: "Place", * type: "string" * }], * objectIdField: "ObjectID", * geometryType: "point" * }); */ constructor(properties?