/*
Created By Gordon Luckett
Arrow Geomatics Inc.
Nov 2005
*/
var theX;
var theY;
var theLat;
var theLon;
var theScale;



function recenter()
{

	var theScale=getMap().getScale();
	var latLonPt = getMap().mcsToLonLat(theX, theY);
    lon = latLonPt.getX();
    lat = latLonPt.getY();
	
	theLat = parseFloat(lat);
	theLon = parseFloat(lon);
	getMap().zoomScale(theLat, theLon, theScale);
	
}

function getThePoint()
{ 


	var mapLayerGroup = getMap().getMapLayerGroup("Shoreline Photos and Videos");
	var mapLayer = mapLayerGroup.getMapLayer("Tracking");
	var mapLayerDataSetup = mapLayer.getLayerSetup().getDatabaseSetup();

	


	var theLocations = mapLayer.getMapObjectsEx();

	if(theLocations.size() > 0)
	{
	
	
	verts = getMap().createObject('MGCollection');
    vertNum = getMap().createObject('MGCollection');
	var result = theLocations.item(0).getVertices(verts, vertNum);
	theX = verts.item(0).getX();
	theY=  verts.item(0).getY();
	var theMapExtent = getMap().getMapExtent("true","true");
	var theMinX = theMapExtent.getMinX();
	var theMaxX = theMapExtent.getMaxX();
	var theMinY = theMapExtent.getMinY();
	var theMaxY = theMapExtent.getMaxY();
	// Check for a 10% buffer around the map to trigger a recenter
	
	var theTolerance = 0.25;
	var theXBuffer = (theMaxX-theMinX) * theTolerance;
	var theYBuffer = (theMaxY-theMinY) * theTolerance;
	
	if(theX < (theMinX + theXBuffer)) 
	{
		recenter();
	}
	if(theX > (theMaxX - theXBuffer)) 
	{
		recenter();
	}
	if(theY < (theMinY + theYBuffer)) 
	{
		recenter();
	}
	if(theY > (theMaxY - theYBuffer)) 
	{
		recenter();
	}
		
		
	}

}


function resetMode()
{
if(getMap().isBusy())
	{
	setTimeout("resetMode()", 100);
	}
else
	{
	
	if(theMode == "ZoomIn")
		getMap().zoomInMode();
	if(theMode == "Pan")
		getMap().panMode();
	if(theMode == "ZoomOut")
		getMap().zoomOutMode();

	
	}



}



