﻿// JScript File

function BAMapIdentify(divid) {
    
    //map = Maps[divid];
    
    
    //map.divObject.onmousedown = BAMapIdClick;

    var map = $find('Map1');    
    //alert('adding mouseDown for Id tool');	
    map.add_mouseDown(BAMapIdClick);

    //MapPoint(divid, mode, showLoading)
    //    Sets up event handling to MapPoint. 
    //    Parameters:
    //    divid - Id of Map WebControl
    //    mode - Tool identifier to be passed to server-side application
    //    showLoading - Display Loading banner (true/false)
    MapPoint(map.get_uniqueID(), "BAMapIdentify", false);

}

function BAMapIdClick(sender,eventArgs) 
{
    var mapID = "Map1";
    
    var map = $find(mapID);    	
    
    map.cursor = map.divObject.style.cursor;
	//map.divObject.style.cursor = "wait";

    var mapX = eventArgs.coordinate.get_x();
    var mapY = eventArgs.coordinate.get_y();
	var mapPt = new ESRI.ADF.Geometries.Point(mapX,mapY);
    var scrnPt = map.toScreenPoint(mapPt);

    //log("X, Y = " + mapPt.get_x() + ", " + mapPt.get_y() + ", " + scrnPt.offsetX + ", " + scrnPt.offsetY );
    
	// add "i" graphic to map
	clearIdentifyIcon();
	var identifyMapCallout = $create(ESRI.ADF.Graphics.GraphicFeature,
			{"id":mapID+'_identifyicon',"geometry":mapPt,"symbol":new ESRI.ADF.Graphics.MarkerSymbol("../images/identify-map-icon.png",12,24)});
//			"mapTips":this.identifyMapTips,
//			"attributes":pointAttributes[0]});
	identifyMapCallout.get_symbol().set_imageFormat("png32");
	//if(this.waitIcon) { map.removeGraphic(this.waitIcon); }	    
	map.addGraphic(identifyMapCallout);

    // initiate callback to query layers and populate results display
	// DEV NOTE: instead of converting map coords to screen coords and passing those to server (only to be
	//   converted serverside back to map coords), just pass the map coordinates.
	//var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + scrnPt.offsetX + "&miny=" + scrnPt.offsetY + "&idtype=" + "identify";
	var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + mapPt.get_x() + "&miny=" + mapPt.get_y() + "&idtype=" + "identify";

	var context = map.get_id();
    //alert("map.idCFS: " + map.identifyCallbackFunctionString);
  	//alert("idCFS: " + identifyCallbackFunctionString);
  	//eval(map.identifyCallbackFunctionString); <- not valid property at 9.3
  	eval(identifyCallbackFunctionString);

//	map.mode = map.tempMode;
//	map.actionType = map.tempAction;
//	map.cursor = map.tempCursor;
    
    return false;
}

// Event handler for Identify
//function BAMapIdClick(e) 
//{

//    var map = $find('Map1');    	

//    map.cursor = map.divObject.style.cursor;
//	//map.divObject.style.cursor = "wait";
//	getXY(e);
//	var box = calcElementPosition(map.containerDivId);
//	zleft = mouseX - box.left;
//	ztop = mouseY - box.top;

//	map.xMin=zleft;
//	map.yMin=ztop;
//	var div = document.getElementById("IdentifyLocation");
//	if (div==null) {
//	    BAaddIdentifyLocation();
//	}
//	//showFloatingPanel('IdentifyResults');
//    //dockFloatingPanel('IdentifyResults');
//    //undockFloatingPanel('IdentifyResults');
//    //expandFloatingPanel('IdentifyResults');
//	
//	map.getTopLeftTile();
//	var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + zleft + "&miny=" + ztop + "&idtype=" + "identify";
//	var context = map.controlName;
//	eval(map.identifyCallbackFunctionString);
//	var div = document.getElementById("IdentifyLocation");
//	
//	// point is bottom center... 2 pixels up for shadow
//	var cWidth = Math.floor(div.clientWidth / 2);
//	var cHeight = div.clientHeight;
//	//alert(cWidth + " x " + cHeight); // width and height might not be available on first time.... if so, approximate size needed
//	if (cWidth==0) cWidth = 12;
//	if (cHeight==0) cHeight = 29;
//	var idLeft = zleft - parseInt(map.divObject.style.left) - cWidth;
//	var idTop = ztop - parseInt(map.divObject.style.top) - cHeight + 2; // add two back for icon bottom
////	if (isIE) {
////	    idTop+=2; 
////	    //idLeft+=2;
////	}
////	var pos = YAHOO.util.Dom.getXY('IdentifyLocation'); 
////	YAHOO.util.Dom.setXY('IdentifyResults', pos); 
//	
//	window.setTimeout('moveLayer("IdentifyLocation", ' + idLeft + ', ' + idTop + '); showLayer("IdentifyLocation");', 0);
//	map.mode = map.tempMode;
//	map.actionType = map.tempAction;
//	map.cursor = map.tempCursor;
//	return false;
//}

function BAaddIdentifyLocation() {

  var imagePath = "../images/";
  var content = '<div id="IdentifyLocation" style="position: absolute; left: 0px; top: 0px; visibility: hidden;">';
  
  if (isIE  && ieVersion < 7) 
	  content += '<img src="' + imagePath + 'blank.gif" alt="" border="0"  hspace="0" vspace="0" style="filter:  progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imagePath + 'identify-map-icon.png\');" />\n';
	else
	  content += '<img src="' + imagePath + 'identify-map-icon.png" alt="" border="0"  hspace="0" vspace="0" />\n';
  
  content += '</div>';
  map.overlayObject.insertAdjacentHTML("BeforeEnd", content);
}


function clearIdentifyIcon()
{
    var mapID = "Map1";

	var imcallout = $find(mapID+'_identifyicon');
	if (imcallout) 
	{
	    var map = $find(mapID); 
		map.removeGraphic(imcallout);
		imcallout.dispose();
		imcallout = null; 
	}

}