123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import React, { Component, PureComponent } from 'react';
- import PropTypes from 'prop-types';
- import { createPolygon, updatePolygon } from './api';
- const __com__ = 'Polygon';
- //const debug = console.log;
- const debug = () => {};
- export class Polygon extends Component {
- static propTypes = {
- AMap: PropTypes.object,
- __map__: PropTypes.object,
- options: PropTypes.object,
- events: PropTypes.object
- };
- constructor() {
- super();
- this.refElement = null;
- this._entity = null;
- debug(__com__, 'constructor', this._entity);
- }
- componentWillMount() {
- debug(__com__, 'componentWillMount', this._entity);
- }
- componentDidMount() {
- debug(__com__, 'componentDidMount', this._entity);
- let { AMap, __map__, options, events, children } = this.props;
- //let opts = { ...(options || {}), map: __map__, content: children };
- let opts = { ...(options || {}), map: __map__ };
- this._entity = createPolygon(AMap, opts, events);
- }
- componentWillReceiveProps(nextProps) {
- debug(__com__, 'componentWillReceiveProps', this._entity);
- }
- componentWillUpdate() {
- debug(__com__, 'componentWillUpdate', this._entity);
- }
- componentDidUpdate(prevProps) {
- debug(__com__, 'componentDidUpdate', this._entity);
- let { AMap, __map__, options, events, children } = this.props;
- //let opts = { ...(options || {}), map: __map__, content: children };
- let opts = { ...(options || {}), map: __map__ };
- if (!this._entity) {
- this._entity = createPolygon(AMap, opts, events);
- return;
- }
- // need check props changes, then update.
- let oldOpts = {
- ...(prevProps.options || {}),
- map: prevProps.__map__
- };
- updatePolygon(this._entity, opts, events, oldOpts, prevProps.events);
- }
- componentWillUnmount() {
- debug(__com__, 'componentWillUnmount', this._entity);
- if (this._entity) {
- // this._entity.clearMap();
- this._entity.setMap(null);
- delete this._entity;
- // delete this._entity;
- this._entity = null;
- }
- }
- // shouldComponentUpdate(nextProps, nextState) {
- // debug(__com__, 'shouldComponentUpdate', this._entity);
- // return false;
- // }
- render() {
- debug(__com__, 'render', this._entity);
- let {
- AMap,
- options,
- events,
- match,
- location,
- history,
- staticContext,
- ...rest
- } = this.props;
- return null;
- // return (
- // <React.Fragment>
- // </React.Fragment>
- // )
- }
- }
- export default Polygon;
|