rc-leaflet
Version:
React Map Components of Leaflet
99 lines (98 loc) • 5.81 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("leaflet.markercluster/dist/MarkerCluster.css");
require("leaflet.markercluster/dist/MarkerCluster.Default.css");
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var leaflet_1 = __importDefault(require("leaflet"));
require("leaflet.markercluster");
var PropTypes_1 = require("../../util/PropTypes");
var Layer_1 = __importDefault(require("../Layer"));
var Context_1 = __importDefault(require("../Point/Context"));
var Polyline_1 = require("../Polyline");
var creator_1 = require("../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 leaflet_1.default.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 ? creator_1.defaultIcon : _b;
this.instance.addLayers(points.map(function (position) { return leaflet_1.default.marker(position, { icon: icon }); }));
};
ClusterPoints.prototype.render = function () {
var _a = this.props.icon, icon = _a === void 0 ? creator_1.defaultIcon : _a;
return (react_1.default.createElement(Context_1.default.Provider, { value: { instance: this.instance, icon: icon } }, _super.prototype.render.call(this)));
};
ClusterPoints.propTypes = __assign({}, Layer_1.default.propTypes, { points: prop_types_1.default.arrayOf(PropTypes_1.Point).isRequired, icon: PropTypes_1.Icon, clusterPane: prop_types_1.default.string, chunkProgress: prop_types_1.default.func, showCoverageOnHover: prop_types_1.default.bool, zoomToBoundsOnClick: prop_types_1.default.bool, spiderfyOnMaxZoom: prop_types_1.default.bool, removeOutsideVisibleBounds: prop_types_1.default.bool, animate: prop_types_1.default.bool, animateAddingMarkers: prop_types_1.default.bool, disableClusteringAtZoom: prop_types_1.default.number, maxClusterRadius: prop_types_1.default.oneOfType([prop_types_1.default.number, prop_types_1.default.func]), polygonOptions: prop_types_1.default.shape(Polyline_1.PolylinePropTypes), singleMarkerMode: prop_types_1.default.bool, spiderLegPolylineOptions: prop_types_1.default.shape(Polyline_1.PolylinePropTypes), spiderfyDistanceMultiplier: prop_types_1.default.number, iconCreateFunction: prop_types_1.default.func, chunkedLoading: prop_types_1.default.bool, chunkDelay: prop_types_1.default.number, chunkInterval: prop_types_1.default.number });
ClusterPoints.defaultProps = {
disableClusteringAtZoom: 18,
chunkedLoading: true
};
return ClusterPoints;
}(Layer_1.default));
exports.default = ClusterPoints;