5

ドキュメントに書かれているように、ポリラインのパスでエッジのインデックスを取得しようとしています。ただし、ポリラインでクリック イベントをトリガーするたびに、未定義の値が返されます。

これが私のコードです:エッジ、パス、頂点はすべて未定義です

route = new google.maps.Polyline({
path: polyLineArray,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 5,
clickable: true,
editable: false
});
    
google.maps.event.addListener(route, 'click', function(evt) {           
  console.log("route click1: " + evt.edge);
  console.log("route click2: " + evt.path);
  console.log("route click2: " + evt.vertex);
  console.log("route click3: " + evt);
  for(var property in evt) {
   console.log("route click4: " + property + " - " + evt[property]);
  }

} });

ここで何か不足していますか?どうもありがとう

4

1 に答える 1

10

テストケースでも同じ結果が表示されます

さらにテストすると、「編集可能な」ポリラインで使用できるように見えます。白い四角をクリックすると頂点が真になり、ポリラインを編集して「新しい」頂点の1つをクリックするとパスが真になります。 テスト編集可能なポリラインのあるケース

ドキュメントを詳しく見ると、編集可能なポリライン/ポリゴンにのみ適用されることは明らかです。

google.maps.PolyMouseEvent object
This object is returned from mouse events on polylines and polygons.

This object extends MouseEvent.
Properties
Properties | Type   | Description
edge       | number | The index of the edge within the path beneath the cursor when 
                    | the event occurred, if the event occurred on a mid-point on an 
                    | editable polygon.
path       | number | The index of the path beneath the cursor when the event 
                    | occurred, if the event occurred on a vertex and the polygon
                    | is editable. Otherwise undefined.
vertex     | number | 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. If the event does not occur on a vertex, 
                    | the value is undefined.

詳しくは。小さな白い四角(「編集ハンドル」)をクリックすると、頂点番号またはエッジ番号が表示されます。パスを未定義にする方法は見つかりませんでしたが、これまではポリラインでしか遊んでいないことが原因である可能性があります。 。

于 2012-08-21T18:29:42.757 に答える