GithubHelp home page GithubHelp logo

emiyagm / leaflet.layergroup.collision Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mazemap/leaflet.layergroup.collision

0.0 1.0 1.0 767 KB

Leaflet plugin for uncluttering L.Markers using basic collision detection.

License: MIT License

JavaScript 100.00%

leaflet.layergroup.collision's Introduction

Leaflet.LayerGroup.Collision

Provides basic collision detection in order to declutter large or overlapping sets of Leaflet markers.

Don't like READMEs? Then see http://mazemap.github.io/Leaflet.LayerGroup.Collision/demo/demo.html

What?

Inspired by the ClusterMarker plugin, this plugin works by hiding any markers that overlap each other - only the marker which was first added to the LayerGroup will be shown.

How?

Collision detection is done by using the dimensions of the DOM elements inside the L.Marker's icon; this has been tested only using display:block elements. L.Layers which are not markers will be always shown.

This plugin uses Vladimir Agafonkin's rbush library for the grunt work of detecting bounding box collisions.

Caveats: this plugin expects markers to not change dynamically, to not be draggable, and marker deletion is not supported (yet). Currently everything is recalculated on zoom change. Only partial data caching is done - marker bounding boxes are cached; collisions per zoom level are recalculated.

Usage

Works as a normal Leaflet LayerGroup, just add your markers to it.

When instantiating, can take the 'margin' option. This defines the margin between markers, in pixels, and defaults to zero.

var collisionLayer = L.layerGroup.collision({margin:5});
collisionLayer.addTo(map);

collisionLayer.add( L.marker( markeroptions ) );

This plugin also extends L.FeatureGroup into L.FeatureGroup.collision and L.GeoJSON into L.GeoJSON.collision.

Demo

There is a live demo at http://mazemap.github.io/Leaflet.LayerGroup.Collision/demo/demo.html

The demo loads about 1000 placenames, each of them being a L.DivIcon with two boxes.

The demo includes data from Natural Earth, which is public domain. Please visit http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-populated-places/ for more information.

In order to try the demo locally, just clone the repo, run bower install (if using the gh-pages branch, use git clone --recursive instead to pull the rbush submodule), and see the file demo/demo.html. You can choose to load more or less data by commenting/uncommenting the lines that include the natural earth data files.

PS

做了一点针对我个人地图组件的调整

主要是修改了聚合点显示逻辑,超出地图可视区域内的聚合点将不予显示

以此来优化大量聚合点带来的性能问题

优化第一次加载大量点引起的卡顿问题

leaflet.layergroup.collision's People

Contributors

ivansanchez avatar turban avatar emiyagm avatar gustavat avatar simon04 avatar

Watchers

 avatar

Forkers

yangkghjh

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.