@wayz/react-gl
Version:
React Component for DeckGL, Base on AMap, Mapbox GL
61 lines (60 loc) • 2.22 kB
JavaScript
import { CompositeLayer } from '@deck.gl/core';
import { PolygonLayer } from '@deck.gl/layers';
import { getGeoHashPolygon } from './geohash-util';
const defaultProps = {
...PolygonLayer.defaultProps,
getGeoHash: { type: 'accessor', value: (d) => d.geohash },
};
class GeoHashLayer extends CompositeLayer {
renderLayers() {
// Layer prop
const { data, getGeoHash } = this.props;
// Rendering props underlying layer
const { elevationScale, extruded, wireframe, filled, stroked, lineWidthUnits, lineWidthScale, lineWidthMinPixels, lineWidthMaxPixels, lineJointRounded, lineMiterLimit, getElevation, getFillColor, getLineColor, getLineWidth,
//@ts-ignore
lineDashJustified,
//@ts-ignore
getLineDashArray, } = this.props;
// Accessor props for underlying layers
const { updateTriggers, material } = this.props;
// Filled Polygon Layer
const CellLayer = this.getSubLayerClass('cell', PolygonLayer);
return new CellLayer({
filled,
wireframe,
extruded,
elevationScale,
stroked,
lineWidthUnits,
lineWidthScale,
lineWidthMinPixels,
lineWidthMaxPixels,
lineJointRounded,
lineMiterLimit,
lineDashJustified,
material,
getElevation,
getFillColor,
getLineColor,
getLineWidth,
getLineDashArray,
}, this.getSubLayerProps({
id: 'cell',
updateTriggers: {
getElevation: updateTriggers.getElevation,
getFillColor: updateTriggers.getFillColor,
getLineColor: updateTriggers.getLineColor,
getLineWidth: updateTriggers.getLineWidth,
getLineDashArray: updateTriggers.getLineDashArray,
},
}), {
data,
// _normalize: false,
positionFormat: 'XY',
getPolygon: (x) => getGeoHashPolygon(getGeoHash(x)),
});
}
}
GeoHashLayer.layerName = 'GeoHashLayer';
GeoHashLayer.defaultProps = defaultProps;
export default GeoHashLayer;