UNPKG

@wayz/react-gl

Version:

React Component for DeckGL, Base on AMap, Mapbox GL

66 lines (65 loc) 2.95 kB
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 __()); }; })(); import { CompositeLayer } from '@deck.gl/core'; import { IconLayer } from '@deck.gl/layers'; import { point } from '@turf/helpers'; import bboxPolygon from '@turf/bbox-polygon'; import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; var IconLayerInViewport = /** @class */ (function (_super) { __extends(IconLayerInViewport, _super); function IconLayerInViewport() { return _super !== null && _super.apply(this, arguments) || this; } IconLayerInViewport.prototype.shouldUpdateState = function (_a) { var changeFlags = _a.changeFlags; return changeFlags.somethingChanged; }; IconLayerInViewport.prototype.updateState = function (_a) { var props = _a.props, oldProps = _a.oldProps, changeFlags = _a.changeFlags; var rebuildIndex = changeFlags.viewportChanged || props.sizeScale !== oldProps.sizeScale; // @ts-expect-error var bbox = this.context.viewport.getBounds(); var poly = bboxPolygon(bbox); var data = props.data.filter(function (d) { var pt = point(props.getPosition(d)); return booleanPointInPolygon(pt, poly); }); if (rebuildIndex) { this.setState({ data: data }); } }; IconLayerInViewport.prototype.renderLayers = function () { var _a = this.state.data, data = _a === void 0 ? [] : _a; var updateTriggers = this.props.updateTriggers; var IconLayerInViewport = this.getSubLayerClass('viewport', IconLayer); return new IconLayerInViewport(this.props, this.getSubLayerProps({ id: 'viewport', updateTriggers: { getIcon: updateTriggers.getIcon, getPosition: updateTriggers.getPosition, getColor: updateTriggers.getColor, getAngle: updateTriggers.getAngle, getPixelOffset: updateTriggers.getPixelOffset, getSize: updateTriggers.getSize, }, }), { data: data, }); }; return IconLayerInViewport; }(CompositeLayer)); IconLayerInViewport.layerName = 'IconLayerInViewport'; export default IconLayerInViewport;