﻿var map = null;
var dataLayer = new VEShapeLayer();
var searchShapeLayer = new VEShapeLayer();
var ruralLayer = new VEShapeLayer();

var c = [
	new VEColor(0xcc,0xcc,0xff,.5),
	new VEColor(0xcc,0xff,0xff,.5),
	new VEColor(0xff,0xcc,0x99,.5),
	new VEColor(0xff,0xff,0x99,.5),
	new VEColor(0xff,0xff,0x99,.5),
	new VEColor(0xff,0xcc,0xff,.5),
	new VEColor(0xcc,0xff,0x99,.5),
	new VEColor(0x99,0xcc,0xff,.5),
	new VEColor(0xff,0xcc,0x33,.5),
	new VEColor(0xff,0x53,0x53,.5),
	new VEColor(0xff,0x53,0x53,.5),
	new VEColor(0xff,0x53,0x53,.5),
	new VEColor(0xE9,0x94,0xAB,.5),
	new VEColor(0x91,0x91,0xff,.5),
	new VEColor(0x8d,0xc7,0xbb,.5),
	new VEColor(0xd8,0x81,0xed,.5),
	new VEColor(0xd8,0x81,0xed,.5),
	new VEColor(0xff,0xf0,0x6a,.5)
	];
	
var l = [
	new VEColor(0xcc,0xcc,0xff,1),
	new VEColor(0xcc,0xff,0xff,1),
	new VEColor(0xff,0xcc,0x99,1),
	new VEColor(0xff,0xff,0x99,1),
	new VEColor(0xff,0xff,0x99,1),
	new VEColor(0xff,0xcc,0xff,1),
	new VEColor(0xcc,0xff,0x99,1),
	new VEColor(0x99,0xcc,0xff,1),
	new VEColor(0xff,0xcc,0x33,1),
	new VEColor(0xff,0x53,0x53,.8),
	new VEColor(0xff,0x53,0x53,.8),
	new VEColor(0xff,0x53,0x53,.8),
	new VEColor(0xE9,0x94,0xAB,1),
	new VEColor(0x91,0x91,0xff,1),
	new VEColor(0x8d,0xc7,0xbb,1),
	new VEColor(0xd8,0x81,0xed,1),
	new VEColor(0xd8,0x81,0xed,1),
	new VEColor(0xff,0xf0,0x6a,1)
	];
var init = 1;

function GetSmallMap() {

    try {
        map = new VEMap('myMap');
        map.SetDashboardSize(VEDashboardSize.Small);
        map.LoadMap();
        map.HideDashboard();
		map.HideScalebar();
		init = 2;
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/USD475ElementryBoundaries.xml", dataLayer);
        var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/gpsSchools.xml", dataLayer);
        //var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "gpsSchools.xml", dataLayer);
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/USD475ElementryBoundaries.xml", dataLayer);
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, "http://www.skydivekstate.com/tmp/shape.kml", dataLayer);

        // map.ImportShapeLayerData(veLayerSpec, showAllShapes);

        map.ImportShapeLayerData(veLayerSpec, function () {
            //alert(dataLayer.GetShapeCount());
            for (var i = 0; i < dataLayer.GetShapeCount(); ++i) {
                var s = dataLayer.GetShapeByIndex(i);
                //alert(s.GetType() + "\r\n" + s.GetTitle());
                if (s.GetType() == "Polygon") {
                    s.HideIcon();
                    if (i < 18) {
                        s.SetFillColor(c[i]);
                        s.SetLineColor(l[i]);
                    } else {
                        ruralLayer.AddShape(ShapeCopy(s));
                        dataLayer.DeleteShape(s);
                        i--;
                    }
                } else {
                    var str = s.GetTitle();
                    //var icon = new VECustomIconSpecification();
                    s.SetDescription(s.GetDescription().replace('\n', '<br />'));
                    if (str.match("Elementary") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/elementary5.png"></div>'); //s.SetCustomIcon('img/elementary5.png');
                    } else if (str.match("Middle") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/middle5.png"></div>');
                    } else if (str.match("Freshman") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/freshman5.png"></div>');
                    } else {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/high5.png"></div>');
                    }
                    /*if (str.match("Elementary") != null) {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/elementary5.png';
                    } else if (str.match("Middle") != null) {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/middle5.png';
                    } else {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/high5.png';
                    }*/
                    //icon.ImageOffset = new VEPixel(0, -60);
                    //s.SetCustomIcon(icon);
                }
            }
            showAllShapes();
        }, true);


        map.AddShapeLayer(searchShapeLayer);
        map.AddShapeLayer(ruralLayer);
		map.SetMapView(new VEMapViewSpecification(new VELatLong(39.09756, -96.85478),11));
        map.AttachEvent("onendzoom", zoomEnd);
        //map.AttachEvent("onclick", PixelClick);
        map.AttachEvent("onchangeview", initZoom);
        
        var location = window.location.href;
		var x = location.indexOf("=")+1;
        if (x > 0)
		{
			FindLoc(decodeURI(location.substring(x)));
			init = 0;
		}
    } 
    catch (e) {
        alert(e.Message);
    }
}



function GetMap() {

    try {
        map = new VEMap('myMap');
        map.SetDashboardSize(VEDashboardSize.Small);
        map.LoadMap();
        
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/USD475ElementryBoundaries.xml", dataLayer);
        var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/gpsSchools.xml", dataLayer);
        //var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "gpsSchools.xml", dataLayer);
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/depts/communications/Web%20Pages/Enrollment%20Boundaries/USD475ElementryBoundaries.xml", dataLayer);
        //  var veLayerSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, "http://www.skydivekstate.com/tmp/shape.kml", dataLayer);

        // map.ImportShapeLayerData(veLayerSpec, showAllShapes);

        map.ImportShapeLayerData(veLayerSpec, function () {
            //alert(dataLayer.GetShapeCount());
            for (var i = 0; i < dataLayer.GetShapeCount(); ++i) {
                var s = dataLayer.GetShapeByIndex(i);
                //alert(s.GetType() + "\r\n" + s.GetTitle());
                if (s.GetType() == "Polygon") {
                    s.HideIcon();
                    if (i < 18) {
                        s.SetFillColor(c[i]);
                        s.SetLineColor(l[i]);
                    } else {
                        ruralLayer.AddShape(ShapeCopy(s));
                        dataLayer.DeleteShape(s);
                        i--;
                    }
                } else {
                    var str = s.GetTitle();
                    //var icon = new VECustomIconSpecification();
                    s.SetDescription(s.GetDescription().replace('\n', '<br />'));
                    if (str.match("Elementary") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/elementary5.png"></div>'); //s.SetCustomIcon('img/elementary5.png');
                    } else if (str.match("Middle") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/middle5.png"></div>');
                    } else if (str.match("Freshman") != null) {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/freshman5.png"></div>');
                    } else {
                        s.SetCustomIcon('<div style="position:relative; top: 9px; right: -9px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/high5.png"></div>');
                    }
                    /*if (str.match("Elementary") != null) {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/elementary5.png';
                    } else if (str.match("Middle") != null) {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/middle5.png';
                    } else {
                    icon.Image = '/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/high5.png';
                    }*/
                    //icon.ImageOffset = new VEPixel(0, -60);
                    //s.SetCustomIcon(icon);
                }
            }
            showAllShapes();
        }, true);


        map.AddShapeLayer(searchShapeLayer);
        map.AddShapeLayer(ruralLayer);
        
		map.SetMapView(new VEMapViewSpecification(new VELatLong(39.09756, -96.85478),11));
        map.AttachEvent("onendzoom", zoomEnd);
        //map.AttachEvent("onclick", PixelClick);
        map.AttachEvent("onchangeview", initZoom);
        
        var location = window.location.href;
		var x = location.indexOf("=")+1;
        if (x > 0)
		{
			str = decodeURI(location.substring(x));
			aspnetForm.txtWhere.value = decodeURI(str);
			FindLoc(str);
			init = 0;
		}
    } 
    catch (e) {
        alert(e.Message);
    }
}




function initZoom(zEvent) {
    if (init == 1) {
        map.SetMapView(new VEMapViewSpecification(new VELatLong(39.09756, -96.85478), 11));
        init = 0;
        for (var j = 0; j < ruralLayer.GetShapeCount(); j++) {
            var shape = ruralLayer.GetShapeByIndex(j);
            shape.HideIcon();
            shape.Hide();
        }
    } else if (init == 2) {
        map.SetMapView(new VEMapViewSpecification(new VELatLong(39.02825, -96.83967), 11));
        init = 0;
        for (var j = 0; j < ruralLayer.GetShapeCount(); j++) {
            var shape = ruralLayer.GetShapeByIndex(j);
            shape.HideIcon();
            shape.Hide();
        }
    }
}

function zoomEnd( mEvent) {
    var z = Math.floor(parseInt(mEvent.zoomLevel)/2);
	for (var i = 0; i < dataLayer.GetShapeCount(); ++i) {
		var s = dataLayer.GetShapeByIndex(i);
        if(z>9)
			z=9
		else if (z<5)
			z=5
		if (s.GetType() == "Point" && s.GetCustomIcon() != null) {
			//var ci =  new VECustomIconSpecification();
			var str = s.GetCustomIcon();
			var x = str.lastIndexOf(".png");
			/*ci.Image = str.substr(0, x - 1) + z + str.substr(x);
			switch (z)
			{ 	case 5:
					ci.ImageOffset =  new VEPixel(0,-60);
					break;
				case 6:
					ci.ImageOffset =  new VEPixel(0,-56);
					break;
				case 7:
					ci.ImageOffset =  new VEPixel(0,-48);
					break;
				case 8:
					ci.ImageOffset =  new VEPixel(0,-40);
					break;
				case 9:
					ci.ImageOffset =  new VEPixel(0,-32);
					break;
			}
			s.SetCustomIcon(ci);*/
			s.SetCustomIcon(str.substr(0, x - 1) + z + str.substr(x));
			//alert(z+' -' +str.substr(0,str.length-13) + z + str.substr(str.length-12));
			//i=dataLayer.GetShapeCount();
		}
	}
    for (var j = 0; j < searchShapeLayer.GetShapeCount(); ++j) {
		var s = searchShapeLayer.GetShapeByIndex(j);
		if(z>9)
			z=9
		else if (z<5)
			z=5
		if (s.GetType() == "Point" && s.GetCustomIcon() != null) {
			//var ci = new VECustomIconSpecification();
			var str = s.GetCustomIcon();
			var x = str.lastIndexOf(".png");
			//ci.Image = str.substr(0, x - 1) + z + str.substr(x);
			//ci.Image = "img/point.png";
			/*switch (z)
			{ 	case 5:
					ci.ImageOffset =  new VEPixel(0,-60);
					break;
				case 6:
					ci.ImageOffset =  new VEPixel(0,-56);
					break;
				case 7:
					ci.ImageOffset =  new VEPixel(0,-48);
					break;
				case 8:
					ci.ImageOffset =  new VEPixel(0,-40);
					break;
				case 9:
					ci.ImageOffset =  new VEPixel(0,-32);
					break;
			}*/
			//ci.ImageOffset =  new VEPixel(0,0);
			//s.SetCustomIcon(ci);
            s.SetCustomIcon(str.substr(0, x - 1) + z + str.substr(x));
            /*var str = s.GetCustomIcon();
			var x = str.lastIndexOf(".png");
			
			*/
			//alert(z+' -' +str.substr(0,str.length-13) + z + str.substr(str.length-12));
			//i=dataLayer.GetShapeCount();
		} else {
			//alert(s.GetType());
		 }
	}
	//alert(map.GetShapeLayerCount())
}

function hideEachShape() {
    for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
        var shape = dataLayer.GetShapeByIndex(i);
        shape.Hide();
    }
    for (var i = 0; i < ruralLayer.GetShapeCount(); i++) {
        var shape = ruralLayer.GetShapeByIndex(i);
        shape.Hide();
    }
}

function showAllShapes() {
    for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
        var shape = dataLayer.GetShapeByIndex(i);
        shape.Show();
    }
    searchShapeLayer.DeleteAllShapes();
    map.SetMapView(new VEMapViewSpecification(new VELatLong(39.09756, -96.85478), 11));

}
/*
function boundingBoxSearch() {
    //hide previous results
    hideEachShape();

    //clear the search shape layer
    searchShapeLayer.DeleteAllShapes();

    //bounding box coordinates
    var topLeft = new VELatLong(39.058517, -96.817403);
    var bottomRight = new VELatLong(39.037186, -96.837401);

    //checks to see if bounding box crosses 180 degrees
    if (topLeft.Longitude > bottomRight.Longitude) {
        //iterate through shapes in dataLayer
        for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
            var shape = dataLayer.GetShapeByIndex(i);
            var latlong = shape.GetPoints()[0];
            var lat = latlong.Latitude;
            var lon = latlong.Longitude;

            if (topLeft.Longitude >= lon && bottomRight.Longitude <= lon && topLeft.Latitude >= lat && bottomRight.Latitude <= lat) {
                shape.Show();
            }
        }
    }
    else {
        //iterate through shapes in dataLayer
        for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
            var shape = dataLayer.GetShapeByIndex(i);
            var latlong = shape.GetPoints()[0];
            var lat = latlong.Latitude;
            var lon = latlong.Longitude;

            if (topLeft.Longitude <= lon && bottomRight.Longitude >= lon && topLeft.Latitude >= lat && bottomRight.Latitude <= lat) {
                shape.Show();
            }
        }
    }

    //draw search area
    drawBox(topLeft, bottomRight);

    map.SetMapView([topLeft, bottomRight]);
}

function drawBox(topLeft, bottomRight) {
    var topRight = new VELatLong(topLeft.Latitude, bottomRight.Longitude);
    var bottomLeft = new VELatLong(bottomRight.Latitude, topLeft.Longitude);
    var box = new VEShape(VEShapeType.Polyline, [topLeft, topRight, bottomRight, bottomLeft, topLeft]);
    box.HideIcon();
    searchShapeLayer.AddShape(box);
}

function radiusSearch() {
    //hide previous results
    hideEachShape();

    //clear the search shape layer
    searchShapeLayer.DeleteAllShapes();

    //center of search Radius
    var origin = new VELatLong(39.029919, -96.849117);

    //search radius in km
    var radius = 1;

    for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
        var shape = dataLayer.GetShapeByIndex(i);
        var latlong = shape.GetPoints()[0];

        var d = distance(origin, latlong);

        if (Math.abs(d) <= Math.abs(radius)) {
            shape.Show();
        }
    }

    drawCircle(origin, radius);
}

//calculation of Haversine Forumla
function distance(latlong, latlong2) {
    var lat1 = latlong.Latitude;
    var lon1 = latlong.Longitude;
    var lat2 = latlong2.Latitude;
    var lon2 = latlong2.Longitude;
    var earthRadius = 6371;

    var factor = Math.PI / 180;
    var dLat = (lat2 - lat1) * factor;
    var dLon = (lon2 - lon1) * factor;
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * factor) * Math.cos(lat2 * factor) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = earthRadius * c;

    return d;
}

function drawCircle(origin, radius) {
    var earthRadius = 6371;

    //latitude in radians
    var lat = (origin.Latitude * Math.PI) / 180;

    //longitude in radians
    var lon = (origin.Longitude * Math.PI) / 180;

    //angular distance covered on earth's surface
    var d = parseFloat(radius) / earthRadius;

    var points = new Array();
    for (i = 0; i <= 360; i++) {
        var point = new VELatLong(0, 0)
        var bearing = i * Math.PI / 180; //rad
        point.Latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(bearing));
        point.Longitude = ((lon + Math.atan2(Math.sin(bearing) * Math.sin(d) * Math.cos(lat), Math.cos(d) - Math.sin(lat) * Math.sin(point.Latitude))) * 180) / Math.PI;
        point.Latitude = (point.Latitude * 180) / Math.PI;
        points.push(point);
    }

    var circle = new VEShape(VEShapeType.Polyline, points);
    circle.HideIcon();
    searchShapeLayer.AddShape(circle);

    map.SetMapView(points);
}

function polygonSearch() {
    //hide previous results
    hideEachShape();

    //clear the search shape layer
    searchShapeLayer.DeleteAllShapes();

    //polygon coordinates
    var points = new Array(new VELatLong(39.04486433588385, -96.8791389465332),
new VELatLong(39.04508171979899, -96.8930435180664),
new VELatLong(39.03682057801007, -96.88437461853027),
new VELatLong(39.03946054004705, -96.86819553375244),
new VELatLong(39.052720712083266, -96.87201499938965),
new VELatLong(39.05793702655821, -96.89111232757568),
new VELatLong(39.04927396999741, -96.87222957611084),
new VELatLong(39.04486433588385, -96.8791389465332));

    for (var i = 0; i < dataLayer.GetShapeCount(); i++) {
        var shape = dataLayer.GetShapeByIndex(i);
        var latlong = shape.GetPoints()[0];
        var lat = latlong.Latitude;
        var lon = latlong.Longitude;

        if (pointInPolygon(points, lat, lon)) {
            shape.Show();
        }
    }

    drawPolygon(points);
}


function drawPolygon(points) {
    var polygon = new VEShape(VEShapeType.Polyline, points);
    polygon.HideIcon();
    searchShapeLayer.AddShape(polygon);

    map.SetMapView(points);
}*/

function pointInPolygon(points, lat, lon) {
    var i;
    var j = points.length - 1;
    var inPoly = false;

    for (i = 0; i < points.length; i++) {
        if (points[i].Longitude < lon && points[j].Longitude >= lon || points[j].Longitude < lon && points[i].Longitude >= lon) {
            if (points[i].Latitude + (lon - points[i].Longitude) / (points[j].Longitude - points[i].Longitude) * (points[j].Latitude - points[i].Latitude) < lat) {
                inPoly = !inPoly;
            }
        }
        j = i;
    }

    return inPoly;
}

function FindLoc(str) {
    //alert('FindLoc');
	try {
		
        map.Find(null, str, null, null, null, null, null, null, null, null, callback);
    }
    catch (e) {
        alert(e.message);
    }
}

function callback(a, b, c, d, e) {
    if (c != null && c.length > 1) {
        var results = "More than one location was retruned. Please select the location you were looking for:<br>";
        for (x = 0; x < c.length; x++) {
            results += "<a href='javascript:map.Find(null, \"" + c[x].Name + "\", null, null, null, null, null, null, null, null, callback);'>" + c[x].Name + "</a><br>";
        }
        document.getElementById('resultDiv').innerHTML = results;
    }
    else {
        AddPin(c[0].Name);
    }
}

function AddPin(str) {
    var center = map.GetCenter();
    var pin = new VEShape(VEShapeType.Pushpin, center);
	//pin.SetCustomIcon('<div style="position:relative;"><img src="img/house9.png"></div>');
	//var ci =  new VECustomIconSpecification();
	//ci.Image = "img/house7.png";
	//ci.ImageOffset =  new VEPixel(0,64);
	//pin.SetCustomIcon(ci);
    pin.SetCustomIcon('<div style="position: relative; top: 0px; right: 0px;"><img src="/depts/communications/Web%20Pages/Enrollment%20Boundaries/img/house7.png"/></div>');
    searchShapeLayer.DeleteAllShapes();
    pin.SetTitle(str);
    pin.SetDescription('This is your home.');
    searchShapeLayer.AddShape(pin);
    var shape = SearchShapes(center);
    
}

function SearchShapes(center) {
    var i;
    var max = dataLayer.GetShapeCount();
    var name;
    hideEachShape();
    for ( i = 0; i < max; i++) {
        var shape = dataLayer.GetShapeByIndex(i);
        var points = shape.GetPoints();
        var lat = center.Latitude;
        var lon = center.Longitude;

        if (pointInPolygon(points, lat, lon)) {
            shape.Show();
            name=shape.GetTitle();
            var x = name.indexOf(" Elementary")+11;
            name=name.substring(0,x);
        }
        if (name == shape.GetTitle()) {
            searchShapeLayer.AddShape(ShapeCopy(shape));
        }
    }

    if (searchShapeLayer.GetShapeCount() < 2) {
        for (i = 0; i < ruralLayer.GetShapeCount(); i++) {
            var shape = ruralLayer.GetShapeByIndex(i);
            var points = shape.GetPoints();
            var lat = center.Latitude;
            var lon = center.Longitude;

            if (pointInPolygon(points, lat, lon)) {
                name = shape.GetDescription();
            }
        }
        for (i = 0; i < dataLayer.GetShapeCount(); i++) {
            var shape = dataLayer.GetShapeByIndex(i);
            if (shape.GetType() == VEShapeType.Pushpin && shape.GetTitle() == name) {
                searchShapeLayer.AddShape(ShapeCopy(shape));
            }
        }
    }

	if (center.Latitude > 39.06052 && center.Longitude > -96.83212) {
		searchShapeLayer.AddShape(ShapeCopy(dataLayer.GetShapeByIndex(max - 4)));
	} else
	{
		searchShapeLayer.AddShape(ShapeCopy(dataLayer.GetShapeByIndex(max - 3)));
	}
	searchShapeLayer.AddShape(ShapeCopy(dataLayer.GetShapeByIndex(max - 2)));
	searchShapeLayer.AddShape(ShapeCopy(dataLayer.GetShapeByIndex(max - 1)));
	
	map.SetMapView(searchShapeLayer.GetBoundingRectangle());
}

function ShapeCopy(shape) {
    if (shape.GetShapeType() == VEShapeType.Pushpin) {
        var s = new VEShape(VEShapeType.Pushpin, shape.GetPoints());
        s.SetTitle(shape.GetTitle());
        s.SetDescription(shape.GetDescription());
        s.SetCustomIcon(shape.GetCustomIcon());
    } else if (shape.GetShapeType() == VEShapeType.Polygon) {
        var s = new VEShape(VEShapeType.Polygon, shape.GetPoints());
        s.SetTitle(shape.GetTitle());
        s.SetDescription(shape.GetDescription());
        s.SetCustomIcon(shape.GetCustomIcon());
        s.Hide();
        s.HideIcon();
    }
    return s;
}

function PixelClick(e) {
    var x = e.mapX;
    var y = e.mapY;
    pixel = new VEPixel(x, y);
    LL = map.PixelToLatLong(pixel);

    map.FindLocations(LL, GetResults);

}


function GetResults(locations) {
    var s = "Results for " + LL.Latitude + ", " + LL.Longitude + ": ";
    if (locations != null) {
        searchShapeLayer.DeleteAllShapes();
        SearchShapes(LL);

    }
    else {
        s = "No Result found.";
        alert(s);
    }

}

function GetInfo()
         {  
            // VEMap.GetTop returns the position of the top edge of the map control, in pixels.
            // VEMap.GetLeft returns the position of the left edge of the map control, in pixels.
            // These units are defined using standard DHTML markup.
            // See the style attribute for the <div> element 'myMap'.
            var info = 'The top edge of the map on the Web page is at pixel: '+ map.GetTop() + "\n";
            info += 'The left edge of the map on the Web page is at pixel: '+ map.GetLeft() + "\n";
            info += 'The latitude,longitude at the center of the map is: '+ map.GetCenter() + "\n";
            info += 'The current zoom level of the map is: '+ map.GetZoomLevel() + "\n";
            info += 'The map control version is: '+ VEMap.GetVersion() + "\n";            
            alert(info);
         }
