Git Product home page Git Product logo

markerclustering's Introduction

MarkerClustering

MarkerClusterung on Nuget

If you have lots and lots of markers to display on a map then often your map becomes slow or you can't see the forest for the trees because those markers are basically everywhere. A common strategy is to use cluster markers and to only show how many markers are in a given area. Javascript map components often already have support for this. Here you can read how client side clustering can be done with GoogleMaps API.

Sometimes this client side clustering is not enough since you still have to send lots and lots of data down to the client. This is when server side clustering comes into play.

This is library is for such server side clustering of map points. It's a netstandard library and can be used in all .NET Core programs and ASP.NET Core.

Clustering Img

Original Lib

This library is inspired by Google Maps Server-side Clustering with C# , but the algorithm here is a bit simplified for performance reasons.

Installation

  • The latest version of MarkerClusterung is available on NuGet.

Usage

The following code describes a typical usage in ASP.NET Core and GoogleMaps:

    // Retrieve map markers from data store
    let markers = getAllMarkers()

    // filter markers to the bounding box of your map (optional)
    let filtered =
        markers
        |> Array.filter (fun m ->
            m.Lat <= ne.Lat && m.Long >= ne.Long &&
              m.Lat >= sw.Lat && m.Long <= sw.Long)

    // Map to library's MapPoint<'a>
    let points : MapPoint<_VisibleChargingPoint_> [] =
        filtered
        |> Array.map (fun m -> { X = m.Lat; Y = m.Long; Data = m })

    // run clustering with your map's current zoom level
    let clustering = Clustering(zoomLevel)
    let result = clustering.RunClustering points

Caching

If your markers don't change that often then you may want to put the clustering in a separate task. A good strategy could be to use FaaS Azure Functions or AWS Lambda to calculate all clusters for all zoom levels. Those clusters could be stored in a distributed cache like Redis, which then allows you to query the clusters by map center and radius.

markerclustering's People

Contributors

forki avatar

Watchers

 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.