### Install BlazorLeaflet package
Source: https://github.com/mehigh17/blazorleaflet/blob/master/README.md
Use the .NET CLI to add the BlazorLeaflet package to your project.
```bash
dotnet add package BlazorLeaflet
```
--------------------------------
### Bind map parameters
Source: https://github.com/mehigh17/blazorleaflet/blob/master/README.md
Initialize the Map object and starting coordinates in your C# code.
```csharp
private Map _map = new Map(jsRuntime);
private PointF _startAt = new PointF(47.5574007f, 16.3918687f);
```
--------------------------------
### TileLayer Subdomains
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/classBlazorLeaflet_1_1Models_1_1TileLayer.html
Defines the subdomains for the tile service. Example shows initialization with a single subdomain.
```csharp
string [] BlazorLeaflet.Models.TileLayer.Subdomains = new string [] { "abc" }
```
--------------------------------
### Configure and Add Marker with Icon, Tooltip, and Popup
Source: https://context7.com/mehigh17/blazorleaflet/llms.txt
Create and configure a Marker with custom icon, tooltip, and popup. Handles marker events like click and drag, updating its position and popup content.
```csharp
using System.Drawing;
using BlazorLeaflet.Models;
using BlazorLeaflet.Models.Events;
// Create a basic marker
var marker = new Marker(47.5574007f, 16.3918687f)
{
Title = "Vienna",
Draggable = true,
Opacity = 1.0,
RiseOnHover = true
};
// Add custom icon
marker.Icon = new Icon
{
Url = "images/custom-marker.png",
Size = new Size(32, 32),
Anchor = new Point(16, 32),
PopupAnchor = new Point(0, -32)
};
// Add tooltip (shown on hover)
marker.Tooltip = new Tooltip
{
Content = "Hover tooltip content",
Direction = "top",
IsPermanent = false,
IsSticky = false,
Opacity = 0.9
};
// Add popup (shown on click)
marker.Popup = new Popup
{
Content = "Vienna Capital of Austria",
MaximumWidth = 300,
MinimumWidth = 50,
AutoPanEnabled = true,
ShowCloseButton = true
};
// Handle marker events
marker.OnClick += (sender, e) =>
{
Console.WriteLine($"Marker clicked at {e.LatLng.Lat}, {e.LatLng.Lng}");
};
marker.OnDrag += (sender, e) =>
{
Console.WriteLine($"Dragging to {e.LatLng.Lat}, {e.LatLng.Lng}");
};
marker.OnDragEnd += (sender, e) =>
{
marker.Position = e.LatLng;
marker.Popup.Content = $"Moved to {e.LatLng.Lat:0.00}, {e.LatLng.Lng:0.00}";
await LeafletInterops.UpdatePopupContent(jsRuntime, _map.Id, marker);
};
_map.AddLayer(marker);
```
--------------------------------
### BlazorLeaflet Models Overview
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/classBlazorLeaflet_1_1Models_1_1Tooltip-members.html
Overview of the Layer model and its associated properties and event handlers.
```APIDOC
## BlazorLeaflet.Models.Layer
### Description
The Layer class serves as the base model for map layers in BlazorLeaflet, supporting Tooltips and Popups.
### Properties
- **Opacity** (float) - Controls the transparency of the layer.
- **Pane** (string) - The map pane where the layer is rendered.
- **Popup** (Popup) - Associated popup content for the layer.
- **Tooltip** (Tooltip) - Associated tooltip content for the layer.
### Event Handlers
- **PopupEventHandler**(Layer sender, PopupEvent e) - Triggered when a popup event occurs on the layer.
- **TooltipEventHandler**(Layer sender, TooltipEvent e) - Triggered when a tooltip event occurs on the layer.
```
--------------------------------
### Map Methods
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/classBlazorLeaflet_1_1Map.html
Core methods for managing layers and initializing the map.
```APIDOC
## Map Methods
### AddLayer
- **Description**: Adds a layer to the map.
- **Parameters**:
- **layer** (Layer) - Required - The layer to be added.
- **Exceptions**:
- System.ArgumentNullException: Throws when the layer is null.
- UninitializedMapException: Throws when the map has not been yet initialized.
### GetLayers
- **Description**: Retrieves a read-only collection of the current layers on the map.
- **Returns**: IReadOnlyCollection - A read-only collection of layers.
### RaiseOnInitialized
- **Description**: This method MUST be called only once by the Blazor component upon rendering, and never by the user.
### RemoveLayer
- **Description**: Removes a layer from the map.
- **Parameters**:
- **layer** (Layer) - Required - The layer to be removed.
- **Exceptions**:
- System.ArgumentNullException: Throws when the layer is null.
- UninitializedMapException: Throws when the map has not been yet initialized.
```
--------------------------------
### Create a Circle Layer
Source: https://context7.com/mehigh17/blazorleaflet/llms.txt
Draws a circle with a center point and radius in meters, supporting dynamic updates.
```csharp
using BlazorLeaflet.Models;
var circle = new Circle
{
Position = new LatLng(51.508f, -0.11f),
Radius = 500f, // Radius in meters
DrawStroke = true,
StrokeColor = Color.Green,
StrokeWidth = 2,
Fill = true,
FillColor = Color.LightGreen,
FillOpacity = 0.4,
Tooltip = new Tooltip
{
Content = "500m radius zone"
}
};
// Update circle radius dynamically
circle.Radius = 1000f;
await LeafletInterops.UpdateShape(jsRuntime, _map.Id, circle);
_map.AddLayer(circle);
```
--------------------------------
### Reference interop script
Source: https://github.com/mehigh17/blazorleaflet/blob/master/README.md
Include the required JavaScript interop file in your HTML head section.
```html
```
--------------------------------
### Initialize map component
Source: https://github.com/mehigh17/blazorleaflet/blob/master/README.md
Wrap the LeafletMap component in a container with defined dimensions.
```html
```
--------------------------------
### BlazorLeaflet Models Reference
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/classBlazorLeaflet_1_1Models_1_1Polygon-members.html
Overview of the properties and event handlers for BlazorLeaflet models.
```APIDOC
## BlazorLeaflet Models Reference
### Description
This section details the properties and event handlers available for various BlazorLeaflet models, including Polyline, Path, and Layer.
### Properties
- **Shape** (Polyline) - Defines the shape configuration.
- **SmoothFactory** (Polyline) - Factory for smoothing polyline shapes.
- **StrokeColor** (Path) - The color of the stroke.
- **StrokeDashArray** (Path) - A string that defines the stroke dash pattern.
- **StrokeDashOffset** (Path) - The offset of the stroke dash pattern.
- **StrokeOpacity** (Path) - The opacity of the stroke.
- **StrokeWidth** (Path) - The width of the stroke in pixels.
- **Tooltip** (Layer) - The tooltip associated with the layer.
### Event Handlers
- **TooltipEventHandler** (Layer) - Delegate: (Layer sender, TooltipEvent e). Handles tooltip events for layers.
```
--------------------------------
### Including Open Iconic with Foundation
Source: https://github.com/mehigh17/blazorleaflet/blob/master/BlazorLeaflet/BlazorLeaflet.Samples/wwwroot/css/open-iconic/README.md
Link to the Foundation stylesheet for Open Iconic. This enables the use of 'fi' prefixed classes for icons.
```html
```
```html
```
--------------------------------
### Create a Polyline Layer
Source: https://context7.com/mehigh17/blazorleaflet/llms.txt
Connects multiple coordinate points with line segments.
```csharp
using System.Drawing;
using BlazorLeaflet.Models;
var polyline = new Polyline
{
Shape = new[]
{
new[]
{
new PointF(45.51f, -122.68f),
new PointF(37.77f, -122.43f),
new PointF(34.04f, -118.2f)
}
},
DrawStroke = true,
StrokeColor = Color.Purple,
StrokeWidth = 4,
StrokeOpacity = 0.8,
SmoothFactory = 1.0, // Line simplification factor
NoClipEnabled = false,
Tooltip = new Tooltip
{
Content = "West Coast Route"
}
};
_map.AddLayer(polyline);
```
--------------------------------
### Add marker to map
Source: https://github.com/mehigh17/blazorleaflet/blob/master/README.md
Create a marker with a tooltip and icon, then add it to the map layers.
```csharp
// Create the marker
var marker = new Marker(0.23f, 32f);
marker.Tooltip = new Tooltip { Content = "This is a nice location!" };
marker.Icon = new Icon { Url = "... some url" };
// Add it to the layers collection
_map.AddLayer(marker);
```
--------------------------------
### Tooltip Event Handling
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/classBlazorLeaflet_1_1Models_1_1DivOverlay-members.html
Details on how to handle tooltip events for layers within the BlazorLeaflet library.
```APIDOC
## TooltipEventHandler
### Description
This event handler is used to manage tooltip events associated with a Layer in BlazorLeaflet. It is defined within the BlazorLeaflet.Models.Layer class.
### Method
TooltipEventHandler
### Endpoint
N/A (This is a callback/event handler signature, not a REST endpoint)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```csharp
// Example usage within a Blazor component:
// Assuming 'myLayer' is an instance of BlazorLeaflet.Models.Layer
myLayer.TooltipEventHandler = (sender, e) => {
// Handle tooltip event logic here
Console.WriteLine("Tooltip event triggered!");
};
```
### Response
#### Success Response (N/A)
This is an event handler, not an API endpoint that returns a response.
#### Response Example
N/A
```
--------------------------------
### BlazorLeaflet.Utils Namespace
Source: https://github.com/mehigh17/blazorleaflet/blob/master/docs/namespaceBlazorLeaflet_1_1Utils.html
Overview of the classes available within the BlazorLeaflet.Utils namespace.
```APIDOC
## BlazorLeaflet.Utils Namespace
### Description
The BlazorLeaflet.Utils namespace provides utility functionality to support the BlazorLeaflet component library.
### Classes
- **StringHelper** (class) - Provides string manipulation utilities for the library.
```
--------------------------------
### Blazor Leaflet Interactive Map Demo
Source: https://context7.com/mehigh17/blazorleaflet/llms.txt
This Blazor component demonstrates a complete interactive map with features like adding markers, fitting bounds to markers, clearing markers, and displaying map center and zoom information. It requires BlazorLeaflet and System.Drawing namespaces.
```csharp
@page "/map-demo"
@using System.Drawing
@using BlazorLeaflet
@using BlazorLeaflet.Models
@using BlazorLeaflet.Models.Events
@inject IJSRuntime jsRuntime