-
Notifications
You must be signed in to change notification settings - Fork 11
/
SymbolLayerWithFeatures.razor
75 lines (65 loc) · 3.15 KB
/
SymbolLayerWithFeatures.razor
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
@page "/Layers/SymbolLayerWithFeatures"
@rendermode InteractiveServer
@using AzureMapsControl.Components.Map
<AzureMap Id="map"
CameraOptions="new CameraOptions { Zoom = 16, Center = new AzureMapsControl.Components.Atlas.Position(-122.13284, 47.63699) }"
EventActivationFlags="MapEventActivationFlags
.None()
.Enable(MapEventType.Ready, MapEventType.Click, MapEventType.SourceAdded)"
OnReady="OnMapReady"
OnSourceAdded="OnDatasourceAdded"/>
@code {
private readonly string _datasourceId = "datasourceId";
public async Task OnMapReady(MapEventArgs eventArgs)
{
var datasource = new AzureMapsControl.Components.Data.DataSource(_datasourceId);
await eventArgs.Map.AddSourceAsync(datasource);
var feature = new AzureMapsControl.Components.Atlas.Feature<AzureMapsControl.Components.Atlas.Point>(new AzureMapsControl.Components.Atlas.Point(
new AzureMapsControl.Components.Atlas.Position(-122.13284, 47.63699)
), new Dictionary<string, object> {
{ "title", "Cafeteria" },
{ "subtitle", "Building 40"}
});
await datasource.AddAsync(feature);
}
public async Task OnDatasourceAdded(MapSourceEventArgs sourceEventArgs)
{
var textFieldExpressionJsonString = "[\"format\", [\"get\", \"title\"], {\"text-font\": [\"literal\", [\"StandardFont-Bold\"]], \"font-scale\": 1.25}, \"\\n\", {}, [\"get\", \"subtitle\"], {\"font-scale\": 0.75}]";
var layer = new AzureMapsControl.Components.Layers.SymbolLayer
{
Options = new AzureMapsControl.Components.Layers.SymbolLayerOptions
{
Source = _datasourceId,
TextOptions = new AzureMapsControl.Components.Layers.TextOptions
{
TextField = new AzureMapsControl.Components.Atlas.ExpressionOrString(
System.Text.Json.JsonDocument.Parse(textFieldExpressionJsonString)
)
}
},
EventActivationFlags = AzureMapsControl.Components.Layers.LayerEventActivationFlags.None().Enable(AzureMapsControl.Components.Layers.LayerEventType.Click)
};
layer.OnClick += eventArgs =>
{
var firstShape = eventArgs.Shapes?.FirstOrDefault();
if (firstShape != null)
{
if(firstShape.Geometry is AzureMapsControl.Components.Atlas.Point point)
{
Console.WriteLine(point.Coordinates.Longitude);
Console.WriteLine(point.Coordinates.Latitude);
}
}
var firstFeature = eventArgs.Features?.FirstOrDefault();
if (firstFeature != null)
{
if(firstFeature.Geometry is AzureMapsControl.Components.Atlas.Point point)
{
Console.WriteLine(point.Coordinates.Longitude);
Console.WriteLine(point.Coordinates.Latitude);
}
}
};
await sourceEventArgs.Map.AddLayerAsync(layer);
}
}