Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在使用router 切换时,发生了Uncaught (in promise) TypeError: Cannot read property 'setterMap' of null错误 #242

Open
3 tasks done
susanforme opened this issue Feb 23, 2021 · 0 comments

Comments

@susanforme
Copy link

susanforme commented Feb 23, 2021

  • 我已经搜索过 issue,没有类似的问题,或者类似的问题仍然没有解决方案。
  • 我已经搜索过文档,并且仍然没有找到解决方案。
  • 我写了个问题重现的例子,链接或者代码将会贴在下面。

Reproduce Example Link or Code Fragment

该组件位于 路由中

const MyMap: React.FC<MyMapProps> = ({ position, onClick }) => {
  const [ranging, setRanging] = useState(false);
  const [rule, setRule] = useState<any>({});
  const style = useStyles();
  const plugins: any = [
    'Scale',
    'OverView',
    // v1.1.0 新增
    'ControlBar',
    'ToolBar',
  ];
  const events = {
    click: (map: any) => {
      onClick(map);
    },
    created(instance: any) {
      window.AMap.plugin(['AMap.RangingTool'], () => {
        const rule = new window.AMap.RangingTool(instance, getMapPlugins());
        setRule(rule);
      });
    },
  };
  useEffect(() => {
    if (!rule.turnOn) {
      return;
    }
    if (ranging) {
      rule.turnOn();
    } else {
      rule.turnOff();
    }
  }, [rule, ranging]);
  return (
    <Map
      viewMode="3D"
      zoom={15}
      plugins={plugins}
      loading={
        <div className={style.loadingFather}>
          <Spin tip="加载中" size="large" />
        </div>
      }
      center={position}
      events={events}
    >
      <Marker position={position} draggable visible={!ranging} />
      <div className={style.customLayer}>
        <Button title="开启测距" onClick={() => setRanging(true)}>
          开启测距
        </Button>
        <Button title="关闭测距" onClick={() => setRanging(false)}>
          结束测距
        </Button>
      </div>
    </Map>
  );
};

export default MyMap;

What is actually happening?

在切换组件的时候发生了如下错误
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant