/// <summary> /// 初始化地图 /// </summary> private void InitMAP() { if (!GMapControl.IsDesignerHosted) { //GMapProviders.GoogleMap.TryCorrectVersion = false; //GMapProviders.GoogleSatelliteMap.TryCorrectVersion = false; //GMapProviders.GoogleChinaMap.TryCorrectVersion = false; //GMapProviders.GoogleChinaSatelliteMap.TryCorrectVersion = false; //MainMap.MapProvider = GMapProviders.GoogleSatelliteMap; // 默认地图 MainMap.MapProvider = CustomProvider.Instance; // 默认地图 MainMap.Position = new PointLatLng(24.305555555555557, 109.43); // 地图中心点(北京)GPS坐标 MainMap.MinZoom = GMapProviders.GoogleSatelliteMap.MinZoom; // 地图最小比例 MainMap.MaxZoom = GMapProviders.GoogleSatelliteMap.MaxZoom ?? 24; // 地图最大比例 MainMap.Zoom = 18; // 当前缩放等级 MainMap.DragButton = MouseButtons.Left; // 鼠标平移键 // 鼠标 MainMap.MouseDown += MainMap_MouseDown; MainMap.MouseMove += MainMap_MouseMove; MainMap.MouseUp += MainMap_MouseUp; MainMap.OnMapZoomChanged += MainMap_OnMapZoomChanged; MainMap.OnMarkerLeave += MainMap_OnMarkerLeave; MainMap.OnMarkerEnter += MainMap_OnMarkerEnter; MainMap.Overlays.Add(_panos); MainMap.Overlays.Add(_markers); // 加载已有全景点 WCFClient client = new WCFClient(); string html = client.PanoList(); object json = Json.JsonDeserialize <object>(html); object[] panos = null; if (json is object[]) { panos = (object[])json; } else if (json is Dictionary <string, object> ) { panos = (object[])((Dictionary <string, object>)json)["features"]; } foreach (object item in panos) { //{ // "type": "Feature", // "geometry": { // "type": "Point", // "coordinates": [ // 109.4517117, // 24.29770159 // ] // }, // "properties": { // "uid": "7be54ce31c31438b9714620432d6b88f", // "type": "高空全景", // "name": "一五八医院", // "shottime": -62135596800000, // "maketime": -62135596800000, // "remark": "D:\\wwwroot\\panos_整理\\gaokong\\158yiyuan.html" // } //}, Dictionary <string, object> pano = (Dictionary <string, object>)item; Dictionary <string, object> geometry = (Dictionary <string, object>)pano["geometry"]; object[] coordinates = (object[])geometry["coordinates"]; double lng = Convert.ToDouble(coordinates[0]); double lat = Convert.ToDouble(coordinates[1]); Dictionary <string, object> properties = (Dictionary <string, object>)pano["properties"]; string uid = Convert.ToString(properties["uid"]); string name = Convert.ToString(properties["name"]); long shottime = Convert.ToInt64(properties["shottime"]); GMapMarker marker = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.blue_small); marker.ToolTipMode = MarkerTooltipMode.OnMouseOver; marker.ToolTipText = name; _panos.Markers.Add(marker); } //_panos } }
/// <summary> /// 处理线程 /// </summary> private void SubmmitPano(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (worker.CancellationPending) { e.Cancel = true; return; } try { WCFClient client = new WCFClient(); ImageListViewItem[] items = (ImageListViewItem[])e.Argument; int index = 0; List <string> uids = new List <string>(); foreach (ImageListViewItem item in items) { if (worker.CancellationPending) { e.Cancel = true; return; } string file = item.FileName; string name = item.PanoName; string category = item.PanoCategory; long date = (item.PanoDate.ToUniversalTime().Ticks - 621355968000000000) / 10000000; int heading = item.PanoHeading; double lat = item.PanoLat; double lng = item.PanoLng; string author = item.PanoAuthor; string remark = item.PanoRemark; worker.ReportProgress(index, string.Format("{0} {1}/{2}: 开始上传图片: {3}.", DateTime.Now.ToString("HH:mm:ss"), ++index, items.Length, name)); if (item.Dimensions.Width != item.Dimensions.Height * 2) { worker.ReportProgress(index, string.Format("{0} {1}/{2}: 图片比例不是 2:1 无法提交.", DateTime.Now.ToString("HH:mm:ss"), index, items.Length)); continue; } // 上传文件 string result1 = client.Add(item.FileName); object json1 = Json.JsonDeserialize <object>(result1); bool success1 = Convert.ToBoolean(((Dictionary <string, object>)json1)["success"]); string message1 = Convert.ToString(((Dictionary <string, object>)json1)["message"]); string uid = Convert.ToString(((Dictionary <string, object>)json1)["uid"]); if (success1 == true) { worker.ReportProgress(index, string.Format("{0} {1}/{2}: 上传成功.", DateTime.Now.ToString("HH:mm:ss"), index, items.Length)); } else { worker.ReportProgress(index, string.Format("{0} {1}/{2}: 上传失败: {3}", DateTime.Now.ToString("HH:mm:ss"), index, items.Length, message1)); } // 创建全景 if (success1 == false) { continue; } worker.ReportProgress(index, string.Format("{0} {1}/{2}: 正在生成全景: {3}", DateTime.Now.ToString("HH:mm:ss"), index, items.Length, name)); string result2 = client.Build(uid, name, category, date, heading, lat, lng, author, remark); object json2 = Json.JsonDeserialize <object>(result2); bool success2 = Convert.ToBoolean(((Dictionary <string, object>)json2)["success"]); string message2 = Convert.ToString(((Dictionary <string, object>)json2)["message"]); if (success2) { uids.Add(uid); } if (success2 == true) { worker.ReportProgress(index, string.Format("{0} {1}/{2}: 全景生成成功: {3}.", DateTime.Now.ToString("HH:mm:ss"), index, items.Length, uid)); } else { worker.ReportProgress(index, string.Format("{0} {1}/{2}: 全景生成失败: {3}", DateTime.Now.ToString("HH:mm:ss"), index, items.Length, message2)); } } // 全景制作完成 worker.ReportProgress(++index, string.Format("{0} ----------------------\r\n{1}", DateTime.Now.ToString("HH:mm:ss"), string.Join("\r\n", uids.ToArray()))); } catch (Exception ex) { MessageBox.Show(string.Format("提交全景失败!\r\n{0}\r\n{1}", ex.Message, ex.StackTrace), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; } }