问题
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