Provides Beautiful Animated Marker Clustering functionality for maps. Parameters ---------- locations: list of list or array of shape (n, 2). Data points of the form [[lat, lng]]. popups: list of length n, default None Popup for each marker, either a Popup objec
| 5 | |
| 6 | |
| 7 | class MarkerCluster(JSCSSMixin, Layer): |
| 8 | """ |
| 9 | Provides Beautiful Animated Marker Clustering functionality for maps. |
| 10 | |
| 11 | Parameters |
| 12 | ---------- |
| 13 | locations: list of list or array of shape (n, 2). |
| 14 | Data points of the form [[lat, lng]]. |
| 15 | popups: list of length n, default None |
| 16 | Popup for each marker, either a Popup object or a string or None. |
| 17 | icons: list of length n, default None |
| 18 | Icon for each marker, either an Icon object or a string or None. |
| 19 | name : string, default None |
| 20 | The name of the Layer, as it will appear in LayerControls |
| 21 | overlay : bool, default True |
| 22 | Adds the layer as an optional overlay (True) or the base layer (False). |
| 23 | control : bool, default True |
| 24 | Whether the Layer will be included in LayerControls. |
| 25 | show: bool, default True |
| 26 | Whether the layer will be shown on opening. |
| 27 | icon_create_function : string, default None |
| 28 | Override the default behaviour, making possible to customize |
| 29 | markers colors and sizes. |
| 30 | options : dict, default None |
| 31 | A dictionary with options for Leaflet.markercluster. See |
| 32 | https://github.com/Leaflet/Leaflet.markercluster for options. |
| 33 | |
| 34 | Example |
| 35 | ------- |
| 36 | >>> icon_create_function = ''' |
| 37 | ... function(cluster) { |
| 38 | ... return L.divIcon({html: '<b>' + cluster.getChildCount() + '</b>', |
| 39 | ... className: 'marker-cluster marker-cluster-small', |
| 40 | ... iconSize: new L.Point(20, 20)}); |
| 41 | ... } |
| 42 | ... ''' |
| 43 | |
| 44 | """ |
| 45 | |
| 46 | _template = Template( |
| 47 | """ |
| 48 | {% macro script(this, kwargs) %} |
| 49 | var {{ this.get_name() }} = L.markerClusterGroup( |
| 50 | {{ this.options|tojavascript }} |
| 51 | ); |
| 52 | {%- if this.icon_create_function is not none %} |
| 53 | {{ this.get_name() }}.options.iconCreateFunction = |
| 54 | {{ this.icon_create_function.strip() }}; |
| 55 | {%- endif %} |
| 56 | {% endmacro %} |
| 57 | """ |
| 58 | ) |
| 59 | |
| 60 | default_js = [ |
| 61 | ( |
| 62 | "markerclusterjs", |
| 63 | "https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js", |
| 64 | ) |