Learn how to display feature attributes in a pop-up .
A pop-up , also known as a "popup", is a visual element that displays information about a feature when it is clicked. You typically style and configure a pop-up using HTML and CSS for each layer in a map. Pop-ups can display attribute values, calculated values, or rich content such as images, charts, or videos.
In this tutorial, you customize the interactive pop-up created by CesiumJS for the Trailheads feature service in the Santa Monica Mountains. When a feature is clicked, a pop-up will display containing the name of the trail and the service that manages it.
Prerequisites You need an ArcGIS Developer or ArcGIS Online account to access the developer dashboard and create an API key .
Steps Create a new pen To get started, either complete the Display a scene tutorial or use this pen . Set the API key To access location services , you need an API key or OAuth 2.0 access token . To learn how to create and scope your key, visit the Create an API key tutorial.
Go to your dashboard to get an API key. The API key must be scoped to access the services used in this tutorial.
In CodePen , update api Key
to use your key. Update cesium Access Token
to use your Cesium ion access token .
Use dark colors for code blocks
Change line Change line
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
const apiKey = "YOUR_API_KEY" ;
Cesium.ArcGisMapService.defaultAccessToken = apiKey;
const cesiumAccessToken = "YOUR_CESIUM_ACCESS_TOKEN" ;
Cesium.Ion.defaultAccessToken = cesiumAccessToken;
const arcGisImagery = Cesium.ArcGisMapServerImageryProvider.fromBasemapType(Cesium.ArcGisBaseMapType.SATELLITE);
const viewer = new Cesium.Viewer( "cesiumContainer" , {
baseLayer : Cesium.ImageryLayer.fromProviderAsync(arcGisImagery),
});
Add references to ArcGIS REST JS In the <head>
element, reference the feature-service
and request
packages from ArcGIS REST JS.
Expand
Use dark colors for code blocks
Add line. Add line.
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
< script src = "https://cesium.com/downloads/cesiumjs/releases/1.105/Build/Cesium/Cesium.js" > </ script >
< link href = "https://cesium.com/downloads/cesiumjs/releases/1.105/Build/Cesium/Widgets/widgets.css" rel = "stylesheet" >
< script src = "https://unpkg.com/@esri/arcgis-rest-request@4.0.0/dist/bundled/request.umd.js" > </ script >
< script src = "https://unpkg.com/@esri/arcgis-rest-feature-service@4.0.0/dist/bundled/feature-service.umd.js" > </ script >
Add the trailheads layer Use arcgis Rest.query Features
to query the Trailheads URL and add features to the scene as GeoJSON.
In the <body>
, create an arcgis Rest.Api K e y Manager
using your API key to authenticate requests to the feature service .
Expand
Use dark colors for code blocks
Add line.
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
const apiKey = "YOUR_API_KEY" ;
Cesium.ArcGisMapService.defaultAccessToken = apiKey;
const authentication = arcgisRest.ApiKeyManager.fromKey(apiKey);
Use arcgis Rest.query Features
to make an authenticated request to the Trailheads feature service. Set the f
property to geojson
to format the response as GeoJSON.
Expand
Use dark colors for code blocks
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
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
destination : Cesium.Cartesian3.fromDegrees(- 118.705 , 33.957 , 35000 ),
orientation : {
heading : Cesium.Math.toRadians( 0.0 ),
pitch : Cesium.Math.toRadians(- 70.0 ),
}
});
const trailheadsURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0" ;
arcgisRest.queryFeatures({
url : trailheadsURL,
authentication,
f : "geojson"
}).then( ( response ) => {
})
Load the features into your scene using a Geo Json Data Source
Expand
Use dark colors for code blocks
Add line. Add line. Add line. Add line. Add line. Add line.
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
const trailheadsURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0" ;
arcgisRest.queryFeatures({
url : trailheadsURL,
authentication,
f : "geojson"
}).then( ( response ) => {
Cesium.GeoJsonDataSource.load(response,{
clampToGround : true ,
markerColor : Cesium.Color.fromCssColorString( '#5491f5' ),
}).then( ( data )=> {
viewer.dataSources.add(data);
})
})
Customize the pop-up Cesium automatically creates popups for GeoJSON layers using the properties
of each feature. You can set the title
and description
properties of each feature to customize the popup content.
Access the GeoJSON response from arcgis Rest.query Features
and iterate through each feature. Set the title
property of each trailhead to the trail name (TRL_ NAME
).
Expand
Use dark colors for code blocks
Add line. Add line. Add line. Add line. Add line.
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
const trailheadsURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0" ;
arcgisRest.queryFeatures({
url : trailheadsURL,
authentication,
f : "geojson"
}).then( ( response ) => {
for ( let i= 0 ; i<response.features.length; i++) {
let feature = response.features[i];
feature.properties.title = feature.properties.TRL_NAME;
}
Cesium.GeoJsonDataSource.load(response,{
clampToGround : true ,
markerColor : Cesium.Color.fromCssColorString( '#5491f5' ),
}).then( ( data )=> {
viewer.dataSources.add(data);
})
})
Set the description
property of each trailhead to include additional feature attributes .
Expand
Use dark colors for code blocks
Add line. Add line. Add line.
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
for ( let i= 0 ; i<response.features.length; i++) {
let feature = response.features[i];
feature.properties.title = feature.properties.TRL_NAME;
feature.properties.description = `<b> ${feature.properties.PARK_NAME} </b><br>
Zip code: ${feature.properties.ZIP_CODE} <br>
Elevation: ${feature.properties.ELEV_FT} ft`
}
Run the app In CodePen , run your code to display the map.
You should see the trailheads feature layer represented as points in the scene. Click on a trailhead to open a pop-up that displays information about it.
What's next? Learn how to use additional ArcGIS location services in these tutorials: