0

这是我的测试示例的链接和我试图弄清楚的代码。 http://www.gaiser-vfx.com/media/maptest.html

<div id="googleMap">
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
    <div id="map_canvas" style="width:100%; height:300px"></div>
<script>
    var noLocation = new google.maps.LatLng(52.1307, -3.78371);
    var initialLocation;
    var browserSupportFlag =  new Boolean();
    var map;
    var myOptions = {
        zoom: 6,
        draggable: true,
        minZoom: 0,
        maxZoom: 20,
        disableDefaultUI: true,
        zoomControl: true,
        scrollwheel: true,
        disableDoubleClickZoom: true,
        mapTypeId: google.maps.MapTypeId.false
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    google.maps.event.addListener(map, 'bounds_changed', function() {
    var center = map.getCenter();
    var zoomLevel = map.getZoom();
    $('#LocationLatitude').val(center.lat().toFixed(5));$('#LocationLongitude').val(center.lng().toFixed(5));$('#LocationZoom').val(zoomLevel);});


    var poly
    var path = new google.maps.MVCArray;
    poly = new google.maps.Polygon({
        strokeWeight: 3,
        fillColor: '#5555FF'
    });

    poly.setMap(map);
    poly.setPaths(new google.maps.MVCArray([path]));
    google.maps.event.addListener(map, 'click', addPoint);

    function addPoint(event) {
        path.insertAt(path.length, event.latLng);
        var marker = new google.maps.Marker({
        position: event.latLng,
        map: map,
        draggable: true
    });

    markers.push(marker);
    marker.setTitle("#" + path.length);
    google.maps.event.addListener(marker, 'click', function() {
        marker.setMap(null);
        for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
            markers.splice(i, 1);
            path.removeAt(i);
        });

        google.maps.event.addListener(marker, 'dragend', function() {
            for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
                path.setAt(i, marker.getPosition());
            }
        );
    }
</script>

`

这是我要遵循的示例。

http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/poly_edit.html

我的代码和示例之间的主要区别之一是示例中使用了初始化函数调用,而我只是在加载页面时尝试加载我的。在我的地图测试中,我能够在地图上放置标记并将它们拾起并移动它们,但是每个标记上将多边形更新为新标记点的功能以及删除每个标记的功能似乎不起作用。

4

1 回答 1

0

看起来您所要做的就是声明一个markers对事件侦听器可见的变量:

...
var markers = [];
var poly;
var path = new google.maps.MVCArray;
...
于 2012-06-01T19:03:30.893 回答