-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathLineLayerOnReady.razor
More file actions
105 lines (93 loc) · 5.08 KB
/
LineLayerOnReady.razor
File metadata and controls
105 lines (93 loc) · 5.08 KB
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
@page "/Layers/LineLayerOnReady"
@rendermode InteractiveServer
@using AzureMapsControl.Components.Map
<AzureMap Id="map"
CameraOptions="new CameraOptions { Center = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534), Zoom = 14 }"
StyleOptions="StyleOptions"
EventActivationFlags="MapEventActivationFlags
.None()
.Enable(MapEventType.Ready, MapEventType.SourceAdded)"
OnReady="OnMapReady"
OnSourceAdded="OnDatasourceAdded"/>
@code {
private readonly string _dataSourceId = "dataSource";
public StyleOptions StyleOptions = new StyleOptions
{
Style = MapStyle.GrayscaleDark
};
public async Task OnMapReady(MapEventArgs eventArgs)
{
var dummyDataSourceId = "_empty";
var dummyDataSource = new AzureMapsControl.Components.Data.DataSource(dummyDataSourceId);
await eventArgs.Map.AddSourceAsync(dummyDataSource);
var dataSource = new AzureMapsControl.Components.Data.DataSource(_dataSourceId)
{
Options = new AzureMapsControl.Components.Data.DataSourceOptions
{
LineMetrics = true
}
};
await eventArgs.Map.AddSourceAsync(dataSource);
}
public async Task OnDatasourceAdded(MapSourceEventArgs eventArgs)
{
if (eventArgs.Source.Id == _dataSourceId)
{
var dataSource = eventArgs.Map.Sources.OfType<AzureMapsControl.Components.Data.DataSource>()
.FirstOrDefault(s => s.Id == _dataSourceId);
if (dataSource != null)
{
await dataSource.AddAsync(new AzureMapsControl.Components.Atlas.Shape<AzureMapsControl.Components.Atlas.LineString>(
new AzureMapsControl.Components.Atlas.LineString(new[] {
new AzureMapsControl.Components.Atlas.Position(11.575454, 48.137392),
new AzureMapsControl.Components.Atlas.Position(11.576029, 48.137094),
new AzureMapsControl.Components.Atlas.Position(11.577248, 48.138912),
new AzureMapsControl.Components.Atlas.Position(11.578434, 48.138737),
new AzureMapsControl.Components.Atlas.Position(11.578826, 48.139409),
new AzureMapsControl.Components.Atlas.Position(11.580140, 48.139179),
new AzureMapsControl.Components.Atlas.Position(11.581237, 48.141555),
new AzureMapsControl.Components.Atlas.Position(11.581155, 48.141852),
new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534),
new AzureMapsControl.Components.Atlas.Position(11.583355, 48.143896),
new AzureMapsControl.Components.Atlas.Position(11.583662, 48.144258)
}),
new Dictionary<string, object>()
{
{ "Color", "#00FF00" }
}));
await dataSource.AddAsync(new AzureMapsControl.Components.Atlas.Shape<AzureMapsControl.Components.Atlas.LineString>(
new AzureMapsControl.Components.Atlas.LineString(new[] {
new AzureMapsControl.Components.Atlas.Position(11.585458, 48.145596),
new AzureMapsControl.Components.Atlas.Position(11.587910, 48.145779),
new AzureMapsControl.Components.Atlas.Position(11.589632, 48.146608),
new AzureMapsControl.Components.Atlas.Position(11.590771, 48.148219),
new AzureMapsControl.Components.Atlas.Position(11.591979, 48.150743),
new AzureMapsControl.Components.Atlas.Position(11.592885, 48.150611),
new AzureMapsControl.Components.Atlas.Position(11.593161, 48.150874),
new AzureMapsControl.Components.Atlas.Position(11.593594, 48.151084),
new AzureMapsControl.Components.Atlas.Position(11.594028, 48.151803),
new AzureMapsControl.Components.Atlas.Position(11.592281, 48.152074)
}),
new Dictionary<string, object>()
{
{ "Color", "#FF0000" }
}));
var layer = new AzureMapsControl.Components.Layers.LineLayer
{
Options = new AzureMapsControl.Components.Layers.LineLayerOptions
{
Source = _dataSourceId,
StrokeWidth = new AzureMapsControl.Components.Atlas.ExpressionOrNumber(6),
StrokeColor = new AzureMapsControl.Components.Atlas.ExpressionOrString(
new AzureMapsControl.Components.Atlas.Expression[]
{
new AzureMapsControl.Components.Atlas.ExpressionOrString("get"),
new AzureMapsControl.Components.Atlas.ExpressionOrString("Color")
})
}
};
await eventArgs.Map.AddLayerAsync(layer);
}
}
}
}