Skip to content

Commit ef97648

Browse files
Resolves #104 and #105 (#112)
* Resolves #105 Removing multiple markers only removes 1. * fixes #104 updating marker options can't be used to make marker invisible (or un-draggable) * Improve performance after many html marker add/remove operations. * Fix linter warnings using UpdateHtmlMarkersAsync() updates the options in stored in c# also. this didn't work: var options = new AzureMapsControl.Components.Markers.HtmlMarkerOptions { Visible = !Marker.Options.Visible };
1 parent fbd2e5e commit ef97648

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/AzureMapsControl.Components/Map/Map.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public async ValueTask AddHtmlMarkersAsync(IEnumerable<HtmlMarker> markers)
444444
if (markers != null)
445445
{
446446
_logger?.LogAzureMapsControlInfo(AzureMapLogEvent.Map_AddHtmlMarkersAsync, "Adding html markers");
447-
HtmlMarkers = (HtmlMarkers ?? Array.Empty<HtmlMarker>()).Concat(markers);
447+
HtmlMarkers = (HtmlMarkers ?? Array.Empty<HtmlMarker>()).Concat(markers).ToArray();
448448
_logger?.LogAzureMapsControlInfo(AzureMapLogEvent.Map_AddHtmlMarkersAsync, $"{markers.Count()} new html markers will be added");
449449
var parameters = GetHtmlMarkersCreationParameters(markers);
450450
await _jsRuntime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.AddHtmlMarkers.ToCoreNamespace(),
@@ -530,6 +530,48 @@ await _jsRuntime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.UpdateHtmlMa
530530
} : null
531531
}));
532532

533+
foreach (var updateWithOptions in updates.Where(u => u.Options != null))
534+
{
535+
var targetMarker = HtmlMarkers.First(marker => marker.Id == updateWithOptions.Marker.Id);
536+
537+
if (updateWithOptions.Options.Anchor.ToString() != null)
538+
{
539+
targetMarker.Options.Anchor = updateWithOptions.Options.Anchor;
540+
}
541+
if (updateWithOptions.Options.Color != null)
542+
{
543+
targetMarker.Options.Color = updateWithOptions.Options.Color;
544+
}
545+
if (updateWithOptions.Options.Draggable != null)
546+
{
547+
targetMarker.Options.Draggable = updateWithOptions.Options.Draggable;
548+
}
549+
if (updateWithOptions.Options.HtmlContent != null)
550+
{
551+
targetMarker.Options.HtmlContent = updateWithOptions.Options.HtmlContent;
552+
}
553+
if (updateWithOptions.Options.Position != null)
554+
{
555+
targetMarker.Options.Position = updateWithOptions.Options.Position;
556+
}
557+
if (updateWithOptions.Options.PixelOffset != null)
558+
{
559+
targetMarker.Options.PixelOffset = updateWithOptions.Options.PixelOffset;
560+
}
561+
if (updateWithOptions.Options.SecondaryColor != null)
562+
{
563+
targetMarker.Options.SecondaryColor = updateWithOptions.Options.SecondaryColor;
564+
}
565+
if (updateWithOptions.Options.Text != null)
566+
{
567+
targetMarker.Options.Text = updateWithOptions.Options.Text;
568+
}
569+
if (updateWithOptions.Options.Visible != null)
570+
{
571+
targetMarker.Options.Visible = updateWithOptions.Options.Visible;
572+
}
573+
}
574+
533575
foreach (var updateWithPopup in updates.Where(update => update.Options?.Popup != null))
534576
{
535577
var marker = HtmlMarkers.First(marker => marker.Id == updateWithPopup.Marker.Id);
@@ -565,7 +607,7 @@ public async ValueTask RemoveHtmlMarkersAsync(IEnumerable<HtmlMarker> markers)
565607
_logger?.LogAzureMapsControlInfo(AzureMapLogEvent.Map_RemoveHtmlMarkersAsync, "Removing html markers");
566608
if (HtmlMarkers != null && markers != null)
567609
{
568-
HtmlMarkers = HtmlMarkers.Where(marker => markers.Any(m => m != null && m.Id != marker.Id));
610+
HtmlMarkers = HtmlMarkers.Where(marker => !markers.Any(m => m != null && m.Id == marker.Id)).ToArray();
569611
_logger?.LogAzureMapsControlDebug(AzureMapLogEvent.Map_RemoveHtmlMarkersAsync, $"{markers.Count()} html markers will be removed");
570612
var ids = markers.Select(marker => marker.Id);
571613
_logger?.LogAzureMapsControlDebug(AzureMapLogEvent.Map_RemoveHtmlMarkersAsync, $"Ids: {string.Join('|', ids)}");

src/AzureMapsControl.Components/typescript/core/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class Core {
384384
}
385385

386386
public static removeHtmlMarkers(markerIds: string[]): void {
387-
this._map.markers.remove(this._map.markers.getMarkers().find(marker => markerIds.indexOf((marker as any).amc.id) > -1));
387+
this._map.markers.remove(this._map.markers.getMarkers().filter(marker => markerIds.includes((marker as any).amc.id)));
388388
}
389389

390390
public static removeLayers(ids: string[]): void {
@@ -458,7 +458,7 @@ export class Core {
458458
if (htmlMarkerOption.options.color) {
459459
options.color = htmlMarkerOption.options.color;
460460
}
461-
if (htmlMarkerOption.options.draggable) {
461+
if (htmlMarkerOption.options.draggable !== null) {
462462
options.draggable = htmlMarkerOption.options.draggable;
463463
}
464464
if (htmlMarkerOption.options.htmlContent) {
@@ -476,7 +476,7 @@ export class Core {
476476
if (htmlMarkerOption.options.text) {
477477
options.text = htmlMarkerOption.options.text;
478478
}
479-
if (htmlMarkerOption.options.visible) {
479+
if (htmlMarkerOption.options.visible !== null) {
480480
options.visible = htmlMarkerOption.options.visible;
481481
}
482482
if (htmlMarkerOption.popupOptions) {

0 commit comments

Comments
 (0)