|
var map = null; // this var holds the VE map
// Initializes the VE map and calls the method to load the data function InitializeMap() {
// make sure map is initialized if (map == null) { map = new VEMap('myMap'); // initialize map map.LoadMap(); // load it map.SetMapStyle('r'); // set the MapStype to "Road" map.SetCenter(new VELatLong("48.132241398091125", "11.575480699539175")); // and zoom to Munich }
// load the locations and display them on the map
GetLocations(); }
// calls the WS and retrieves the Locations. Since this call is async we need // to wire up a method which should be called when the call to the webservice // succeeds and one if the call fails function GetLocations() {
// wire up the methods to call in case of success and failure ShowLocationsOnVirtualEarth.Locations.set_defaultSucceededCallback(OnSucceededCallbackRoute); ShowLocationsOnVirtualEarth.Locations.set_defaultFailedCallback(OnErrorCallbackRoute);
// call the webservice ShowLocationsOnVirtualEarth.Locations.GetLocations(); }
// Callback function invoked when the call to // the Web service methods succeeds. function OnSucceededCallbackRoute(result) {
// draw the locations on the map DrawLocationsOnMap(result); }
// this function draws the locations on a map function DrawLocationsOnMap(ListOfLocations) {
if ((map != null) && (ListOfLocations != null) && (ListOfLocations.length > 0)) {
// this array holds all the VELatLong values // used later to set the zoom of the map to display // all the locations var points = new Array(); var vELatLong;
// draw the Locations on the map for (i = 0; i < ListOfLocations.length; i++) {
vELatLong = CreateVELatLongFromLocations(ListOfLocations[i]); points[i] = vELatLong;
// add the location to the map map.AddShape(AddDot(vELatLong, ListOfLocations[i].Name, ListOfLocations[i].Description, ListOfLocations[i].MatchedAddress, ListOfLocations[i].URL));
// Zoom the map according to all locations map.SetMapView(points); } } }
// ************************************************************ // *** some tools ;-) *** // ************************************************************
// Converts a Location into a VELatLong object // Parameters: // Location: a Location // return: a VELatLong instance function CreateVELatLongFromLocations(Location) { return new VELatLong(Location.Latitude, Location.Longitude); }
// Creates a custom VEShape (which represents a dot on the map) function AddDot(Point, Name, Description, MatchedAddress, URL) {
var shape = new VEShape(VEShapeType.Pushpin, Point); shape.SetTitle(Name);
var descriptionText = '<b>Description:</b> ' + Description + '<br /><br /><b>Address:</b> ' + MatchedAddress + '<br /><br /><b>Homepage:</b> <a href = "' + URL + '">' + URL + '</a>';
shape.SetDescription(descriptionText); shape.SetCustomIcon('<div><img src="images/info.png" /></div>'); return shape; }
// Callback function invoked when the call to // the Web service methods fails. function OnErrorCallbackRoute(error) { alert("Error (route): " + error.get_message()); }
if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded(); |