import "@arcgis/map-components/components/arcgis-map";- Inheritance:
- ArcgisMap→
PublicLitElement
- Since
- ArcGIS Maps SDK for JavaScript 4.28
The ArcGIS Map component is used to add 2D maps to web applications. For 3D maps, use the arcgis-scene.
Initializing the Map component
The Map component creates a MapView and can be initialized in one of three ways:
1. Using a WebMap
Load a WebMap from ArcGIS Online or an ArcGIS Enterprise portal by specifying the itemId attribute.
<arcgis-map item-id="05e015c5f0314db9a487a9b46cb37eca"></arcgis-map>2. Setting Map component attributes directly
Define the Map component using attributes like basemap, center, and zoom directly.
<arcgis-map basemap="satellite" center="-154.88, 19.46" zoom="15"></arcgis-map>3. Providing a Map instance
Alternatively, you can provide your own Map instance to the component. This allows full control over map configuration, including basemap, operational layers and spatialReference. See the Select features by rectangle sample for an example of this approach in action.
<arcgis-map></arcgis-map><script type="module"> const viewElement = document.querySelector("arcgis-map");
// set the basemap of the map to states feature layer // add national parks feature layer and a polygon graphics layer viewElement.map = new Map({ basemap: new Basemap({ baseLayers: [states] }), layers: [nationalParksLayer, polygonGraphicsLayer] });
// set the spatial reference of the map to NAD 1983 Albers contiguous USA viewElement.spatialReference = { wkid: 102003 };</script>Adding components and customizing the Map
Other components can be added and connected to the Map component.
<arcgis-map item-id="05e015c5f0314db9a487a9b46cb37eca"> <arcgis-zoom slot="top-left"></arcgis-zoom> <arcgis-legend slot="bottom-left"></arcgis-legend></arcgis-map>The Map component can be customized further using any of the core API functionalities of the ArcGIS Maps SDK for JavaScript.
const viewElement = document.querySelector("arcgis-map");viewElement.addEventListener("arcgisViewReadyChange", () => { const layer = new GraphicsLayer({ title: "My Layer" }); viewElement.map.add(layer);});See also:
Demo
Properties
| Property | Attribute | Type |
|---|---|---|
allLayerViews readonly | | |
| ||
animations-disabled | ||
| MapView["aria"] | |
attributionItems readonly | | MapView["attributionItems"] |
attribution-mode | ||
auto-destroy-disabled | ||
| ||
basemap | ||
| ||
canZoomIn readonly | | |
canZoomOut readonly | | |
center | MapView["center"] | |
| ||
display-filter-disabled | ||
| MapView["extent"] | |
| ||
| ||
gamepad readonly | | |
| ||
ground | Ground | |
hide-attribution | ||
| ||
interacting readonly | | |
| ||
itemId reflected | item-id | |
layerViews readonly | | |
| ||
magnifier readonly | | |
| ||
navigating readonly | | |
| ||
| ||
| ||
popup-component-enabled | ||
popup-disabled | ||
popupElement readonly | | |
ready readonly | | |
resize-align | ||
resolution readonly | | |
rotation | ||
scale | ||
selectionManager readonly | | |
| ||
spatial-reference-locked | ||
stationary readonly | | |
suspended readonly reflected | suspended | |
| ||
| TimeExtent | null | undefined | |
time-zone | ||
updating readonly | | |
view readonly | | |
| ||
visibleArea readonly | | |
zoom |
allLayerViews
- Type
- ReadonlyCollection<LayerView>
Collection containing a flat list of all the created LayerViews related to the basemap, operational layers, and group layers in this view.
- See also
analyses
- Type
- Collection<Analysis>
- Since
- ArcGIS Maps SDK for JavaScript 4.34
A collection of analyses associated with the view.
Examples
// Adds an analysis to the Viewview.analyses.add(elevationProfileAnalysis);// Removes an analysis from the Viewview.analyses.remove(elevationProfileAnalysis); animationsDisabled
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.34
Indicates whether animations are disabled in the view. This includes animated symbols (animated
CIMSymbol,
PictureMarkerSymbol
from a GIF/animated PNG), animated renderers
(FlowRenderer),
animated layers (MediaLayer,
VideoLayer), and
animations triggered by view navigation (for example,
goTo()).
Setting this property to true disables all animations in the view.
- Attribute
- animations-disabled
- Default value
- false
aria
- Type
- MapView["aria"]
- Since
- ArcGIS Maps SDK for JavaScript 4.34
The ARIA attributes for the view container. Provides accessibility information to assistive technologies such as screen readers. Supports the following properties: label, description, describedByElements, and labelledByElements.
attributionItems
- Type
- MapView["attributionItems"]
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The attribution items displayed in the view's attribution.
attributionMode
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The light or dark mode used to display the attribution. By default, the mode is inherited from the Calcite's mode. You can override the value to style the attribution alongside the map or scene content.
- Attribute
- attribution-mode
autoDestroyDisabled
- Type
- boolean
If true, the component will not be destroyed automatically when it is disconnected from the document. This is useful when you want to move the component to a different place on the page, or temporarily hide it. If this is set, make sure to call the destroy() method when you are done to prevent memory leaks.
- Attribute
- auto-destroy-disabled
- Default value
- false
background
- Type
- ColorBackground | null | undefined
The background color of the Map component.
Example
let view = new MapView({ container: "viewDiv", map: map, background: { // autocasts new ColorBackground() color: "magenta" // autocasts as new Color() }}); basemap
Specifies a basemap for the map. The basemap is a set of layers that give geographic context to the view and the other operational layers in the map. It can either be set using a basemap ID string (see values), Basemap or BasemapStyle.
- Attribute
- basemap
basemapView
- Type
- BasemapView<LayerView>
Represents the view for a single basemap after it has been added to the map.
canZoomIn
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 5.0
Indicates if the view component can zoom in.
- Default value
- false
canZoomOut
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 5.0
Indicates if the view component can zoom out.
- Default value
- false
center
- Type
- MapView["center"]
Represents the view's center point; when setting the center, you may pass a
Point instance, numbers representing
a longitude/latitude pair ([-100.4593, 36.9014]), or a string attribute representing a longitude/latitude pair ("-100.4593, 36.9014").
Setting the center immediately changes the current view. For animating the view, see this component's goTo() method.
The returned Point object is always in the spatial reference of the view and may be modified internally. To persist the returned object, create a clone using clone() method.
Notes
- If the spatial reference of
centerset in the constructor does not match the spatialReference of the view, then the projectOperator will be loaded dynamically. - At runtime, the projectOperator must be
loaded when
setting the
centerto a spatial reference that doesn't match the view spatial reference. You can check if the projectOperator is loaded prior to setting the center by calling isLoaded() method. If it is not yet loaded, you can call load() method.
- Attribute
- center
Examples
<arcgis-map zoom="4" center="-98, 39"></arcgis-map>// Sets the initial center point of the map component to lon/lat coordinates// lon/lat will be projected to match the spatial reference of the viewconst viewElement = document.querySelector("arcgis-map");viewElement.center = [-98, 39]; // lon, lat// Updates the view's center point to a pre-determined Point objectlet centerPoint = new Point({ x: 12804.24, y: -1894032.09, spatialReference: { wkid: view.spatialReference // wkid 2027 }});const viewElement = document.querySelector("arcgis-map");view.center = centerPoint;// the point's spatialReference does not match the view's spatialReference// the projectOperator will be used to project the point to match// the view's spatialReferenceconst centerPoint = new Point({ x: -8746995, y: 4352308, spatialReference: { wkid: 8857 }});if (!projectOperator.isLoaded()) { await projectOperator.load();}const viewElement = document.querySelector("arcgis-map");viewElement.center = centerPoint; constraints
- Type
- MapViewConstraints
Specifies constraints to scale, zoom, and rotation that may be applied to the map.
- See also
Examples
view.constraints = { geometry: { // Constrain lateral movement to Lower Manhattan type: "extent", xmin: -74.020, ymin: 40.700, xmax: -73.971, ymax: 40.73 }, minScale: 500000, // User cannot zoom out beyond a scale of 1:500,000 maxScale: 0, // User can overzoom tiles rotationEnabled: false // Disables map rotation};// This snippet shows how to set the MapView scale 1:1 while generating additional LODs for the MapView.constraints.const spatialReference = new SpatialReference({ wkid: 2154});const center = new Point({ x: 0, y: 0, spatialReference});
// Create LODs from level 0 to 31const tileInfo = TileInfo.create({ spatialReference, numLODs: 32});const lods = tileInfo.lods;
let view = new MapView({ container: "viewDiv", map, scale: 1, center, spatialReference, constraints: { lods: lods, snapToZoom: false }}); displayFilterDisabled
- Type
- boolean
Indicates whether a layer's displayFilterInfo is honored when rendering layers in the view.
If false, display filters are ignored and all features are rendered.
- Attribute
- display-filter-disabled
- Default value
- false
extent
- Type
- MapView["extent"]
The extent represents the visible portion of a map within the view as an instance of Extent. Setting the extent immediately changes the view without animation. To animate the view, see this component's goTo() method. When the view is rotated, the extent does not update to include the newly visible portions of the map.
Notes
- If the spatial reference of
extentset does not match the spatialReference of the view, then the projectOperator will be loaded dynamically. - At runtime, the projectOperator
must be loaded when
setting the
extentto a spatial reference that doesn't match the view spatial reference. You can check if the projectOperator is loaded prior to setting the extent by calling isLoaded() method. If it is not yet loaded, you can call the load method.
floors
- Type
- Collection<string>
Applies a display filter on the view for a specific set of floor levels. It can filter the map display on floor-aware layers by zero or more level IDs.
graphics
- Type
- Collection<Graphic>
Allows for adding graphics directly to the default graphics in the View.
Examples
// Adds a graphic to the Viewgraphics.add(pointGraphic);// Removes a graphic from the Viewgraphics.remove(pointGraphic); ground
- Type
- Ground
Specifies the surface properties for the map.
- See also
- Attribute
- ground
Examples
// Use the world elevation serviceconst map = new Map({ basemap: "topo-vector", ground: "world-elevation"});// Create a map with the world elevation layer overlaid by a custom elevation layerconst worldElevation = new ElevationLayer({ url: "//elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"});const customElevation = new ElevationLayer({ url: "https://my.server.com/arcgis/rest/service/MyElevationService/ImageServer"});const map = new Map({ basemap: "topo-vector", ground: new Ground({ layers: [ worldElevation, customElevation ] })}); hideAttribution
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 5.0
Indicates whether the attribution is hidden in the view.
Esri requires that when you use an ArcGIS Online basemap in your app, the map must include Esri attribution and you must be licensed to use the content. For detailed guidelines on working with attribution, please visit the official attribution in your app documentation. For information on terms of use, see the Terms of Use FAQ.
- Attribute
- hide-attribution
- Default value
- false
highlights
- Type
- Collection<HighlightOptions>
- Since
- ArcGIS Maps SDK for JavaScript 4.32
Represents a collection of HighlightOptions objects which can be used to highlight features throughout an application. Highlighting works by applying highlight options to one or more features. You can configure these options (such as color or opacity) to define how a feature will be visually emphasized.
A maximum of six HighlightOptions objects are supported in the collection, and they can be added, removed, and reordered freely. Their order in the collection determines priority, with the last object having the highest priority. If you apply more than one highlight to a feature, the one that is last within the collection will be applied. The HighlightOptions object must be part of this collection in order to be applied to features.
To highlight a feature, use the highlight()
method on the relevant LayerView instance. To apply specific
HighlightOptions, include the
name in the highlight() method's options parameter.
If no name is provided, the feature will use the default highlight options.
The table below shows the default highlight options in the View's highlights collection if the collection has not been modified:
| Highlight options name | Description | Default settings |
|---|---|---|
| default | The default highlight options. Used when layerView.highlight() is called without specifying any particular highlight options. | { name: "default", color: "cyan", haloOpacity: 1, fillOpacity: 0.25, shadowColor: "black", shadowOpacity: 0.4, shadowDifference: 0.2} |
| temporary | The temporary highlight options, pre-configured for common use cases such as hovering over a feature in the view. | { name: "temporary", color: "yellow", haloOpacity: 1, fillOpacity: 0.25, shadowColor: "black", shadowOpacity: 0.4, shadowDifference: 0.2 } |
Examples
// Use the default highlights collection to apply a highlight to features when you hover over them
// A handler can be used to remove any previous highlight when applying a new onelet hoverHighlight;
view.on("pointer-move", (event) => { // Search for the first feature in the featureLayer at the hovered location view.hitTest(event, { include: featureLayer }).then((response) => { if (response.results[0]) { const graphic = response.results[0].graphic; view.whenLayerView(graphic.layer).then((layerView) => { // Remove any previous highlight, if it exists hoverHighlight?.remove(); // Highlight the hit features with the temporary highlight options, which are pre-configured for this use case hoverHighlight = layerView.highlight(graphic, { name: "temporary"}); }); } });});// Override the default highlights collection
const view = new MapView({ map: map, container: "viewDiv",
// Set the highlight options to be used in the view highlights: [ { name: "default", color: "orange" }, { name: "temporary", color: "magenta" }, { name: "table", color: "cyan", fillOpacity: 0.5, haloOpacity: 0} ]});// Add highlight options to the collection after initialization
const selectionHighlightOptions = { name: "selection", color: "#ff00ff", // bright fuchsia haloOpacity: 0.8, fillOpacity: 0.2};
// Add the options to the highlights collection at the first positionview.highlights.add(selectionGroup, 0); interacting
- Type
- boolean
Indicates whether the view is being interacted with (for example, when panning or via an interactive tool).
- Default value
- false
itemId
The ID of a WebMap from ArcGIS Online or ArcGIS Enterprise portal.
To configure the portal url you must set the portalUrl property on config before the Map component loads.
- Attribute
- item-id
layerViews
- Type
- Collection<LayerView>
A collection containing a hierarchical list of all the created LayerViews of the operational layers in the map.
- See also
loadErrorSources
- Type
- LoadErrorSource[] | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.34
An array of objects that encountered an error while loading the component or any of its dependencies (e.g., basemap, ground, layers, tables). You may inspect the errors by accessing each object's loadError property.
magnifier
- Type
- Magnifier
The magnifier allows for showing a portion of the view as a magnifier image on top of the view.
navigating
- Type
- boolean
Indication whether the view is being navigated (for example when panning).
- Default value
- false
navigation
- Type
- Navigation
Options to configure the navigation behavior of the View.
Example
// Disable the gamepad usage, single touch panning, panning momentum and mouse wheel zooming.const view = new MapView({ container: "viewDiv", map: new Map({ basemap: "satellite" }), center: [176.185, -37.643], zoom: 13, navigation: { gamepad: { enabled: false }, actionMap: { dragSecondary: "none", // Disable rotating the view with the right mouse button mouseWheel: "none" // Disable zooming with the mouse wheel }, browserTouchPanEnabled: false, momentumEnabled: false, }}); padding
- Type
- ViewPadding
Padding to make the map's center and extent work off a subsection of the full map. This is particularly useful when layering UI elements or semi-transparent content on top of portions of the map.
- See also
- Default value
- {left: 0, top: 0, right: 0, bottom: 0}
popup
A Popup widget object that displays general content or attributes from layers in the map. Consider using the popupElement (beta), which represents the Popup component, instead.
By default, the popup property is an empty object that allows you to set the popup options. A Popup instance is automatically created and assigned to the view's popup when the user clicks on the view and popupEnabled is true, when the openPopup() method is called, or when some widgets need the popup, such as Search. If popup is null, the popup instance will not be created.
popupComponentEnabled
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 5.0
Indicates whether the popup component (beta) is enabled as the default popup. When set to true, the popupElement property (representing the component) will be used for popups instead of the popup property (representing the widget).
Note: This is a beta feature and may change in future releases. At version 6.0, the Popup component will be used by default instead of the Popup widget and the popup-component-enabled attribute will no longer be necessary.
- See also
- Attribute
- popup-component-enabled
- Default value
- false
Example
<arcgis-map item-id="WEBMAP-ID" popup-component-enabled></arcgis-map> popupDisabled
- Type
- boolean
Controls whether the default popup opens automatically when users click on the view. This controls both the popupElement and popup properties. When set to true, the popup will not open on click or when triggered programmatically.
- See also
- Attribute
- popup-disabled
- Default value
- false
popupElement
- Type
- ArcgisPopup | null
- Since
- ArcGIS Maps SDK for JavaScript 5.0
A reference to the current arcgis-popup (beta). The popupComponentEnabled property must be set to true to use this property.
Note: This is a beta feature and may change in future releases.
- See also
Example
<arcgis-map item-id="WEBMAP-ID" popup-component-enabled></arcgis-map><script type="module">const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();viewElement.popupElement.dockEnabled = true;viewElement.popupElement.dockOptions = { buttonEnabled: false, breakpoint: false, position: "top-right",};</script> ready
- Type
- boolean
When true, this property indicates whether the view has successfully satisfied all dependencies, signaling that the following conditions are met:
- The view has a map. If map is a WebMap, then the map must be loaded.
- The view has a spatialReference, a center, and a scale. These also can be inferred by setting an extent.
When a view becomes ready it will resolve itself and invoke the callback defined in viewOnReady() where code can execute on a working view.
- See also
- Default value
- false
resizeAlign
- Type
- ResizeAlign
Defines which anchor stays still while resizing the browser window. The default, center,
ensures the view's center point remains constantly visible as the window size changes. The other
options allow the respective portion of the view to remain visible when the window's size is changed.
- Attribute
- resize-align
- Default value
- "center"
resolution
- Type
- number
Represents the current value of one pixel in the unit of the view's spatialReference. The value of resolution is calculated by dividing the view's extent width by its width.
rotation
- Type
- number
The clockwise rotation of due north in relation to the top of the view in degrees.
The view may be rotated by directly setting
the rotation or by using the following mouse event: Right-click + Drag.
Map rotation may be disabled by setting the rotationEnabled property
in constraints to false. See the code snippet below for
an example of this.
- Attribute
- rotation
- Default value
- 0
Examples
// Due north is rotated 90 degrees, pointing to the right side of the viewview.rotation = 90;// Due north is rotated 180 degrees, pointing to the bottom of the viewview.rotation = 180;// Due north is rotated 270 degrees, pointing to the left side of the viewview.rotation = 270;// Due north is rotated 0 degrees, pointing to the top of the view (the default)view.rotation = 0; // 360 or multiple of 360 (e.g. 720) works here as well.// Disables map rotationview.constraints = { rotationEnabled: false}; selectionManager
- Type
- SelectionManager
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The default SelectionManager for this view. Used to manage selections of features across layers.
spatialReference
- Type
- SpatialReference
The spatial reference of the view. This indicates the projected or geographic coordinate system used to locate geographic features in the map.
You can change the spatialReference of the view after it is initialized by either directly changing
this property, or by changing the basemap from the arcgis-basemap-gallery
and arcgis-basemap-toggle components.
Set spatialReferenceLocked property to true to prevent users from changing the view's spatial reference at runtime.
Prior to changing the spatial reference, check if the projectOperator
is loaded by calling projectOperator.isLoaded() method.
If it is not yet loaded, call projectOperator.load() method.
If the projectOperator is not loaded, the view's center will default to [0, 0] in the new spatial reference of the view and a console error will be thrown.
Notes
- LayerViews not compatible with the view's spatial reference
are not displayed. In such case, the layer view's suspended
property is
trueand spatialReferenceSupported property isfalse. - When setting view's spatial reference, the center, extent or viewpoint properties are projected to the new spatial reference. The scale and rotation properties are adjusted to keep the content of the map at the same size and orientation on screen.
- To ensure TileLayers and VectorTileLayers are displayed in a basemap correctly, the spatialReference of the view must be set match their tileInfo's spatial reference.
- Switching spatial reference with an imageCoordinateSystem is not supported.
- See also
Example
const viewElement = document.querySelector("arcgis-map");// check if the projectOperator is loadedif (!projectOperator.isLoaded()) { // load the projectOperator if it is not loaded projectOperator.load().then(() => { // change the spatial reference of the map component to equal earth projection viewElement.spatialReference = new SpatialReference({ wkid: 54035 //equal earth projection }); });} else { // the projectOperator is already loaded. // change the spatial reference of the view to equal earth projection viewElement.spatialReference = new SpatialReference({ wkid: 54035 //equal earth projection });} spatialReferenceLocked
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.34
Indicates if the map's spatialReference can be changed after it is ready.
The default is false, indicating the map's spatialReference can be changed at runtime.
When true, basemaps with spatial references that do not match the map's spatial reference
will be disabled in arcgis-basemap-gallery and arcgis-basemap-toggle components and the map's spatialReference cannot be changed at runtime.
- Attribute
- spatial-reference-locked
- Default value
- false
stationary
- Type
- boolean
Indication whether the view is animating, being navigated with or resizing.
- Default value
- false
suspended
- Type
- boolean
Indicates if the view is visible on the page.
- Attribute
- suspended
- Default value
- false
timeExtent
- Type
- TimeExtent | null | undefined
The view's time extent. Time-aware layers display their temporal data that falls within the view's time extent. Setting the view's time extent is similar to setting the spatial extent because once the time extent is set, the view updates automatically to conform to the change.
Example
// Create a csv layer from an online spreadsheet.let csvLayer = new CSVLayer({ url: "http://test.com/daily-magazines-sold-in-new-york.csv", timeInfo: { startField: "SaleDate" // The csv field contains date information. }});
// Create a mapview showing sales for the last week of March 2019 only.const view = new MapView({ map: map, container: "viewDiv", timeExtent: { start: new Date("2019, 2, 24"), end: new Date("2019, 2, 31") }}); timeZone
- Type
- string
Defines the time zone of the view. The time zone property determines how dates and times are represented to the user, but the underlying data is unchanged.
- Attribute
- time-zone
- Default value
- "system"
Example
// Date and time will be displayed in Pacific/Auckland (NZ) time zoneconst view = new MapView({ map: map, container: "viewDiv", timeZone: "Pacific/Auckland"}); updating
- Type
- boolean
Indicates whether the view is being updated by additional data requests to the network, or by processing received data.
- Default value
- false
visibleArea
- Since
- ArcGIS Maps SDK for JavaScript 4.31
The visibleArea represents the visible portion of a Map within the view as an instance of a Polygon. This is similar to the view MapView#extent but is a more accurate representation of the visible area especially when the view is rotated. An example use of the visible area is to spatially filter visible features in a layer view query.
- See also
zoom
- Type
- number
Represents the level of detail (LOD) at the center of the map. A zoom level (or scale) is a number that defines how large or small the contents of a map appear in a Map component. Zoom level is a number usually between 0 (global view) and 23 (very detailed view) and is used as a shorthand for predetermined scale values. A value of -1 means the map has no LODs. When setting the zoom value, the component converts it to the corresponding scale, or interpolates it if the zoom is a fractional number.
Setting the zoom immediately changes the current view. For animating the view, see this component's goTo() method.
Setting this property in conjunction with center is a convenient way to set the initial extent of the view.
- Attribute
- zoom
Methods
| Method | Signature |
|---|---|
closePopup(): Promise<void> | |
componentOnReady inherited | componentOnReady(): Promise<this> |
destroy(): Promise<void> | |
goTo(target: GoToTarget2D, options?: GoToOptions2D): Promise<unknown> | |
hitTest(screenPoint: MouseEvent | ScreenPoint, options?: HitTestOptions): Promise<ViewHitTestResult> | |
openPopup(options?: ViewPopupOpenOptions): Promise<void> | |
takeScreenshot(options?: UserSettings): Promise<Screenshot> | |
toMap(screenPoint: MouseEvent | ScreenPoint): Point | |
toScreen(point: Point, options?: ToScreenOptions2D): ScreenPoint | null | undefined | |
tryFatalErrorRecovery(): Promise<void> | |
viewOnReady(callback?: () => void, errback?: (error: Error) => void): Promise<void> | |
whenAnalysisView(analysis: Analysis): Promise<AnalysisView2DUnion> | |
whenLayerView<TLayer extends Layer>(layer: TLayer): Promise<LayerView2DFor<TLayer>> | |
zoomIn(): Promise<void> | |
zoomOut(): Promise<void> |
componentOnReady
- Signature
-
componentOnReady (): Promise<this>
Creates a promise that resolves once the component is fully loaded.
- Returns
- Promise<this>
Example
const arcgisMap = document.querySelector("arcgis-map");document.body.append(arcgisMap);await arcgisMap.componentOnReady();console.log("arcgis-map is ready to go!"); hitTest
- Signature
-
hitTest (screenPoint: MouseEvent | ScreenPoint, options?: HitTestOptions): Promise<ViewHitTestResult>
Returns hit test results from each layer that intersects the specified screen coordinates. The results are organized as an array of objects containing different result types.
The following layer types will return all features if a hit is made on intersecting features: FeatureLayer, CatalogLayer, CSVLayer, GeoJSONLayer, GeoRSSLayer, GraphicsLayer, KMLLayer, MapNotesLayer, OGCFeatureLayer, StreamLayer, SubtypeSublayer, VectorTileLayer, and WFSLayer.
The ParquetLayer hit result returns only the topmost feature when the hit occurs on overlapping features in a ParquetLayer.
The VectorTileLayer hit test result contains an array of objects containing
a graphic.
The graphic returns attributes of a style layer. In addition, the graphic's origin
contains the style layer's id and layer index within the vector tile style.
Spatial information about the actual feature represented in the style layer is returned only if the style layer is a symbol layer.
Otherwise, the graphic's geometry is null.
The MediaLayer hit test result contains all media elements if the hit is made on intersecting elements. The RouteLayer hit test result contains all route elements if the hit is made on intersecting elements.
If the polygon feature's symbol
style is set to none, the hitTest method will not
return results when the fill is clicked. However, it will return results when the outline is clicked. To get results when clicking the fill, set the
color to a transparent color instead.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| screenPoint | | | |
| options | | |
- Returns
- Promise<ViewHitTestResult>
Examples
viewElement.addEventListener("arcgisViewClick", (event) => { viewElement.hitTest(event.detail).then((response) => { const result = response.results[0]; if (result?.type === "graphic") { const { longitude, latitude } = result.mapPoint; console.log(`Hit graphic at (${longitude}, ${latitude})`, result.graphic); } else { console.log("Did not hit any graphic"); } });});// get screenpoint from view's click eventviewElement.addEventListener("arcgisViewClick", async (event) => { // Search for all media elements only on included mediaLayer at the clicked location const response = await viewElement.hitTest(event.detail, { include: {mediaLayer} }); // if media elements are returned from the mediaLayer, do something with results if (response.results.length){ // do something console.log(response.results.length, "elements returned"); }}); takeScreenshot
- Signature
-
takeScreenshot (options?: UserSettings): Promise<Screenshot>
Create a screenshot of the current view.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| options | | |
- Returns
- Promise<Screenshot>
toMap
- Signature
-
toMap (screenPoint: MouseEvent | ScreenPoint): Point
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| screenPoint | | |
- Returns
- Point
toScreen
- Signature
-
toScreen (point: Point, options?: ToScreenOptions2D): ScreenPoint | null | undefined
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| point | | | |
| options | | |
- Returns
- ScreenPoint | null | undefined
viewOnReady
- Signature
-
viewOnReady (callback?: () => void, errback?: (error: Error) => void): Promise<void>
- Since
- ArcGIS Maps SDK for JavaScript 4.33
viewOnReady() may be leveraged once an instance of the component and its underlying view is created and ready.
This method takes two input parameters, a callback function and an errback function, and returns a promise. The callback executes when the promise resolves, and the errback executes if the promise is rejected.
Example
const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// The view is now ready to be used.viewElement.map.add(new FeatureLayer({...})); whenAnalysisView
- Signature
-
whenAnalysisView (analysis: Analysis): Promise<AnalysisView2DUnion>
- Since
- ArcGIS Maps SDK for JavaScript 4.34
Gets the analysis view created for the given analysis object.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| analysis | | |
- Returns
- Promise<AnalysisView2DUnion>
whenLayerView
- Signature
-
whenLayerView <TLayer extends Layer>(layer: TLayer): Promise<LayerView2DFor<TLayer>>
- Type parameters
- <TLayer extends Layer>
Gets the LayerView created on the view for the given layer.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| layer | TLayer | | |
- Returns
- Promise<LayerView2DFor>
Events
| Name | Type |
|---|---|
arcgisLoadError
arcgisLoadError: CustomEvent<void> - Since
- ArcGIS Maps SDK for JavaScript 4.34
Fires when an arcgis-map fails to load or if one of its dependencies fails to load (e.g., basemap, ground, layers).
- See also
Example
viewElement.addEventListener("arcgisLoadError", () => { console.log(viewElement.loadErrorSources);}); arcgisViewAnalysisViewCreate
arcgisViewAnalysisViewCreate: CustomEvent<AnalysisViewCreateEvent> arcgisViewAnalysisViewCreateError
arcgisViewAnalysisViewCreateError: CustomEvent<AnalysisViewCreateErrorEvent> - Since
- ArcGIS Maps SDK for JavaScript 4.34
Fires when an error occurs during the creation of an analysis view after an analysis is added to the view.
arcgisViewAnalysisViewDestroy
arcgisViewAnalysisViewDestroy: CustomEvent<AnalysisViewDestroyEvent> arcgisViewChange
arcgisViewChange: CustomEvent<void> This event is triggered when view-related properties change, such as zoom, scale, center, rotation, extent, viewpoint, or stationary. It reflects user interactions (e.g. panning or zooming) or programmatic updates to the view.
Example
// get the number of features in a layer view whenever the view becomes stationaryviewElement.addEventListener("arcgisViewChange", async (event) =>{ if (viewElement.stationary) { // Returns number of features available for drawing in a given layer view const count = await layerView.queryFeatureCount({ geometry: viewElement.extent }); // use the features count }}); arcgisViewClick
arcgisViewClick: CustomEvent<ClickEvent> Fires after a user clicks on the view. This event emits slightly slower than an @arcgisViewImmediateClick
event to make sure that an @arcgisViewDoubleClick event isn't triggered instead. The arcgisViewImmediateClick
event can be used for responding to an arcgisViewClick event without delay.
Example
// Listen for clicks on the view and perform a hit test on a feature layerviewElement.addEventListener("arcgisViewClick", (event) => { // Return hit test results from the feature layer // where it intersects the screen coordinates from the click event. // The result is a polygon representing the state that was clicked. viewElement.hitTest(event.detail).then((response) => { if (response.results.length) { const stateBoundaryPolygon = response.results.find((result) => { return result.graphic.layer === stateBoundaryFeatureLayer; }).graphic.geometry;
getPolygonCentroid(stateBoundaryPolygon); } });}); arcgisViewDoubleClick
arcgisViewDoubleClick: CustomEvent<DoubleClickEvent> Fires after double-clicking on the view.
Example
viewElement.addEventListener("arcgisViewDoubleClick", async (event) => { // Prevent the default zoom-in behavior on double-click event.detail.stopPropagation();}); arcgisViewDoubleTapDrag
arcgisViewDoubleTapDrag: CustomEvent<DoubleTapDragEvent> - Since
- ArcGIS Maps SDK for JavaScript 5.0
Fires while the pointer is dragged following a double-tap gesture on the view.
Example
viewElement.addEventListener("arcgisViewDoubleTapDrag", (event) => { // Display the distance moved from the drag origin. console.log("x distance:", event.detail.x, "y distance:", event.detail.y);}); arcgisViewDrag
arcgisViewDrag: CustomEvent<DragEvent> Fires during a pointer drag on the view.
arcgisViewHold
arcgisViewHold: CustomEvent<HoldEvent> Fires after holding either a mouse button or a single finger on the view for a short amount of time.
arcgisViewImmediateClick
arcgisViewImmediateClick: CustomEvent<ImmediateClickEvent> Fires right after a user clicks on the view. In contrast to the @arcgisViewClick event, the arcgisViewImmediateClick
is emitted as soon as the user clicks on the view, and is not inhibited by a @arcgisViewDoubleClick event.
This event is useful for interactive experiences that require feedback without delay.
Example
viewElement.addEventListener("arcgisViewImmediateClick", async (event) => { // Prevent the default zoom-in behavior on arcgisViewImmediateClick event.detail.stopPropagation();}); arcgisViewImmediateDoubleClick
arcgisViewImmediateDoubleClick: CustomEvent<ImmediateDoubleClickEvent> Fires after two consecutive @arcgisViewImmediateClick events. In contrast to @arcgisViewDoubleClick,
an arcgisViewImmediateDoubleClick cannot be prevented by use of stopPropagation() on the @arcgisViewImmediateClick
event and can therefore be used to react to double-clicking independently of usage of the @arcgisViewImmediateClick event.
arcgisViewKeyDown
arcgisViewKeyDown: CustomEvent<KeyDownEvent> Fires after a keyboard key is pressed.
Example
// Disable zooming with the keyboard// Stop event propagation when `+` and `-` keys are pressed.viewElement.addEventListener("arcgisViewKeyDown", function(event){ console.log("key-down", event);
const prohibitedKeys = ["+", "-"]; const keyPressed = event.detail.key; if (prohibitedKeys.indexOf(keyPressed) !== -1) { event.detail.stopPropagation(); }}); arcgisViewKeyUp
arcgisViewKeyUp: CustomEvent<KeyUpEvent> Fires after a keyboard key is released.
arcgisViewLayerviewCreate
arcgisViewLayerviewCreate: CustomEvent<LayerViewCreateEvent> Fires after each layer in the map has a corresponding LayerView created and rendered in the view.
arcgisViewLayerviewCreateError
arcgisViewLayerviewCreateError: CustomEvent<LayerViewCreateErrorEvent> Fires when an error occurs during the creation of a LayerView after a layer has been added to the map.
arcgisViewLayerviewDestroy
arcgisViewLayerviewDestroy: CustomEvent<LayerViewDestroyEvent> Fires after a LayerView is destroyed and is no longer rendered in the view.
arcgisViewMouseWheel
arcgisViewMouseWheel: CustomEvent<ViewMouseWheelEvent> Fires when a wheel button of a pointing device (typically a mouse) is scrolled on the view.
Example
viewElement.addEventListener("arcgisViewMouseWheel", async (event) => { // Prevent the default zoom-in and zoom-out behavior on arcgisViewMouseWheel event.detail.stopPropagation();}); arcgisViewPointerDown
arcgisViewPointerDown: CustomEvent<PointerDownEvent> Fires after a mouse button is pressed, or a finger touches the display.
arcgisViewPointerEnter
arcgisViewPointerEnter: CustomEvent<PointerEnterEvent> Fires after a mouse cursor enters the view, or a display touch begins.
arcgisViewPointerLeave
arcgisViewPointerLeave: CustomEvent<PointerLeaveEvent> Fires after a mouse cursor leaves the view, or a display touch ends.
arcgisViewPointerMove
arcgisViewPointerMove: CustomEvent<PointerMoveEvent> Fires after the mouse or a finger on the display moves.
arcgisViewPointerUp
arcgisViewPointerUp: CustomEvent<PointerUpEvent> Fires after a mouse button is released, or a display touch ends.
arcgisViewReadyChange
arcgisViewReadyChange: CustomEvent<void> This event is for the ready property and is emitted when the view is ready.
Fires also when the map is updated.
arcgisViewReadyError
arcgisViewReadyError: CustomEvent<void> - Since
- ArcGIS Maps SDK for JavaScript 4.34
Fires if the view encounters a content or rendering error.
Example
viewElement.addEventListener("arcgisViewReadyError", () => { // handle error}); arcgisViewVerticalTwoFingerDrag
arcgisViewVerticalTwoFingerDrag: CustomEvent<VerticalTwoFingerDragEvent> - Since
- ArcGIS Maps SDK for JavaScript 5.0
Fires while the two pointers are dragged vertically on the view.
Example
viewElement.addEventListener("arcgisViewVerticalTwoFingerDrag", (event) => { // Display the distance moved vertically from the drag origin. console.log("y distance:", event.detail.y);});Slots
| Name | Description |
|---|---|
| Default slot for adding components to the map. User is responsible for positioning the content via CSS. | |
| Slot for components positioned in the top-left corner. | |
| Slot for components positioned in the top-right corner. | |
| Slot for components positioned in the bottom-left corner. | |
| Slot for components positioned in the bottom-right corner. | |
| Slot for components positioned at the top-start (top-left in LTR, top-right in RTL). | |
| Slot for components positioned at the top-end (top-right in LTR, top-left in RTL). | |
| Slot for components positioned at the bottom-start (bottom-left in LTR, bottom-right in RTL). | |
| Slot for components positioned at the bottom-end (bottom-right in LTR, bottom-left in RTL). | |
| Slot for the arcgis-popup component to open automatically on click. Only the Popup component can be placed in this slot. |
Styles
| Name | Default | Description |
|---|---|---|
| Since 4.34 Specifies the top padding for the layout. | |
| Since 4.34 Specifies the bottom padding for the layout. | |
| Since 4.34 Specifies the left padding for the layout. | |
| Since 4.34 Specifies the right padding for the layout. | |
| Since 5.0 Specifies the focus outline color for the view. |