MapXtreme+Asp.net 動態軌跡(請求大神指點)

功能簡介:在MapXtreme+Asp.net的環境下實現軌跡回放功能,通過兩天的努力基本實現此功能。但還有部分問題須要解決,求大神們指點迷津,問題會在結尾處提出。javascript

客戶端前臺頁面

<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="800" Height="600" 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="50" 
            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, 24);

        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 = 4999 + myRandom.NextDouble() * 2;
        double pointY = pointX;

        this.input1.Value = pointX.ToString();
        this.input2.Value = pointY.ToString();
    }

問題:該功能採用異步更新圖元位置,並設置Timer的Interval爲50ms(甚至更小),使用IE瀏覽器座標點更新速度1-3次/s,使用搜狗瀏覽器座標點的更新速度則更慢。怎麼樣才能使更新速度更快,問題出在何處?是MapXtreme異步更新自己的問題嗎?java

相關文章
相關標籤/搜索