[Pkg-javascript-commits] [leaflet-markercluster] 24/31: Change option name to avoid collision with Leaflet. Document default. Add pane unit tests.
Jonas Smedegaard
dr at jones.dk
Sun Oct 22 17:29:30 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.1.0_dfsg
in repository leaflet-markercluster.
commit 90004e431369f295f65e4f3b9ef39e911cea5632
Author: ckrahe <chris at krahe.org>
Date: Sun Aug 20 12:38:53 2017 -0400
Change option name to avoid collision with Leaflet. Document default. Add pane unit tests.
---
README.md | 2 +-
example/marker-clustering-pane.html | 2 +-
spec/suites/PaneSpec.js | 97 +++++++++++++++++++++++++++++++++++++
src/MarkerCluster.js | 4 +-
4 files changed, 101 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 399eac0..b8e9052 100644
--- a/README.md
+++ b/README.md
@@ -130,7 +130,7 @@ If you need to update the clusters icon (e.g. they are based on markers real-tim
* **spiderLegPolylineOptions**: Allows you to specify [PolylineOptions](http://leafletjs.com/reference.html#polyline-options) to style spider legs. By default, they are `{ weight: 1.5, color: '#222', opacity: 0.5 }`.
* **spiderfyDistanceMultiplier**: Increase from 1 to increase the distance away from the center that spiderfied markers are placed. Use if you are using big marker icons (Default: 1).
* **iconCreateFunction**: Function used to create the cluster icon. See [the default implementation](https://github.com/Leaflet/Leaflet.markercluster/blob/15ed12654acdc54a4521789c498e4603fe4bf781/src/MarkerClusterGroup.js#L542) or the [custom example](https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-custom.html).
-* **pane**: Map pane where the cluster icons will be added. [See the pane example](https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-pane.html).
+* **mapPane**: Map pane where the cluster icons will be added. Defaults to markerPane. [See the pane example](https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-pane.html).
#### Chunked addLayers options
Options for the [addLayers](#bulk-adding-and-removing-markers) method. See [#357](https://github.com/Leaflet/Leaflet.markercluster/issues/357) for explanation on how the chunking works.
diff --git a/example/marker-clustering-pane.html b/example/marker-clustering-pane.html
index 6a1e095..760456f 100644
--- a/example/marker-clustering-pane.html
+++ b/example/marker-clustering-pane.html
@@ -62,7 +62,7 @@
return L.divIcon({ html: n, className: className, iconSize: L.point(40, 40) });
},
//Disable all of the defaults & specify the pane:
- spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: false, pane: pane
+ spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: false, mapPane: pane
});
return(mcg);
}
diff --git a/spec/suites/PaneSpec.js b/spec/suites/PaneSpec.js
new file mode 100644
index 0000000..a2221fe
--- /dev/null
+++ b/spec/suites/PaneSpec.js
@@ -0,0 +1,97 @@
+describe('Map pane selection', function() {
+ /**
+ * Avoid as much as possible creating and destroying objects for each test.
+ * Instead, try re-using them, except for the ones under test of course.
+ * PhantomJS does not perform garbage collection for the life of the page,
+ * i.e. during the entire test process (Karma runs all tests in a single page).
+ * http://stackoverflow.com/questions/27239708/how-to-get-around-memory-error-with-karma-phantomjs
+ *
+ * The `beforeEach` and `afterEach do not seem to cause much issue.
+ * => they can still be used to initialize some setup between each test.
+ * Using them keeps a readable spec/index.
+ *
+ * But refrain from re-creating div and map every time. Re-use those objects.
+ */
+
+ /////////////////////////////
+ // SETUP FOR EACH TEST
+ /////////////////////////////
+
+ beforeEach(function () {
+
+ // Nothing for this test suite.
+
+ });
+
+ afterEach(function () {
+
+ if (group instanceof L.MarkerClusterGroup) {
+ group.clearLayers();
+ map.removeLayer(group);
+ }
+
+ // Throw away group as it can be assigned with different configurations between tests.
+ group = null;
+
+ });
+
+
+ /////////////////////////////
+ // PREPARATION CODE
+ /////////////////////////////
+
+ var div, map, group;
+
+ div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '200px';
+ document.body.appendChild(div);
+
+ map = L.map(div, { maxZoom: 18 });
+
+ // Create map pane
+ map.createPane('testPane');
+
+ // Corresponds to zoom level 8 for the above div dimensions.
+ map.fitBounds(new L.LatLngBounds([
+ [1, 1],
+ [2, 2]
+ ]));
+
+
+ /////////////////////////////
+ // TESTS
+ /////////////////////////////
+
+ it('recognizes and applies option', function() {
+ group = new L.MarkerClusterGroup({mapPane: 'testPane'});
+
+ var marker = new L.Marker([1.5, 1.5]);
+ var marker2 = new L.Marker([1.5, 1.5]);
+
+ group.addLayers([marker, marker2]);
+ map.addLayer(group);
+
+ expect(map._panes.testPane.childNodes.length).to.be(1);
+ });
+
+ it('defaults to markerPane', function() {
+ group = new L.MarkerClusterGroup();
+
+ var marker = new L.Marker([1.5, 1.5]);
+ var marker2 = new L.Marker([1.5, 1.5]);
+
+ group.addLayers([marker, marker2]);
+ map.addLayer(group);
+
+ expect(map._panes.markerPane.childNodes.length).to.be(1);
+ });
+
+ /////////////////////////////
+ // CLEAN UP CODE
+ /////////////////////////////
+
+ map.remove();
+ document.body.removeChild(div);
+
+});
\ No newline at end of file
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index 9272eea..a4487b3 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -2,8 +2,8 @@ L.MarkerCluster = L.Marker.extend({
initialize: function (group, zoom, a, b) {
var options = { icon: this };
- if (group.options.pane) {
- options.pane = group.options.pane;
+ if (group.options.mapPane) {
+ options.pane = group.options.mapPane;
}
L.Marker.prototype.initialize.call(this, a ? (a._cLatLng || a.getLatLng()) : new L.LatLng(0, 0), options);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git
More information about the Pkg-javascript-commits
mailing list