Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra methods to facilitate icons refresh #564

Merged
merged 11 commits into from
Oct 13, 2015
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,35 @@ markers.on('clusterclick', function (a) {
### Getting the visible parent of a marker
If you have a marker in your MarkerClusterGroup and you want to get the visible parent of it (Either itself or a cluster it is contained in that is currently visible on the map).
This will return null if the marker and its parent clusters are not visible currently (they are not near the visible viewpoint)
```
```javascript
var visibleOne = markerClusterGroup.getVisibleParent(myMarker);
console.log(visibleOne.getLatLng());
```

### Refreshing the clusters icon
If you have [customized](#customising-the-clustered-markers) the clusters icon to use some data from the contained markers, and later that data changes, use this method to force a refresh of the cluster icons.
You can use the method:
- without arguments to force all cluster icons in the Marker Cluster Group to be re-drawn.
- with an array or a mapping of markers to force only their parent clusters to be re-drawn.
- with an L.MarkerClusterGroup, L.LayerGroup, or L.MarkerCluster. The method will look for all markers in these objects. Make sure they contain only markers which are also within this Marker Cluster Group.
- with a single marker.
```javascript
markers.refreshClusters();
markers.refreshClusters([myMarker0, myMarker33]);
markers.refreshClusters({id_0: myMarker0, id_any: myMarker33]);
markers.refreshClusters(markers); // a Marker Cluster Group that contains all or a sub-set of this markers.
markers.refreshClusters(myLayerGroup);
markers.refreshClusters(myMarkerCluster);
markers.refreshClusters(myMarker);
```

The plugin also adds a method on L.Marker to easily update the underlying icon options and refresh the icon.
If passing a second argument that evaluates to `true`, the method will also trigger a `refreshCluster` on the parent MarkerClusterGroup for that single marker.
```javascript
myMarker.refreshIconOptions(optionsMap); // Use as many times as required to update markers, before calling refreshClusters.
myMarker.refreshIconOptions(optionsMap, true); // Refreshes the marker's parent clusters right away.
```

### Adding and removing Markers
addLayer, removeLayer and clearLayers are supported and they should work for most uses.

Expand Down
6 changes: 6 additions & 0 deletions build/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ var deps = {
src: ['MarkerCluster.Spiderfier.js'],
desc: 'Provides the ability to show all of the child markers of a cluster.',
heading: 'Spiderfier'
},

Refresh: {
src: ['MarkerClusterGroup.Refresh.js'],
desc: 'Method to request refreshing of clusters icon to reflect changes in markers data.',
heading: 'Refresh'
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"test": "jake test",
"prepublish": "jake"
},
"keywords": ["gis", "map"]
"keywords": ["gis", "map"],
"license": "MIT"
}
3 changes: 3 additions & 0 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script type="text/javascript" src="../src/MarkerCluster.QuickHull.js"></script>
<script type="text/javascript" src="../src/MarkerCluster.Spiderfier.js"></script>
<script type="text/javascript" src="../src/MarkerOpacity.js"></script>
<script type="text/javascript" src="../src/MarkerClusterGroup.Refresh.js"></script>

<script>
mocha.setup('bdd');
Expand Down Expand Up @@ -59,6 +60,8 @@

<script type="text/javascript" src="suites/RememberOpacity.js"></script>

<script type="text/javascript" src="suites/RefreshSpec.js"></script>

<script>
(window.mochaPhantomJS || window.mocha).run();
</script>
Expand Down
Loading