Skip to content

Commit a23fcc0

Browse files
Adding popups support (#2) (#3)
* Adding popups * Pipelines should be triggered according to paths * Adding OpenAsync on popup * Adding CloseAsync on popup * Adding RemoveAsync on popup * Updating readme * Options should be passed on the constructor of the popup * Reorganizing AzureMap component * Adding UpdateAsync on popup * ClearMap should also clear the popups * Adding RemovePopupAsync on map * Adding ClearPopupsAsync on map
1 parent 2e7df1e commit a23fcc0

17 files changed

Lines changed: 1022 additions & 264 deletions

File tree

.github/workflows/CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ on:
66
- features/**
77
- hotfix/**
88
paths:
9-
src/**
10-
tests/**
9+
- src/**
10+
- tests/**
1111
pull_request:
1212
branches:
1313
- develop
1414
- master
1515
paths:
16-
src/**
17-
tests/**
16+
- src/**
17+
- tests/**
1818

1919
jobs:
2020
build:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- develop
88
- master
99
paths:
10-
src/**
10+
- src/**
1111

1212
jobs:
1313
build:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ public void ConfigureServices(IServiceCollection services)
7272
- [Drawing Toolbar](docs/drawingtoolbar)
7373
- [Html Markers](docs/htmlmarkers)
7474
- [Layers](docs/layers)
75+
- [Popups](docs/popups)
7576
- [Traffic](docs/traffic)

docs/assets/popup.png

407 KB
Loading

docs/popups/README.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
## Popups
2+
3+
![Popup](../assets/popup.png)
4+
5+
Popups can be added to the map using the `AddPopupAsync` method on the map. If the `OpenOnAdd` property is set to true, the popup will be opened once it has been added to the map.
6+
7+
```
8+
@page "/PopupOnReady"
9+
10+
@using AzureMapsControl.Components.Map
11+
<AzureMap Id="map"
12+
Style="grayscale_dark"
13+
EventActivationFlags="MapEventActivationFlags
14+
.None()
15+
.Enable(MapEventType.Ready)"
16+
OnReady="OnMapReady" />
17+
18+
@code {
19+
20+
public async Task OnMapReady(MapEventArgs eventArgs)
21+
{
22+
await eventArgs.Map.AddPopupAsync(new Components.Popups.PopupOptions
23+
{
24+
CloseButton = false,
25+
Content = "Please customize me",
26+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
27+
});
28+
}
29+
30+
}
31+
```
32+
33+
A popup can also be opened using the `OpenAsync` method.
34+
35+
```
36+
@page "/PopupOnReady"
37+
38+
@using AzureMapsControl.Components.Map
39+
<AzureMap Id="map"
40+
Style="grayscale_dark"
41+
EventActivationFlags="MapEventActivationFlags
42+
.None()
43+
.Enable(MapEventType.Ready)"
44+
OnReady="OnMapReady" />
45+
46+
@code {
47+
48+
public async Task OnMapReady(MapEventArgs eventArgs)
49+
{
50+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
51+
{
52+
CloseButton = false,
53+
Content = "Please customize me",
54+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
55+
});
56+
await eventArgs.Map.AddPopupAsync(popup);
57+
await popup.OpenAsync();
58+
}
59+
60+
}
61+
```
62+
63+
The popup can then be close by calling the `CloseAsync` method.
64+
65+
```
66+
@page "/PopupOnReady"
67+
68+
@using AzureMapsControl.Components.Map
69+
<AzureMap Id="map"
70+
Style="grayscale_dark"
71+
EventActivationFlags="MapEventActivationFlags
72+
.None()
73+
.Enable(MapEventType.Ready)"
74+
OnReady="OnMapReady" />
75+
76+
@code {
77+
78+
public async Task OnMapReady(MapEventArgs eventArgs)
79+
{
80+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
81+
{
82+
CloseButton = false,
83+
Content = "Please customize me",
84+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
85+
});
86+
await eventArgs.Map.AddPopupAsync(popup);
87+
await popup.OpenAsync();
88+
await popup.CloseAsync();
89+
}
90+
91+
}
92+
```
93+
94+
Calling the `RemoveAsync` method will remove the popup from the map. You can also call the `RemovePopupAsync` method on the map and provide the popup to remove.
95+
96+
```
97+
@page "/PopupOnReady"
98+
99+
@using AzureMapsControl.Components.Map
100+
<AzureMap Id="map"
101+
Style="grayscale_dark"
102+
EventActivationFlags="MapEventActivationFlags
103+
.None()
104+
.Enable(MapEventType.Ready)"
105+
OnReady="OnMapReady" />
106+
107+
@code {
108+
109+
public async Task OnMapReady(MapEventArgs eventArgs)
110+
{
111+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
112+
{
113+
CloseButton = false,
114+
Content = "Please customize me",
115+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
116+
});
117+
await eventArgs.Map.AddPopupAsync(popup);
118+
await popup.OpenAsync();
119+
120+
await popup.RemoveAsync();
121+
}
122+
123+
}
124+
```
125+
126+
The popup can be updated by calling the `UpdateAsync` method and providing the update to apply on the options. The following example only updates the content of the popup.
127+
128+
```
129+
@page "/PopupOnReady"
130+
131+
@using AzureMapsControl.Components.Map
132+
<AzureMap Id="map"
133+
Style="grayscale_dark"
134+
EventActivationFlags="MapEventActivationFlags
135+
.None()
136+
.Enable(MapEventType.Ready)"
137+
OnReady="OnMapReady" />
138+
139+
@code {
140+
141+
public async Task OnMapReady(MapEventArgs eventArgs)
142+
{
143+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
144+
{
145+
CloseButton = false,
146+
Content = "Please customize me",
147+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
148+
});
149+
await eventArgs.Map.AddPopupAsync(popup);
150+
await popup.OpenAsync();
151+
152+
await popup.UpdateAsync(options => options.Content = "Thanks for updating me");
153+
}
154+
155+
}
156+
```
157+
158+
All the popups can be cleared using the `ClearPopupsAsync` method on the map.
159+
160+
```
161+
@page "/PopupOnReady"
162+
163+
@using AzureMapsControl.Components.Map
164+
<AzureMap Id="map"
165+
Style="grayscale_dark"
166+
EventActivationFlags="MapEventActivationFlags
167+
.None()
168+
.Enable(MapEventType.Ready)"
169+
OnReady="OnMapReady" />
170+
171+
@code {
172+
173+
public async Task OnMapReady(MapEventArgs eventArgs)
174+
{
175+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
176+
{
177+
CloseButton = false,
178+
Content = "Please customize me",
179+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
180+
});
181+
await eventArgs.Map.AddPopupAsync(popup);
182+
await popup.OpenAsync();
183+
184+
await popup.UpdateAsync(options => options.Content = "Thanks for updating me");
185+
await eventArgs.Map.ClearPopupsAsync();
186+
}
187+
188+
}
189+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@page "/PopupOnReady"
2+
3+
@using AzureMapsControl.Components.Map
4+
<AzureMap Id="map"
5+
Style="grayscale_dark"
6+
EventActivationFlags="MapEventActivationFlags
7+
.None()
8+
.Enable(MapEventType.Ready)"
9+
OnReady="OnMapReady" />
10+
11+
@code {
12+
13+
public async Task OnMapReady(MapEventArgs eventArgs)
14+
{
15+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
16+
{
17+
CloseButton = false,
18+
Content = "Please customize me",
19+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
20+
});
21+
await eventArgs.Map.AddPopupAsync(popup);
22+
await popup.OpenAsync();
23+
24+
await popup.UpdateAsync(options => options.Content = "Thanks for updating me");
25+
await eventArgs.Map.ClearPopupsAsync();
26+
}
27+
28+
}

src/AzureMapsControl.Components/Constants/Constants.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,36 @@ internal static class JsConstants
1212

1313
internal const string MethodAddMap = "addMap";
1414
internal const string MethodClearMap = "clearMap";
15+
internal const string MethodSetOptions = "setOptions";
16+
1517
internal const string MethodAddControl = "addControls";
18+
1619
internal const string MethodAddHtmlMarkers = "addHtmlMarkers";
1720
internal const string MethodClearHtmlMarkers = "clearHtmlMarkers";
18-
internal const string MethodSetOptions = "setOptions";
1921
internal const string MethodRemoveHtmlMarkers = "removeHtmlMarkers";
2022
internal const string MethodUpdateHtmlMarkers = "updateHtmlMarkers";
23+
2124
internal const string MethodAddDrawingToolbar = "addDrawingToolbar";
2225
internal const string MethodUpdateDrawingToolbar = "updateDrawingToolbar";
2326
internal const string MethodRemoveDrawingToolbar = "removeDrawingToolbar";
27+
2428
internal const string MethodAddLayer = "addLayer";
2529
internal const string MethodRemoveLayers = "removeLayers";
2630
internal const string MethodClearLayers = "clearLayers";
31+
2732
internal const string MethodAddDataSource = "addDataSource";
2833
internal const string MethodRemoveDataSource = "removeDataSource";
2934
internal const string MethodClearDataSources = "clearDataSources";
3035
internal const string MethodDataSourceImportDataFromUrl = "dataSource_importDataFromUrl";
3136
internal const string MethodDataSourceAdd = "dataSource_add";
3237
internal const string MethodDataSourceRemove = "dataSource_remove";
3338
internal const string MethodDataSourceClear = "dataSource_clear";
39+
40+
internal const string MethodAddPopup = "addPopup";
41+
internal const string MethodPopupOpen = "popup_open";
42+
internal const string MethodPopupClose = "popup_close";
43+
internal const string MethodPopupRemove = "popup_remove";
44+
internal const string MethodPopupUpdate = "popup_update";
45+
internal const string MethodClearPopups = "clearPopups";
3446
}
3547
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AzureMapsControl.Components.Exceptions
2+
{
3+
using System;
4+
5+
public sealed class PopupAlreadyExistingException : Exception
6+
{
7+
internal PopupAlreadyExistingException(string id) : base($"A data source with the id {id} has already been added") { }
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AzureMapsControl.Components.Exceptions
2+
{
3+
using System;
4+
5+
public sealed class PopupAlreadyRemovedException : Exception
6+
{
7+
internal PopupAlreadyRemovedException() : base("This popup has already been removed") { }
8+
}
9+
}

0 commit comments

Comments
 (0)