UNPKG

rc-bmap

Version:

<p align="center"> <img src="https://bmap.jser-club.com/home.png" width="200px"> </p> <p align="center">基于 React 的百度地图组件</p>

59 lines (45 loc) 1.26 kB
import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { Util } from '../../core'; class BaseControl extends PureComponent { static contextTypes = { getMapInstance: PropTypes.func, } static childContextTypes = { centralizedUpdates: PropTypes.func, } control = null mapInstance = null config = {} getChildContext() { return { centralizedUpdates: this.centralizedUpdates, }; } componentDidMount() { const { context, props } = this; const { children, ...resetProps } = props; this.config = { ...this.config, ...resetProps }; this.mapInstance = context.getMapInstance(); const control = this.getRealControl(); this.control = control; this.instance = control.instance; } componentDidUpdate() { const { children, ...resetProps } = this.props; this.config = { ...this.config, ...resetProps }; this.control.repaint(this.config); } componentWillUnmount() { this.control.destroy(); } centralizedUpdates = ({ name, data }) => { const configName = Util.firstLowerCase(name); this.config[configName] = data; } render() { const { children } = this.props; return children || null; } } export default BaseControl;