0

以下にJavaScriptコードを添付します。2 つの押しピンが Bing マップに追加されます。ピンをホバーすると、ピンの横に説明が表示されます。2 つのボタンが追加され、クリック イベントで ShowInfoBox(shape) が呼び出されます。ボタンをクリックすると、何らかの理由で、画鋲の位置に関係なく常にインフォボックスが中央からポップアップします。これは既知のバグですか? 誰でも回避策を提案できますか?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
  <script type="text/javascript">
  var shape;
  var shape1;

 var map = null;
 var infobox = "You can add html codes into the info box or change the style of the info box. You can design and show any info box you want!<br>";

 function ShowInfoBox(sh)
 {
    // The anchor param does not seem to have any effect ???
    map.ShowInfoBox(sh, new VELatLong(sh.Latitude, sh.Longitude), new VEPixel(0, 0));

 }

 function HideInfoBox()
 {
    map.HideInfoBox();
 }


 function GetMap()
 {
    map = new VEMap('myMap');

    map.LoadMap(new VELatLong(47.610377,  -122.200679), 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true);

    shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());


    shape.SetTitle("<h2>Custom Pin0</h2>");
    shape.SetDescription(infobox);

    //Add the shape the the map
    map.AddShape(shape);

    shape1 = new VEShape(VEShapeType.Pushpin, new VELatLong(47.612379,  -122.201677));

    shape1.SetTitle("<h2>Custom Pin1</h2>");
    shape1.SetDescription(infobox);

    //Add the shape the the map
    map.AddShape(shape1);
 }

 </script>
 </head>
 <body onload="GetMap();">
  <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
  <input type="button" value="1" onclick="ShowInfoBox(shape);">
  <input type="button" value="2" onclick="ShowInfoBox(shape1);">
 </body>
</html> 
4

1 に答える 1

2

アンカーが設定されないということではなく、最初にクリックした緯度/経度にアンカーが固定されているということです。クリックの間にズームしてみてください。動作することがわかります。

あなたがする必要があるのは、ショーの直前に HideInfoBox() をスローすることです。

関数 ShowInfoBox(sh)
 {
    // アンカー パラメータは何の効果もないようです ???
    HideInfoBox();
    map.ShowInfoBox(shape,new VELatLong(sh.Latitude, sh.Longitude));

 }

注意: GetShapeByTitle() などのプロトタイプを作成するのではなく、グローバルにシェイプを設定すると、これをスケールアップすると悲しくなります。VEMap.GetShapeByID(); を使用できる場合。および VEShape.GetID(); 形状データによって動的に取得するメソッドを使用すると、(長期的には) 扱いやすくなります。

于 2010-06-01T18:36:05.470 に答える