DevCrew.SuperCluster 1.0.1

dotnet add package DevCrew.SuperCluster --version 1.0.1                
NuGet\Install-Package DevCrew.SuperCluster -Version 1.0.1                
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="DevCrew.SuperCluster" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DevCrew.SuperCluster --version 1.0.1                
#r "nuget: DevCrew.SuperCluster, 1.0.1"                
#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 DevCrew.SuperCluster as a Cake Addin
#addin nuget:?package=DevCrew.SuperCluster&version=1.0.1

// Install DevCrew.SuperCluster as a Cake Tool
#tool nuget:?package=DevCrew.SuperCluster&version=1.0.1                

SuperCluster-CSharp

license alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

A C# library that provides an efficient way to cluster large point datasets. This library is based on the popular SuperCluster JavaScript library by Mapbox and has been optimized for performance in .NET environments. It helps to implement clustering feature in Unity3d WebGL and in any .NET framework.

Installation

Install using NuGet

We'll soon publish our library to NuGet Packages Gallery and then you can search for DevCrew.SuperCluster or SuperCluster on NuGet package manager in Visual Studio and add it to your project.

Install as open source

The second option is to add SuperCluster as an open source module to your .NET or Unity project if you don't use NuGet.

  • Clone the repo https://github.com/DevCrew-io/SuperCluster-CSharp.git
  • Make sure to checkout main branch
  • Copy the DevCrew.SuperCluster folder and remove DevCrew.SuperCluster.csproj file
  • Now Paste the whole DevCrew.SuperCluster package into your project and you are ready to use

Usage

GeoPoint

Map your data set into list of GeoPoint

private readonly List<GeoPoint> _points = new List<GeoPoint>();

//here we have added some dummy geo coordinates 
_points.Add(new GeoPoint(longitude: -112.8384399, latitude: 49.696595));
_points.Add(new GeoPoint(longitude: -112.838563, latitude: 49.694496));
_points.Add(new GeoPoint(longitude: -112.8412346, latitude: 49.696189));

Options

Create a new object of SuperCluster with clustering options

//superCluster with default clustering options
private readonly SuperCluster _superCluster = new(options: SuperCluster.DefaultOptions);

//or you can provide your own clustering options like this:
Options customOptions = new(
    minZoom: 0,
    maxZoom: 16,
    minPoints: 2,
    radius: 30,
    extent: 512,
    nodeSize: 64,
    log: true,
    generateId: false
);
Option Default Description
minZoom 0 Minimum zoom level at which clusters are generated
maxZoom 16 Maximum zoom level at which clusters are generated
minPoints 2 Minimum number of points to form a cluster
radius 40 Cluster radius, in pixels
extent 512 (Tiles) Tile extent. Radius is calculated relative to this value
generateId false Whether to generate ids for input features in vector tiles
nodeSize 64 Size of the KD-tree leaf node. Affects performance
log false Whether timing info should be logged

Methods

Load(points)

Once we have create a super cluster object then we can cluster our points using Load() method. It creates all possible clusters for different zoom levels at once.

//This method should be called only once 
_superCluster.Load(points: _points);
GetClusters(bbox, zoom)

For the given bbox array [westLng, southLat, eastLng, northLat] and integer zoom, returns an array of clusters and points.

var bbox = new double[] { -180, -85, 180, 85 };
//This method should be called on zoom in and zoom out events.
var clusterData = _superCluster.GetClusters(bbox: bbox, zoom: 16);

Console.WriteLine("clusterData.count: " + clusterData.Count);

//print clustered data
foreach (var output in clusterData.Select(JsonConvert.SerializeObject))
{
    Console.WriteLine(output);
}   

//you can filter between clusters and individual points from clusterData output like this
foreach (var geoJsonFeature in clusterData)
{
    if (geoJsonFeature is GeoPoint)
    {
        //This is single geo point
    }
    else
    {
        //This is a cluster
    }
}

Authors

DevCrew.IO

Connect with Us

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Contributing

Contributions, issues, and feature requests are welcome!

Show your Support

Give a star if this project helped you.

Code copyright 2023–2024 DevCrew I/O. Code released under the MIT license.

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
1.0.1 856 4/7/2023
1.0.0 180 4/7/2023

logo update
readme updated