【问题标题】:Google Maps Api V3: How to bind a marker to the vertices of a Polygon?Google Maps Api V3:如何将标记绑定到多边形的顶点?
【发布时间】:2023-03-12 23:26:01
【问题描述】:

我正在尝试将标记绑定到多边形的顶点,这样移动标记会改变多边形的形状。

    var polygonLine = new google.maps.Polyline(
    {
        path: [],
        map: map,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });
    polygonLine.getPath().push(new google.maps.LatLng(-31.95202, 115.8548));
    polygonLine.getPath().push(new google.maps.LatLng(-31.94980, 115.8586));
    polygonLine.getPath().push(new google.maps.LatLng(-31.95246, 115.8625));
    polygonLine.getPath().push(new google.maps.LatLng(-31.95508, 115.8558));

    var polygon = new google.maps.Polygon({map: map, path: polygonLine.getPath()});
    var vertices = polygon.getPath();

    for (var i = 0; i < vertices.getLength(); i++)
    {
        markers[i] = new google.maps.Marker({ position:vertices.getAt(i), map: map, draggable: true });
        vertices.getAt(i).bindTo('position', markers[i], 'position');      // Throws an error
    }

现在这不起作用,因为在最后一行的第 2 行,vertices.getAt(i) 返回一个 LatLng,它不支持 'position' 属性。

有谁知道我如何将标记绑定到顶点?谢谢:)

【问题讨论】:

    标签: javascript binding google-maps-api-3 google-maps-markers


    【解决方案1】:

    我会查看Google Code project with v3 API examples 的来源。

    它似乎基本上添加了一个处理绑定数组的简单类,然后将其与 bindTo 调用一起使用。

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      • 2013-11-16
      • 2012-02-08
      • 2014-05-09
      • 2016-06-17
      • 1970-01-01
      相关资源
      最近更新 更多