在Google地图v3中无法看到绘制多边形,直到移动地图中心

时间:2014-01-26 10:27:27

标签: javascript google-maps-api-3

我跟随 Demo ,我尝试使用Google地图v3绘制多边形。

但是当我尝试绘制Polygon时,它会变得不可见,直到我改变地图中心。

我需要以某种方式重新粉刷吗?

以下是代码:

var map2;

function linesmap(){

    var myOptions = {
    zoom: 14,
    center: new google.maps.LatLng(51.425, -0.955),
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    // map2 = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

     var options = {                                
                         zoom: 14,
                         center: new google.maps.LatLng(51.425, -0.955),
                         mapTypeId: google.maps.MapTypeId.ROADMAP,
                         panControl: false,
                         scrollwheel: true,
                         draggable: true,
                         rotateControl: false,
                         mapTypeControl: true,
                         scaleControl: true,
                         streetViewControl: true,
                         zoomControl: true,
                         disableDoubleClickZoom: false
    };


    map2 = new google.maps.Map(document.getElementById("map_canvas"), options);
    buildDrawManager();
}
var buildDrawManager = function(){
     console.log('buildDrawManager');

     // Creates a drawing manager attached to the map that allows the user to draw
     // markers, lines, and shapes.
     drawingManager = new google.maps.drawing.DrawingManager({
     drawingMode: null,
     drawingControlOptions: {
                position: google.maps.ControlPosition.TOP_CENTER,
                drawingModes: [
                google.maps.drawing.OverlayType.POLYGON
                ]
            },
            polygonOptions: {
                fillColor: '#1E90FF',
                strokeWeight: 0,
                fillOpacity: 0.3,
                editable: true
            },
            map: map2
        });

    google.maps.event.addListener(drawingManager, 'polygoncomplete',  function(polygon) { });

}

[编辑]

它发生在Chrome版本32.0.1700.76

2 个答案:

答案 0 :(得分:2)

@fessy你的修复似乎对我不起作用。通过触摸缩放级别,我能够使它工作。你事件没有注意到它发生。

document.getElementById("map_canvas").onclick = function(){
    if(drawingManager.getDrawingMode() !== google.maps.drawing.OverlayType.HAND){
        map2.setZoom(map2.getZoom() + 1);
        map2.setZoom(map2.getZoom() - 1);
    }
};

http://plnkr.co/edit/TP8TIjvdRHHOyg6NKQWc?p=preview

答案 1 :(得分:0)

感谢@geocodezip发布了解决此问题的解决方法。

这是一个修复: 更改版本

https://maps.googleapis.com/maps/api/js?sensor=false&v=3&libraries=geometry,visualization,drawing

到exp。:

https://maps.googleapis.com/maps/api/js?sensor=false&v=3.exp&libraries=geometry,visualization,drawing

Plunker with fix