mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-09 06:17:11 +08:00
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:
4
types/leaflet.markercluster/index.d.ts
vendored
4
types/leaflet.markercluster/index.d.ts
vendored
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user