1

嗨,我在标记与折线之间有连接,比如这个 Image 。我在这里附上一个样本。 带标记的折线

我添加了带有标记的折线。我在“点击”事件上绘制折线和标记。基本上标记带有编号的路径。我实际上想要什么 - 我能够分别编辑折线和标记,但我想将标记与折线绑定。当我拖动标记折线时,也应该用标记拖动。你可以看看我的代码

4

1 回答 1

1

我已经使用标记“拖动”事件解决了这个问题。在拖动事件中,我正在用新路径重绘折线。像那样。

   google.maps.event.addListener(marker, "drag", (mark) => {
      let lat = mark.latLng.lat().toString();
      let lng = mark.latLng.lng().toString();
      this.setState((state) => ({
        ...state,
        lattitude: lat,
        longitude: lng,
      }));
      let newPath = polyPath;
      newPath[marker.index-1] = mark.latLng;
      poly.setMap(null);
      poly = new google.maps.Polyline({
        strokeColor: "orange",
        strokeOpacity: 1.0,
        strokeWeight: 5,
        path: newPath,
        geodesic:false,
      });
      poly.setMap(map);
  });
于 2020-07-25T11:27:17.053 回答