Skip to content

Commit 769e3e3

Browse files
Releases/0.6.0 (#15)
* Reworking way of setting the options on the map (#12) * Adding SetStyleOptionsAsync on map * Adding SetUserInteractionAsync on Map * Adding SetTrafficAsync on Map * Reworking CameraOptions binding on map * Reworking StyleOptions bindings on map * Reworking UserInteractionOptions bindings on map * Reworking ServiceOptions * Updating docs * Adding events on popup (#14) * Adding events on popups * Updating popup docs * Map and drawing toolbar events should be triggered by map instance on map service
1 parent daad648 commit 769e3e3

15 files changed

Lines changed: 1228 additions & 8 deletions

File tree

docs/drawingtoolbar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ You can specify the events to enable or disable on the `DrawingToolbarOptions` o
6969
| `DrawingModeChanged` | Fired when the drawing mode has changed. The new drawing mode is passed into the event handler. |
7070
| `DrawingStarted` | Fired when the user starts drawing a shape or puts a shape into edit mode. |
7171

72+
Those events are also triggered by the `Map` property on `IMapService`.
7273

7374
### Updating the toolbar
7475

docs/map/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ The events of the map are exposed as `EventCallback` on the `AzureMap` component
8080
| `zoomend` | `OnZoomEnd` | Fired just after the map completes a transition from one zoom level to another, as the result of either user interaction or methods. |
8181
| `zoomstart` | `OnZoomStart` | Fired just before the map begins a transition from one zoom level to another, as the result of either user interaction or methods. |
8282

83+
Those events are also triggered by the `Map` property on `IMapService`.
84+
8385
### Activate or deactivate events
8486

8587
It is possible and recommended to active only the events you need, or at least deactivate the events which are often triggered in order to avoid overflowing the WebSocket communication between the component and the server application. The `AzureMap` component accepts an `EventActivationFlags` parameter where you can define which events should be triggered by the map. By default, all events except `Ready` are deactivated.

docs/popups/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,52 @@ All the popups can be cleared using the `ClearPopupsAsync` method on the map.
215215
await eventArgs.Map.ClearPopupsAsync();
216216
}
217217
218+
}
219+
```
220+
221+
### Events
222+
223+
You can subscribe to events triggered on the popup by defining the `EventActivationFlags` and subscribing to the corresponding event on the `Popup`.
224+
225+
The following events are available : `Open`, `DragStart`, `DragEnd`, `Drag` and `Close`.
226+
227+
The following example reacts to the opening of a popup :
228+
229+
```
230+
@page "/PopupOnReady"
231+
232+
@using AzureMapsControl.Components.Map
233+
<AzureMap Id="map"
234+
StyleOptions="StyleOptions"
235+
EventActivationFlags="MapEventActivationFlags
236+
.None()
237+
.Enable(MapEventType.Ready)"
238+
OnReady="OnMapReady" />
239+
240+
@code {
241+
242+
public StyleOptions StyleOptions = new StyleOptions
243+
{
244+
Style = "grayscale_dark"
245+
};
246+
247+
public async Task OnMapReady(MapEventArgs eventArgs)
248+
{
249+
var popup = new Components.Popups.Popup(new Components.Popups.PopupOptions
250+
{
251+
CloseButton = false,
252+
Content = "Please customize me",
253+
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
254+
}, AzureMapsControl.Components.Popups.PopupEventActivationFlags.None().Enable(AzureMapsControl.Components.Popups.PopupEventType.Open));
255+
256+
popup.OnOpen += eventArgs =>
257+
{
258+
Console.WriteLine("Popup opened");
259+
};
260+
261+
await eventArgs.Map.AddPopupAsync(popup);
262+
await popup.OpenAsync();
263+
}
264+
218265
}
219266
```

samples/AzureMapsControl.Sample/Pages/PopupOnReady.razor

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
CloseButton = false,
2323
Content = "Please customize me",
2424
Position = new AzureMapsControl.Components.Atlas.Position(11.581990, 48.143534)
25-
});
25+
}, AzureMapsControl.Components.Popups.PopupEventActivationFlags.None().Enable(AzureMapsControl.Components.Popups.PopupEventType.Open));
26+
27+
popup.OnOpen += eventArgs =>
28+
{
29+
Console.WriteLine("Popup opened");
30+
};
31+
2632
await eventArgs.Map.AddPopupAsync(popup);
2733
await popup.OpenAsync();
28-
29-
await popup.UpdateAsync(options => options.Content = "Thanks for updating me");
30-
await eventArgs.Map.ClearPopupsAsync();
3134
}
3235

3336
}

src/AzureMapsControl.Components/Map/AzureMap.razor

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
private Markers.HtmlMarkerInvokeHelper _htmlMarkerEventInvokeHelper;
2121
private Drawing.DrawingToolbarEventInvokeHelper _drawingToolbarEventInvokeHelper;
2222
private Layers.LayerEventInvokeHelper _layerEventInvokeHelper;
23+
private Popups.PopupInvokeHelper _popupInvokeHelper;
2324

2425
private string _id;
2526

@@ -408,6 +409,7 @@
408409
_htmlMarkerEventInvokeHelper = new Markers.HtmlMarkerInvokeHelper(HtmlMarkerEventReceivedAsync);
409410
_drawingToolbarEventInvokeHelper = new Drawing.DrawingToolbarEventInvokeHelper(DrawingToolbarEventReceivedAsync);
410411
_layerEventInvokeHelper = new Layers.LayerEventInvokeHelper(LayerEventReceivedAsync);
412+
_popupInvokeHelper = new Popups.PopupInvokeHelper(PopupEventReceivedAsync);
411413
base.OnInitialized();
412414
}
413415

@@ -512,6 +514,7 @@
512514

513515
private async Task DrawingToolbarEventReceivedAsync(AzureMapsControl.Components.Drawing.DrawingToolbarJsEventArgs drawingToolbarEvent)
514516
{
517+
MapService.Map.DispatchDrawingToolbarEvent(drawingToolbarEvent);
515518
switch (drawingToolbarEvent.Type)
516519
{
517520
case "drawingchanged":
@@ -739,6 +742,7 @@
739742
&& EventActivationFlags.EnabledEvents != null
740743
&& EventActivationFlags.EnabledEvents.Contains(mapEvent.Type))
741744
{
745+
MapService.Map.DispatchEvent(mapEvent);
742746
switch (mapEvent.Type)
743747
{
744748
case "boxzoomend":
@@ -837,7 +841,7 @@
837841
case "sourceadded":
838842
await OnSourceAdded.InvokeAsync(new MapDataEventArgs(MapService.Map, mapEvent));
839843
break;
840-
case "sourcedate":
844+
case "sourcedata":
841845
await OnSourceData.InvokeAsync(new MapDataEventArgs(MapService.Map, mapEvent));
842846
break;
843847
case "sourceremoved":
@@ -886,7 +890,7 @@
886890

887891
private async Task AddPopupAsync(AzureMapsControl.Components.Popups.Popup popup)
888892
{
889-
await JSRuntime.InvokeVoidAsync(Constants.JsConstants.MethodAddPopup.ToAzureMapsControlNamespace(), popup.Id, popup.Options);
893+
await JSRuntime.InvokeVoidAsync(Constants.JsConstants.MethodAddPopup.ToAzureMapsControlNamespace(), popup.Id, popup.Options, popup.EventActivationFlags.EnabledEvents, DotNetObjectReference.Create(_popupInvokeHelper));
890894
popup.OpenPopupCallback = Popup_OpenAsync;
891895
popup.ClosePopupCallback = Popup_CloseAsync;
892896
popup.RemoveCallback = Popup_RemoveAsync;
@@ -903,5 +907,8 @@
903907
private async Task Popup_UpdateAsync(string id, AzureMapsControl.Components.Popups.PopupOptions options) => await JSRuntime.InvokeVoidAsync(Constants.JsConstants.MethodPopupUpdate.ToAzureMapsControlNamespace(), id, options);
904908
private async Task ClearPopupsAsync() => await JSRuntime.InvokeVoidAsync(Constants.JsConstants.MethodClearPopups.ToAzureMapsControlNamespace());
905909

910+
private async Task PopupEventReceivedAsync(AzureMapsControl.Components.Popups.PopupEventArgs eventArgs) =>
911+
await Task.Run(() => MapService.Map.Popups.First(popup => popup.Id == eventArgs.Id).DispatchEvent(eventArgs));
912+
906913
#endregion
907914
}

0 commit comments

Comments
 (0)