LeafletForBlazor 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package LeafletForBlazor --version 1.2.2
NuGet\Install-Package LeafletForBlazor -Version 1.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LeafletForBlazor" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LeafletForBlazor --version 1.2.2
#r "nuget: LeafletForBlazor, 1.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LeafletForBlazor as a Cake Addin
#addin nuget:?package=LeafletForBlazor&version=1.2.2

// Install LeafletForBlazor as a Cake Tool
#tool nuget:?package=LeafletForBlazor&version=1.2.2

LealletForBlazor32 Leaflet Map for Blazor

You can quickly add a map to the blazor page. In addition, you can add GeoJSON data in the map, symbolize Map items, add tooltips to map items, working with basemap and overlay layers and others

NuGet Package

This package is under development, but I will keep the code compatible from one version to another.

You can find more information:


What's New?

Working with GeoJOSN string array

GeoJSON data can be loaded as strings.

Add in your Blazor Page:
<Map
	width="800px"
	height="600px"
	Parameters="@parameters"
	GeoJSON_strings="@date_geojson.ToArray()"
></Map>
Blazor code block:
List<string> date_geojson = new List<string>()
{
   "[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[26.097369,44.444941]},\"properties\":{\"name\":\"Beautiful Memories Store\"}}]"
};

Basic Map configuration

Add in _Imports.razor project file
@using LeafletForBlazor
Add in your Blazor Page:
<Map 
	width="600px" 
	height="600px"
	Parameters="@parameters"
></Map>
Blazor code block:
@code {
	//map initialization parameters
	Map.LoadParameters parameters = new Map.LoadParameters()
	{
		location = new Map.Location()
		{
			longitude = 26.097133,
			latitude = 44.446165
		},
		zoom_level = 12
	};
}

Basic Map configuration - GitHub example code

Map scale

Blazor Page:
<Map 
	width="600px" 
	height="600px"
	Parameters="@parameters"
></Map>
Blazor code block:
@code {
	//map initialization parameters
	Map.LoadParameters parameters = new Map.LoadParameters()
	{
		map_scale = new Map.MapScale()
		{
			has = true,
			meters = true,
			miles = false
		}
	};
}

Map Scale - GitHub example code

Basemaps

Now, you can define a base map list, from various sources (Open Street Map, Open Cycle Map and so one).

The user of the application, created by you, will be able to change the basemap.

Blazor page:
<Map
	width="800px"
	height="700px"
	Parameters="@parameters"
	></Map>
Blazor code block
	Map.LoadParameters parameters = new Map.LoadParameters()
	{
		....
		basemap_layers = new List<Map.BasemapConfigLayer>
		{
			new Map.BasemapConfigLayer()
			{
				url = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
				attribution = "�Open Street Map",
				title = "Open Street Map",
				detect_retina = true
			},
			new Map.BasemapConfigLayer()
			{
				url = "https://tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=[your API Key]",
				attribution = "�Open Cycle Map",
				title = "Open Cycle Map"
			}
		}
	};

basemap

Basemap - GitHub example code

Map events

LeafletForBlazor Map provide some events:

  • OnLoadMap();
  • OnMapClick();
  • OnZoomChange();
Blazor page:
<Map 
	width="600px" 
	height="600px"
	onLoadMap="@OnLoadMap"
	onMapClick="@OnMapClick"
	onZoomChange="@OnZoomChange">
</Map>
Blazor code block:
@code {
	//Map events
	public void OnLoadMap(Map.OnLoadEventParameters event_args)
	{

	}
	public void OnZoomChange(int zoom_level)
	{
    
	}
	public void OnMapClick(Map.Location event_args)
	{
    
	}
}

JSON file example (GeoJSON_urls Map parameter)

Blazor Page:
<Map 
	width="600px" 
	height="600px"
	GeoJSON_urls="@urls.ToArray()"
></Map>
Blazor Code:
@code {
	//working with GEOJson file
	/*	
		GeoJSON_urls <Map> parameter expects an array of JSON url
		1. The JSON data complies with the Leaflet documentation
		2. A improved format that allows custom symbolization
		3. The simultaneous use of the two types of format (RFC 7946 format and improved format)
	*/
	List<string> urls = new List<string>() { 
		"http://localhost:5078/polygonsfile.json", 
		"http://localhost:5078/pointsfile.json"  
		};
	}

1. Leaflet documentation format

Is the format shown in the Leaflet documentation

2. Improved Leaflet Format. This format allows configuring the symbolization of map elements

Is an leaflet format in which symbolization (with scaling) and tooltip configuration (with scaling) has been added to the leaflet data (RFC 7946).

Advantages

  • The symbology and tooltips configuration are stored along with the data;

  • Changing the symbolization will be done without changing the code;

  • Also, changing tooltips configuration will be done without changing the code;

  • Several applications (web, mobile, etc.) will display the same map, the same symbols;

      	{
      		  "data": [...GeoJSON specification (RFC 7946)...],
      		  "symbology": { ... },
      		  "tooltip": { ... }
      	}
    

Meaning of JSON (improved format) parameters:

  • JSON "data" paratemeter expects an array of GeoJSON items GeoJSON specification (RFC 7946)

  • JSON "symbology" parameter expects the custom symbology of GeoJSON items

    "symbology": {
     	"default": {
     	"color": "red",
     	"weight": 5,
     	"opacity": 0.4
     	},
     	"case": {
     		"field_name": "name",
     		"classes": [
     				{
     				"value": "Bdul Magheru",
     				"symbol": {
     					"color": "yellow",
     					"weight": 5,
     					"opacity": 0.4
     					}
     				},
     				{
     			  "value": "Bdul Dacia",
     			  "symbol": {
     					"color": "green",
     					"weight": 5,
     					"opacity": 0.4
     				}
     			}
     		]
     	}
     	"scaling": {
     		"start_with": 16,
     		"stop_with": 18
     		}
     }
    

In the previous example, we have a default symbol and two other symbols for two predefined classes. This two classes are defined based on the values in the "name" field.

Result of polygons classes symbolization of GitHub example:

Symbolization by classes is done based on a property (field) of the GeoJSON elements.

for example:

  • commercial areas were symbolized in yellow;
  • residential areas were symbolized in green;
  • other areas were symbolized in red;

PolygonsSymbolization

Working with JSON file - GitHub example code

Symbology and tooltip scaling

Map elements (with symbology) and tooltips will be displayed in the map only for zoom levels between start_with and stop_with.

scaling01

In the case of the GeoJSON layer, scaling will only work when we have defined at least one default symbol

  • JSON "symbology" parameter expects the definition of GeoJSON items tooltip. "scaling" parameter is not mandatory.

      "symbology": {
     	"default": {
     		"color": "red",
     		"weight": 5,
     		"opacity": 0.4
     	},
     	"scaling": {
     		"start_with": 15,
     		"stop_with": 18
     	}
       }
    
  • JSON "tooltip" parameter expects the definition of GeoJSON items tooltip. "scaling" parameter is not mandatory.

    "tooltip": {
     	"fields_name": [ "name", "lanes" ],
     	"offset": [ 0, 0 ],
     	"permanent": true,
     	"opacity": 0.5,
     	"coordinate_inversion": true,
     	    "scaling": {
     			"start_with": 16,
     			"stop_with": 18
     			}
     }
    

GeoJSON files and working with Layers Control

The Load Map boolean parmeter (anyway_overlay_layers_control) forces the display of GeoJSON layers in the Layers Control.

	Map.LoadParameters parameters = new Map.LoadParameters()
    {
        anyway_overlay_layers_control = true
	}

Overlay Layers

The names of the files will be displayed in the Layers Control, the overlay layers section.

Working with Leaflet Plungins

Starting with 1.1.8 version, LeafletForBlazor NuGet is able to implement Leaflet plugins. These plugins will be adapted for use in Blazor.

Configuring the Geolet plugin

The configuration parameters have the same names as those in the Leaflet documentation:

Blazor page
<Map
    width="800px"
    height="700px"
    Plugins="@plugins"
></Map>
Blazor code block
Map.PluginsConfig plugins = new Map.PluginsConfig()
{
    display_all = true,
    plugins = new List<Map.Plugin>() { 
	new Map.Plugin() { 
	    name = "Geolet",
	    config = "{\"title\": \"Locatia mea\", \"position\": \"topleft\", \"popupContent\": \"`latitudine ${latlng.lat}<br>longitudine ${latlng.lng}`\"}" 
		} 
    }
};

The "config" parameter is a string json object.

Geolet

Using Esri plugins

Esri is the most important player of the GIS market. Esri software solutions are complete and guarantee high performance. In addition, Esri offers users many open and/or freely used software solutions. You can freely use the power of Esri tools, only on the basis of an Esri API Key code

Extending the Leaflet API with Esri Basemaps plugin

Adding Esri basemaps is done on the PluginsConfig interface and the Plugins parameter of the LeafletForBlazor package.

First of all, you will need an Esri API Key code. Generating an Esri API Key code is free, but you need an Esri developer account.

Here you will find a guide for generating an Esri API Key code

Add in your Blazor Page:
<Map
	width="800px"
	height="700px"
	Plugins="@plugins"
></Map>
Blazor code block:
@code{
	Map.PluginsConfig plugins = new Map.PluginsConfig()
	{
		display_all = true,
		plugins = new List<Map.Plugin>() 
		{ 
			new Map.Plugin()
			{
				name = "Esri",
				config =  new Map.EsriPlugin()
					{
						apiKey = "[your Esri API Key code]",
						esri_plugins_config = new List<object>()
						{
							new Map.EsriBasemapConfig()
							{
							enable = true,
							esri_basemap_layers = new List<Map.EsriBasemapLayer>()
								{
									new Map.EsriBasemapLayer(){basemap_id ="ArcGIS:Imagery"},
									new Map.EsriBasemapLayer(){basemap_id = "ArcGIS:Imagery:Standard"},
									new Map.EsriBasemapLayer(){basemap_id = "ArcGIS:Imagery:Labels"}
								}
							}
						}
					}
			}
		}
	};
};

Esri Basemaps

Esri Basemap - GitHub example code

Extending the Leaflet API with Esri Geocoding Search plugin

First of all, you will need an Esri API Key code. Generating an Esri API Key code is free, but you need an Esri developer account.

Here you will find a guide for generating an Esri API Key code

Add in your Blazor Page:
<Map
	width="800px"
	height="800px"
	Plugins="@plugins"
></Map>
Blazor code block:
Map.PluginsConfig plugins = new Map.PluginsConfig()
{
	display_all = true,
	plugins = new List<Map.Plugin>() { 
			new Map.Plugin()
			{
				name = "Esri",
				config =  new Map.EsriPlugin()
				{
					apiKey = "[your Esri API Key code]",
					esri_plugins_config = new List<object>()
					{

						new Map.EsriGeocodingSearchParameters()
						{
							enable = true,
							placeholder = "Your address",
							position = "topleft",
							nearby = new Map.EsriNearby(){lat = 0,lng = 0}
						}
					}
				}
			}
		}
};

GeocodingSearch

Esri Geocoding Search - GitHub example code

Extending the Leaflet API with Esri Reverse Geocoding plugin

First of all, you will need an Esri API Key code. Generating an Esri API Key code is free, but you need an Esri developer account.

Here you will find a guide for generating an Esri API Key code

Add in your Blazor Page:
<Map
	width="800px"
	height="800px"
	Plugins="@plugins"
></Map>
Blazor code block:
   Map.PluginsConfig plugins = new Map.PluginsConfig()
   {
		display_all = true,
		plugins = new List<Map.Plugin>() 
		{
			new Map.Plugin()
			{
				name = "Esri",
				config =  new Map.EsriPlugin()
				{
					apiKey = "[your Esri API Key code]",
					esri_plugins_config = new List<object>()
					{
						new Map.EsriReverseGeocodingParameters()
						{
							enable = true,
							remove_last_result = true
						}
					}
				}
			}
		
		}
	};

ReverseGeoconding

Reverse Geocoding - GitHub example code

O-L I

Thank you for choosing this package!

Laurentiu Ichim

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.6.4 123 5/29/2024
2.0.6.2 87 5/28/2024
2.0.4.8 150 5/23/2024
2.0.4.6 1,126 4/18/2024
2.0.4.4 635 3/27/2024
2.0.4.2 196 3/22/2024
2.0.2.8 571 3/3/2024
2.0.2.6 441 2/28/2024
2.0.2.4 493 2/19/2024
2.0.2.2 1,286 1/24/2024
2.0.0.8 387 1/18/2024
2.0.0.6 1,038 12/25/2023
2.0.0.4 1,036 12/6/2023
1.2.4 1,316 4/7/2023
1.2.3 746 4/4/2023
1.2.2 794 3/27/2023
1.2.1 769 3/12/2023
1.2.0 746 3/11/2023
1.1.9 722 3/9/2023
1.1.8 729 3/8/2023
1.1.5 931 3/2/2023
1.1.4 696 2/28/2023
1.1.2 750 2/25/2023
1.1.1 673 2/24/2023
1.1.0 698 2/23/2023
1.0.9 787 2/23/2023
1.0.8 702 2/22/2023
1.0.6 869 2/18/2023
1.0.5 788 2/17/2023
1.0.4 856 2/14/2023
1.0.3 716 2/14/2023
1.0.2 724 2/14/2023
1.0.1 713 2/13/2023
1.0.0 745 2/13/2023

2023 03 27
Working with GeoJSON strings.
2023 03 27
bug0004 The data without symbolization was not loaded