forked from Esri/arcgis-maps-sdk-dotnet-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeSublayerRenderer.cs
147 lines (123 loc) · 7.58 KB
/
ChangeSublayerRenderer.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2018 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 System;
using System.Collections.Generic;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI.Controls;
using Foundation;
using UIKit;
namespace ArcGISRuntime.Samples.ChangeSublayerRenderer
{
[Register("ChangeSublayerRenderer")]
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
"Change sublayer renderer",
"Layers",
"This sample demonstrates how to change the sub-layer renderer of an ArcGIS map image layer. A unique value renderer is applied to see different population ranges in the counties sub-layer data.",
"Click the 'Change Sublayer Renderer' button to apply a unique value renderer to the counties sub-layer.",
"")]
public class ChangeSublayerRenderer : UIViewController
{
// Hold references to the UI controls.
private MapView _myMapView;
// ArcGIS map image layer that contains four Census sub-layers.
private ArcGISMapImageLayer _arcGISMapImageLayer;
public ChangeSublayerRenderer()
{
Title = "Change sublayer renderer";
}
private void Initialize()
{
// Create a new map based on the streets base map.
Map newMap = new Map(Basemap.CreateStreets());
// Create an envelope that covers the continental US in the web Mercator spatial reference.
Envelope continentalUSEnvelope = new Envelope(-14193469.5655232, 2509617.28647268, -7228772.04749191, 6737139.97573925, SpatialReferences.WebMercator);
// Zoom the map to the extent of the envelope.
newMap.InitialViewpoint = new Viewpoint(continentalUSEnvelope);
// Assign the map to the MapView.
_myMapView.Map = newMap;
// Create an ArcGIS map image layer based on the Uri to that points to an ArcGIS Server map service that contains four Census sub-layers.
// NOTE: sub-layer[0] = Census Block Points, sub-layer[1] = Census Block Group, sub-layer[3] = Counties, sub-layer[3] = States.
_arcGISMapImageLayer = new ArcGISMapImageLayer(new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer"));
// Add the ArcGIS map image layer to the map's operation layers collection.
newMap.OperationalLayers.Add(_arcGISMapImageLayer);
}
private ClassBreaksRenderer CreateClassBreaksRenderer()
{
// Define the colors that will be used by the unique value renderer.
System.Drawing.Color gray = System.Drawing.Color.FromArgb(255, 153, 153, 153);
System.Drawing.Color blue1 = System.Drawing.Color.FromArgb(255, 227, 235, 207);
System.Drawing.Color blue2 = System.Drawing.Color.FromArgb(255, 150, 194, 191);
System.Drawing.Color blue3 = System.Drawing.Color.FromArgb(255, 97, 166, 181);
System.Drawing.Color blue4 = System.Drawing.Color.FromArgb(255, 69, 125, 150);
System.Drawing.Color blue5 = System.Drawing.Color.FromArgb(255, 41, 84, 120);
// Create a gray outline and five fill symbols with different shades of blue.
SimpleLineSymbol outlineSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, gray, 1);
SimpleFillSymbol simpleFileSymbol1 = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blue1, outlineSimpleLineSymbol);
SimpleFillSymbol simpleFileSymbol2 = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blue2, outlineSimpleLineSymbol);
SimpleFillSymbol simpleFileSymbol3 = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blue3, outlineSimpleLineSymbol);
SimpleFillSymbol simpleFileSymbol4 = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blue4, outlineSimpleLineSymbol);
SimpleFillSymbol simpleFileSymbol5 = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blue5, outlineSimpleLineSymbol);
// Create a list of five class breaks for different population ranges.
List<ClassBreak> listClassBreaks = new List<ClassBreak>
{
new ClassBreak("-99 to 8560", "-99 to 8560", -99, 8560, simpleFileSymbol1),
new ClassBreak("> 8,560 to 18,109", "> 8,560 to 18,109", 8560, 18109, simpleFileSymbol2),
new ClassBreak("> 18,109 to 35,501", "> 18,109 to 35,501", 18109, 35501, simpleFileSymbol3),
new ClassBreak("> 35,501 to 86,100", "> 35,501 to 86,100", 35501, 86100, simpleFileSymbol4),
new ClassBreak("> 86,100 to 10,110,975", "> 86,100 to 10,110,975", 86100, 10110975, simpleFileSymbol5)
};
// Create and return the a class break renderer for use with the POP2007 field in the counties sub-layer.
return new ClassBreaksRenderer("POP2007", listClassBreaks);
}
private void ChangeSublayerRendererButton_TouchUpInside(object sender, EventArgs e)
{
// Get the counties sub-layer (the 3rd layer) from the ArcGIS map image layer.
ArcGISMapImageSublayer countiesArcGISMapImageSubLayer = (ArcGISMapImageSublayer) _arcGISMapImageLayer.Sublayers[2];
// Set the renderer of the ArcGIS map image sub-layer to a class break renderer based on population.
countiesArcGISMapImageSubLayer.Renderer = CreateClassBreaksRenderer();
// Disable the button after has been used.
((UIBarButtonItem) sender).Enabled = false;
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
Initialize();
}
public override void LoadView()
{
// Create the views.
View = new UIView {BackgroundColor = UIColor.White};
_myMapView = new MapView();
_myMapView.TranslatesAutoresizingMaskIntoConstraints = false;
UIToolbar toolbar = new UIToolbar();
toolbar.TranslatesAutoresizingMaskIntoConstraints = false;
toolbar.Items = new[]
{
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
new UIBarButtonItem("Change sublayer renderer", UIBarButtonItemStyle.Plain, ChangeSublayerRendererButton_TouchUpInside),
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
};
// Add the views.
View.AddSubviews(_myMapView, toolbar);
// Lay out the views.
NSLayoutConstraint.ActivateConstraints(new[]
{
_myMapView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
_myMapView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
_myMapView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
_myMapView.BottomAnchor.ConstraintEqualTo(toolbar.TopAnchor),
toolbar.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor),
toolbar.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
toolbar.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
});
}
}
}