-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMultipleGeometriesExample.cs
130 lines (107 loc) · 3.45 KB
/
MultipleGeometriesExample.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
namespace MapboxMauiQs;
public class MultipleGeometriesExample : ContentPage, IExamplePage, IQueryAttributable
{
MapboxView map;
IExampleInfo info;
class Constants
{
public const string geoJSONDataSourceIdentifier = "geoJSON-data-source";
}
public MultipleGeometriesExample()
{
iOSPage.SetUseSafeArea(this, false);
Content = map = new MapboxView();
map.MapReady += Map_MapReady;
map.MapLoaded += Map_MapLoaded;
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
private void Map_MapReady(object sender, EventArgs e)
{
var centerLocation = new MapPosition(38.93490939383946, -77.03619251024163);
var cameraOptions = new CameraOptions
{
Center = centerLocation,
Zoom = 11,
};
map.CameraOptions = cameraOptions;
}
private async void Map_MapLoaded(object sender, EventArgs e)
{
var geojsonSource = await AddGeoJSONSource();
MainThread.BeginInvokeOnMainThread(() =>
{
map.Sources = new[] { geojsonSource };
map.Layers = new MapboxLayer[]
{
AddPolygonLayer(),
AddLineStringLayer(),
AddPointLayer(),
};
});
}
private static CircleLayer AddPointLayer()
{
// Create a circle layer associated with the GeoJSON data source,
// filter it so that only the point data is shown,
// and apply basic styling to it.
var circleLayer = new CircleLayer(id: "circle-layer", Constants.geoJSONDataSourceIdentifier)
{
Filter = DslExpression.Eq(
"$type",
"Point"
),
CircleColor = Colors.Red,
CircleRadius = 6.0,
CircleStrokeWidth = 2.0,
CircleStrokeColor = Colors.Black
};
return circleLayer;
}
private static LineLayer AddLineStringLayer()
{
// Create and style a LineLayer that uses the Line String Feature's coordinates in the GeoJSON data
var lineLayer = new LineLayer(id: "line-layer", Constants.geoJSONDataSourceIdentifier)
{
Filter = DslExpression.Eq(
"$type",
"LineString"
),
LineColor = Colors.Red,
LineWidth = 2
};
return lineLayer;
}
private static FillLayer AddPolygonLayer()
{
var polygonLayer = new FillLayer(id: "fill-layer", Constants.geoJSONDataSourceIdentifier)
{
Filter = DslExpression.Eq(
"$type",
"Polygon"
),
FillColor = Color.FromRgb(68, 105, 247),
FillOpacity = 0.3
};
return polygonLayer;
}
private static async Task<GeoJSONSource> AddGeoJSONSource()
{
var geojson = await LoadGeojson();
// Create a GeoJSON data source.
var geoJSONSource = new GeoJSONSource(Constants.geoJSONDataSourceIdentifier)
{
Data = new RawGeoJSONObject(geojson)
};
return geoJSONSource;
}
async static Task<string> LoadGeojson()
{
using var stream = await FileSystem.OpenAppPackageFileAsync("GeoJSONSourceExample.geojson");
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}