ryry886 / mapbox-gl-measure

distance and area measure
MIT License
1 stars 0 forks source link

这个工具不能与mapbox-gl-draw控件同时存在 #2

Open anders86755 opened 1 year ago

anders86755 commented 1 year ago

我的项目中因为需要画图,所以有mapbox-gl-draw控件,加载您这个工具后,发现不能正常工作,控制台报错: caught Error: There is already a source with this ID at Qt.addSource (style.js:718:19) at Map.addSource (map.js:2004:20) at Object.addLayers (mapbox-gl-measure.js:1:30514) at Object.connect (mapbox-gl-measure.js:1:23587) at mapbox-gl-measure.js:1:30450

去掉mapbox-gl-draw控件后就正常了。因此您这个工具与mapbox-gl-draw控件看来有冲突。

ryry886 commented 1 year ago

这是 因为mapbox-gl-measure是基于mapbox-gl-draw的基础改写的,内部就使用了mapbox-gl-draw,所以导致sourceID重复,可以直接 let measure= new MapboxMeasure({ //language:"cn" }) measure._removeEvents(); measure._drawCtrl.changeMode("draw_polygon") measure._drawCtrl 其实就是MapboxMeasure这个类。可以直接使用。然后再移除掉添加标注的事件,就和MapboxMeasure一模一样了。不用再重新new MapboxMeasure()。