-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSkyLayerExample.cs
148 lines (122 loc) · 4.81 KB
/
SkyLayerExample.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
namespace MapboxMauiQs;
public class SkyLayerExample : ContentPage, IExamplePage, IQueryAttributable
{
static readonly Color skyBlue = new Color(0.53f, 0.81f, 0.92f, 1.00f);
static readonly Color lightPink = new Color(1.00f, 0.82f, 0.88f, 1.00f);
MapboxView map;
Switch @switch;
IExampleInfo info;
SkyLayer skyLayer;
public SkyLayerExample()
{
iOSPage.SetUseSafeArea(this, false);
var stackLayout = new HorizontalStackLayout()
{
new Label
{
Margin = new Thickness(8,0),
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.End,
Text = "Gradient",
TextColor = Colors.Black,
WidthRequest = 96,
},
(@switch = new Switch()),
new Label
{
Margin = new Thickness(8,0),
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Start,
Text = "Atmostphere",
TextColor = Colors.Black,
WidthRequest = 96,
},
};
stackLayout.HorizontalOptions = LayoutOptions.Center;
stackLayout.VerticalOptions = LayoutOptions.End;
stackLayout.Margin = new Thickness(16, 120);
stackLayout.BackgroundColor = Colors.Gray.WithAlpha(0.5f);
Content = new Grid
{
(map = new MapboxView()),
stackLayout,
};
map.MapReady += Map_MapReady;
@switch.Toggled += @switch_Toggled;
}
private void @switch_Toggled(object sender, ToggledEventArgs e)
{
skyLayer.SkyType = new PropertyValue<SkyType>(
e.Value
? SkyType.Atmosphere
: SkyType.Gradient
);
map.Layers = new List<MapboxLayer>
{
skyLayer,
};
}
private void Map_MapReady(object sender, EventArgs e)
{
var center = new MapPosition(35.67283, 127.60597);
var cameraOptions = new CameraOptions
{
Center = center,
Zoom = 12.5f,
Pitch = 83,
};
map.CameraOptions = cameraOptions;
map.MapboxStyle = (MapboxStyle)@"mapbox://styles/mapbox-map-design/ckhqrf2tz0dt119ny6azh975y";
map.StyleLoaded += Map_StyleLoaded;
}
private void Map_StyleLoaded(object sender, EventArgs e)
{
AddSkyLayer();
AddTerrain();
}
private void AddTerrain()
{
// Add a `RasterDEMSource`. This will be used to create and add a terrain layer.
var demSource = new RasterDemSource("mapbox-dem");
demSource.Url = "mapbox://mapbox.mapbox-terrain-dem-v1";
demSource.TileSize = 514;
demSource.MaxZoom = 14.0;
map.Sources = new List<MapboxSource>
{
demSource,
};
var terrain = new Terrain(sourceId: "mapbox-dem");
terrain.Exaggeration = new PropertyValue<double>(1.5);
map.Terrain = terrain;
}
private void AddSkyLayer()
{
// Initialize a sky layer with a sky type of `gradient`, which applies a gradient effect to the sky.
// Read more about sky layer types on the Mapbox blog: https://www.mapbox.com/blog/sky-api-atmospheric-scattering-algorithm-for-3d-maps
skyLayer = new SkyLayer("sky-layer");
skyLayer.SkyType = new PropertyValue<SkyType>(SkyType.Atmosphere);
// Define the position of the sun.
// The azimuthal angle indicates the sun's position relative to 0 degrees north. When the map's bearing
// is `0` and the azimuthal angle is `0`, the sun will appear horizontally centered.
double azimuthalAngle = 0;
// Indicates the sun's position relative to the horizon. A value of `90` places the sun's center at the
// horizon line. Lower values place the sun below the horizon line, while higher values place the sun's
// center further above the horizon line.
double polarAngle = 90;
skyLayer.SkyAtmosphereSun = new PropertyValue<double[]>(new[] { azimuthalAngle, polarAngle });
// The intensity or brightness of the sun.
skyLayer.SkyAtmosphereSunIntensity = new PropertyValue<double>(10);
// Set the sky's color to light blue with a light pink halo effect.
skyLayer.SkyAtmosphereColor = new PropertyValue<Color>(skyBlue);
skyLayer.SkyAtmosphereHaloColor = new PropertyValue<Color>(lightPink);
map.Layers = new List<MapboxLayer>
{
skyLayer,
};
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
}