-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOfflineManagerExample.cs
111 lines (97 loc) · 3.63 KB
/
OfflineManagerExample.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
namespace MapboxMauiQs;
public class OfflineManagerExample : ContentPage, IExamplePage, IQueryAttributable
{
MapboxView map;
IExampleInfo info;
IPosition tokyoCoord;
string tileRegionId = @"myTileRegion";
float tokyoZoom = 12;
IOfflineManager offlineManager;
public OfflineManagerExample()
{
iOSPage.SetUseSafeArea(this, false);
Content = map = new MapboxView();
tokyoCoord = new MapPosition(35.682027, 139.769305);
map.MapReady += Map_MapReady;
}
private void Map_MapReady(object sender, EventArgs e)
{
var cameraOptions = new CameraOptions
{
Center = tokyoCoord,
Zoom = tokyoZoom,
};
map.CameraOptions = cameraOptions;
map.MapboxStyle = MapboxStyle.OUTDOORS;
offlineManager = new OfflineManager(
MauiProgram.ACCESS_TOKEN,
cameraOptions);
offlineManager.IsMapboxStackConnected = true;
offlineManager.DownloadStyle(
MapboxStyle.OUTDOORS.Value,
new StylePackLoadOptions
{
Mode = GlyphsRasterizationMode.IdeographsRasterizedLocally,
Metadata = new Dictionary<string, object>
{
{ @"tag", @"my-outdoors-style-pack" }
}
},
(progress) =>
{
System.Diagnostics.Debug.WriteLine($"PROGRESS:DownloadStyle {
progress.CompletedResourceCount}/{
progress.RequiredResourceCount}");
},
(stylePack, exception) =>
{
if (exception != null)
{
System.Diagnostics.Debug.WriteLine($"ERR:DownloadStyle {exception.Message}");
return;
}
System.Diagnostics.Debug.WriteLine($"DONE:DownloadStyle {
stylePack.CompletedResourceCount}/{
stylePack.RequiredResourceCount}");
});
var tilesetDescriptorOptions = new TilesetDescriptorOptions(
MapboxStyle.OUTDOORS.Value,
MinZoom: 0,
MaxZoom: 16
);
var tileRegionLoadOptions = new TileRegionLoadOptions(
Geometry: new GeoJSON.Text.Geometry.Point(tokyoCoord),
TilesetDescriptors: [tilesetDescriptorOptions],
AcceptsExpired: true,
NetworkRestriction: NetworkRestriction.None,
Metadata: new Dictionary<string, object>
{
{ @"tag", @"my-outdoors-tile-region" }
});
offlineManager.DownloadTile(
tileRegionId,
tileRegionLoadOptions,
progress =>
{
System.Diagnostics.Debug.WriteLine($"PROGRESS:DownloadTile {
progress.CompletedResourceCount}/{
progress.RequiredResourceCount}");
},
(tileRegion, exception) =>
{
if (exception != null)
{
System.Diagnostics.Debug.WriteLine($"ERR:DownloadTile {exception.Message}");
return;
}
System.Diagnostics.Debug.WriteLine($"DONE:DownloadTile {
tileRegion.CompletedResourceCount}/{
tileRegion.RequiredResourceCount}");
});
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
}