Skip to content

Commit

Permalink
Simplified custom dictionary style sample (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackAllen authored Nov 11, 2019
1 parent 25611f0 commit 71baaae
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
using Android.OS;
using Android.Widget;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;

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

// The custom dictionary style for symbolizing restaurants.
private DictionarySymbolStyle _restaurantStyle;

// Uri for the restaurants feature service.
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");

Expand All @@ -56,9 +50,6 @@ private async void Initialize()
{
try
{
// Open the custom style file.
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create a new map with a streets basemap.
Map map = new Map(Basemap.CreateStreets());

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

// Load the feature table for the restaurants layer.
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
await restaurantTable.LoadAsync();
await restaurantLayer.FeatureTable.LoadAsync();

// Open the custom style file.
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);

// Set the restaurant layer renderer to the dictionary renderer.
restaurantLayer.Renderer = dictRenderer;

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

// Set the map to the map view.
_myMapView.Map = map;

// Apply the custom dictionary to the restaurant feature layer.
ApplyCustomDictionary();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

public void ApplyCustomDictionary()
{
// Create overrides for expected field names that are different in this dataset.
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
styleToFieldMappingOverrides.Add("style", "Style");
styleToFieldMappingOverrides.Add("price", "Price");
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
styleToFieldMappingOverrides.Add("rating", "Rating");

// Create overrides for expected text field names (if any).
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
textFieldOverrides.Add("name", "Name");

// Set the text visibility configuration setting.
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);

// Apply the dictionary renderer to the layer.
FeatureLayer restaurantLayer = _myMapView.Map.OperationalLayers.First() as FeatureLayer;
restaurantLayer.Renderer = dictRenderer;
}

private void CreateLayout()
{
// Create a new vertical layout for the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
## How it works

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

## Relevant API

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

using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;

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

// The custom dictionary style for symbolizing restaurants.
private DictionarySymbolStyle _restaurantStyle;

// Uri for the restaurants feature service.
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");

Expand All @@ -45,9 +39,6 @@ private async void Initialize()
{
try
{
// Open the custom style file.
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create a new map with a streets basemap.
Map map = new Map(Basemap.CreateStreets());

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

// Load the feature table for the restaurants layer.
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
await restaurantTable.LoadAsync();
await restaurantLayer.FeatureTable.LoadAsync();

// Open the custom style file.
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);

// Set the restaurant layer renderer to the dictionary renderer.
restaurantLayer.Renderer = dictRenderer;

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

// Set the map to the map view.
MyMapView.Map = map;

// Apply the custom dictionary to the restaurant feature layer.
ApplyCustomDictionary();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void ApplyCustomDictionary()
{
// Create overrides for expected field names that are different in this dataset.
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
styleToFieldMappingOverrides.Add("style", "Style");
styleToFieldMappingOverrides.Add("price", "Price");
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
styleToFieldMappingOverrides.Add("rating", "Rating");

// Create overrides for expected text field names (if any).
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
textFieldOverrides.Add("name", "Name");

// Set the text visibility configuration setting.
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);

// Apply the dictionary renderer to the layer.
FeatureLayer restaurantLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;
restaurantLayer.Renderer = dictRenderer;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
## How it works

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

## Relevant API

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

using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Collections.Generic;
using System.Linq;

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

// The custom dictionary style for symbolizing restaurants.
private DictionarySymbolStyle _restaurantStyle;

// Uri for the restaurants feature service.
private readonly Uri _restaurantUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/Redlands_Restaurants/FeatureServer/0");

Expand All @@ -44,9 +38,6 @@ private async void Initialize()
{
try
{
// Open the custom style file.
_restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create a new map with a streets basemap.
Map map = new Map(Basemap.CreateStreetsVector());

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

// Load the feature table for the restaurants layer.
FeatureTable restaurantTable = restaurantLayer.FeatureTable;
await restaurantTable.LoadAsync();
await restaurantLayer.FeatureTable.LoadAsync();

// Open the custom style file.
DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);

// Set the restaurant layer renderer to the dictionary renderer.
restaurantLayer.Renderer = dictRenderer;

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

// Set the map to the map view.
MyMapView.Map = map;

// Apply the custom dictionary to the restaurant feature layer.
ApplyCustomDictionary();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

public void ApplyCustomDictionary()
{
// Create overrides for expected field names that are different in this dataset.
Dictionary<string, string> styleToFieldMappingOverrides = new Dictionary<string, string>();
styleToFieldMappingOverrides.Add("style", "Style");
styleToFieldMappingOverrides.Add("price", "Price");
styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
styleToFieldMappingOverrides.Add("rating", "Rating");

// Create overrides for expected text field names (if any).
Dictionary<string, string> textFieldOverrides = new Dictionary<string, string>();
textFieldOverrides.Add("name", "Name");

// Set the text visibility configuration setting.
_restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";

// Create the dictionary renderer with the style file and the field overrides.
DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);

// Apply the dictionary renderer to the layer.
FeatureLayer restaurantLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;
restaurantLayer.Renderer = dictRenderer;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ Pan and zoom the map to see the symbology from the custom dictionary style.
## How it works

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

## Relevant API

Expand Down
Loading

0 comments on commit 71baaae

Please sign in to comment.