MarkerCluster and MarkerClusterGroup should be classes, to be consistent with definitions of similar layers in Leaflet.ts (TileLayer, GridLayer, etc...). Using interface definitions also breaks inheritance chain.

This commit is contained in:
Nenad Vićentić
2018-02-16 09:54:44 +01:00
parent 6d08c4cece
commit 0c37383d3e
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();