<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Identify | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
<arcgis-map basemap="osm" zoom="13" center="-117.23502, 34.23911" popup-disabled popup-component-enabled>
<!-- Add the popup component to the default slot -->
<arcgis-popup slot="popup"></arcgis-popup>
<arcgis-zoom slot="top-left"></arcgis-zoom>
const [MapImageLayer, identify, IdentifyParameters] = await $arcgis.import([
"@arcgis/core/layers/MapImageLayer.js",
"@arcgis/core/rest/identify.js",
"@arcgis/core/rest/support/IdentifyParameters.js",
// Get a reference to the map component.
const viewElement = document.querySelector("arcgis-map");
// Get a reference to the popup component.
const popupComponent = document.querySelector("arcgis-popup");
// Listen for when the component is ready.
await viewElement.viewOnReady();
await popupComponent.componentOnReady();
// URL for the map service.
const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/MtBaldy_BaseMap/MapServer";
const view = viewElement.view;
// Add the map service as a MapImageLayer.
// Use identify to query the service to add interactivity to the app.
const mapImageLayer = new MapImageLayer({
viewElement.map.add(mapImageLayer);
params = new IdentifyParameters({
layerIds: [0, 1, 2, 3, 4],
viewElement.addEventListener("arcgisViewClick", executeIdentify);
// Executes each time the view is clicked.
async function executeIdentify(event) {
const mapPoint = event.detail?.mapPoint;
params.geometry = mapPoint;
params.mapExtent = view.extent;
params.width = view.width;
params.height = view.height;
viewElement.style.cursor = "wait";
// This function returns a promise that resolves to an array of features.
// A custom popupTemplate is set for each feature based on the layer it
const { results = [] } = await identify.identify(url, params);
const features = results.map((result) => {
const feature = result.feature;
const layerName = result.layerName;
feature.attributes.layerName = layerName;
if (layerName === "Roads") {
feature.popupTemplate = {
"<b>Block ID:</b> " + feature.attributes.BLOCK_ID +
"<br><b>Geometry Type:</b> " + feature.attributes.Shape +
"<br><b>Road Length:</b> " + feature.attributes.Shape_Length,
} else if (layerName === "water") {
feature.popupTemplate = {
title: feature.attributes.LABEL_LOCAL,
"<b>Block ID:</b> " + feature.attributes.BLOCK_ID +
"<br><b>Geometry Type:</b> " + feature.attributes.Shape +
"<br><b>Water Area:</b> " + feature.attributes.Shape_Area,
} else if (layerName === "Urban") {
feature.popupTemplate = {
"<b>Block ID:</b> " + feature.attributes.BLOCK_ID +
"<br><b>Geometry Type:</b> " + feature.attributes.Shape +
"<br><b>Urban Area:</b> " + feature.attributes.Shape_Area,
} else if (layerName === "Landuse") {
feature.popupTemplate = {
"<b>Block ID:</b> " + feature.attributes.BLOCK_ID +
"<br><b>Geometry Type:</b> " + feature.attributes.Shape +
"<br><b>Landuse Area:</b> " + feature.attributes.Shape_Area,
} else if (layerName === "Counties") {
feature.popupTemplate = {
"<b>ObjectID:</b> " + feature.attributes.OBJECTID +
"<br><b>Geometry Type:</b> " + feature.attributes.Shape +
"<br><b>Landuse Area:</b> " + feature.attributes.Shape_Area,
// set popup component title and content.
if (features.length > 0) {
popupComponent.location = mapPoint;
popupComponent.heading = features[0].popupTemplate.title;
popupComponent.content = features[0].popupTemplate.content;
popupComponent.open = true;
viewElement.style.cursor = "default";