﻿// Virtual Earth JScript File

var map = null;
var lat1 = 47.61374; 
var lon1 = -122.33579;
var latLong01 = new VELatLong(lat1, lon1); //Traverse City
var poly01 = null;
var pin01 = null;
var shape = null;
var index = 0;
var results = null;

//Loads map
function GetMap()
{
	map = new VEMap('myMap');
	map.LoadMap();

	// This sample only works in 2D mode (SetCustomIcon w/HTML)
	if (map.GetMapMode() != VEMapMode.Mode2D)
	{
		alert("This sample only works in 2D mode");
		return;
	}

	map.SetCenterAndZoom(latLong01, 17);
	map.SetMapStyle(VEMapStyle.Hybrid);
	map.AttachEvent("onclick", ShapeInfo);
	AddShapes();
	HideDashboard();
}  
         
//Pushpin Properties
function AddShapes()
{
	//Create VEShape objects, assign parameters, and add to the map.
	pin01 = new VEShape(VEShapeType.Pushpin, latLong01);
	
	//pin01 = new VEShape('1', latLong01, 'blank1.gif', null, null,VEShapeType.Pushpin);
	pin01.SetTitle("<img src='images/pushpin/50x32IGISLogo.jpg'/><br />Integral GIS <br /> 1809 Seventh Avenue <br /> Seattle, WA    98101 <br /><br /><img src='images/contactus/contactus3.gif'/>");
	pin01.SetCustomIcon("<span style='font-family:Arial; font-size:x-small;" + "color:Black; background-color:transparent'>" + "<img src='images/pushpin/pin1_purple48.png'></span>"); 
	
	map.AddShape(pin01);
} 
         
//Hides Dashboard controls.
function HideDashboard()
{
	map.HideDashboard();
}

function ShapeInfo(e)
{
	if(e.elementID != null)
	{
		shape = map.GetShapeByID(e.elementID);

		//Respond to ctrl-click event (toggle polygon icon visibility).
		//Note that pushpin shapes ignore ShowIcon and HideIcon.
        if(e.ctrlKey == 1)
        {
            shape.HideIcon();
        }
        else
        {
            shape.ShowIcon();
        }
         
        //Display information for the selected shape.
        var info = "";
        info += "ID (event object): " + e.elementID + "<br />";
        info += "ID (GetID method): " + shape.GetID() + "<br />";
        info += "Type: " + shape.GetType() + "<br />";
        info += "Title: " + shape.GetTitle() + "<br />";                 
        icon = shape.GetCustomIcon();
        info += "Icon: " + icon + "<br />";
            
        //Note that the Icon Anchor value for pushpin shapes is always
        //the latitude and longitude of the pin itself.
        info += "Icon Anchor: " + shape.GetIconAnchor() + "<br />";
        label.innerHTML = info;
	}
}
         
//Finds Businesses
function FindLoc(numResults)
{
	try
	{
	results = map.Find(document.getElementById('txtWhat').value,
						document.getElementById('txtWhere').value,
						null,
						null,
						index,
						numResults,
						true,
						true,
						true,
						true,
						MoreResults);
						index = parseInt(index)+9;
	}
	catch(e)
	{
		alert(e.message);
	}
}
        
function MoreResults(layer, resultsArray, places, hasMore, veErrorMessage)
{
	if(hasMore)
	{
		var r = "<a href='#' onclick='javascript:FindLoc(parseInt(txtNumResults.value));'>" + "Click for More Results</a>";
		
		document.getElementById('results').innerHTML = r;
	}
	else
	{
		index=0;
		number=Number(txtNumResults.value); 
		
		document.getElementById('results').innerHTML = "";
		document.getElementById('results').innerHTML = "No More Results Available";
	}
}
         
//Get Driving Direction
function GetRoute()
{
	var from = document.getElementById('txtFrom').value;
	var to = document.getElementById('txtTo').value;
	var locations = new Array(from,to);
	var options = new VERouteOptions();
	var color = new VEColor(129,226,35,0.7);
	
	options.DrawRoute = true;
	options.RouteColor = color;
	
	map.GetDirections(locations,options);
}
