BlazorMaps is a Blazor library that provides a C# interface for maps provided by Leaflet.js library. It includes several Leaflet.js features which are easily accessible from C# level within a project and it does not require any use of JavaScript.
builder.Services.AddBlazorLeafletMaps();
in Main method of your Program class.@using FisSst.BlazorMaps
to your _Import.cshtml file.<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
</head>
<body>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
</body>
Remember to include proper dependency injections in your code, e.g.
[Inject]
private IMarkerFactory MarkerFactory { get; init; }
Get familiar with our examples of usage and descriptive comments in public classes if you are not sure which interfaces should be injected in a given case.
So far, BlazorMap includes:
The above functionalities have been developed in a way that allows to use them in the same way (or at least similar) to those from Leaflet.js library. Some of them are limited or incomplete but the main goal of BlazorMaps is to cover them all.
There is an example project available in this repository. You can play around with functionalities and execute performance tests.
An example below shows how to initialize a component with Leaflet's map in Blazor:
<Map @ref="mapRef" MapOptions="@mapOptions"></Map>
<style>
#mapId {
height: 400px;
}
</style>
@code {
private Map mapRef;
private MapOptions mapOptions = new MapOptions()
{
DivId = "mapId",
Center = new LatLng(50.279133, 18.685578),
Zoom = 13,
UrlTileLayer = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
SubOptions = new MapSubOptions()
{
Attribution = "© <a lhref='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>",
TileSize = 512,
ZoomOffset = -1,
MaxZoom = 19,
}
};
}
Feel free to report issues regarding bugs and improvements. If you want to report an issue, try to stick to the rules:
In case of not being sure how to report, contact us info@fis-sst.pl.
BlazorMaps works under MIT license. You can find the license in LICENSE.txt file in the root directory of our project.