UNPKG

rlayers

Version:

React Components for OpenLayers

60 lines 2.06 kB
import { Vector as LayerVector } from 'ol/layer'; import { Vector as SourceVector } from 'ol/source'; import { default as RLayerBaseVector } from './RLayerBaseVector'; import { isOLFlatStyle, default as RStyle } from '../style/RStyle'; /** * A vector layer * * Supports loading of features from external sources. * * Requires an `RMap` context. * * Provides a vector layer context for JSX-declared `RFeature`s. * * @example * <RLayerVector> * <RFeature geometry={geom1} /> * <RFeature geometry={geom2} /> * </RLayerVector> * * Features can also be typed when using TSX: * * @example * <RLayerVector<Feature<Point>> * <RFeature geometry={point1} /> * <RFeature geometry={point1} /> * </RLayerVector> * * In this case, all callbacks will be automatically typed. * * Since 3.0, RLayerVector also supports OpenLayers light-weight RenderFeatures. * Currently these light-weight feature cannot be created using TSX/JSX and must * be read from a file. * * @example * <RLayerVector<RenderFeature> format={new GeoJSON({featureProjection: 'EPSG:3857'})} /> */ export default class RLayerVector extends RLayerBaseVector { createSource(props) { this.source = 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, attributions: this.props.attributions }); const style = isOLFlatStyle(props.style) ? props.style : RStyle.getStyle(props.style); this.ol = new LayerVector(Object.assign(Object.assign({}, props), { style, source: this.source })); return [this.ol, this.source]; } refresh(prevProps) { super.refresh(prevProps); if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.url) !== this.props.url) { this.source.setUrl(this.props.url); this.source.refresh(); } } } //# sourceMappingURL=RLayerVector.js.map