UNPKG

rc-leaflet

Version:
94 lines (93 loc) 5.12 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import 'leaflet.markercluster/dist/MarkerCluster.css'; import 'leaflet.markercluster/dist/MarkerCluster.Default.css'; import React from 'react'; import PropTypes from 'prop-types'; import L from 'leaflet'; import 'leaflet.markercluster'; import { Point, Icon } from '../../util/PropTypes'; import Layer from '../Layer'; import PointContext from '../Point/Context'; import { PolylinePropTypes } from '../Polyline'; import { defaultIcon } from '../DivIcon/creator'; var ClusterPoints = /** @class */ (function (_super) { __extends(ClusterPoints, _super); function ClusterPoints(props, context) { var _this = _super.call(this, props, context) || this; _this.instance.on('animationend', function () { return _this.forceUpdate(); }); _this.instance.on('click', function (e) { return e.layer.once('remove', function () { return _this.instance.isPopupOpen() && _this.instance.closePopup(); }); }); _this.addPoints(); context.map.addLayer(_this.instance); return _this; } ClusterPoints.prototype.componentDidUpdate = function (prevProps) { var prevPoints = prevProps.points, prevIcon = prevProps.icon; var _a = this.props, points = _a.points, icon = _a.icon, children = _a.children, options = __rest(_a, ["points", "icon", "children"]); Object.assign(this.instance.options, __assign({}, this.getTheme(), options)); if (points !== prevPoints || icon !== prevIcon) { this.instance.clearLayers(); this.addPoints(); this.forceUpdate(); } _super.prototype.componentDidUpdate.call(this, prevProps); }; ClusterPoints.prototype.createInstance = function (props) { var points = props.points, icon = props.icon, options = __rest(props, ["points", "icon"]); return L.markerClusterGroup(options); }; ClusterPoints.prototype.getTheme = function () { if (this.context && this.context.theme && this.context.theme.path) { return { polygonOptions: this.context.theme.path }; } return {}; }; ClusterPoints.prototype.addPoints = function () { var _a = this.props, points = _a.points, _b = _a.icon, icon = _b === void 0 ? defaultIcon : _b; this.instance.addLayers(points.map(function (position) { return L.marker(position, { icon: icon }); })); }; ClusterPoints.prototype.render = function () { var _a = this.props.icon, icon = _a === void 0 ? defaultIcon : _a; return (React.createElement(PointContext.Provider, { value: { instance: this.instance, icon: icon } }, _super.prototype.render.call(this))); }; ClusterPoints.propTypes = __assign({}, Layer.propTypes, { points: PropTypes.arrayOf(Point).isRequired, icon: Icon, clusterPane: PropTypes.string, chunkProgress: PropTypes.func, showCoverageOnHover: PropTypes.bool, zoomToBoundsOnClick: PropTypes.bool, spiderfyOnMaxZoom: PropTypes.bool, removeOutsideVisibleBounds: PropTypes.bool, animate: PropTypes.bool, animateAddingMarkers: PropTypes.bool, disableClusteringAtZoom: PropTypes.number, maxClusterRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), polygonOptions: PropTypes.shape(PolylinePropTypes), singleMarkerMode: PropTypes.bool, spiderLegPolylineOptions: PropTypes.shape(PolylinePropTypes), spiderfyDistanceMultiplier: PropTypes.number, iconCreateFunction: PropTypes.func, chunkedLoading: PropTypes.bool, chunkDelay: PropTypes.number, chunkInterval: PropTypes.number }); ClusterPoints.defaultProps = { disableClusteringAtZoom: 18, chunkedLoading: true }; return ClusterPoints; }(Layer)); export default ClusterPoints;