Purlin.Maps.Clustering
1.0.4
Prefix Reserved
See the version list below for details.
dotnet add package Purlin.Maps.Clustering --version 1.0.4
NuGet\Install-Package Purlin.Maps.Clustering -Version 1.0.4
<PackageReference Include="Purlin.Maps.Clustering" Version="1.0.4" />
paket add Purlin.Maps.Clustering --version 1.0.4
#r "nuget: Purlin.Maps.Clustering, 1.0.4"
// Install Purlin.Maps.Clustering as a Cake Addin #addin nuget:?package=Purlin.Maps.Clustering&version=1.0.4 // Install Purlin.Maps.Clustering as a Cake Tool #tool nuget:?package=Purlin.Maps.Clustering&version=1.0.4
Purlin.Maps.Clustering
C# library for clustering map points for server side
Original Lib
This is a fork of GoogleMaps.AspNetCore.Clustering repo. The project was no longer powered since Jul 20, 2018.
Installation
You can download the Purlin.Maps.Clustering package to install the latest version of Purlin.Maps.Clustering Lib.
Features
1․ Server-side clustering
2․ K-nearest neighbors - (Haversine formula)
Usage
First, configure Program.cs
class:
using Purlin.GoogleMaps.Clustering.Data.Configuration;
using Purlin.GoogleMaps.Clustering.Data.Params;
using Purlin.GoogleMaps.Clustering.Sample.Lib;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseGmc(builder.Configuration.GetSection("GoogleMapsNetClustering"));
You will also need to add the following section to your appsettings.json
file.
"GoogleMapsNetClustering": {
"DoShowGridLinesInGoogleMap": false,
"OuterGridExtend": 0,
"DoUpdateAllCentroidsToNearestContainingPoint": false,
"DoMergeGridIfCentroidsAreCloseToEachOther": true,
"CacheServices": true,
"MergeWithin": 2.9,
"MinClusterSize": 2,
"MaxMarkersReturned": 500,
"AlwaysClusteringEnabledWhenZoomLevelLess": 2,
"ZoomlevelClusterStop": 15,
"GridX": 6,
"GridY": 5,
"MarkerTypes": [1,2,3],
"MaxPointsInCache": 100000000
},
Next, this is an example of how to used cached clustering.
public static class SampleCluster
{
public static async Task<IList<MapPoint>> Clustering(GetMarkersParams markersParams = null!)
{
try
{
using var r = new StreamReader("path to file");
var data = await r.ReadToEndAsync();
var list = JsonSerializer.Deserialize<List<Point>>(data);
var marker = GetClusters(list, markersParams);
return marker;
}
catch
{
return new List<MapPoint>();
}
}
private static IList<MapPoint> GetClusters(IEnumerable<Point> data, GetMarkersParams markersParams = null)
{
const string clusterPointsCacheKey = "somecachekey";
var points = GetClusterPointCollection(data, clusterPointsCacheKey);
var mapService = new ClusterService(points);
var option = markersParams ?? new GetMarkersParams()
{
ZoomLevel = 6,
PointType = clusterPointsCacheKey,
};
var markers = mapService.GetClusterMarkers(option);
return markers.Markers;
}
private static PointCollection GetClusterPointCollection(IEnumerable<Point> data, string clusterPointsCacheKey)
{
var points = new PointCollection();
var dbPoints = data.Select(p => new MapPoint
{
X = p.Lng!.Value,
Y = p.Lat!.Value
}).ToList();
var cacheDuration = TimeSpan.FromHours(6);
points.Set(dbPoints, cacheDuration, clusterPointsCacheKey);
return points;
}
}
public class Point
{
public float? Lat { get; set; }
public float? Lng { get; set; }
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.Extensions.Configuration (>= 2.1.1)
- Microsoft.Extensions.Configuration.Binder (>= 2.1.1)
- Newtonsoft.Json (>= 11.0.2)
- System.Runtime.Caching (>= 4.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release of the package.