Accessor

AMD: require(["esri/core/Accessor"], (Accessor) => { /* code goes here */ });
ESM: import Accessor from "@arcgis/core/core/Accessor.js";
Class: esri/core/Accessor
Subclasses: ActionBase , ActionColumn , ActiveLayerInfo , AddressCandidate , AggregateField , AggregatedGeometry , ApplicationProperties , ApplicationProperties , AreaMeasurement3DViewModel , AreaMeasurementAnalysis , ArealUnit , AreasAndLengthsParameters , Association , AssociationGeometriesResult , AttachmentInfo , AttachmentInput , AttachmentQuery , AttachmentsColumn , AttachmentsViewModel , AttributeColorInfo , AttributeTableElement , AttributeTableTemplate , AttributionViewModel , AudioInput , AuthoringInfo , AuthoringInfoVisualVariable , Background , BarChartMediaInfo , BarcodeScannerInput , Basemap , BasemapGalleryItem , BasemapGalleryViewModel , BasemapLayerListViewModel , BasemapStyle , BasemapToggleViewModel , BasemapView , Bookmark , BookmarksViewModel , BufferParameters , BuildingComponentSublayerView , BuildingExplorerViewModel , BuildingFilter , BuildingLevel , BuildingPhase , BuildingSublayer , BuildingSummaryStatistics , ButtonMenuItem , ButtonMenuViewModel , Callout3D , Camera , CameraLayout , CatalogLayerListViewModel , ChartMediaInfoValue , ChartMediaInfoValueSeries , ClassBreakInfo , ClosestFacilityParameters , ClosestFacilitySolveResult , CloudyWeather , Collection , ColorBackground , ColorRamp , ColorSizeStop , ColorStop , ColormapInfo , Column , ColumnTemplateBase , ComboBoxInput , CompassViewModel , Content , ControlPointsGeoreference , Conversion , CoordinateConversionViewModel , CornersGeoreference , CreateFeaturesWorkflowData , Credential , CustomTemplate , DataFile , DataLayer , DataModel , DatePickerInput , DateTimeOffsetPickerInput , DateTimePickerInput , DaylightViewModel , DensifyParameters , DeviceLocationFeed , DimensionAnalysis , DimensionAnalysisView , DimensionSimpleStyle , DimensionalDefinition , DirectLineMeasurement3DViewModel , DirectLineMeasurementAnalysis , DirectionLine , DirectionPoint , DirectionalPadViewModel , DirectionsEvent , DirectionsFeatureSet , DirectionsViewModel , DistanceMeasurement2DViewModel , DistanceParameters , DocumentInput , Domain , Draw , DrawAction , Edges3D , EditorItem , EditorViewModel , Edits , Element , ElementExpressionInfo , ElevationProfileLine , ElevationProfileViewModel , Environment , ExpandViewModel , ExpressionInfo , ExpressionInfo , ExpressionInfo , ExpressionInfo , ExtentAndRotationGeoreference , FacilityLayerInfo , FeatureEffect , FeatureFenceParameters , FeatureFilter , FeatureFilter , FeatureFormViewModel , FeatureLayerSource , FeatureReductionBinning , FeatureReductionCluster , FeatureReductionSelection , FeatureSet , FeatureSnappingLayerSource , FeatureTableViewModel , FeatureTemplate , FeatureTemplatesViewModel , FeatureType , FeatureViewModel , FeaturesViewModel , Field , FieldColumn , FieldIndex , FieldInfo , FieldInfoFormat , FieldInput , FindParameters , FindResult , FloorFilterViewModel , FlowRenderer , FoggyWeather , Font , FormTemplate , Format , FullscreenViewModel , FunctionResult , GPMessage , GamepadInputDevice , GamepadSettings , GamepadSettings , GeneralizeParameters , Geometry , GeometryFieldsInfo , Geotrigger , GeotriggerNotificationOptions , GeotriggersInfo , GraphApplyEdits , GraphApplyEditsResult , GraphObject , GraphObjectType , GraphProperty , GraphQuery , GraphQueryResult , GraphQueryStreamingResult , GraphSearch , Graphic , GridControlsViewModel , Ground , GroundView , GroupColumn , GroupInput , HeatmapColorStop , HeightModelInfo , HistogramViewModel , HomeViewModel , IPSInfo , IdentifyParameters , IdentifyResult , ImageAngleParameters , ImageAngleResult , ImageAreaParameters , ImageAreaResult , ImageBoundaryParameters , ImageBoundaryResult , ImageDistanceParameters , ImageDistanceResult , ImageElement , ImageHeightParameters , ImageHeightResult , ImageHistogramParameters , ImageIdentifyParameters , ImageIdentifyResult , ImageInput , ImageMediaInfo , ImageMediaInfoValue , ImageParameters , ImagePixelLocationParameters , ImagePixelLocationResult , ImagePointParameters , ImagePointResult , ImageSample , ImageSampleParameters , ImageSampleResult , ImageUrlResult , InitialViewProperties , InitialViewProperties , Input , InputQuantizationParameters , JobInfo , KMLSublayer , KnowledgeGraph , LOD , LabelClass , Layer , LayerFloorInfo , LayerListViewModel , LayerOptions , LayerView , LegendLayer , LegendViewModel , LengthDimension , LengthsParameters , LevelLayerInfo , LineChartMediaInfo , LineOfSightAnalysis , LineOfSightAnalysisObserver , LineOfSightAnalysisTarget , LineOfSightTarget , LineOfSightViewModel , LineStyleMarker3D , LineStylePattern3D , LineSymbolMarker , LinearUnit , ListItem , LocalBasemapsSource , LocalMediaElementSource , LocateViewModel , Magnifier , Map , MapFloorInfo , MapImage , MeasureAreaFromImageResult , MeasureFromImageParameters , MeasureLengthFromImageResult , MeasurementViewModel , MeshComponent , MeshGeoreferencedVertexSpace , MeshLocalVertexSpace , MeshMaterial , MeshTexture , MeshTextureTransform , MeshTransform , MosaicRule , MultidimensionalSubset , NAMessage , Navigation , NavigationToggleViewModel , Network , NetworkElement , NetworkFeatureSet , NetworkSystemLayers , NetworkUrl , OAuthInfo , OffsetParameters , OpacityStop , OrientedImageryViewerViewModel , OutputQuantizationParameters , ParameterValue , Path , PieChartMediaInfo , PixelBlock , PlaceResult , PlacesParameters , PlacesQueryResult , PointBarrier , PointCloudFilter , PointCloudRenderer , PolygonBarrier , PolylineBarrier , PopupTemplate , Portal , PortalFolder , PortalGroup , PortalItem , PortalItemResource , PortalQueryParams , PortalQueryResult , PortalRating , PortalUser , PositioningService , Presentation , PrintParameters , PrintTemplate , PrintViewModel , ProjectParameters , PublishingInfo , Query , QueryAssociationsParameters , QueryAssociationsResult , RadioButtonsInput , RainyWeather , RasterBandInfo , RasterColormapRenderer , RasterData , RasterFunction , RasterInfo , RasterPresetRenderer , RasterSensorInfo , RasterShadedReliefRenderer , RasterStretchRenderer , RelatedRecordsInfo , RelatedRecordsInfoFieldOrder , RelationParameters , Relationship , RelationshipColumn , RelationshipInput , RelationshipQuery , RenderNode , Renderer , RouteInfo , RouteParameters , RouteResult , RouteSolveResult , RouteStopSymbols , RouteSymbols , ScaleBarViewModel , ScaleRangeSliderViewModel , ScaleRanges , SceneFilter , SceneModification , Search , SearchIndex , SearchLayer , SearchLayerField , SearchSource , SearchTable , SearchTableField , SearchViewModel , ServerInfo , ServiceAreaParameters , ServiceAreaSolveResult , ServiceDefinition , ShadowCastViewModel , SignatureInput , SiteLayerInfo , SizeStop , SketchLabelOptions , SketchTooltipOptions , SketchValueOptions , SketchViewModel , SliceAnalysis , SlicePlane , SliceViewModel , Slide , SliderViewModel , SnappingControlsViewModel , SnappingOptions , SnowyWeather , SpatialReference , StatisticDefinition , Stop , StyleOrigin , StylePattern3D , Sublayer , Subtype , SubtypeSublayer , SunLighting , SunnyWeather , SwipeViewModel , SwitchInput , Symbol , Symbol3DLayer , Symbol3DVerticalOffset , SynthesizeAssociationGeometriesParameters , TableListViewModel , TableTemplate , TelemetryData , TelemetryDisplay , TemplateItem , TemplateItemGroup , TemplateOptions , Terminal , TerminalConfiguration , TextBoxInput , Theme , TileInfo , TileMatrixSet , TimeExtent , TimeExtent , TimeInfo , TimeInterval , TimeInterval , TimePickerInput , TimeSlider , TimeSliderViewModel , Tooltip , TopFeaturesQuery , TopFilter , TopologyValidationJobInfo , TraceJobInfo , TraceLocation , TraceParameters , TraceResult , TrackViewModel , TravelMode , TrimExtendParameters , UI , UniqueValue , UniqueValueClass , UniqueValueGroup , UniqueValueInfo , UpdateWorkflowData , UtilityNetworkAssociationsViewModel , UtilityNetworkTraceViewModel , ValidateNetworkTopologyParameters , VectorFieldRenderer , VersionManagementViewModel , VideoElement , VideoInput , VideoPlayerViewModel , VideoTimeExtent , View , ViewAnimation , ViewState , Viewing , Viewpoint , Viewshed , ViewshedAnalysis , VirtualLighting , VisualVariable , WMSSublayer , WMTSStyle , WMTSSublayer , WeatherViewModel , Widget , Workflow , ZoomViewModel
Since: ArcGIS Maps SDK for JavaScript 4.0

Accessor is an abstract class that facilitates the access to instance properties as well as a mechanism to watch for property changes. Every sub-class of Accessor defines properties that are directly accessible or by using the get() and set() methods. It is possible to watch for a property changes by using the watch() method.

See also

Property Overview

Name Type Summary Class

The name of the class.

Accessor

Property Details

declaredClass

Property
declaredClass Stringreadonly
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.

Method Overview

Name Return Type Summary Class

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

Accessor

Creates a subclass of the class calling this method.

Accessor
*

Gets the value of a property.

Accessor

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor
*

Sets the value of a property.

Accessor

Watches for property changes on the instance.

Accessor

Method Details

addHandles

Method
addHandles(handleOrHandles, groupKey)
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.

createSubclass

Method
createSubclass(classDefinition){Accessor}static
Since: ArcGIS Maps SDK for JavaScript 4.21 Accessor since 4.0, createSubclass added at 4.21.

Creates a subclass of the class calling this method.

Parameter
classDefinition Object

An object with properties and methods to mix in to the newly created class.

Returns
Type Description
Accessor Returns a constructor of the newly created class.

get

Method
get(path){*}
Deprecated since version 4.28. Use optional chaining

Gets the value of a property.

The name of the property can refer to a property in the instance.

view.get("scale");

It can also be a path to a property deeper in the instance. get() returns undefined if a property in the path doesn't exist.

let title = map.get("basemap.title");

// equivalent of
let title = map.basemap && map.basemap.title || undefined;
Parameter
path String

The path of the property to get.

Returns
Type Description
* The property's value.

hasHandles

Method
hasHandles(groupKey){Boolean}
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");
}

removeHandles

Method
removeHandles(groupKey)
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");

set

Method
set(path, value){*}

Sets the value of a property.

Call set() with a property name and a value to change the value of the property.

// setting the basemap of the map
map.set("basemap", "topo-vector");
// is equivalent to
map.basemap = "topo-vector";

// currying set
let updateViewScale = view.set.bind(view, "scale");
updateViewScale(5000);

set() can be called with the path to a property and a value. The property is not set if a property in the path doesn't exist.

// updating the title of the basemap
map.set("basemap.title", "World Topographic Map");

// is equivalent to
if (map.basemap != null) {
  map.basemap.title = "World Topographic Map";
}

An object with key-value pairs may be passed into set() to update multiple properties at once.

// setting a viewpoint on the view
view.set({
  center: [-4.4861, 48.3904],
  scale: 5000
});

// currying set
let updateView = view.set.bind(view);

updateView({
  center: [-4.4861, 48.3904],
  scale: 5000
});
Parameters
path String|Object

The path to the property to set, or an object of key-value pairs

value *

The new value to set on the property.

Returns
Type Description
* The instance.

watch

Method
watch(path, callback){WatchHandle}

Watches for property changes on the instance. For additional capabilities when observing changes on properties, see reactiveUtils.

Watching for property changes is essential for tracking changes on objects. To start watching for changes on a property, call watch() with the property name and a callback function that will execute each time the property changes.

let handle = mapview.watch("scale", function(newValue, oldValue, propertyName, target) {
  console.log(propertyName + " changed from " + oldValue + " to " + newValue);
});

To stop watching for changes, call the remove() method on the object that watch() returns.

handle.remove();

It is important to store the resulting objects from watch() to properly clean up the references.

let viewHandles = [];
function setView(view) {
  // remove the handles for the current view.
  viewHandles.forEach(function(handle) {
    handle.remove();
  });
  viewHandles.length = 0;

  this.view = view;

  // watch for properties on the newly set view.
  if (view) {
    viewHandles.push(
      view.watch("scale", scaleWatcher);
    );
  }
}

setView(mapView);
setView(null);

Like get() and set(), it is possible to watch for a property deep in the object hierarchy by passing a path. If a property in the path doesn't exist the watch callback is called with undefined.

let view = new SceneView({
  map: new Map({
    basemap: "streets-vector"
  })
});

view.watch("map.basemap.title", (newValue, oldValue) => {
  console.log("basemap's title changed from " + oldValue + " to " + newValue);
});

view.map.basemap = "topo-vector";
// output: "basemap's title changed from Streets to Topographic"

view.map = null;
// output: "basemap's title changed from Topographic to undefined"

Pass a comma delimited list of property paths, or an array of property paths, to watch multiple properties with the same callback. Use the third parameter of the callback call to determine what property changed.

view.watch("center, scale, rotation", (newValue, oldValue, propertyName) => {
  console.log(propertyName + " changed");
});

// equivalent of
view.watch(["center", "scale", "rotation"], (newValue, oldValue, propertyName) => {
  console.log(propertyName + " changed");
});

// equivalent of
let callback = (newValue, oldValue, propertyName) => {
  console.log(propertyName + " changed");
}
view.watch("center", callback);
view.watch("scale", callback);
view.watch("rotation", callback);

Accessor doesn't call the watch callbacks for a property immediately after its value changes. Instead, when a property's value changes and if that property is watched, Accessor schedules a notification which is then processed at a later time. Properties that change frequently like view.scale can be watched without having to throttle the callback.

// Divides the view.scale three times
view.watch("scale", (newValue, oldValue) => {
  console.log("view's scale changed from " + oldValue + " to " + newValue);
});
console.log("current view scale: " + view.scale);
view.scale = view.scale / 2;
view.scale = view.scale / 2;
view.scale = view.scale / 2;
console.log("current view scale: " + view.scale);

// output the following:
// current view scale: 36978595.474472
// current view scale: 4622324.434309
// view's scale changed from 36978595.474472 to 4622324.434309
Parameters

The property or properties to watch. Multiple properties can be specified as a comma-separated list.

callback watchCallback

The callback to execute when the property value has changed.

Returns
Type Description
WatchHandle A watch handle

Type Definitions

WatchHandle

Type Definition
WatchHandle Object

Represents a watch or event handler which can be removed.

Property
remove Function

Removes the watch handle.

Example
let handle = reactiveUtils.watch(() => map.basemap, (newVal) => {
  // Each time the value of map.basemap changes, it is logged in the console
  console.log("new basemap: ", newVal);
});

// When remove() is called on the watch handle, the map no longer watches for changes to basemap
handle.remove();

watchCallback

Type Definition
watchCallback(newValue, oldValue, propertyName, target)

Callback to be called when a watched property changes.

Parameters
newValue *

The new value of the watched property.

oldValue *

The old value of the watched property.

propertyName String

The property name.

target Accessor

The object containing the property being watched.

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