UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

124 lines (123 loc) 5.81 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) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import * as React from 'react'; import { reaction } from 'mobx'; import { observer } from 'mobx-react'; import { ZoomControl } from 'react-mapbox-gl'; import { utils } from '@qn-pandora/app-sdk'; import bind from '../../../utils/bind'; import { MAX_ZOOM } from '../../../constants'; import BasicComponent from '../../Base/BasicComponent'; import ReactMapboxFactory from '../../Base/Mapbox'; import ChartContainer from '../components/ChartContainer'; import { IGNORE_CENTER_GAP, IGNORE_ZOOM_GAP } from './constants'; import * as style from './style.mless'; var toFixed = utils.unit.toFixed; var MapBoxGl = ReactMapboxFactory({ maxZoom: MAX_ZOOM }); var BaseMapboxChart = /** @class */ (function (_super) { __extends(BaseMapboxChart, _super); function BaseMapboxChart() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.store = _this.props.store; _this.onStyleLoad = function (map, e) { var onStyleLoad = _this.props.onStyleLoad; var maxZoom = _this.store.chartStyleService.maxZoom; _this.map = map; map.resize(); _this.changeMaxZoom(maxZoom); _this.addDisposer(reaction(function () { return _this.store.chartStyleService.maxZoom; }, function (maxZoom) { _this.changeMaxZoom(maxZoom); })); if (onStyleLoad) { onStyleLoad(map, e); } }; _this.handleZoom = function (map) { var newZoom = map.getZoom(); var _a = _this.store.chartStyleService, zoom = _a.zoom, setZoom = _a.setZoom; if (Math.abs(newZoom - zoom[0]) > IGNORE_ZOOM_GAP) { setZoom([parseFloat(toFixed(newZoom, 6))]); } }; _this.handleMove = function (map) { var _a = map.getCenter(), lng = _a.lng, lat = _a.lat; var _b = _this.store.chartStyleService, center = _b.center, setCenter = _b.setCenter; if (Math.abs(center[0] - lng) > IGNORE_CENTER_GAP || Math.abs(center[1] - lat) > IGNORE_CENTER_GAP) { setCenter([parseFloat(toFixed(lng, 6)), parseFloat(toFixed(lat, 6))]); } }; return _this; } BaseMapboxChart.prototype.handleResize = function (client) { if (this.map) { this.map.resize(); } this.store.debounceHandleClient(client); }; BaseMapboxChart.prototype.changeMaxZoom = function (maxZoom) { this.map.setMaxZoom(maxZoom); var zoom = this.store.chartStyleService.zoom; if (Math.abs(this.map.getZoom() - zoom[0]) > IGNORE_ZOOM_GAP) { this.map.setZoom(zoom[0]); } }; BaseMapboxChart.prototype.render = function () { var _a = this.props, queryPath = _a.queryPath, tilePath = _a.tilePath; var zoomPosition = this.store.chartStyleService.zoomPosition; return (React.createElement(ChartContainer, { onClient: this.handleResize }, React.createElement(MapBoxGl, __assign({ renderChildrenInPortal: true, onZoomEnd: this.handleZoom, onMoveEnd: this.handleMove, onStyleLoad: this.onStyleLoad, queryPath: queryPath, tilePath: tilePath }, this.store.props, { className: style.mapboxMap }), zoomPosition !== "none" /* NONE */ ? (React.createElement(ZoomControl, { position: zoomPosition })) : undefined, this.props.children))); }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], BaseMapboxChart.prototype, "handleResize", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BaseMapboxChart.prototype, "changeMaxZoom", null); BaseMapboxChart = __decorate([ observer ], BaseMapboxChart); return BaseMapboxChart; }(BasicComponent)); export default BaseMapboxChart;