|
| 1 | +## Popups |
| 2 | + |
| 3 | + |
| 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 | +``` |
0 commit comments