我可以在Google地图中限制多边形线长度(如100米)吗?

时间:2016-02-03 05:59:33

标签: javascript google-maps

我的要求是根据给定的输入限制多边形线长度。我尝试了以下代码,但我无法成功限制该行的长度。

enter image description here

上面的图片是我想限制长度的线段类型。

Var drawingManager;

var Map;
map = new google.maps.Map(document.getElementById('map'), {
    zoom: 5,
    center: {lat: 24.886, lng: -70.268},
    mapTypeId: google.maps.MapTypeId.TERRAIN
});

var polyOptions = {
    draggable: true, // turn off if it gets annoying
    editable: true,
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35
};

drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: google.maps.drawing.OverlayType.POLYGON,
    markerOptions: {
        draggable: true
    },
    polylineOptions: {
        editable: false
    },
    rectangleOptions: polyOptions,
    circleOptions: polyOptions,
    polygonOptions: polyOptions,
    map: map
});

google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
    alert();
        if (e.type != google.maps.drawing.OverlayType.MARKER) {
        drawingManager.setDrawingMode(null);
        var newShape = e.overlay;
        newShape.type = e.type;
        google.maps.event.addListener(newShape, 'click', function() {

        });
    }
     google.maps.event.addListener(newShape, 'set_at', function() {
        // complete functions
        alert();
      });

      google.maps.event.addListener(newShape, 'insert_at', function() {
        // complete functions
        alert();
      });
});

0 个答案:

没有答案