Gmap添加点线面

代码如下 :
function CreatePoints() {
    // #画点之前移除map范围内的click事件
    GEvent.clearListeners(map, 'click');
   
    var id = 0;
    var points = [];
    var str;
    GEvent.addListener(map, 'click', function(marker, point) {
        if (point) {
            id++;
            var NewMarker = new GMarker(point, { draggable: true });
            var html = "<span><b>" + point + "</b><br/><span>";
            map.addOverlay(NewMarker);
            NewMarker.openInfoWindowHtml(html);
            NewMarker.setIndex(id);
            str = point.lat() + " " + point.lng() + " " + id;
            points.push(str);
            document.getElementById("hidPoints").value = points.toString();
// #双击新建的点删除该点的marker
            GEvent.addListener(NewMarker, 'dblclick', function() {
                deleteMarker(NewMarker);
// #删除数组中存的该点的值
                points.splice(NewMarker.index - 1, 1);
                document.getElementById("hidPoints").value = points.toString();
            });
// #拖动事件
            GEvent.addListener(NewMarker, "dragstart", function() {
                map.closeInfoWindow();
                points.splice(NewMarker.index - 1, 1);
            });
// #拖动的点落下
            GEvent.addListener(NewMarker, "dragend", function() {
                var htmls = "<span><b>" + NewMarker.getPoint() + "</b><br/><span>";
                NewMarker.openInfoWindowHtml(htmls);
                str = NewMarker.getPoint().lat() + " " + NewMarker.getPoint().lng() + " " + NewMarker.index;
                points.push(str);
                document.getElementById("hidPoints").value = points.toString();
            });
        }
    });
}
有没有哪位大大做个demo 看看 我试了很多次 不知道哪里出了错 谢了

你可能感兴趣的:(html)