diff --git a/demo/Blazor.GoogleMap.Server/Shared/NavMenu.razor b/demo/Blazor.GoogleMap.Server/Shared/NavMenu.razor
new file mode 100644
index 0000000..2127987
--- /dev/null
+++ b/demo/Blazor.GoogleMap.Server/Shared/NavMenu.razor
@@ -0,0 +1,27 @@
+
+
+
+
+@code {
+ bool collapseNavMenu = true;
+
+ string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
+
+ void ToggleNavMenu()
+ {
+ collapseNavMenu = !collapseNavMenu;
+ }
+}
diff --git a/demo/Blazor.GoogleMap.Server/Startup.cs b/demo/Blazor.GoogleMap.Server/Startup.cs
index 4d8bb09..0343329 100644
--- a/demo/Blazor.GoogleMap.Server/Startup.cs
+++ b/demo/Blazor.GoogleMap.Server/Startup.cs
@@ -1,46 +1,57 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.ResponseCompression;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-using Newtonsoft.Json.Serialization;
-using System.Linq;
namespace Blazor.GoogleMap.Server
{
public class Startup
{
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
- services.AddMvc().AddNewtonsoftJson();
- services.AddResponseCompression(opts =>
+ services.AddRazorPages();
+ services.AddServerSideBlazor().AddCircuitOptions(options => options.DetailedErrors = true);
+
+ services.AddGoogleMaps(options =>
{
- opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
- new[] { "application/octet-stream" });
+ options.ApiKey = Configuration["GoogleAPI"];
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
- app.UseResponseCompression();
-
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
- app.UseBlazorDebugging();
+ }
+ else
+ {
+ app.UseExceptionHandler("/Error");
+ // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
+ app.UseHsts();
}
+ app.UseHttpsRedirection();
+ app.UseStaticFiles();
+
app.UseRouting();
app.UseEndpoints(endpoints =>
{
- endpoints.MapDefaultControllerRoute();
+ endpoints.MapBlazorHub();
+ endpoints.MapFallbackToPage("/_Host");
});
-
- app.UseBlazor
();
}
}
}
diff --git a/demo/Blazor.GoogleMap.Client/_Imports.razor b/demo/Blazor.GoogleMap.Server/_Imports.razor
similarity index 56%
rename from demo/Blazor.GoogleMap.Client/_Imports.razor
rename to demo/Blazor.GoogleMap.Server/_Imports.razor
index b6b2538..0310bd2 100644
--- a/demo/Blazor.GoogleMap.Client/_Imports.razor
+++ b/demo/Blazor.GoogleMap.Server/_Imports.razor
@@ -1,10 +1,12 @@
-@using System.Net.Http
+@using System.Net.Http
+@using Microsoft.AspNetCore.Authorization
+@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
-@using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components.Routing
+@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
-@using Blazor.GoogleMap.Client
-@using Blazor.GoogleMap.Client.Shared
+@using Blazor.GoogleMap.Server
+@using Blazor.GoogleMap.Server.Shared
@using Blazor.GoogleMap.Components;
@using Blazor.GoogleMap.Map.Events;
@using Blazor.GoogleMap.Map.Markers;
diff --git a/demo/Blazor.GoogleMap.Server/appsettings.json b/demo/Blazor.GoogleMap.Server/appsettings.json
new file mode 100644
index 0000000..ff17aef
--- /dev/null
+++ b/demo/Blazor.GoogleMap.Server/appsettings.json
@@ -0,0 +1,11 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "AllowedHosts": "*",
+ "GoogleAPI": ""
+}
diff --git a/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapInterop.js b/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapInterop.js
new file mode 100644
index 0000000..9a1db77
--- /dev/null
+++ b/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapInterop.js
@@ -0,0 +1,75 @@
+// This file is to show how a library package may provide JavaScript interop features
+// wrapped in a .NET API
+
+window.blazorGoogleMap = {
+ infoWindowContentNodes: [],
+
+ initMapCallback: function () {
+ var currentThis = this === window
+ ? this.blazorGoogleMap
+ : this;
+
+ currentThis.map = new google.maps.Map(document.getElementById('map'), currentThis.initialMapOptions);
+ currentThis.infoWindow = new google.maps.InfoWindow();
+
+ if (currentThis.eventHandlersInvoker === undefined) {
+ return false;
+ }
+
+ currentThis.initDotnetCallback.invokeMethodAsync('OnInitFinished');
+ currentThis.eventHandlersInvoker.invokeMethodAsync('GetMouseEvents')
+ .then((events) => {
+ events.map(eventName => {
+ currentThis.map.addListener(eventName,
+ (function (e) {
+ return this.eventHandlersInvoker
+ .invokeMethodAsync('InvokeMouseEvent', eventName, e);
+ }).bind(currentThis)
+ );
+ });
+ });
+
+ return true;
+ },
+
+ initMap: function (initialMapOptions) {
+ blazorGoogleMap.initialMapOptions = initialMapOptions;
+ },
+
+ openInfoWindow: function (id, positionableObject, htmlContent) {
+ var content = {};
+ if (htmlContent !== undefined) {
+ content = htmlContent;
+ } else {
+ var nodeContent = blazorGoogleMap.infoWindowContentNodes.find(function (n) {
+ return n.id === id;
+ });
+
+ if (nodeContent === undefined) {
+ var node = document.getElementById(id);
+ node.removeAttribute("style");
+ blazorGoogleMap.infoWindowContentNodes.push({ id: id, node: node });
+ content = node;
+ } else {
+ content = nodeContent.node;
+ }
+ }
+
+ blazorGoogleMap.infoWindow.setContent(content);
+
+ var marker = blazorGoogleMap.markersModule.findMarker(positionableObject.id);
+ if (marker !== undefined) {
+ blazorGoogleMap.infoWindow.open(blazorGoogleMap.map, marker);
+ } else {
+ blazorGoogleMap.infoWindow.setPosition(positionableObject.position);
+ blazorGoogleMap.infoWindow.open(blazorGoogleMap.map);
+ }
+ },
+ registerEventInvokers: function (eventHandlersInvoker, initDotnetCallback) {
+ if (blazorGoogleMap) {
+
+ blazorGoogleMap.eventHandlersInvoker = eventHandlersInvoker;
+ blazorGoogleMap.initDotnetCallback = initDotnetCallback;
+ }
+ }
+};
diff --git a/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapMarkerInterop.js b/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapMarkerInterop.js
new file mode 100644
index 0000000..687fd83
--- /dev/null
+++ b/demo/Blazor.GoogleMap.Server/wwwroot/GoogleMapMarkerInterop.js
@@ -0,0 +1,109 @@
+window.blazorGoogleMap = window.blazorGoogleMap || {};
+window.blazorGoogleMap.markersModule = {
+ markers: [],
+
+ addMarker: function (markerRef, marker, markerId) {
+ var that = blazorGoogleMap.markersModule;
+ var mapMarker = new google.maps.Marker({
+ map: blazorGoogleMap.map,
+ position: marker.position,
+ title: marker.title,
+ animation: marker.animation,
+ label: marker.label,
+ icon: marker.icon,
+ opacity: marker.opacity,
+ draggable: marker.draggable,
+ clickable: marker.clickable,
+ cursor: marker.cursor
+ });
+
+ mapMarker.addListener('dragend', function (e) {
+ return markerRef.invokeMethodAsync('OnDragEndHandle', e);
+ });
+
+ if (marker.onClick !== null) {
+ mapMarker.addListener('click', function () {
+ return markerRef.invokeMethodAsync('OnClickHandle');
+ });
+ }
+
+ if (marker.onMarkerRightClick !== null) {
+ mapMarker.addListener('rightclick', function () {
+ return markerRef.invokeMethodAsync('OnRightClickHandle');
+ });
+ }
+
+ if (marker.onMarkerDblClick !== null) {
+ mapMarker.addListener('dblclick', function () {
+ return markerRef.invokeMethodAsync('OnDoubleClickHandle');
+ });
+ }
+
+ mapMarker.id = markerId;
+ that.markers.push({ mapMarker: mapMarker, markerRef: markerRef });
+
+ return true;
+ },
+
+ removeMarker: function (markerId) {
+ var markerPair = blazorGoogleMap.markersModule.markers.find(function (m) {
+ return m.mapMarker.id === markerId;
+ });
+
+ if (markerPair === undefined) {
+ return false;
+ }
+
+ markerPair.mapMarker.setMap(null);
+ const filteredMarkers = blazorGoogleMap.markersModule.markers.filter(
+ function (marker) {
+ return marker.id !== markerId;
+ }
+ );
+
+ var removeResult = filteredMarkers.length === blazorGoogleMap.markersModule.markers.length - 1;
+ blazorGoogleMap.markersModule.markers = filteredMarkers;
+
+ return removeResult;
+ },
+
+ setAnimation: function (markerId, animation) {
+ var marker =blazorGoogleMap.markersModule.findMarker(markerId);
+ if (marker !== undefined) {
+ marker.setAnimation(animation);
+ }
+ },
+
+ setIcon: function (markerId, icon) {
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
+ if (marker !== undefined) {
+ marker.setIcon(icon);
+ }
+ },
+
+ setOpacity: function (markerId, opacity) {
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
+ if (marker !== undefined) {
+ marker.setOpacity(opacity);
+ }
+ },
+
+ setVisibility: function (markerId, visible) {
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
+ if (marker !== undefined) {
+ marker.setVisible(visible);
+ }
+ },
+
+ findMarker: function (markerId) {
+ var that = this === window
+ ? blazorGoogleMap.markersModule
+ : this;
+
+ var marker = that.markers.find(function (m) {
+ return m.mapMarker.id === markerId;
+ });
+
+ return marker.mapMarker;
+ }
+};
\ No newline at end of file
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/bootstrap/bootstrap.min.css b/demo/Blazor.GoogleMap.Server/wwwroot/css/bootstrap/bootstrap.min.css
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/bootstrap/bootstrap.min.css
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/bootstrap/bootstrap.min.css
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/bootstrap/bootstrap.min.css.map b/demo/Blazor.GoogleMap.Server/wwwroot/css/bootstrap/bootstrap.min.css.map
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/bootstrap/bootstrap.min.css.map
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/bootstrap/bootstrap.min.css.map
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/FONT-LICENSE b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/FONT-LICENSE
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/FONT-LICENSE
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/FONT-LICENSE
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/ICON-LICENSE b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/ICON-LICENSE
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/ICON-LICENSE
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/ICON-LICENSE
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/README.md b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/README.md
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/README.md
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/README.md
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.eot
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.eot
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.otf
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.otf
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.svg b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.svg
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff b/demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.woff
similarity index 100%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/open-iconic/font/fonts/open-iconic.woff
diff --git a/demo/Blazor.GoogleMap.Client/wwwroot/css/site.css b/demo/Blazor.GoogleMap.Server/wwwroot/css/site.css
similarity index 56%
rename from demo/Blazor.GoogleMap.Client/wwwroot/css/site.css
rename to demo/Blazor.GoogleMap.Server/wwwroot/css/site.css
index fa2c7f1..c127ff7 100644
--- a/demo/Blazor.GoogleMap.Client/wwwroot/css/site.css
+++ b/demo/Blazor.GoogleMap.Server/wwwroot/css/site.css
@@ -1,9 +1,19 @@
-@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
+@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
+a, .btn-link {
+ color: #0366d6;
+}
+
+.btn-primary {
+ color: #fff;
+ background-color: #1b6ec2;
+ border-color: #1861ac;
+}
+
app {
position: relative;
display: flex;
@@ -20,61 +30,66 @@ app {
flex: 1;
}
- .main .top-row {
- background-color: #e6e6e6;
- border-bottom: 1px solid #d6d5d5;
- }
+.main .top-row {
+ background-color: #f7f7f7;
+ border-bottom: 1px solid #d6d5d5;
+ justify-content: flex-end;
+}
+
+.main .top-row > a {
+ margin-left: 1.5rem;
+}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
- .sidebar .top-row {
- background-color: rgba(0,0,0,0.4);
- }
+.sidebar .top-row {
+ background-color: rgba(0,0,0,0.4);
+}
- .sidebar .navbar-brand {
- font-size: 1.1rem;
- }
+.sidebar .navbar-brand {
+ font-size: 1.1rem;
+}
- .sidebar .oi {
- width: 2rem;
- font-size: 1.1rem;
- vertical-align: text-top;
- top: -2px;
- }
+.sidebar .oi {
+ width: 2rem;
+ font-size: 1.1rem;
+ vertical-align: text-top;
+ top: -2px;
+}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
- .nav-item:first-of-type {
- padding-top: 1rem;
- }
+.nav-item:first-of-type {
+ padding-top: 1rem;
+}
- .nav-item:last-of-type {
- padding-bottom: 1rem;
- }
+.nav-item:last-of-type {
+ padding-bottom: 1rem;
+}
- .nav-item a {
- color: #d7d7d7;
- border-radius: 4px;
- height: 3rem;
- display: flex;
- align-items: center;
- line-height: 3rem;
- }
+.nav-item a {
+ color: #d7d7d7;
+ border-radius: 4px;
+ height: 3rem;
+ display: flex;
+ align-items: center;
+ line-height: 3rem;
+}
- .nav-item a.active {
- background-color: rgba(255,255,255,0.25);
- color: white;
- }
+.nav-item a.active {
+ background-color: rgba(255,255,255,0.25);
+ color: white;
+}
- .nav-item a:hover {
- background-color: rgba(255,255,255,0.1);
- color: white;
- }
+.nav-item a:hover {
+ background-color: rgba(255,255,255,0.1);
+ color: white;
+}
.content {
padding-top: 1.1rem;
diff --git a/demo/Blazor.GoogleMap.Server/wwwroot/favicon.ico b/demo/Blazor.GoogleMap.Server/wwwroot/favicon.ico
new file mode 100644
index 0000000..a3a7999
Binary files /dev/null and b/demo/Blazor.GoogleMap.Server/wwwroot/favicon.ico differ
diff --git a/demo/Blazor.GoogleMap.Shared/Blazor.GoogleMap.Shared.csproj b/demo/Blazor.GoogleMap.Shared/Blazor.GoogleMap.Shared.csproj
deleted file mode 100644
index 2a77f0c..0000000
--- a/demo/Blazor.GoogleMap.Shared/Blazor.GoogleMap.Shared.csproj
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
- netstandard2.0
- 7.3
-
-
-
diff --git a/demo/Blazor.GoogleMap.Shared/WeatherForecast.cs b/demo/Blazor.GoogleMap.Shared/WeatherForecast.cs
deleted file mode 100644
index ef56edb..0000000
--- a/demo/Blazor.GoogleMap.Shared/WeatherForecast.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Blazor.GoogleMap.Shared
-{
- public class WeatherForecast
- {
- public DateTime Date { get; set; }
-
- public int TemperatureC { get; set; }
-
- public string Summary { get; set; }
-
- public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
- }
-}
diff --git a/src/Blazor.GoogleMap/Blazor.GoogleMap.csproj b/src/Blazor.GoogleMap/Blazor.GoogleMap.csproj
index 519d1a5..6b8f829 100644
--- a/src/Blazor.GoogleMap/Blazor.GoogleMap.csproj
+++ b/src/Blazor.GoogleMap/Blazor.GoogleMap.csproj
@@ -1,7 +1,7 @@
- netstandard2.0
+ netcoreapp3.0
Library
true
false
@@ -34,11 +34,8 @@
-
-
-
-
+
diff --git a/src/Blazor.GoogleMap/Components/GoogleMap.cs b/src/Blazor.GoogleMap/Components/GoogleMap.cs
index 335be75..aff9e0d 100644
--- a/src/Blazor.GoogleMap/Components/GoogleMap.cs
+++ b/src/Blazor.GoogleMap/Components/GoogleMap.cs
@@ -2,7 +2,9 @@
using Blazor.GoogleMap.Map;
using Blazor.GoogleMap.Map.Events;
using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.RenderTree;
+using System;
using System.Threading.Tasks;
namespace Blazor.GoogleMap.Components
@@ -18,15 +20,15 @@ public class GoogleMap : ComponentBase
[Inject] IMouseEventsInovkable MouseEventsInovkable { get; set; }
- [Parameter] string Id { get; set; } = "map";
+ [Parameter] public string Id { get; set; } = "map";
- [Parameter] string CssClasses { get; set; } = "map";
+ [Parameter] public string CssClasses { get; set; } = "map";
- [Parameter] InitialMapOptions InitialMapOptions { get; set; } = new InitialMapOptions();
+ [Parameter] public InitialMapOptions InitialMapOptions { get; set; } = new InitialMapOptions();
- [Parameter] EventCallback OnClick { get; set; }
+ [Parameter] public EventCallback OnClick { get; set; }
- [Parameter] EventCallback OnDoubleClick { get; set; }
+ [Parameter] public EventCallback OnDoubleClick { get; set; }
public GoogleMap()
{
@@ -37,45 +39,48 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
base.BuildRenderTree(builder);
var internalBuilder = new BlazorRendererTreeBuilder(builder);
+ if(string.IsNullOrEmpty(GoogleMapOptions.Width) || string.IsNullOrEmpty(GoogleMapOptions.Height))
+ {
+ throw new ArgumentNullException("Map width and height must have some values.");
+ }
+
internalBuilder
.OpenElement("div")
+ .AddAttribute("style", $"width: {GoogleMapOptions.Width}; height: {GoogleMapOptions.Height}")
.AddAttribute("id", Id)
.AddAttribute("class", CssClasses)
.OpenElement("script")
.AddAttribute("async", "")
.AddAttribute("defer", "")
- .AddAttribute("src", GoogleMapOptions.MapJsWasIncluded
- ? string.Empty
- : $"https://maps.googleapis.com/maps/api/js?key={GoogleMapOptions.ApiKey}&callback=blazorGoogleMap.initMapCallback")
+ .AddAttribute("src", !string.IsNullOrEmpty(GoogleMapOptions.ApiKey)
+ ? $"https://maps.googleapis.com/maps/api/js?key={GoogleMapOptions.ApiKey}&callback=blazorGoogleMap.initMapCallback"
+ : string.Empty
+ )
.CloseElement()
.CloseElement();
}
- protected override async Task OnInitAsync()
+ protected async override Task OnAfterRenderAsync(bool firstRender)
{
+
MouseEventsInovkable
- .RegisterCallback(MouseEvent.Click, OnClick)
- .RegisterCallback(MouseEvent.DblClick, OnDoubleClick);
+ .RegisterCallback(MouseEvent.Click, OnClick)
+ .RegisterCallback(MouseEvent.DblClick, OnDoubleClick);
- await GoogleMapInterop.RegisterCallbacks(new Map.InitMapCallback(MapInitialized));
+ await GoogleMapInterop.RegisterCallbacks(new InitMapCallback(MapInitialized));
await GoogleMapInterop.InitMap(InitialMapOptions);
- }
- protected override Task OnAfterRenderAsync()
- {
- if (GoogleMapOptions.MapJsWasIncluded && !mapWasInitialized)
+ if (!mapWasInitialized && firstRender)
{
- return GoogleMapInterop.ExecuteInitMapCallback();
+ await GoogleMapInterop.ExecuteInitMapCallback();
+ mapWasInitialized = true;
}
-
- return Task.CompletedTask;
}
private void MapInitialized()
{
- GoogleMapOptions.MapJsWasIncluded = true;
- mapWasInitialized = true;
+ //TODO: Do some extra operations if needed when map is initialized
}
}
}
diff --git a/src/Blazor.GoogleMap/Components/GoogleMapInfoWindow.cs b/src/Blazor.GoogleMap/Components/GoogleMapInfoWindow.cs
index 4eccf08..8e247e4 100644
--- a/src/Blazor.GoogleMap/Components/GoogleMapInfoWindow.cs
+++ b/src/Blazor.GoogleMap/Components/GoogleMapInfoWindow.cs
@@ -1,5 +1,6 @@
using Blazor.GoogleMap.Components.Rendering;
using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.RenderTree;
using System;
@@ -8,9 +9,9 @@ namespace Blazor.GoogleMap.Components
[Route("/googlemapinfowindow")]
public class GoogleMapInfoWindow : ComponentBase
{
- [Parameter] RenderFragment ChildContent { get; set; }
+ [Parameter] public RenderFragment ChildContent { get; set; }
- [Parameter] string Id { get; set; }
+ [Parameter] public string Id { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
diff --git a/src/Blazor.GoogleMap/Components/Rendering/BlazorRendererTreeBuilder.cs b/src/Blazor.GoogleMap/Components/Rendering/BlazorRendererTreeBuilder.cs
index 497c0ee..0d4708a 100644
--- a/src/Blazor.GoogleMap/Components/Rendering/BlazorRendererTreeBuilder.cs
+++ b/src/Blazor.GoogleMap/Components/Rendering/BlazorRendererTreeBuilder.cs
@@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Components;
-using Microsoft.AspNetCore.Components.RenderTree;
+using Microsoft.AspNetCore.Components.Rendering;
using System;
namespace Blazor.GoogleMap.Components.Rendering
@@ -42,7 +42,7 @@ public IRendererTreeBuilder AddAttribute(string name, MulticastDelegate value)
return this;
}
- public IRendererTreeBuilder AddAttribute(string name, Action value)
+ public IRendererTreeBuilder AddAttribute(string name, Action value)
{
renderTreeBuilder.AddAttribute(++sequence, name, value);
diff --git a/src/Blazor.GoogleMap/Components/Rendering/IRendererTreeBuilder.cs b/src/Blazor.GoogleMap/Components/Rendering/IRendererTreeBuilder.cs
index 7200fce..09af4c0 100644
--- a/src/Blazor.GoogleMap/Components/Rendering/IRendererTreeBuilder.cs
+++ b/src/Blazor.GoogleMap/Components/Rendering/IRendererTreeBuilder.cs
@@ -19,7 +19,7 @@ public interface IRendererTreeBuilder
IRendererTreeBuilder AddAttribute(string name, Func value);
- IRendererTreeBuilder AddAttribute(string name, Action value);
+ IRendererTreeBuilder AddAttribute(string name, Action value);
IRendererTreeBuilder AddContent(string textContent);
diff --git a/src/Blazor.GoogleMap/GoogleMapInterop.cs b/src/Blazor.GoogleMap/GoogleMapInterop.cs
index 1ef6b3d..92a4680 100644
--- a/src/Blazor.GoogleMap/GoogleMapInterop.cs
+++ b/src/Blazor.GoogleMap/GoogleMapInterop.cs
@@ -18,27 +18,29 @@ public GoogleMapInterop(IJSRuntime jSRuntime, IMouseEventsInovkable mouseEventsI
this.mouseEventsInovkable = mouseEventsInovkable ?? throw new ArgumentNullException(nameof(mouseEventsInovkable));
}
- public Task InitMap(InitialMapOptions initialMapOptions)
+ public async Task InitMap(InitialMapOptions initialMapOptions)
{
- return jSRuntime.InvokeAsync("blazorGoogleMap.initMap", initialMapOptions);
+
+ await jSRuntime.InvokeVoidAsync("blazorGoogleMap.initMap", initialMapOptions);
}
- public Task ExecuteInitMapCallback()
+ public async Task ExecuteInitMapCallback()
{
- return jSRuntime.InvokeAsync("blazorGoogleMap.initMapCallback");
+ await jSRuntime.InvokeAsync("blazorGoogleMap.initMapCallback");
}
- public Task RegisterCallbacks(InitMapCallback initMapCallback)
+ public async Task RegisterCallbacks(InitMapCallback initMapCallback)
{
- return jSRuntime.InvokeAsync(
- "blazorGoogleMap.registerEventInvokers",
- new DotNetObjectRef(mouseEventsInovkable), new DotNetObjectRef(initMapCallback));
+ var mouseEvents = DotNetObjectReference.Create(mouseEventsInovkable);
+ var mapCallBack = DotNetObjectReference.Create(initMapCallback);
+
+ await jSRuntime.InvokeAsync("blazorGoogleMap.registerEventInvokers", mouseEvents,mapCallBack );
+
}
- public Task CreateInfoWindow(string id, LatLng position)
+ public async Task CreateInfoWindow(string id, LatLng position)
{
- return jSRuntime.InvokeAsync(
- "blazorGoogleMap.createInfoWindow", id, position);
+ return await jSRuntime.InvokeAsync("blazorGoogleMap.createInfoWindow", id, position);
}
}
}
diff --git a/src/Blazor.GoogleMap/GoogleMapOptions.cs b/src/Blazor.GoogleMap/GoogleMapOptions.cs
index 881a6fa..3d04508 100644
--- a/src/Blazor.GoogleMap/GoogleMapOptions.cs
+++ b/src/Blazor.GoogleMap/GoogleMapOptions.cs
@@ -3,6 +3,9 @@
public class GoogleMapOptions
{
public string ApiKey { get; set; }
+ public string Width { get; set; } = "600px";
+ public string Height { get; set; } = "600px";
+
}
internal class GoogleMapRestrictedOptions : GoogleMapOptions
diff --git a/src/Blazor.GoogleMap/Map/InfoWindows/IInfoWindowHandle.cs b/src/Blazor.GoogleMap/Map/InfoWindows/IInfoWindowHandle.cs
index 3a47495..47a93c2 100644
--- a/src/Blazor.GoogleMap/Map/InfoWindows/IInfoWindowHandle.cs
+++ b/src/Blazor.GoogleMap/Map/InfoWindows/IInfoWindowHandle.cs
@@ -5,8 +5,8 @@ namespace Blazor.GoogleMap.Map.InfoWindows
{
public interface IInfoWindowHandle
{
- Task Open(string infoWindowId, ILocationable locationable);
+ Task Open(string infoWindowId, ILocationable locationable);
- Task Open(MarkupString htmlContent, ILocationable locationable);
+ Task Open(MarkupString htmlContent, ILocationable locationable);
}
}
diff --git a/src/Blazor.GoogleMap/Map/InfoWindows/InfoWindow.cs b/src/Blazor.GoogleMap/Map/InfoWindows/InfoWindow.cs
index 86c25b0..6ed0a30 100644
--- a/src/Blazor.GoogleMap/Map/InfoWindows/InfoWindow.cs
+++ b/src/Blazor.GoogleMap/Map/InfoWindows/InfoWindow.cs
@@ -11,15 +11,15 @@ public InfoWindow(IJSRuntime jSRuntime)
{
}
- public Task Open(string infoWindowId, ILocationable locationable = null)
+ public async Task Open(string infoWindowId, ILocationable locationable = null)
{
- return jSRuntime.InvokeAsync(
+ return await jSRuntime.InvokeAsync(
"blazorGoogleMap.openInfoWindow", infoWindowId, locationable);
}
- public Task Open(MarkupString htmlContent, ILocationable locationable)
+ public async Task Open(MarkupString htmlContent, ILocationable locationable)
{
- return jSRuntime.InvokeAsync(
+ return await jSRuntime.InvokeAsync(
"blazorGoogleMap.openInfoWindow", string.Empty, locationable, htmlContent.ToString());
}
}
diff --git a/src/Blazor.GoogleMap/Map/Markers/Marker.cs b/src/Blazor.GoogleMap/Map/Markers/Marker.cs
index c671e15..fd69db6 100644
--- a/src/Blazor.GoogleMap/Map/Markers/Marker.cs
+++ b/src/Blazor.GoogleMap/Map/Markers/Marker.cs
@@ -83,21 +83,21 @@ await jSRuntime.InvokeAsync(
"blazorGoogleMap.markersModule.setAnimation", Id, markerAnimation);
}
- public Task SetIcon(string iconUrl)
+ public async Task SetIcon(string iconUrl)
{
Options.Icon = iconUrl;
- return jSRuntime.InvokeAsync(
+ return await jSRuntime.InvokeAsync(
"blazorGoogleMap.markersModule.setIcon", Id, iconUrl);
}
- public Task SetOpacity(double opacity)
+ public async Task> SetOpacity(double opacity)
{
Options.Opacity = opacity;
return jSRuntime.InvokeAsync(
"blazorGoogleMap.markersModule.setOpacity", Id, opacity);
}
- public Task SetVisibility(bool visible)
+ public async Task> SetVisibility(bool visible)
{
Options.Visible = visible;
return jSRuntime.InvokeAsync(
diff --git a/src/Blazor.GoogleMap/Map/Markers/MarkerCollection.cs b/src/Blazor.GoogleMap/Map/Markers/MarkerCollection.cs
index fb83dfa..79c608f 100644
--- a/src/Blazor.GoogleMap/Map/Markers/MarkerCollection.cs
+++ b/src/Blazor.GoogleMap/Map/Markers/MarkerCollection.cs
@@ -32,7 +32,7 @@ public async Task Add(MarkerOptions markerOptions)
await jSRuntime.InvokeAsync(
"blazorGoogleMap.markersModule.addMarker",
- new DotNetObjectRef(marker), markerOptions, marker.Id);
+ DotNetObjectReference.Create(marker), markerOptions, marker.Id);
markers.Add(marker.Id, marker);
diff --git a/src/Blazor.GoogleMap/ServiceCollectionExtensions.cs b/src/Blazor.GoogleMap/ServiceCollectionExtensions.cs
index 259bfcc..908f7d2 100644
--- a/src/Blazor.GoogleMap/ServiceCollectionExtensions.cs
+++ b/src/Blazor.GoogleMap/ServiceCollectionExtensions.cs
@@ -20,11 +20,11 @@ public static IServiceCollection AddGoogleMaps(this IServiceCollection services,
configure.Invoke(googleMapOptions);
services.AddSingleton(googleMapOptions);
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
return services;
}
diff --git a/src/Blazor.GoogleMap/content/GoogleMapInterop.js b/src/Blazor.GoogleMap/content/GoogleMapInterop.js
index 7cc73da..de50d2a 100644
--- a/src/Blazor.GoogleMap/content/GoogleMapInterop.js
+++ b/src/Blazor.GoogleMap/content/GoogleMapInterop.js
@@ -8,7 +8,6 @@ window.blazorGoogleMap = {
var currentThis = this === window
? this.blazorGoogleMap
: this;
-
currentThis.map = new google.maps.Map(document.getElementById('map'), currentThis.initialMapOptions);
currentThis.infoWindow = new google.maps.InfoWindow();
@@ -33,7 +32,7 @@ window.blazorGoogleMap = {
},
initMap: function (initialMapOptions) {
- this.blazorGoogleMap.initialMapOptions = initialMapOptions;
+ blazorGoogleMap.initialMapOptions = initialMapOptions;
},
openInfoWindow: function (id, positionableObject, htmlContent) {
@@ -41,33 +40,35 @@ window.blazorGoogleMap = {
if (htmlContent !== undefined) {
content = htmlContent;
} else {
- var nodeContent = this.blazorGoogleMap.infoWindowContentNodes.find(function (n) {
+ var nodeContent = blazorGoogleMap.infoWindowContentNodes.find(function (n) {
return n.id === id;
});
if (nodeContent === undefined) {
var node = document.getElementById(id);
node.removeAttribute("style");
- this.blazorGoogleMap.infoWindowContentNodes.push({ id: id, node: node });
+ blazorGoogleMap.infoWindowContentNodes.push({ id: id, node: node });
content = node;
} else {
content = nodeContent.node;
}
}
-
- this.blazorGoogleMap.infoWindow.setContent(content);
- var marker = this.blazorGoogleMap.markersModule.findMarker(positionableObject.id);
+ blazorGoogleMap.infoWindow.setContent(content);
+
+ var marker = blazorGoogleMap.markersModule.findMarker(positionableObject.id);
if (marker !== undefined) {
- this.blazorGoogleMap.infoWindow.open(this.blazorGoogleMap.map, marker);
+ blazorGoogleMap.infoWindow.open(blazorGoogleMap.map, marker);
} else {
- this.blazorGoogleMap.infoWindow.setPosition(positionableObject.position);
- this.blazorGoogleMap.infoWindow.open(this.blazorGoogleMap.map);
+ blazorGoogleMap.infoWindow.setPosition(positionableObject.position);
+ blazorGoogleMap.infoWindow.open(blazorGoogleMap.map);
}
},
-
registerEventInvokers: function (eventHandlersInvoker, initDotnetCallback) {
- this.blazorGoogleMap.eventHandlersInvoker = eventHandlersInvoker;
- this.blazorGoogleMap.initDotnetCallback = initDotnetCallback;
+ if (blazorGoogleMap) {
+
+ blazorGoogleMap.eventHandlersInvoker = eventHandlersInvoker;
+ blazorGoogleMap.initDotnetCallback = initDotnetCallback;
+ }
}
};
diff --git a/src/Blazor.GoogleMap/content/GoogleMapMarkerInterop.js b/src/Blazor.GoogleMap/content/GoogleMapMarkerInterop.js
index df5d9f7..d981793 100644
--- a/src/Blazor.GoogleMap/content/GoogleMapMarkerInterop.js
+++ b/src/Blazor.GoogleMap/content/GoogleMapMarkerInterop.js
@@ -3,9 +3,9 @@ window.blazorGoogleMap.markersModule = {
markers: [],
addMarker: function (markerRef, marker, markerId) {
- var that = this.blazorGoogleMap.markersModule;
+ var that = blazorGoogleMap.markersModule;
var mapMarker = new google.maps.Marker({
- map: this.blazorGoogleMap.map,
+ map: blazorGoogleMap.map,
position: marker.position,
title: marker.title,
animation: marker.animation,
@@ -46,7 +46,7 @@ window.blazorGoogleMap.markersModule = {
},
removeMarker: function (markerId) {
- var markerPair = this.blazorGoogleMap.markersModule.markers.find(function (m) {
+ var markerPair = blazorGoogleMap.markersModule.markers.find(function (m) {
return m.mapMarker.id === markerId;
});
@@ -55,41 +55,41 @@ window.blazorGoogleMap.markersModule = {
}
markerPair.mapMarker.setMap(null);
- const filteredMarkers = this.blazorGoogleMap.markersModule.markers.filter(
+ const filteredMarkers = blazorGoogleMap.markersModule.markers.filter(
function (marker) {
return marker.id !== markerId;
}
);
- var removeResult = filteredMarkers.length === this.blazorGoogleMap.markersModule.markers.length - 1;
- this.blazorGoogleMap.markersModule.markers = filteredMarkers;
+ var removeResult = filteredMarkers.length === blazorGoogleMap.markersModule.markers.length - 1;
+ blazorGoogleMap.markersModule.markers = filteredMarkers;
return removeResult;
},
setAnimation: function (markerId, animation) {
- var marker = this.blazorGoogleMap.markersModule.findMarker(markerId);
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
if (marker !== undefined) {
marker.setAnimation(animation);
}
},
setIcon: function (markerId, icon) {
- var marker = this.blazorGoogleMap.markersModule.findMarker(markerId);
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
if (marker !== undefined) {
marker.setIcon(icon);
}
},
setOpacity: function (markerId, opacity) {
- var marker = this.blazorGoogleMap.markersModule.findMarker(markerId);
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
if (marker !== undefined) {
marker.setOpacity(opacity);
}
},
setVisibility: function (markerId, visible) {
- var marker = this.blazorGoogleMap.markersModule.findMarker(markerId);
+ var marker = blazorGoogleMap.markersModule.findMarker(markerId);
if (marker !== undefined) {
marker.setVisible(visible);
}
@@ -97,7 +97,7 @@ window.blazorGoogleMap.markersModule = {
findMarker: function (markerId) {
var that = this === window
- ? this.blazorGoogleMap.markersModule
+ ? blazorGoogleMap.markersModule
: this;
var marker = that.markers.find(function (m) {