diff --git a/types/leaflet.markercluster.layersupport/index.d.ts b/types/leaflet.markercluster.layersupport/index.d.ts new file mode 100644 index 0000000000..aec703c67f --- /dev/null +++ b/types/leaflet.markercluster.layersupport/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for Leaflet.MarkerCluster.LayerSupport 1.0 +// Project: https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport +// Definitions by: 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; + } +} } diff --git a/types/leaflet.markercluster.layersupport/leaflet.markercluster.layersupport-tests.ts b/types/leaflet.markercluster.layersupport/leaflet.markercluster.layersupport-tests.ts new file mode 100644 index 0000000000..1c9682bd77 --- /dev/null +++ b/types/leaflet.markercluster.layersupport/leaflet.markercluster.layersupport-tests.ts @@ -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); diff --git a/types/leaflet.markercluster.layersupport/tsconfig.json b/types/leaflet.markercluster.layersupport/tsconfig.json new file mode 100644 index 0000000000..4e82ec1409 --- /dev/null +++ b/types/leaflet.markercluster.layersupport/tsconfig.json @@ -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" + ] +} diff --git a/types/leaflet.markercluster.layersupport/tslint.json b/types/leaflet.markercluster.layersupport/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/leaflet.markercluster.layersupport/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }