[leaflet.markercluster.layersupport] Introduce typings (#18328)

This commit is contained in:
AsamK
2017-07-24 20:42:02 +02:00
committed by Andy
parent bfe76bd350
commit 2d0796af06
4 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// Type definitions for Leaflet.MarkerCluster.LayerSupport 1.0
// Project: https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport
// Definitions by: AsamK <https://github.com/AsamK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as Leaflet from "leaflet";
import * as MakerCluster from "leaflet.markercluster";
export = Leaflet;
declare global { namespace L {
namespace MarkerClusterGroup {
interface LayerSupport extends MarkerClusterGroup {
/**
* Stamps the passed layers as being part of this group, but without adding
* them to the map right now.
*/
checkIn(layers: Layer | Layer[]): this;
/**
* Un-stamps the passed layers from being part of this group. It has to
* remove them from map (if they are) since they will no longer cluster.
*/
checkOut(layers: Layer | Layer[]): this;
}
}
namespace markerClusterGroup {
/**
* Create a layer support marker cluster group, optionally given marker cluster group options.
*/
function layerSupport(options?: MarkerClusterGroupOptions): MarkerClusterGroup.LayerSupport;
}
} }

View File

@@ -0,0 +1,88 @@
import L = require("leaflet.markercluster.layersupport");
const polylineOptions: L.PolylineOptions = {};
const icon: L.Icon = L.icon({ iconUrl: 'foo' });
let markerClusterGroupOptions: L.MarkerClusterGroupOptions = {};
markerClusterGroupOptions = {
showCoverageOnHover: true,
zoomToBoundsOnClick: false,
spiderfyOnMaxZoom: true,
removeOutsideVisibleBounds: false,
animate: true,
animateAddingMarkers: false,
disableClusteringAtZoom: 12,
maxClusterRadius: 40,
polygonOptions: polylineOptions,
singleMarkerMode: true,
spiderLegPolylineOptions: polylineOptions,
spiderfyDistanceMultiplier: 2,
iconCreateFunction: (cluster: L.MarkerCluster) => {
const childMarkers: L.Marker[] = cluster.getAllChildMarkers();
const childCount: number = cluster.getChildCount();
cluster.zoomToBounds();
const bounds: L.LatLngBounds = cluster.getBounds();
return icon;
},
chunkedLoading: false,
chunkDelay: 100
};
markerClusterGroupOptions.iconCreateFunction = (cluster: L.MarkerCluster) => {
return L.divIcon();
};
let mcgLayerSupportGroup: L.MarkerClusterGroup.LayerSupport;
mcgLayerSupportGroup = L.markerClusterGroup.layerSupport();
mcgLayerSupportGroup = L.markerClusterGroup.layerSupport(markerClusterGroupOptions);
let map = L.map('foo');
mcgLayerSupportGroup = mcgLayerSupportGroup.addTo(map);
map = map
.addLayer(mcgLayerSupportGroup)
.removeLayer(mcgLayerSupportGroup);
const latLng: L.LatLng = L.latLng(10, 10);
const layer: L.Layer = L.marker(latLng);
const layers: L.Layer[] = [layer];
let marker: L.Marker = L.marker(latLng);
let markers: L.Marker[] = [marker];
const layerGroup: L.LayerGroup = L.layerGroup(layers);
layerGroup.addTo(map);
marker = mcgLayerSupportGroup.getVisibleParent(marker);
mcgLayerSupportGroup = mcgLayerSupportGroup
// Sub layers
.checkIn(layerGroup)
.checkOut(layerGroup)
// Layers
.addLayer(layer)
.removeLayer(layer)
.addLayers(layers)
.removeLayers(layers)
.clearLayers()
// RefreshClusters
.refreshClusters()
.refreshClusters(layerGroup)
.refreshClusters(marker)
.refreshClusters(markers)
.refreshClusters(mcgLayerSupportGroup)
.refreshClusters({ id_any: layer });
const childCount: number = mcgLayerSupportGroup.getChildCount();
markers = mcgLayerSupportGroup.getAllChildMarkers();
mcgLayerSupportGroup.zoomToShowLayer(marker);
mcgLayerSupportGroup.zoomToShowLayer(marker, () => {});
let hasLayer: boolean;
hasLayer = mcgLayerSupportGroup.hasLayer(layer);
hasLayer = mcgLayerSupportGroup.hasLayer(marker);
hasLayer = mcgLayerSupportGroup.hasLayer(layerGroup);

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"leaflet.markercluster.layersupport-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }