-
Notifications
You must be signed in to change notification settings - Fork 203
/
ColorMappings.cs
214 lines (185 loc) · 8.13 KB
/
ColorMappings.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using Com.Syncfusion.Maps;
using Org.Json;
using System.Collections.Generic;
using Android.Graphics;
using Android.Widget;
using Android.OS;
using Com.Syncfusion.Sfbusyindicator;
using Com.Syncfusion.Sfbusyindicator.Enums;
using Android.Content;
using Android.Views;
namespace SampleBrowser
{
public class ColorMappings : SamplePage
{
SfMaps maps;
Handler handler;
public override Android.Views.View GetSampleContent (Android.Content.Context context)
{
handler = new Handler();
LinearLayout layout = new LinearLayout(context);
TextView textView = new TextView(context);
textView.TextSize = 16;
textView.SetPadding(10, 20, 0, 0);
textView.SetHeight(90);
textView.Text = "Primary Agricultural Activity of USA";
layout.AddView(textView);
textView.Gravity = Android.Views.GravityFlags.Top;
layout.Orientation = Orientation.Vertical;
maps = new SfMaps (context);
ShapeFileLayer layer = new ShapeFileLayer();
layer.Uri ="usa_state.shp";
layer.ShapeIdTableField ="STATE_NAME";
layer.ShapeIdPath ="Name";
layer.DataSource = GetDataSource ();
layer.ShapeSettings.ShapeColorValuePath = "Type";
layer.ShapeSettings.ShapeFill = Color.ParseColor("#A9D9F7");
SetColorMapping(layer.ShapeSettings);
LayerCustomTooltipSetting layerCustomTooltip = new LayerCustomTooltipSetting(context);
layerCustomTooltip.ShowTooltip = true;
layer.TooltipSettings = layerCustomTooltip;
layer.LegendSetting = new LegendSetting (){ ShowLegend = true, ItemMargin = 0 };
maps.Layers.Add (layer);
SfBusyIndicator sfBusyIndicator = new SfBusyIndicator(context);
sfBusyIndicator.IsBusy = true;
sfBusyIndicator.AnimationType = AnimationTypes.SlicedCircle;
sfBusyIndicator.ViewBoxWidth = 50;
sfBusyIndicator.ViewBoxHeight = 50;
sfBusyIndicator.TextColor = Color.ParseColor("#779772");
layout.AddView(sfBusyIndicator);
Java.Lang.Runnable run = new Java.Lang.Runnable(() =>
{
layout.RemoveView(sfBusyIndicator);
layout.AddView(maps);
});
handler.PostDelayed(run, 100);
return layout;
}
JSONArray GetDataSource()
{
JSONArray array = new JSONArray ();
array.Put(getJsonObject("Alabama", "Vegetables", 9 ));
array.Put(getJsonObject( "Alaska", "Vegetables", 3 ));
array.Put(getJsonObject( "Arizona", "Rice", 11 ));
array.Put(getJsonObject( "Arkansas", "Vegetables", 6 ));
array.Put(getJsonObject( "California", "Rice", 55 ));
array.Put(getJsonObject( "Colorado", "Rice", 9 ));
array.Put(getJsonObject( "Connecticut", "Grains", 7 ));
array.Put(getJsonObject( "Delaware", "Grains", 3 ));
array.Put(getJsonObject( "District of Columbia", "Grains", 3 ));
array.Put(getJsonObject( "Florida", "Rice", 29 ));
array.Put(getJsonObject( "Georgia", "Rice", 16 ));
array.Put(getJsonObject( "Hawaii", "Grains", 4 ));
array.Put(getJsonObject( "Idaho", "Grains", 4 ));
array.Put(getJsonObject( "Illinois", "Vegetables", 20 ));
array.Put(getJsonObject( "Indiana", "Grains", 11 ));
array.Put(getJsonObject( "Iowa", "Vegetables", 6 ));
array.Put(getJsonObject( "Kansas", "Rice", 6 ));
array.Put(getJsonObject( "Kentucky", "Grains", 8 ));
array.Put(getJsonObject( "Louisiana", "Rice", 8 ));
array.Put(getJsonObject( "Maine", "Grains", 4 ));
array.Put(getJsonObject( "Maryland", "Grains", 10 ));
array.Put(getJsonObject( "Massachusetts", "Grains", 11 ));
array.Put(getJsonObject( "Michigan", "Grains", 16 ));
array.Put(getJsonObject( "Minnesota", "Wheat", 10 ));
array.Put(getJsonObject( "Mississippi", "Vegetables", 6 ));
array.Put(getJsonObject( "Missouri", "Vegetables", 10 ));
array.Put(getJsonObject( "Montana", "Grains", 3 ));
array.Put(getJsonObject( "Nebraska", "Rice", 5 ));
array.Put(getJsonObject( "Nevada", "Wheat", 6 ));
array.Put(getJsonObject( "New Hampshire", "Grains", 4 ));
array.Put(getJsonObject( "New Jersey", "Vegetables", 14 ));
array.Put(getJsonObject( "New Mexico", "Rice", 5 ));
array.Put(getJsonObject( "New York", "Vegetables", 29 ));
array.Put(getJsonObject( "North Carolina", "Rice", 15 ));
array.Put(getJsonObject( "North Dakota", "Grains", 3 ));
array.Put(getJsonObject( "Ohio", "Vegetables", 18 ));
array.Put(getJsonObject( "Oklahoma", "Rice", 7 ));
array.Put(getJsonObject( "Oregon", "Wheat", 7 ));
array.Put(getJsonObject( "Pennsylvania", "Vegetables", 20 ));
array.Put(getJsonObject( "Rhode Island", "Grains", 4 ));
array.Put(getJsonObject( "South Carolina", "Rice", 9 ));
array.Put(getJsonObject( "South Dakota", "Grains", 3 ));
array.Put(getJsonObject( "Tennessee", "Vegetables", 11 ));
array.Put(getJsonObject( "Texas", "Vegetables", 38 ));
array.Put(getJsonObject( "Utah", "Rice", 6 ));
array.Put(getJsonObject( "Vermont", "Grains", 3 ));
array.Put(getJsonObject( "Virginia", "Rice", 13 ));
array.Put(getJsonObject( "Washington", "Vegetables", 12 ));
array.Put(getJsonObject( "West Virginia", "Grains", 5 ));
array.Put(getJsonObject( "Wisconsin", "Grains", 10 ));
array.Put(getJsonObject( "Wyoming", "Wheat", 3 ));
return array;
}
JSONObject getJsonObject(String name,String type,double count)
{
JSONObject obj= new JSONObject();
obj.Put ("Name", name);
obj.Put ("Type", type);
return obj;
}
void SetColorMapping(ShapeSetting setting)
{
List<ColorMapping> colorMappings= new List<ColorMapping>();
EqualColorMapping colorMapping2= new EqualColorMapping();
colorMapping2.Value= "Rice";
colorMapping2.LegendLabel= "Rice";
colorMapping2.Color =Color.ParseColor("#FD8C48");
colorMappings.Add(colorMapping2);
EqualColorMapping colorMapping3= new EqualColorMapping();
colorMapping3.Value= "Wheat";
colorMapping3.LegendLabel= "Wheat";
colorMapping3.Color =Color.ParseColor("#E54D42");
colorMappings.Add(colorMapping3);
EqualColorMapping colorMapping4= new EqualColorMapping();
colorMapping4.Value= "Grains";
colorMapping4.LegendLabel= "Grains";
colorMapping4.Color =Color.ParseColor("#3A99D9");
colorMappings.Add(colorMapping4);
EqualColorMapping colorMapping1= new EqualColorMapping();
colorMapping1.Value= "Vegetables";
colorMapping1.LegendLabel= "Vegetables";
colorMapping1.Color =Color.ParseColor("#29BB9C");
colorMappings.Add(colorMapping1);
setting.ColorMapping = colorMappings;
}
}
public class LayerCustomTooltipSetting : TooltipSetting
{
Context context;
public LayerCustomTooltipSetting(Context con)
{
context = con;
}
public override View GetView(object shapeData)
{
LinearLayout layout = new LinearLayout(context);
LinearLayout.LayoutParams linearlayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent,
LinearLayout.LayoutParams.WrapContent);
layout.Orientation = Orientation.Vertical;
layout.LayoutParameters = linearlayoutParams;
layout.SetGravity(GravityFlags.Center);
TextView topLabel = new TextView(context);
topLabel.Text = ((JSONObject)shapeData).GetString("Name");
topLabel.TextSize = 12;
topLabel.SetTextColor(Color.ParseColor("#FFFFFF"));
topLabel.Gravity = GravityFlags.CenterHorizontal;
TextView bottoLabel = new TextView(context);
bottoLabel.Text = ((JSONObject)shapeData).GetString("Type");
bottoLabel.TextSize = 12;
bottoLabel.SetTextColor(Color.ParseColor("#FFFFFF"));
bottoLabel.Gravity = GravityFlags.CenterHorizontal;
layout.AddView(topLabel);
layout.AddView(bottoLabel);
return layout;
}
}
}