MaxCoder


Hello everyone,

I am trying to add pushpins to the VE map according to data from a dataset. I have a dataset in the .cs file of the aspx page containing data and i would like to generate pushpins from that data.

This is the code in the HTML page that generates the map and a createShape() function for creating the shapes.

Code Block

<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=6"></< FONT>script>

<script type="text/javascript">

var myMap = null;

function GetMap()

{

myMap = new VEMap('myMap');

myMap.LoadMap(new VELatLong(52.30, 5.45), 7,VEMapStyle.Road ,'h' ,true);

}

function createShape(latitude,longtitude,title)

{

var latLong = new VELatLong(latitude,longtitude);

var shape = new VEShape(VEShapeType.Pushpin,latLong);

shape.SetTitle(title);

myMap.AddShape(shape);

}

</< FONT>script>

<body onload="GetMap();">

I just dont know where and how to call the createShape() function.

Can anyone please help me . Thanks alot in advance




Re: Adding pushpins according to serverside data from dataset

SoulSolutions


I agree we need some better examples of how to do this. The best that is out there is from Johannes, he has a 7 part series on getting data into VE, look for the ajax example where he writes the javascript serverside and uses ajax to execute it on the client:

http://johanneskebeck.spaces.live.com/

Other people also use the registerstartupscript(), I prefer the ASP.NET AJAX webservices.

I'll add this to the list of simple artcles we need for VE6.

John.







Re: Adding pushpins according to serverside data from dataset

MaxCoder

My problem is that the map gets initialised at the body's onclick event. That event is the last event being fired on the page before it showsup in the browser window. So any script registered in c# wil have no meaning as the map is still null.

The sequence of events being fired is :

1- Page_Load of the cs page

2- Script's defined in the head tag of the HTML page

3- Page_PreRender ( Using registerscriptblock())

4- Script defined in the body tag of the HTML page

5- The script in the body's onload event.

So where could i define it the registerscriptblock()

I have found a quick and temporary work-around for it:

1- Make the head tag's runat propertie set to "server".

2- Write all the scripts in c# in the Page_Load method en attach it to the head tag of the HTML page.

But i think it could be done in a more efficient way !






Re: Adding pushpins according to serverside data from dataset

Craig731

Why not initialize the map in the same script instead of automatically doing it Use an webservice return a javascript string an eval it at the end.

I have most of my script work done by running datasets through a VB string building class I wrote, and return it as eval() arguments.