There is already a source with this ID
在使用移除图层时,发现移除了之后不能再次加载了。原因是在创建图层时,创建图层和添加source时放在一个函数中了,而removelayer只是移除了layer,source还在内存之中,因此会报这个错误。由此可见,mapbox是将layer与source分开管理。因此sourceid一定要唯一
官网给的方式必须使用这种方式来定义sourceid,但由于前后端分离,通常初始化map和数据不在一处,很难操作。
map.addSource("pointSource", {
"type": "geojson",
"data": jsonData
});
如果我们不去指定sourceid,则sourceid会与layerid一致,我们可以用layerid来直接移除source