在map控件外面加一个div,div的宽度和高度和map一样, <div id="map1" onmousemove="DisplayMp(event)" Height="500px" Width="790px">mapcontrol</div>
function DisplayMp(event)
{
// var thisDiv=document.getElementById("map1");
var thisMesaage;
thisMessage=event.offsetX+","+event.offsetY;
getCoords(thisMessage);
}
今天小试了一下:就是鼠标在map控件上移动的时候,在状态栏显示坐标信息
-------------------------------------------------------------------------------------------------
前台:
function getCoords(xy)
{
var argument = "ControlID=Map1&ControlType=Map&Type=getCoords&Args="+xy;
var context = "Map";
//m_Callback 由服务端的Page_load事件中生成的,用于请求服务端的js代码
var script=<%= m_Callback %>
//用eval执行字符串
eval(script);
}
//经纬度转成度分秒格式
function changeUnit(newValue)
{
var du=Math.floor(newValue);
var xiaoshu=(newValue-du)*60;
var fen=Math.floor(xiaoshu);
xiaoshu=(xiaoshu-fen)*60;
var miao=xiaoshu.toFixed(2);
return du+"度"+fen+"分"+miao+"秒";
}
//写入状态栏
function putOutCoord(thisValue)
{
var abc=thisValue.split(',');
var abcd="经度:"+changeUnit(abc[0]+0)+",纬度:"+changeUnit(abc[1]+0);
window.status=abcd;
}
后台代码:
public string m_Callback = "";
protected void Page_Load(object sender, EventArgs e)
{
m_Callback = Page.ClientScript.GetCallbackEventReference(Page, "argument", "processCallbackResult", "content", true);
}
#region ICallbackEventHandler 成员
private string _callbackArg;
string ICallbackEventHandler.GetCallbackResult()
{
return RaiseCallbackEvent(_callbackArg);
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
_callbackArg = eventArgument;
}
#endregion
private string RaiseCallbackEvent(string _callbackArg)
{
string v = "";
NameValueCollection keyValColl = CallbackUtility.ParseStringIntoNameValueCollection(_callbackArg);
if (keyValColl["Type"].ToString() == "getCoords")
{
string temp = keyValColl["Args"].ToString();
string[] coords = temp.Split(new char[] { ',' });
int xPix = Int32.Parse(coords[0]);
int yPix = Int32.Parse(coords[1]);
ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(xPix, yPix, Map2.Extent, (int)Map2.Width.Value, (int)Map2.Height.Value);
string status = point.X.ToString() + "," + point.Y.ToString();
CallbackResult cr = new CallbackResult(null, null, "javascript", "putOutCoord('" + status + "');");
Map2.CallbackResults.Add(cr);
}
return Map2.CallbackResults.ToString();
}
这种方法的弊端:
每次算坐标都是在后台算的,大量的前后台交互,而且在map上move一下,他要算好多次,你停在那,等个2秒种,他就不算了!希望有人帮我找个好的解决办法!
我在网上看到别人获取了map.Extent,然后在前台算,这个方法交互少多了,但没测试过精确不精确
http://www.cnblogs.com/lotus_shelly/archive/2009/08/07/1541272.html