/// <summary> /// 获取指定终端编号在指定时间段内的历史轨迹 /// </summary> /// <param name="aTerminalId">终端编号</param> /// <param name="aStart">开始时间</param> /// <param name="aEnd">结束时间</param> /// <returns></returns> public static JsonHistoryPosition GetHistory(string aTerminalId, DateTime aStart, DateTime aEnd) { string jsonStr = GetApiReply(GetHistoricalPosition(aTerminalId, aStart, aEnd)); if (string.IsNullOrEmpty(jsonStr)) { return(null); } JsonHistoryPosition historyLocation = ModelUtils.GetJsonObject <JsonHistoryPosition>(jsonStr); if (historyLocation != null) { return(historyLocation); } JsonBase errInfo = ModelUtils.GetJsonObject <JsonBase>(jsonStr); if (errInfo == null) { return(null); } // 重新组合返回错误值 return(new JsonHistoryPosition { Status = errInfo.Status, Message = errInfo.Message }); }
/// <summary> /// 进行查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { DateTime startTime = this.dtpStart.Value; DateTime endTime = this.dtpEnd.Value; if (startTime > endTime) { errPrv.SetError(this.dtpStart, "开始时间不能晚于结束时间..."); return; } string terminalId = this.txtTerminalId.Text.Trim(); if (string.IsNullOrEmpty(terminalId)) { errPrv.SetError(this.txtTerminalId, "终端编号不能为空..."); this.txtTerminalId.Focus(); return; } this.History = null; this.btnOk.Enabled = false; var task = Task.Factory.StartNew(() => { var history = UrlApiHelper.GetHistory(terminalId, startTime, endTime); if (history == null) { GuiHelper.MsgBox("服务器连接异常..."); } else if (history.Status != 0) { GuiHelper.MsgBox("轨迹查询失败: " + history.Message); } else if (history.Count < 1 || history.Items.Count < 1) { GuiHelper.MsgBox($"终端[{terminalId}]在该时间段内没有历史轨迹记录..."); } else { this.History = history; } }); task.Wait(); this.btnOk.Enabled = true; if (this.History != null) { this.DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// 播放历史轨迹信息 /// </summary> /// <param name="aHistory"></param> public void PlayHistory(JsonHistoryPosition aHistory) { mHistory.Clear(); var sortLst = aHistory.Items.OrderBy(x => x.GpsTime); mHistoryVehicle = sortLst.FirstOrDefault(); mHistory.AddRange(sortLst); List <Coordinate> points = new List <Coordinate>(aHistory.Count); foreach (var history in sortLst) { Coordinate tmpPoint = new Coordinate(history.BdLongitude, history.BdLatitude); points.Add(tmpPoint); } this.wbMap.ShowRoute(points); this.btnPlay.Visible = true; this.btnStop.Visible = true; this.btnPlay.Checked = true; this.mPlayIndex = 0; this.tmrPlay.Start(); }
/// <summary> /// 播放历史轨迹信息 /// </summary> /// <param name="aHistory"></param> public void PlayHistory(JsonHistoryPosition aHistory) { mFrmMap?.InvokeIfRequired((frm) => frm.PlayHistory(aHistory)); }