Git Product home page Git Product logo

googlemaps.net.clustering's Introduction

GoogleMaps.Net.Clustering

C# library for clustering map points. This library is very suitable for WebAPI (and similar-type) projects that don't depend on ASP.Net MVC.

Clustering Img

Original Lib
This is a fork of Google Maps Server-side Clustering with C# repo. The guys made a fast, working implementation of Google Maps clustering for C#. However, they tightly coupled it with MVC and WebForms where all I needed was a simple C# way to crunch a bunch of simple map points and convert them into cluster points.

Installation
You can download the GoogleMaps.Net.Clustering package to install the latest version of GoogleMaps.Net.Clustering Lib.

Sponsored by Dovetail Technologies.

Usage

This is an example of how to used cached clustering.

public IList<MapPoint> GetClusters(YourFilterObj filter)
{
    var clusterPointsCacheKey = "somecachekey";
    var points = GetClusterPointCollection(clusterPointsCacheKey);

    var mapService = new ClusterService(points);
    var input = new GetMarkersParams()
    {
        NorthEastLatitude = filter.NorthEastLatitude,
        NorthEastLongitude = filter.NorthEastLongitude,
        SouthWestLatitude = filter.SouthWestLatitude,
        SouthWestLongitude = filter.SouthWestLongitude,
        ZoomLevel = filter.ZoomLevel,
        PointType = clusterPointsCacheKey
    };

    var markers = mapService.GetClusterMarkers(input);

    return markers.Markers;
}

private PointCollection GetClusterPointCollection(string clusterPointsCacheKey)
{
    var points = new PointCollection();
    if (points.Exists(clusterPointsCacheKey))
        return points;

    var dbPoints = GetPoints(); // Get your points here
    var mapPoints = dbPoints.Select(p => new MapPoint() { X = p.X, Y = p.Y }).ToList();
    var cacheDuration = TimeSpan.FromHours(6);
    points.Set(mapPoints, cacheDuration, clusterPointsCacheKey);

    return points;
}

You will also need to add the following section to your .conf file (add it before the connectionString and/or appSettings section).

<googleMapsNetClustering>
    <!-- Configuration data for clustering, separate file to make the web.config file cleaner -->
    <!-- Read GmcSettings.cs for description -->
    <!-- debug purpose -->
    <add key="DoShowGridLinesInGoogleMap" value="false" />
    <!-- if bigger value then more expensive -->
    <add key="OuterGridExtend" value="0" />
    <!-- if true, then more expensive -->
    <add key="DoUpdateAllCentroidsToNearestContainingPoint" value="false" />
    <add key="DoMergeGridIfCentroidsAreCloseToEachOther" value="true" />
    <!-- cache get markers and get marker info services -->
    <add key="CacheServices" value="true" />
    <!--heuristic value for when to merge clusters when close to each other -->
    <add key="MergeWithin" value="2.9" />
    <add key="MinClusterSize" value="2" />
    <!-- restrict json length for client -->
    <add key="MaxMarkersReturned" value="500" />
    <!-- server-side control, set to -1 for disabled -->
    <add key="AlwaysClusteringEnabledWhenZoomLevelLess" value="2" />
    <add key="ZoomlevelClusterStop" value="15" />
    <add key="GridX" value="6" />
    <add key="GridY" value="5" />
    <add key="MarkerTypes" value="1;2;3" />
    <add key="MaxPointsInCache" value="100000000" />
</googleMapsNetClustering>

googlemaps.net.clustering's People

Contributors

tihomir-kit avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.