单击此点如何获得折线点?

How to get polyline point on click on this point?

我有一条折线,想通过右键单击删除一些点。那么有没有办法在右键单击时获得多边形点?我可以获得地图的坐标并将它们与点的多边形数组进行比较,但我认为必须有一个简单的方法。

谢谢

右键可以得到直线上某点的坐标:

polyline.addListener('rightclick', function(polyMouseEvent) {
    var coords = polyMouseEvent.latLng;
});

然后确定该点是否是节点之一有点棘手。虽然根据the docs可以查出"The index of the vertex beneath the cursor when the event occurred, if the event occurred on a vertex and the polyline or polygon is editable"。我似乎记得在这方面运气不佳。

而且我认为您需要删除路径的一部分,而不仅仅是从中删除一个坐标。除非你每次都完全重画多段线。

我做了一些大致相似的事情 here,只要您右键单击多段线的那个部分,我就会删除路径的某些部分。

newShape.addListener('rightclick', function (polyMouseEvent) {
    if (google.maps.geometry.poly.isLocationOnEdge(polyMouseEvent.latLng, this, 0.0001)) {
        var vertex = polyMouseEvent.vertex;
        // alert(vertex)
    }
});