Query Attachments

Explore in the sandboxView live

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.

    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.

    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.

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";