0

如果您想知道我为什么要这样做,这是对这个问题的后续。

我需要创建一个 mapkit JS 地图,然后在创建完成后将其销毁。我加载了 mapkit API。然后我创建地图:

mapContainerRef.current=document?.createElement('div');
mapContainerRef.current.style.width='0';
mapContainerRef.current.style.height='0';
mapContainerRef.current.style.position='absolute';
mapContainerRef.current.style.opacity='0';
document.body.appendChild(mapContainerRef.current);

// This line starts loading more scripts, when are they done loading?
const newMap=new mapkit.Map(mapContainerRef.current);

setMap(newMap);

发生这种情况后,地图会进行一些 API 调用。我对此进行了测试。我加载了mapkit脚本,然后等待了 5 秒钟,然后创建了一个新的map. 以下是创建新地图时进行的调用。

在此处输入图像描述

我需要弄清楚它什么时候完成了它正在做的所有工作,以便我可以销毁它并卸载地图。

没有事件处理程序可以说它已准备就绪,有一个未记录的属性:map._impl.state从 更改InitializedReady,但这会立即发生并且在所有工作完成之前发生,因此没有任何帮助。

如果您在创建地图后立即销毁它,则会产生错误:

Uncaught TypeError: Cannot set property 'language' of null
    at n._reConfigureMapNode (VM28093 mapkit.js:3)
    at n._enter_syrup_init (VM28093 mapkit.js:3)
    at n._updateState (VM28093 mapkit.js:3)
    at n._transition (VM28093 mapkit.js:3)
    at n.handleSpileLoad (VM28093 mapkit.js:3)
    at n.<anonymous> (VM28093 mapkit.js:3)
    at n.<anonymous> (VM28093 mapkit.js:3)

目前我只是设置一个超时,希望它就足够了......

4

0 回答 0