Use a custom dictionary style created from a web style or local style file (.stylx) to symbolize features using a variety of attribute values.
Use case
When symbolizing geoelements in your map, you may need to convey several pieces of information with a single symbol. You could try to symbolize such data using a unique value renderer, but as the number of fields and values increases, that approach becomes impractical. With a dictionary renderer you can build each symbol on-the-fly, driven by one or more attribute values, and handle a nearly infinite number of unique combinations.
How to use the sample
Use the radio buttons to toggle between the dictionary symbols from the web style and style file. Pan and zoom around the map to see the symbology from the chosen dictionary symbol style. The web style and style file are slightly different to each other to give a visual indication of the switch between the two.
How it works
Create a DictionarySymbolStyle from a local .stylx file.
Create a DictionaryRenderer from this dictionary symbol style.
Create a PortalItem, referring to a Portal and the item ID of the web style.
Create a DictionarySymbolStyle from this portal item.
Create a DictionaryRenderer from this dictionary symbol style.
Based on the style selected, use featureLayer.setRenderer(...) to the correct dictionary symbol style.
Relevant API
DictionaryRenderer
DictionarySymbolStyle
Portal
PortalItem
About the data
The data used in this sample is from a feature layer showing a subset of restaurants in Redlands, CA hosted as a feature service with attributes for rating, style, health score, and open hours.
The feature layer is symbolized using a dictionary renderer that displays a single symbol for all of these variables. The renderer uses symbols from a custom restaurant dictionary style created from a stylx file and a web style, available as items from ArcGIS Online, to show unique symbols based on several feature attributes. The symbols it contains were created using ArcGIS Pro. The logic used to apply the symbols comes from an Arcade script embedded in the stylx file (which is a SQLite database), along with a JSON string that defines expected attribute names and configuration properties.
Additional information
For information about creating your own custom dictionary style, see the open source dictionary renderer toolkit on GitHub.
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
package com.esri.arcgisruntime.sample.customdictionarystyle
import android.os.Bundle
import android.widget.RadioButton
import androidx.appcompat.app.AppCompatActivity
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
import com.esri.arcgisruntime.data.ServiceFeatureTable
import com.esri.arcgisruntime.layers.FeatureLayer
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.BasemapStyle
import com.esri.arcgisruntime.mapping.Viewpoint
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.sample.customdictionarystyle.databinding.ActivityMainBinding
import com.esri.arcgisruntime.portal.Portal
import com.esri.arcgisruntime.portal.PortalItem
import com.esri.arcgisruntime.symbology.DictionaryRenderer
import com.esri.arcgisruntime.symbology.DictionarySymbolStyle
classMainActivity : AppCompatActivity() {
privateval activityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
privateval mapView: MapView by lazy {
activityMainBinding.mapView
}
privateval styleFileRadioButton: RadioButton by lazy {
activityMainBinding.styleControlsLayout.styleFileRadioButton
}
privateval webStyleRadioButton: RadioButton by lazy {
activityMainBinding.styleControlsLayout.webStyleRadioButton
}
overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(activityMainBinding.root)
// authentication with an API key or named user is required to access basemaps and other// location services ArcGISRuntimeEnvironment.setApiKey(BuildConfig.API_KEY)
// create a feature layer from a service feature tableval featureTable =
ServiceFeatureTable("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0")
val featureLayer = FeatureLayer(featureTable)
// create a new map with a streets basemap and set it to the map view mapView.map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC).apply {
// add the the feature layer to the map's operational layers operationalLayers.add(featureLayer)
// set the initial viewpoint to the Esri Redlands campus initialViewpoint = Viewpoint(34.0574, -117.1963, 5000.0)
}
// create a dictionary symbol style from the stylx fileval dictionarySymbolStyleFromFile =
DictionarySymbolStyle.createFromFile(getExternalFilesDir(null)?.path + "/Restaurant.stylx")
// create a new dictionary renderer from the dictionary symbol styleval dictionaryRendererFromFile = DictionaryRenderer(dictionarySymbolStyleFromFile)
// on style file click styleFileRadioButton.setOnClickListener {
// set the feature layer renderer to the dictionary renderer from local stylx file featureLayer.renderer = dictionaryRendererFromFile
}
// set the initial state to use the dictionary renderer from local stylx file styleFileRadioButton.performClick()
// create a portal item using the portal and the item id of the dictionary web styleval portal = Portal("https://arcgisruntime.maps.arcgis.com")
val portalItem = PortalItem(portal, "adee951477014ec68d7cf0ea0579c800")
// map the input fields in the feature layer to the dictionary symbol style's expected fields for symbols and textval fieldMap: HashMap<String, String> = HashMap()
fieldMap["healthgrade"] = "Inspection"// create a new dictionary symbol style from the web style in the portal itemval dictionarySymbolStyleFromPortal = DictionarySymbolStyle(portalItem)
// create a new dictionary renderer from the dictionary symbol styleval dictionaryRendererFromPortal =
DictionaryRenderer(dictionarySymbolStyleFromPortal, fieldMap, HashMap())
// on web style click webStyleRadioButton.setOnClickListener {
// set the feature layer renderer to the dictionary renderer from portal featureLayer.renderer = dictionaryRendererFromPortal
}
}
overridefunonPause() {
mapView.pause()
super.onPause()
}
overridefunonResume() {
super.onResume()
mapView.resume()
}
overridefunonDestroy() {
mapView.dispose()
super.onDestroy()
}
}