功能简介:在MapXtreme+Asp.net的环境下实现轨迹回放功能,经过两天的努力基本实现此功能。但还有部分问题需要解决,求大神们指点迷津,问题会在结尾处提出。
客户端前台页面 <asp:ScriptManager ID="ScriptManager1" runat="server" /> <%--该js方法写在scriptmanager之后,防止出现Sys未定义错误--%>
<script type="text/javascript">
//获取pagerequestmanager实例后添加事件
//在因同步回发或因异步回发而刷新页面上所有内容后触发
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(TrackPlayBack); //轨迹回放函数
function TrackPlayBack()
{
var myInput1 = document.getElementById("input1");//用来存放X坐标的控件
var myInput2 = document.getElementById("input2");
if(myInput1 != null && myInput2 != null)
{
var pointX = myInput1.value.toString();//地图上X坐标点
var pointY = myInput2.value.toString();//地图上Y坐标点
if(pointX != "" && pointY != "")
{
var mapImage = document.getElementById("MapControl1_Image");//获取地图控件
if(mapImage != null)
{
//传递URL数据
var url = "MapController.ashx?Command=TrackPlayBack&PointX=" + pointX +"&PointY=" + pointY
+ "&MapAlias=" + mapImage.mapAlias + "&Width=" + mapImage.width +"&Height=" + mapImage.height
+ "&ExportFormat=" + mapImage.exportFormat + "&Ran=" + Math.random(); //使用Ajax局部刷新更新地图
var xmlHttp = CreateXMLHttp();
xmlHttp.open("GET",url,false);
xmlHttp.send();
mapImage.src = url;
}
}
}
}
</script> <cc1:MapControl ID="MapControl1" runat="server" Width="" Height="" ExportFormat="Jpeg" MapAlias="Map1"/> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<input id="input1" runat="server" type="text" style="width:200;" />
<input id="input2" runat="server" type="text" style="width:200;" /> <input id="input3" runat="server" type="text" style="width:200;" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
</asp:UpdatePanel> <asp:Timer ID="Timer1" runat="server" Enabled="true" Interval=""
ontick="Timer1_Tick" />
客户端中调用的自定义服务器MapBaseCommand类
/// <summary>
/// 轨迹回放
/// </summary>
[Serializable]
public class TrackPlayBack : MapBaseCommand
{
private Catalog myCatalog = MapInfo.Engine.Session.Current.Catalog;
/// <summary>
/// 动画回放图层别名
/// </summary>
private string animationName = "动画回放";
/// <summary>
/// 动画回放图元Style
/// </summary>
private MapInfo.Styles.BitmapPointStyle trackBmpPointStyle = new MapInfo.Styles.BitmapPointStyle("TRUC1-32.BMP", MapInfo.Styles.BitmapStyles.NativeSize, System.Drawing.Color.Blue, ); public TrackPlayBack(string _animationName, MapInfo.Styles.BitmapPointStyle _trackBmpPointStyle)
{
Name = "TrackPlayBack"; animationName = _animationName;
trackBmpPointStyle = _trackBmpPointStyle;
} public override void Process()
{
//获取分站坐标
double pointX, pointY;
double.TryParse(HttpContext.Current.Request["PointX"].ToString(), out pointX);
double.TryParse(HttpContext.Current.Request["PointY"].ToString(), out pointY);
//获取实现与执行各种操作的MapContorlModel实例
MapControlModel myCtrlModel = MapControlModel.GetModelFromSession();
try
{
//获取地图实例
Map myMap = myCtrlModel.GetMapObj(MapAlias);
if(myMap != null)
{
//清空地图轨迹回放图元
MapInfo.Data.Table myTable = myCatalog.GetTable(animationName);
if(myTable != null)
{
#region 清空图元
SearchInfo mySearchInfo = MapInfo.Data.SearchInfoFactory.SearchWhere("");
IResultSetFeatureCollection myIRetFeaColl = myCatalog.Search(myTable, mySearchInfo);
if(myIRetFeaColl != null)
{
foreach(Feature myObj in myIRetFeaColl)
{
myTable.DeleteFeature(myObj);
}
}
#endregion #region 添加图元
MapInfo.Geometry.Point myPoint = new MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(), new MapInfo.Geometry.DPoint(pointX, pointY)); Feature myFeature = new Feature(myTable.TableInfo.Columns);
myFeature.Geometry = myPoint;
myFeature.Style = trackBmpPointStyle; myTable.InsertFeature(myFeature);
#endregion
}
}
}
finally
{
System.IO.MemoryStream ms = myCtrlModel.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
StreamImageToClient(ms);
} }
}
后台代码 //此处使用Timer模拟生成的点作为动态轨迹的坐标点
protected void Timer1_Tick(object sender, EventArgs e)
{
double pointX = + myRandom.NextDouble() * ;
double pointY = pointX; this.input1.Value = pointX.ToString();
this.input2.Value = pointY.ToString();
}
问题:该功能采用异步更新图元位置,并设置Timer的Interval为50ms(甚至更小),使用IE浏览器坐标点更新速度1-3次/s,使用搜狗浏览器坐标点的更新速度则更慢。怎么样才能使更新速度更快,问题出在何处?是MapXtreme异步更新本身的问题吗?