UNPKG

rlayers

Version:

React Components for OpenLayers

44 lines 1.98 kB
import React from 'react'; import { Vector as LayerVector } from 'ol/layer'; import { Vector as SourceVector, Cluster as SourceCluster } from 'ol/source'; import { RContext } from '../context'; import { default as RLayerBaseVector } from './RLayerBaseVector'; import { default as RStyle } from '../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 */ export default class RLayerCluster extends RLayerBaseVector { createSource(props) { this.cluster = new SourceVector({ features: this.props.features, url: this.props.url, format: this.props.format, loader: this.props.loader, wrapX: this.props.wrapX, strategy: this.props.strategy }); this.source = new SourceCluster({ source: this.cluster, distance: this.props.distance }); this.ol = new LayerVector(Object.assign(Object.assign({}, props), { source: this.source, style: RStyle.getStyle(props.style) })); return [this.ol, this.source, this.cluster]; } refresh(prev) { super.refresh(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(); } } render() { return (React.createElement("div", { className: '_rlayers_RLayerCluster' }, React.createElement(RContext.Provider, { value: Object.assign(Object.assign({}, this.context), { layer: this.ol, source: this.cluster, vectorlayer: this.ol, vectorsource: this.cluster, rLayer: this, rLayerVector: this }) }, this.props.children))); } } //# sourceMappingURL=RLayerCluster.js.map