Show an infobox from a link

Hello everybody,

I'm working on this since yesterday, I can't solve it.

I have added 3 pushpin to the map

Code Snippet

varmap =null;

varlayer01=null;

varpinID = 1;

varmapPopupID=0;

variLoadError=0;

vartmpShapeToPopup=null;

functionGetMap(){

map =newVEMap("mapVE");

map.SetDashboardSize(VEDashboardSize.Small);

map.LoadMap(newVELatLong(13.4419, -87.1419), 5 ,'h' ,false);

map.AttachEvent('onchangeview',ChangeViewManager);

map.AttachEvent("onclick",ShapeLayerAlert);

layer01 =newVEShapeLayer();

layer01.SetTitle("layer01");

map.AddShapeLayer(layer01);

}

functionaddPin(sLat,sLon,sImgPath,sTitle,sText){

varshape =newVEShape(VEShapeType.Pushpin,newVELatLong((sLat), -(-sLon)));

shape.SetTitle(sTitle);

shape.SetDescription(sText);

shape.SetCustomIcon(sImgPath);

layer01.AddShape(shape)

pinID++;

returnshape.GetID();

}

the three points are displayed on the map and into a table as text.

Now what I'm trying to realize is an hyperlink the make a zoom to the point selected by the user and then display the infobox.

I have done the center and zoom procedure but there is no way to dispaly the infobox.

here is the hyperlink generated when I add the pushpin (the first parameter is the shapeID returned by the addPin function:

Code Snippet
link

when the user click on the hyperlink the following function is called:

Code Snippet

functionshowPopup(tmpID,sLat,sLon){

varobjCoords;

mapPopupID=tmpID;

objCoords=newVELatLong((sLat), -(-sLon));

map.SetCenterAndZoom(objCoords, 9);

}

here is the function that manage the view change event:

Code Snippet

functionChangeViewManager(e){

tmpShapeToPopup =layer01.GetShapeByID(mapPopupID);

map.ShowInfoBox(tmpShapeToPopup)

}

The problem is that the methodsshape.GetID() return a value that is not possible to use with the method

map.GetShapeByID

In order to use the methodsShowInfoBoxI need a shape object, and it seems that is not possible to retrieve it without an event that return this object.

to see the difference take a look at this function from MSDN:

Code Snippet

functionShapeLayerAlert(e)

{

if(e.elementID !=null)

{

shape =map.GetShapeByID(e.elementID);

layer =shape.GetShapeLayer();

alert("Shape ID " +e.elementID + "\nbelongs to shape layer '" +layer.GetTitle() + "'.");

}

}

in my code is called when you click over a pushpin, try to replace e.elementID with shape.GetID() and you will see the issue!

please help me!!

thanks

Marco

[12278 byte] By [19764Anonymous] at [2008-1-4]
# 1
Hi Marco,

There shouldn't be any problem using the id you get from shape.GetID() in the VEMap.ShowInfoBox() method.

Code Snippet

//Addding shape to the map

var shape = new VEShape(VEShapeType.Pushpin,new VELatLong(13.4419, -87.1419));
map.AddShape(shape);

var id = shape.GetID();

//Showing the infobox using the id

var s = map.GetShapeByID(id);

map.ShowInfoBox(s);

The above code shows that you can show an info box by getting the shape, and then showing the info box.

I think the problem is that the info box is showing, but it disappears before the infobox is displayed. I don't have any good solutions to offer except the following: Delaying the showinfobox a little seems to make the infobox show.

Code Snippet

function ChangeViewManager(e){
tmpShapeToPopup = map.GetShapeByID(map.s1ID);
setTimeout(function(){map.ShowInfoBox(tmpShapeToPopup )},100);
}

Derrick at 2007-10-3 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...

Windows Live Developer Forums

Site Classified