rlayers
Version:
React Components for OpenLayers
38 lines • 1.38 kB
JavaScript
import { Tile as LayerTile } from 'ol/layer';
import { XYZ } from 'ol/source';
import { default as RLayerRaster } from './RLayerRaster';
import debug from '../debug';
/**
* A layer with XYZ raster tiles
*
* Requires an `RMap` context
*/
export default class RLayerTile extends RLayerRaster {
constructor(props) {
super(props);
this.createSource();
this.ol = new LayerTile({ source: this.source });
this.eventSources = [this.ol, this.source];
}
createSource() {
this.source = new XYZ({
url: this.props.url,
interpolate: !this.props.noIterpolation,
projection: this.props.projection,
tileGrid: this.props.tileGrid,
crossOrigin: this.props.crossOrigin,
attributions: this.props.attributions
});
this.eventSources = [this.ol, this.source];
}
refresh(prevProps) {
super.refresh(prevProps);
if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.tileGrid) !== this.props.tileGrid || (prevProps === null || prevProps === void 0 ? void 0 : prevProps.url) !== this.props.url) {
debug('replacing source', this);
this.createSource();
this.ol.setSource(this.source);
this.attachOldEventHandlers(this.source);
}
}
}
//# sourceMappingURL=RLayerTile.js.map