Adding over 100 pushpins from a database
I am working with a CRM web app that creates lists. I want to pass this list to a page that has the map. My problem is getting the server side data to the client side code of VE? I have tried to use a session array but must be doing something wrong. The code is writen is javascript and I could really use some help. How do people push large amounts of data to VE?
Thanks all!
[390 byte] By [
Webbee] at [2008-2-26]
You need to work with the "and XML" portion of AJAX.
By adding code surrounding the XMLHTTPRequest object, you can communicate with an ASHX (or ASPX or Servlet) file, which you can use to broker messages between your client side JS and your server.
To create an instance of the XMLHTTPRequest object, add the following:
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = someMethodToHandleTheResponse;
The onreadystatechange property of the XMLHTTPRequest object handles the response back from the server. You'll need to create a method or something similar to listen for a response from the XMLHTTPRequest object after the server finishes the transmission.
After you have your xmlhttp object, you can request a "Get" from your ashx page:
xmlhttp.open("Get", "file.ashx?property1=blah&property2=blah");
xmlhttp.send(null);
Then, in your method that's listening for the response, you need to add code to process the returned response - similar to any form postback using the "Get" stack.
well, I think the answer given above was probably out of scope for what you were trying to accomplish. It sounds like what you're wanting to do is plot x number of points at initial load time, not re-plotting each time the map is moved, correct?
this is a simple process ( in php ):
<script src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script type="text/javascript">
var map = null;
var pinID = 1;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}
function AddPin(data, latlon)
{
var pin = new VEPushpin(
pinID,
latlon,
null,
data['title'],
data['message']
);
map.AddPushpin(pin);
pinID++;
}
window.onload = function()
{
GetMap();
map.DeleteAllPushpins();
<?php foreach ($_SESSION['pins'] as $item) { ?>
AddPin($item['data'], new VELatLong($item['latitude'],$item['longitude']));
<?php } ?>
}
</script>
I think that will do what you need, now let me explain the variables that I recommend you use:
$_SESSION['pins'] - this would be a multi-dimensional array of the items that you want to plot.
$item - this would be each of the elements within your $_SESSION['pins'] array.
$item['data'] - this would contain an array of data to be passed and displayed within your pin ( i.e: $item['data']['title'] = 'my pin', $item['data']['message'] = 'look, I made a pin' ).
$item['latitude'] - this is the latitude of the pin.
$item['longitude'] - this is the longitude of the pin.
I hope this works for you.
Have you considered the option of publishing the list as GeoRss, then simply add this GeoRss as a Layer in VE.
for an example visit http://dev.live.com/virtualearth/sdk/ and navigate the sample tree to Working with Layers
What would the GeoRSS file look like for that example?
RedCoat999 wrote: |
| What would the GeoRSS file look like for that example? |
|
Microsoft's example GeoRSS feed is located at http://dev.live.com/virtualearth/sdk/GeoRSSTest.xml .
Using GeoRSS may or may not be viable for you in the current version of the map control since adding a layer will automatically zoom to a best-fit view of the points in the feed. My understanding is that this limitation will be addressed in an upcoming release of the map control.
This is true, when you load the geoRSS it rezooms. I tried a function that saved the current view info before loading the geoRSS and then set the view back to what the user had when the layer loaded.
It gives a cool effect of VE going "i'll just move the screen over....no wait i'll go back then"
John.