Merge pull request #23697 from nenadvicentic/master

`MarkerCluster` and `MarkerClusterGroup` should be classes
This commit is contained in:
Benjamin Lichtman 2018-03-01 15:28:36 -08:00 committed by GitHub
commit a3d43a68ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -7,7 +7,7 @@
import * as L from 'leaflet';
declare module 'leaflet' {
interface MarkerCluster extends Marker {
class MarkerCluster extends Marker {
/*
* Recursively retrieve all child markers of this cluster.
*/
@ -117,7 +117,7 @@ declare module 'leaflet' {
chunkDelay?: number;
}
interface MarkerClusterGroup extends FeatureGroup {
class MarkerClusterGroup extends FeatureGroup {
/*
* Bulk methods for adding and removing markers and should be favoured over the
* single versions when doing bulk addition/removal of markers.

View File

@ -81,3 +81,34 @@ markerClusterGroup.zoomToShowLayer(marker, () => {});
let hasLayer: boolean;
hasLayer = markerClusterGroup.hasLayer(layer);
hasLayer = markerClusterGroup.hasLayer(marker);
// inheritance
const Subclass1 = L.MarkerClusterGroup.extend({
myFunction() {}
});
class Subclass2 extends L.MarkerClusterGroup {
myFunction() {}
}
const Subclass3 = L.MarkerCluster.extend({
myFunction() {}
});
class Subclass4 extends L.MarkerCluster {
myFunction() {}
}
const s1 = new Subclass1(); // any
const s2 = new Subclass2();
const s3 = new Subclass3(); // any
const s4 = new Subclass4([1, 2]);
// call subclass function
s1.myFunction();
s2.myFunction();
s3.myFunction();
s4.myFunction();
// call base class function
s1.refreshClusters();
s2.refreshClusters();
s3.getAllChildMarkers();
s4.getAllChildMarkers();