drawingManager.setDrawingMode(null) causing too much recursion

丶灬走出姿态 提交于 2019-12-23 18:53:35

问题


Please check out this fiddle, http://jsfiddle.net/HoffZ/Zu55b/

Why it is causing error "too much recursion" on drawMan.setDrawingMode(null)

drawMan.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);

google.maps.event.addListener(drawMan, 'overlaycomplete', function (event) {
    // When draw mode is set to null you can edit the polygon you just drawed
    drawMan.setDrawingMode(null);
});

This is not my fiddle but I am having this exact issue in my code


回答1:


I must admit that I don't quite understand why this happens.

But the following code seems to work:

google.maps.event.addListener(drawMan, 'overlaycomplete', function (event) {

    if (drawMan.getDrawingMode()) {

        drawMan.setDrawingMode(null);
    }        
});



回答2:


Looks like a bug. The setDrawingMode function seems to be triggering the overlaycomplete listener. Only started happening to me today.

MrUpsidown's answer actually triggers overlaycomplete a second time. Unless you need to keep listening for the event, you should clear it.

drawMan.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);

google.maps.event.addListener(drawMan, 'overlaycomplete', function (event) {
    google.maps.event.clearListener(drawMan, 'overlaycomplete');
    drawMan.setDrawingMode(null);
});



回答3:


The issue is with 3.exp. For now switch it to 3.8 and the problem will be solved.




回答4:


this code works for me, but this is google bug.

if (drawManager.drawingMode) {
  drawManager.setDrawingMode(null);
}


来源:https://stackoverflow.com/questions/28046582/drawingmanager-setdrawingmodenull-causing-too-much-recursion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!