-
Notifications
You must be signed in to change notification settings - Fork 525
/
Copy pathFeatureLayerDictionaryRenderer.xaml.cs
103 lines (84 loc) · 4.18 KB
/
FeatureLayerDictionaryRenderer.xaml.cs
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
// Copyright 2022 Esri.
//
// 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
// language governing permissions and limitations under the License.
using ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
namespace ArcGIS.Samples.FeatureLayerDictionaryRenderer
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Dictionary renderer with feature layer",
category: "Layers",
description: "Convert features into graphics to show them with mil2525d symbols.",
instructions: "Pan and zoom around the map. Observe the displayed military symbology on the map.",
tags: new[] { "military", "symbol" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData("c78b149a1d52414682c86a5feeb13d30", "e0d41b4b409a49a5a7ba11939d8535dc")]
public partial class FeatureLayerDictionaryRenderer : ContentPage
{
public FeatureLayerDictionaryRenderer()
{
InitializeComponent();
// Setup the control references and execute initialization
_ = Initialize();
}
private async Task Initialize()
{
// Create new Map with basemap
Map myMap = new Map(BasemapStyle.ArcGISTopographic);
// Provide Map to the MapView
MyMapView.Map = myMap;
// Get the path to the geodatabase
string geodbFilePath = GetGeodatabasePath();
// Load the geodatabase from local storage
Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);
// Get the path to the symbol dictionary
string symbolFilepath = GetStyleDictionaryPath();
try
{
// Load the symbol dictionary from local storage
DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.CreateFromFileAsync(symbolFilepath);
// Add geodatabase features to the map, using the defined symbology
foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
{
// Load the table
await table.LoadAsync();
// Create the feature layer from the table
FeatureLayer myLayer = new FeatureLayer(table);
// Load the layer
await myLayer.LoadAsync();
// Create a Dictionary Renderer using the DictionarySymbolStyle
DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);
// Apply the dictionary renderer to the layer
myLayer.Renderer = dictRenderer;
// Add the layer to the map
myMap.OperationalLayers.Add(myLayer);
}
// Create geometry for the center of the map
MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));
// Set the map's viewpoint to highlight the desired content
MyMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555));
}
catch (Exception e)
{
await Application.Current.Windows[0].Page.DisplayAlert("Error", e.ToString(), "OK");
}
}
// Get the file path for the style dictionary
private string GetStyleDictionaryPath()
{
return DataManager.GetDataFolder("c78b149a1d52414682c86a5feeb13d30", "mil2525d.stylx");
}
// Get the file path for the geodatabase
private string GetGeodatabasePath()
{
return DataManager.GetDataFolder("e0d41b4b409a49a5a7ba11939d8535dc", "militaryoverlay.geodatabase");
}
}
}