GraphicsLayer with visibilityTimeExtent

This sample demonstrates how to set a visibilityTimeExtent on a GraphicsLayer so that the graphics layers can be animated over time to show additional information about the Kincade fire perimeter at the same time while the user interacts with the TimeSlider widget.

The visibilityTimeExtent specifies a fixed time extent during which a layer should be visible. This property is used to configure a layer that does not have time values stored in an attribute field to work with time. Once configured, the TimeSlider widget will display the layer within the set time extent.

The map displays the daily perimeters of the Kincade fire of 2019.

When the app is loaded, a query is made against all fire perimeters in the Kincade fire feature service. The query result is ordered by the recordedDate field, and the app loops through the result, adding the date to dates array. It also creates a GraphicsLayer for each date and sets its visibilityTimeExtent to the date. A new graphic is created with a text symbol and its text property points to notes attribute from the query result. The graphic is then added to the GraphicsLayer.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
      // dates array will hold all the unique dates from the query result made to kincade fire perimeters
      let dates = new Array;

      // create a query object that honors layers settings and order the query results by recordedDate
      const query = featureLayer.createQuery();
      query.orderByFields = ["recordedDate"];

      const queryResult = await featureLayer.queryFeatures(query);

      // loop through the query result and add dates to dates array
      // create a new GraphicsLayer for each date and set its visibilityTimeExtent to the date
      // create a graphic with text symbol containing the notes attribute from the query result
      // add the graphic to the GraphicsLayer and set the time slider stops to dates array
      queryResult.features.forEach((feature, i) => {
        const date = new Date(feature.attributes.recordedDate);
        const notes = feature.attributes.Notes;

        // create a new graphic with text symbol and set text property
        // to notes attribute of the query result
        const graphic = new Graphic({
          geometry: {
            type: "point",
            x: feature.geometry.centroid.x,
            y: feature.geometry.centroid.y,
            spatialReference: {
              wkid: 102100
            }
          },
          attributes: {
            acres: feature.attributes.gisacres,
            start: new Date(feature.attributes.recordedData),
          },
          symbol: new TextSymbol({
            text: notes,
            color: "black",
            xoffset: 50,
            yoffset: 10,
            lineWidth: 200,
            horizontalAlignment: "left",
            backgroundColor: "white",
            font: {
              size: 12,
              family: "sans-serif"
            }
          })
        });

        // create a new GraphicsLayer for each date and set its visibilityTimeExtent to the date
        const glayer = createGraphicsLayer(date, new Date(feature.attributes.recordedDate), i);
        glayer.add(graphic);
        map.add(glayer);

        // add the date to dates array
        if (!dates.some(d => d.getTime() === date.getTime())) {
          dates.push(date);
        }
      });

The createGraphicsLayer() function creates a new GraphicsLayer and sets its visibilityTimeExtent to match a given date as shown below.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
      // create a new GraphicsLayer for each date and set its visibilityTimeExtent to the date
      // this function is called from the forEach loop above
      function createGraphicsLayer(startDate, endDate, index) {
        const graphicsLayer = new GraphicsLayer();
        graphicsLayer.id = `graphicsLayer${index}`;

        graphicsLayer.visibilityTimeExtent = {
          start: startDate,
          end: startDate
        };
        return graphicsLayer;
      }

The TimeSlider widget stops are set to a dates array so that the user can visualize how the fire perimeters changed daily. The GraphicsLayer will be visible if its visibilityTimeExtent extent overlaps the TimeSlider's currentTimeExtent. The GraphicsLayer will display additional info about the fire perimeter for the given day.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
      // add a new time slider and set its stops to dates array
      const timeSlider = new TimeSlider({
        container: "timeSlider",
        mode: "instant",
        timeVisible: true,
        playRate: 2000,
        stops: {dates},
        loop: true,
        fullTimeExtent: new TimeExtent({
          start: dates[0],
          end: dates[dates.length-1]
        }),
        view: view
      });
      view.ui.add(timeSlider, "bottom-left");

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