Query Attachments

This sample demonstrates how to query attachments from a FeatureLayer through Beverly Hills tree data by using the queryObjectIDs() and queryAttachments() methods. When user clicks somewhere in the map, the attachments located within 800m of the click location will appear in the div on the left hand side.

How it works

A function is called whenever the user clicks on the map, which first calls a query for all object ids within 800m of the point where the map was clicked.

1
2
3
4
5
6
7
8
layer.queryObjectIds({
    geometry: point,
    spatialRelationship: "intersects",
    distance: 800,
    units: "meters",
    returnGeometry: false,
    outFields: ["*"]
})

This will return an array of object ids which we highlight to show the user the bounds of their query then pass to the queryAttachments() method to query for attachments on any of the objects returned from our first query.

1
2
3
4
layer.queryAttachments({
    attachmentTypes: ["image/jpeg"],
    objectIds: objectIds
});

This method will return an array of ids for the attachments returned from the query, which we display by creating an image element and appending it to the queryResults div in the side panel.

1
2
3
4
5
6
7
8
9
Object.keys(attachmentsByFeatureId).forEach(function(objectId) {
    const attachments = attachmentsByFeatureId[objectId];
    attachments.forEach(function (attachment) {
        const image = document.createElement("img");
        image.src = attachment.url;
        image.className = "queryImg";
        document.getElementById("queryResults").appendChild(image);
    });
});

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

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close