Skip to content

This sample demonstrates how to query attachments from a FeatureLayer with crowd sourced data using the queryObjectIDs() and queryAttachments() methods. When the user clicks somewhere in the map, the attachments located within 3 miles of the click location will appear in the panel on the left hand side.

How it works

A function is called whenever the user clicks on the map, which first queries for all object ids within 3 miles of the point where the map was clicked.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        const objectIds = await layer.queryObjectIds({
          geometry: event.mapPoint,
          spatialRelationship: "intersects",
          returnGeometry: false,
          outFields: ["*"],
          distance: 3,
          units: "miles",
        });

An array of object ids are returned and highlighted to show the user the bounds of their query. The object IDs are then passed to the queryAttachments() method to query for attachments that exist on the queried features.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        const attachmentsByFeatureId = await layer.queryAttachments({
          attachmentTypes: ["image/*"],
          objectIds: objectIds,
        });

An array of queried attachment ids are returned, which are displayed in the Calcite panel.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        Object.keys(attachmentsByFeatureId).forEach((objectId) => {
          const attachments = attachmentsByFeatureId[objectId];
          attachments.forEach((attachment) => {
            const block = document.createElement("calcite-block");
            block.expanded = true;
            block.heading = attachment.name;
            const card = document.createElement("calcite-card");
            const spanHeading = document.createElement("span");
            spanHeading.slot = "description";
            spanHeading.innerHTML = `Attachment type: ${attachment.contentType}`;
            const image = document.createElement("img");
            image.slot = "thumbnail";
            image.src = attachment.url;
            card.append(image, spanHeading);
            block.appendChild(card);
            panel.appendChild(block);
          });
        });

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