UNPKG

rlayers

Version:

React Components for OpenLayers

85 lines 3.8 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = __importDefault(require("react")); var layer_1 = require("ol/layer"); var source_1 = require("ol/source"); var context_1 = require("../context"); var RLayerBaseVector_1 = __importDefault(require("./RLayerBaseVector")); var RStyle_1 = __importDefault(require("../style/RStyle")); /** * A vector layer that clusters its RFeatures * * Compatible with RLayerVector * * Requires an `RMap` context * * Not compatible with a vector layer context for JSX-declared RFeatures */ var RLayerCluster = /** @class */ (function (_super) { __extends(RLayerCluster, _super); function RLayerCluster() { return _super !== null && _super.apply(this, arguments) || this; } RLayerCluster.prototype.createSource = function (props) { this.cluster = new source_1.Vector({ features: this.props.features, url: this.props.url, format: this.props.format, loader: this.props.loader, wrapX: this.props.wrapX, strategy: this.props.strategy, attributions: this.props.attributions }); this.source = new source_1.Cluster({ source: this.cluster, distance: this.props.distance }); this.ol = new layer_1.Vector(__assign(__assign({}, props), { source: this.source, style: RStyle_1.default.getStyle(props.style) })); return [this.ol, this.source, this.cluster]; }; RLayerCluster.prototype.refresh = function (prev) { _super.prototype.refresh.call(this, prev); if ((prev === null || prev === void 0 ? void 0 : prev.distance) !== this.props.distance) this.source.setDistance(this.props.distance); if ((prev === null || prev === void 0 ? void 0 : prev.url) !== this.props.url) { this.cluster.setUrl(this.props.url); this.cluster.refresh(); } }; RLayerCluster.prototype.render = function () { return (react_1.default.createElement("div", { className: '_rlayers_RLayerCluster' }, react_1.default.createElement(context_1.RContext.Provider, { value: __assign(__assign({}, this.context), { layer: this.ol, source: this.cluster, vectorlayer: this.ol, vectorsource: this.cluster, rLayer: this, rLayerVector: this }) }, this.props.children))); }; return RLayerCluster; }(RLayerBaseVector_1.default)); exports.default = RLayerCluster; //# sourceMappingURL=RLayerCluster.js.map