Skip to content

Commit 71baaae

Browse files
authored
Simplified custom dictionary style sample (#709)
1 parent 25611f0 commit 71baaae

File tree

10 files changed

+66
-220
lines changed

10 files changed

+66
-220
lines changed

src/Android/Xamarin.Android/Samples/Symbology/CustomDictionaryStyle/CustomDictionaryStyle.cs

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
using Android.OS;
1212
using Android.Widget;
1313
using ArcGISRuntime.Samples.Managers;
14-
using Esri.ArcGISRuntime.Data;
1514
using Esri.ArcGISRuntime.Mapping;
1615
using Esri.ArcGISRuntime.Symbology;
1716
using Esri.ArcGISRuntime.UI.Controls;
1817
using System;
19-
using System.Collections.Generic;
20-
using System.Linq;
2118

2219
namespace ArcGISRuntimeXamarin.Samples.CustomDictionaryStyle
2320
{
@@ -36,9 +33,6 @@ public class CustomDictionaryStyle : Activity
3633
// Path for the restaurants style file.
3734
private readonly string _stylxPath = DataManager.GetDataFolder("751138a2e0844e06853522d54103222a", "Restaurant.stylx");
3835

39-
// The custom dictionary style for symbolizing restaurants.
40-
private DictionarySymbolStyle _restaurantStyle;
41-
4236
// Uri for the restaurants feature service.
4337
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");
4438

@@ -56,9 +50,6 @@ private async void Initialize()
5650
{
5751
try
5852
{
59-
// Open the custom style file.
60-
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
61-
6253
// Create a new map with a streets basemap.
6354
Map map = new Map(Basemap.CreateStreets());
6455

@@ -67,48 +58,29 @@ private async void Initialize()
6758
map.OperationalLayers.Add(restaurantLayer);
6859

6960
// Load the feature table for the restaurants layer.
70-
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
71-
await restaurantTable.LoadAsync();
61+
await restaurantLayer.FeatureTable.LoadAsync();
62+
63+
// Open the custom style file.
64+
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
65+
66+
// Create the dictionary renderer with the style file and the field overrides.
67+
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);
68+
69+
// Set the restaurant layer renderer to the dictionary renderer.
70+
restaurantLayer.Renderer = dictRenderer;
7271

7372
// Set the map's initial extent to that of the restaurants.
7473
map.InitialViewpoint = new Viewpoint(restaurantLayer.FullExtent);
7574

7675
// Set the map to the map view.
7776
_myMapView.Map = map;
78-
79-
// Apply the custom dictionary to the restaurant feature layer.
80-
ApplyCustomDictionary();
8177
}
8278
catch (Exception ex)
8379
{
8480
Console.WriteLine(ex.Message);
8581
}
8682
}
8783

88-
public void ApplyCustomDictionary()
89-
{
90-
// Create overrides for expected field names that are different in this dataset.
91-
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
92-
styleToFieldMappingOverrides.Add("style", "Style");
93-
styleToFieldMappingOverrides.Add("price", "Price");
94-
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
95-
styleToFieldMappingOverrides.Add("rating", "Rating");
96-
97-
// Create overrides for expected text field names (if any).
98-
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
99-
textFieldOverrides.Add("name", "Name");
100-
101-
// Set the text visibility configuration setting.
102-
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";
103-
104-
// Create the dictionary renderer with the style file and the field overrides.
105-
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);
106-
107-
// Apply the dictionary renderer to the layer.
108-
FeatureLayer restaurantLayer = _myMapView.Map.OperationalLayers.First() as FeatureLayer;
109-
restaurantLayer.Renderer = dictRenderer;
110-
}
111-
11284
private void CreateLayout()
11385
{
11486
// Create a new vertical layout for the app.

src/Android/Xamarin.Android/Samples/Symbology/CustomDictionaryStyle/readme.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
1515
## How it works
1616

1717
1. Create a new `DictionarySymbolStyle` by passing in the path to the custom style (.stylx).
18-
2. Define symbol attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
19-
3. Define text attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
20-
4. If necessary, provide new values for configuration settings defined in `DictionarySymbolStyle.Configurations`.
21-
5. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle and (optionally) the collection of symbol and text attribute overrides.
22-
6. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
18+
2. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle.
19+
3. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
2320

2421
## Relevant API
2522

src/Forms/Shared/Samples/Symbology/CustomDictionaryStyle/CustomDictionaryStyle.xaml.cs

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
55
//
6-
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
6+
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
88
// language governing permissions and limitations under the License.
99

1010
using ArcGISRuntime.Samples.Managers;
11-
using Esri.ArcGISRuntime.Data;
1211
using Esri.ArcGISRuntime.Mapping;
1312
using Esri.ArcGISRuntime.Symbology;
1413
using System;
15-
using System.Collections.Generic;
16-
using System.Linq;
1714
using Xamarin.Forms;
1815

1916
namespace ArcGISRuntimeXamarin.Samples.CustomDictionaryStyle
@@ -29,9 +26,6 @@ public partial class CustomDictionaryStyle : ContentPage
2926
// Path for the restaurants style file.
3027
private readonly string _stylxPath = DataManager.GetDataFolder("751138a2e0844e06853522d54103222a", "Restaurant.stylx");
3128

32-
// The custom dictionary style for symbolizing restaurants.
33-
private DictionarySymbolStyle _restaurantStyle;
34-
3529
// Uri for the restaurants feature service.
3630
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");
3731

@@ -45,9 +39,6 @@ private async void Initialize()
4539
{
4640
try
4741
{
48-
// Open the custom style file.
49-
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
50-
5142
// Create a new map with a streets basemap.
5243
Map map = new Map(Basemap.CreateStreets());
5344

@@ -56,45 +47,27 @@ private async void Initialize()
5647
map.OperationalLayers.Add(restaurantLayer);
5748

5849
// Load the feature table for the restaurants layer.
59-
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
60-
await restaurantTable.LoadAsync();
50+
await restaurantLayer.FeatureTable.LoadAsync();
51+
52+
// Open the custom style file.
53+
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
54+
55+
// Create the dictionary renderer with the style file and the field overrides.
56+
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);
57+
58+
// Set the restaurant layer renderer to the dictionary renderer.
59+
restaurantLayer.Renderer = dictRenderer;
6160

6261
// Set the map's initial extent to that of the restaurants.
6362
map.InitialViewpoint = new Viewpoint(restaurantLayer.FullExtent);
6463

6564
// Set the map to the map view.
6665
MyMapView.Map = map;
67-
68-
// Apply the custom dictionary to the restaurant feature layer.
69-
ApplyCustomDictionary();
7066
}
7167
catch (Exception ex)
7268
{
7369
Console.WriteLine(ex.Message);
7470
}
7571
}
76-
public void ApplyCustomDictionary()
77-
{
78-
// Create overrides for expected field names that are different in this dataset.
79-
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
80-
styleToFieldMappingOverrides.Add("style", "Style");
81-
styleToFieldMappingOverrides.Add("price", "Price");
82-
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
83-
styleToFieldMappingOverrides.Add("rating", "Rating");
84-
85-
// Create overrides for expected text field names (if any).
86-
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
87-
textFieldOverrides.Add("name", "Name");
88-
89-
// Set the text visibility configuration setting.
90-
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";
91-
92-
// Create the dictionary renderer with the style file and the field overrides.
93-
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);
94-
95-
// Apply the dictionary renderer to the layer.
96-
FeatureLayer restaurantLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;
97-
restaurantLayer.Renderer = dictRenderer;
98-
}
9972
}
100-
}
73+
}

src/Forms/Shared/Samples/Symbology/CustomDictionaryStyle/readme.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
1515
## How it works
1616

1717
1. Create a new `DictionarySymbolStyle` by passing in the path to the custom style (.stylx).
18-
2. Define symbol attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
19-
3. Define text attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
20-
4. If necessary, provide new values for configuration settings defined in `DictionarySymbolStyle.Configurations`.
21-
5. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle and (optionally) the collection of symbol and text attribute overrides.
22-
6. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
18+
2. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle.
19+
3. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
2320

2421
## Relevant API
2522

src/UWP/ArcGISRuntime.UWP.Viewer/Samples/Symbology/CustomDictionaryStyle/CustomDictionaryStyle.xaml.cs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
55
//
6-
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
6+
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
88
// language governing permissions and limitations under the License.
99

1010
using ArcGISRuntime.Samples.Managers;
11-
using Esri.ArcGISRuntime.Data;
1211
using Esri.ArcGISRuntime.Mapping;
1312
using Esri.ArcGISRuntime.Symbology;
1413
using System;
15-
using System.Collections.Generic;
16-
using System.Linq;
1714

1815
namespace ArcGISRuntime.UWP.Samples.CustomDictionaryStyle
1916
{
@@ -28,9 +25,6 @@ public partial class CustomDictionaryStyle
2825
// Path for the restaurants style file.
2926
private readonly string _stylxPath = DataManager.GetDataFolder("751138a2e0844e06853522d54103222a", "Restaurant.stylx");
3027

31-
// The custom dictionary style for symbolizing restaurants.
32-
private DictionarySymbolStyle _restaurantStyle;
33-
3428
// Uri for the restaurants feature service.
3529
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");
3630

@@ -44,9 +38,6 @@ private async void Initialize()
4438
{
4539
try
4640
{
47-
// Open the custom style file.
48-
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
49-
5041
// Create a new map with a streets basemap.
5142
Map map = new Map(Basemap.CreateStreetsVector());
5243

@@ -55,46 +46,27 @@ private async void Initialize()
5546
map.OperationalLayers.Add(restaurantLayer);
5647

5748
// Load the feature table for the restaurants layer.
58-
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
59-
await restaurantTable.LoadAsync();
49+
await restaurantLayer.FeatureTable.LoadAsync();
50+
51+
// Open the custom style file.
52+
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);
53+
54+
// Create the dictionary renderer with the style file and the field overrides.
55+
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);
56+
57+
// Set the restaurant layer renderer to the dictionary renderer.
58+
restaurantLayer.Renderer = dictRenderer;
6059

6160
// Set the map's initial extent to that of the restaurants.
6261
map.InitialViewpoint = new Viewpoint(restaurantLayer.FullExtent);
6362

6463
// Set the map to the map view.
6564
MyMapView.Map = map;
66-
67-
// Apply the custom dictionary to the restaurant feature layer.
68-
ApplyCustomDictionary();
6965
}
7066
catch (Exception ex)
7167
{
7268
Console.WriteLine(ex.Message);
7369
}
7470
}
75-
76-
public void ApplyCustomDictionary()
77-
{
78-
// Create overrides for expected field names that are different in this dataset.
79-
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
80-
styleToFieldMappingOverrides.Add("style", "Style");
81-
styleToFieldMappingOverrides.Add("price", "Price");
82-
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
83-
styleToFieldMappingOverrides.Add("rating", "Rating");
84-
85-
// Create overrides for expected text field names (if any).
86-
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
87-
textFieldOverrides.Add("name", "Name");
88-
89-
// Set the text visibility configuration setting.
90-
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";
91-
92-
// Create the dictionary renderer with the style file and the field overrides.
93-
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);
94-
95-
// Apply the dictionary renderer to the layer.
96-
FeatureLayer restaurantLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;
97-
restaurantLayer.Renderer = dictRenderer;
98-
}
9971
}
100-
}
72+
}

src/UWP/ArcGISRuntime.UWP.Viewer/Samples/Symbology/CustomDictionaryStyle/readme.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
1515
## How it works
1616

1717
1. Create a new `DictionarySymbolStyle` by passing in the path to the custom style (.stylx).
18-
2. Define symbol attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
19-
3. Define text attribute overrides (if any) using a collection of key-value pairs: configured attribute name , override attribute name.
20-
4. If necessary, provide new values for configuration settings defined in `DictionarySymbolStyle.Configurations`.
21-
5. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle and (optionally) the collection of symbol and text attribute overrides.
22-
6. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
18+
2. Create a new `DictionaryRenderer`, providing the DictionarySymbolStyle.
19+
3. Apply the dictionary renderer to a feature layer or graphics overlay with the expected attributes.
2320

2421
## Relevant API
2522

0 commit comments

Comments
 (0)