2010-05-18 6 views
0

자바 스크립트 코드는 아래에 첨부되어 있습니다. 두 개의 푸시 핀이 Bing 맵에 추가됩니다. 그들이 떠있을 때 설명은 핀 옆에 표시됩니다. 두 개의 버튼이 추가되고 click 이벤트에서 ShowInfoBox (shape)가 호출됩니다. 어떤 이유로 버튼이 클릭되면 Infobox는 푸시 핀이 어디에 있든 관계없이 항상 센터에서 팝업됩니다. 이것은 알려진 버그입니까? 누구든지 해결 방법을 제안 할 수 있습니까?빙지도 ShowInfoBox()는 항상지도의 중앙에 나타 납니까?

<!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> 
+0

'map.ShowInfoBox()'에 여분의 두 매개 변수를 전달해야한다고 생각하지 않습니까? 모양 만 ... –

답변

2

그것은 앵커가 위도/경도 먼저 클릭 중에 부착되어, 그것은 앵커를 설정하지 않을 수 없습니다. 클릭 수 사이를 확대/축소 해보십시오. 당신은 그것을 볼 수 있습니다 작동합니다.

쇼 바로 앞에 HideInfoBox()를 던져야합니다. 세계에있는 당신의 모양을 설정하는 대신이를 확장 할 경우 슬픔의 원인이됩니다 GetShapeByTitle() 또는 뭔가를 프로토 타이핑 : 그냥 메모

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

} 

. VEMap.GetShapeByID()를 사용할 수 있다면; 및 VEShape.GetID(); 셰이프 데이터를 동적으로 검색하는 메서드는 (장기적으로) 다루기가 더 쉽습니다.