Code Monkey home page Code Monkey logo

markerclustering's Introduction

MarkerClustering

MarkerClusterung on Nuget

Library that allows you to group a number of geo-points (points with longitude and latitude coordinates) into clusters based on their relative proximity to each other and the zoom level of the map being used. Since the library targets netstandard, it can be used on the server with .NET Core applications when you want to minimize the number of points returned to the client application and therefore reducing the network traffic by returning clustered points instead. The library can also be used by Fable projects to enable client-side marker clustering when you are using map components which do not have clustering support built-in like with the Feliz.PigeonMaps package where you need to do clustering yourself using this library. Many map components on the client-side will have clustering support by default. You will not need this library when you are using GoogleMaps API because it already supports clustering.

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 MarkerClustering 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 tforkmann avatar zaid-ajaj 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.