Skip to content

Commit

Permalink
Add Custom Control Removal Functionality #296
Browse files Browse the repository at this point in the history
  • Loading branch information
valentasm committed Dec 5, 2023
1 parent f022c9a commit 73214a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GoogleMapsComponents/GoogleMapsComponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>BlazorGoogleMaps</PackageId>
<Version>3.2.5</Version>
<Version>3.3.1</Version>
<Authors>Rungwiroon</Authors>
<Company>QueueStack Solution</Company>
<Product>BlazorGoogleMaps</Product>
Expand Down
20 changes: 9 additions & 11 deletions GoogleMapsComponents/Maps/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
using System;
using System.Threading.Tasks;

#nullable enable

namespace GoogleMapsComponents.Maps;

/// <summary>
/// google.maps.Map class
/// </summary>
//[JsonConverter(typeof(JsObjectRefConverter<Map>))]
public class Map : EventEntityBase, IJsObjectRef, IDisposable, IAsyncDisposable
public class Map : EventEntityBase, IJsObjectRef, IAsyncDisposable
{
public Guid Guid => _jsObjectRef.Guid;
bool isDisposed;

private bool _isDisposed;
public MapData Data { get; private set; }

public static async Task<Map> CreateAsync(
Expand Down Expand Up @@ -50,9 +48,9 @@ public async Task RemoveControl(ControlPosition position, ElementReference refer
await _jsObjectRef.JSRuntime.MyInvokeAsync<object>("blazorGoogleMaps.objectManager.removeControl", this.Guid.ToString(), position, reference);
}

public async Task RemoveAllControls(ControlPosition position)
public async Task RemoveControls(ControlPosition position)
{
await _jsObjectRef.JSRuntime.MyInvokeAsync<object>("blazorGoogleMaps.objectManager.clearControls", this.Guid.ToString(), position);
await _jsObjectRef.JSRuntime.MyInvokeAsync<object>("blazorGoogleMaps.objectManager.removeControls", this.Guid.ToString(), position);
}

public async Task AddImageLayer(ImageMapType reference)
Expand All @@ -68,7 +66,7 @@ public async Task RemoveAllImageLayers()
await _jsObjectRef.JSRuntime.MyInvokeAsync<object>("blazorGoogleMaps.objectManager.removeAllImageLayers", this.Guid.ToString());
}



/// <summary>
/// Sets the viewport to contain the given bounds.
Expand Down Expand Up @@ -232,7 +230,7 @@ public Task SetOptions(MapOptions mapOptions)
return _jsObjectRef.InvokeAsync("setOptions", mapOptions);
}



public override async ValueTask DisposeAsync()
{
Expand All @@ -256,7 +254,7 @@ protected override async ValueTask DisposeAsyncCore()
protected override void Dispose(bool disposing)
{

if (!isDisposed)
if (!_isDisposed)
{
base.Dispose(disposing);
//_jsObjectRef.Dispose();
Expand All @@ -268,7 +266,7 @@ protected override void Dispose(bool disposing)

// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
isDisposed = true;
_isDisposed = true;
}
}

Expand Down
3 changes: 2 additions & 1 deletion GoogleMapsComponents/wwwroot/js/objectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
addControls(args) {
let map = mapObjects[args[0]];
let elem = args[2];
//Without this the original element is removed and can not be added again.
let clone = elem.cloneNode(true);
//I know i am lazy. Two quotes appear after serialization
let position = getGooglePositionFromString(args[1].replace("\"", "").replace("\"", ""));
Expand All @@ -411,7 +412,7 @@
}
}
},
clearControls(args) {
removeControls(args) {
let map = mapObjects[args[0]];
let position = getGooglePositionFromString(args[1].replace("\"", "").replace("\"", ""));

Expand Down
8 changes: 4 additions & 4 deletions ServerSideDemo/Pages/MapLegendPage.razor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Threading.Tasks;
using GoogleMapsComponents;
using GoogleMapsComponents;
using GoogleMapsComponents.Maps;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Threading.Tasks;

namespace ServerSideDemo.Pages;

Expand Down Expand Up @@ -40,7 +40,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

private async Task AfterMapInit()
{

}

private async Task RemoveLegend()
Expand All @@ -50,7 +50,7 @@ private async Task RemoveLegend()

private async Task RemoveAllControls()
{
await map1.InteropObject.RemoveAllControls(ControlPosition.TopLeft);
await map1.InteropObject.RemoveControls(ControlPosition.TopLeft);
}

private async Task AddLegend()
Expand Down

0 comments on commit 73214a0

Please sign in to comment.