How rungwiroon/blazorgooglemaps works
This project is a Blazor-based library and demonstration suite that provides interop with the Google Maps JavaScript API. In other words, it is a specialized open-source tool designed to enable Blazor applications to easily integrate Google Maps functionality. The repository contains a core library (GoogleMapsComponents) that encapsulates all of the map types, markers, overlays, event-handling and other related classes, plus two demo applications (ClientSideDemo and ServerSideDemo) that illustrate how to use the library in both Blazor WebAssembly and Blazor Server contexts.
Main components
• Core Library – GoogleMapsComponents: This is where nearly all of the functionality is encapsulated. It contains various namespaces, classes, and helper functions related to maps, markers, overlays, event objects, and even serialization.
• Client-Side Demo – ClientSideDemo: A Blazor WebAssembly application demonstrating usage of the library. It includes pages (for example, Maps.razor, MapMarker.razor, etc.), shared components for layout/navigation and uses the library through dependency injection.
• Server-Side Demo – ServerSideDemo: A Blazor Server application with similar pages to the client-side demo, also showcasing the library’s features. It uses standards like _Host.cshtml for server-side hosting.
• Configuration and Build Infrastructure – Including GitHub workflows, package.json, and solution-level files (BlazorGoogleMaps.sln) for project management and CI/CD.
Component Relationships and Interactions
• The GoogleMapsComponents library is the core that provides the map components (like GoogleMap, AdvancedGoogleMap, MarkerComponent, etc.) and the supporting classes representing different map features (e.g., markers, overlays, layers).
• Both Demo projects (ClientSideDemo and ServerSideDemo) consume the library. They set up a dependency injection container (via Startup.cs) that registers the Google Maps key service (IBlazorGoogleMapsKeyService) and load options.
• The demos interact with the library’s components in their pages by including the UI components (e.g., <GoogleMap>, <AdvancedGoogleMap>) and passing configuration options and event handlers.
• Deployment and pipeline configuration is handled in the .github directory, which ensures continuous integration builds run when changes occur.
Architectural Patterns and Design Principles
• Component-Based Architecture: The project is built around reusable Blazor components that encapsulate both the display logic and mapping functionality.
• Dependency Injection: Services are added and managed (for example, Google Maps API key services) ensuring the application is configurable, testable, and maintainable.
• Separation of Concerns: The core mapping functionalities are split into multiple dedicated classes and namespaces (e.g., Maps/Data, Maps/Controls, Maps/Places, etc.), which then get consumed by higher-level UI components.
Technologies and Frameworks
• Blazor (WebAssembly for ClientSideDemo and Server for ServerSideDemo) serves as the foundation for the UI.
• .NET (with migrations to .NET 8) forms the runtime environment.
• Google Maps JavaScript API (integrated via external script loading, along with additional extras like MarkerClusterer) provides the underlying mapping engine.
• JavaScript interop: The library includes JavaScript files (e.g., objectManager.js) to manage direct interactions with the Google Maps API.
• System.Text.Json for JSON serialization (note the migration from Newtonsoft.Json).