Skip to content

Commit

Permalink
GoogleMap component code cleanup (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvreddy04 authored Aug 21, 2024
1 parent 4061db0 commit 9d38484
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Maps/GoogleMap.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
Source="@GoogleMapsJsFileUrl"
OnLoad="OnScriptLoad" />

<div @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" role="alert" @attributes="@AdditionalAttributes">
<div @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" @attributes="@AdditionalAttributes">
</div>
16 changes: 14 additions & 2 deletions blazorbootstrap/Components/ScriptLoader/ScriptLoader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class ScriptLoader : BlazorBootstrapComponentBase
/// <summary>
/// The default content type for scripts.
/// </summary>
private const string type = "text/javascript";
private const string ScriptType = "text/javascript";

/// <summary>
/// A reference to this component instance for use in JavaScript calls.
Expand All @@ -24,7 +24,7 @@ public partial class ScriptLoader : BlazorBootstrapComponentBase
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.scriptLoader.initialize", Id, Async, Defer, ScriptId, Source, type, objRef);
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.scriptLoader.initialize", Id, Async, Defer, ScriptId, Source, ScriptType, objRef);

await base.OnAfterRenderAsync(firstRender);
}
Expand Down Expand Up @@ -72,13 +72,19 @@ public void OnLoadJS()
/// <summary>
/// Gets or sets a value indicating whether the script should be loaded asynchronously.
/// </summary>
/// <remarks>
/// Default value is <see langword="false" />.
/// </remarks>
[Parameter]
public bool Async { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the script is meant to be executed
/// after the document has been parsed, but before firing DOMContentLoaded event..
/// </summary>
/// <remarks>
/// Default value is <see langword="false" />.
/// </remarks>
[Parameter]
public bool Defer { get; set; }

Expand All @@ -97,12 +103,18 @@ public void OnLoadJS()
/// <summary>
/// Gets or sets the ID of the script element.
/// </summary>
/// <remarks>
/// Default value is <see langword="null" />.
/// </remarks>
[Parameter]
public string? ScriptId { get; set; }

/// <summary>
/// Gets or sets the URI of the external script to load.
/// </summary>
/// <remarks>
/// Default value is <see langword="null" />.
/// </remarks>
[Parameter]
[EditorRequired]
public string? Source { get; set; } = default!;
Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/wwwroot/blazor.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ window.blazorBootstrap = {
return window.blazorBootstrap.googlemaps.instances[elementId];
},
initialize: (elementId, zoom, center, markers, clickable, dotNetHelper) => {
window.blazorBootstrap.googlemaps.markerEls[elementId] = window.blazorBootstrap.googlemaps.markerEls[elementId] ?? []
window.blazorBootstrap.googlemaps.markerEls[elementId] = window.blazorBootstrap.googlemaps.markerEls[elementId] ?? [];

let mapOptions = { center: center, zoom: zoom, mapId: elementId };
let map = new google.maps.Map(document.getElementById(elementId), mapOptions);
Expand Down

0 comments on commit 9d38484

Please sign in to comment.