public static void SaveGPSData(List <GpsPointData> points, int filterIndex, string fileName) { string ext = Path.GetExtension(fileName); ExportType exportType = (ExportType)Enum.Parse(typeof(ExportType), ext.Trim('.')); if (filterIndex == 3)//(exportType == ExportType.gpx) { List <Waypoint> list = new List <Waypoint>(); foreach (GpsPointData i in points) { list.Add(new Waypoint(i)); } GpxV2 v2 = new GpxV2(); v2.waypoints = list.ToArray(); string xml = SerializeToString(v2); File.WriteAllText(fileName, xml); } else if (filterIndex == 2) //simple KML (exportType == ExportType.kml) { kml kml = new kml(); kml.SaveToFile(points, fileName); } else if (filterIndex == 1) //extended KML (exportType == ExportType.kml) { GPSDataParser.FileFormats.KML.KmlEx kml = new GPSDataParser.FileFormats.KML.KmlEx(); kml.SaveToFile(points, fileName); } }
private void SaveConfig() { if (Regex.IsMatch(tbxheight.Text, "^\\d+$") == false) { MessageBox.Show("高度只能是数字格式"); return; } if (Regex.IsMatch(tbxtipsinterval.Text, "^\\d+$") == false) { MessageBox.Show("气泡显示时长只能是数字格式"); return; } if (Regex.IsMatch(tbxdetailinterval.Text, "^\\d+$") == false) { MessageBox.Show("详细页面显示时长只能是数字格式"); return; } if (Regex.IsMatch(tbxmainpageinterval.Text, "^\\d+$") == false) { MessageBox.Show("首页停留时间只能是数字格式"); return; } if (Regex.IsMatch(incomeRate.Text, "^\\d+\\.\\d+$") == false) { MessageBox.Show("收益转化率只能是小数"); return; } List <CheckBox> cboxes = findCheckBox(this.displayItems, true); if (cboxes.Count < 4) { MessageBox.Show("至少需要选择4个首页汇总项目"); return; } if (cboxes.Count > 5) { MessageBox.Show("最多不能超过5个显示首页汇总项目"); return; } if (string.IsNullOrEmpty(tboxhyc.Text) == false) { FileUtil.WriteFile(Environment.CurrentDirectory, "text.txt", string.Format("hyc={0}", tboxhyc.Text)); } config.langInfo = string.Format("{0}-{1}", cbxMasterLanguage.SelectedValue, cbxLanguage.SelectedValue); config.MainInterval = tbxmainpageinterval.Text; config.domain = tboxDomain.Text; config.CounterType = cbxCounterType.SelectedIndex; config.currencyType = cbxCurrencyType.SelectedIndex; config.CounterUser = tbxUserName.Text; string displayItems = string.Empty; foreach (CheckBox cbox in cboxes) { displayItems += string.Format("{0}|", Array.FindIndex(ConfigPara.displayItemsName.ToArray(), i => i.Equals(cbox.Name))); } config.displayItems = displayItems; displayItems = string.Empty; cboxes = findCheckBox(displayPages, true); if (cboxes.Count < 1) { MessageBox.Show("至少需要选择1个电站子页面"); return; } foreach (CheckBox cbox in cboxes) { displayItems += string.Format("{0}|", Array.FindIndex(ConfigPara.displayPageName.ToArray(), i => i.Equals(cbox.Name))); } config.displayPages = displayItems;//显示页面配置 decimal rate = 0; decimal.TryParse(incomeRate.Text, out rate); config.incomeRate = rate; foreach (PlantInfoVo plantInfoVo in config.PlantsInfo) { if (!config.height.Equals(tbxheight.Text)) { plantInfoVo.height = tbxheight.Text; } if (!config.TipsInterval.Equals(tbxtipsinterval.Text)) { plantInfoVo.tipInterval = tbxtipsinterval.Text; } if (!config.DetailInterval.Equals(tbxdetailinterval.Text)) { plantInfoVo.detailInterval = tbxdetailinterval.Text; } } config.height = tbxheight.Text; config.TipsInterval = tbxtipsinterval.Text; config.DetailInterval = tbxdetailinterval.Text; if (config.CounterType == ConfigPara.currentUser) { if (string.IsNullOrEmpty(config.CounterUser)) { MessageBox.Show("请输入用户名!"); tbxUserName.Focus(); return; } } config.sysname = tboxSysname.Text; // if (selected == 0) { //展示电站列表 List <PlantInfoVo> checkedPlants = new List <PlantInfoVo>(); // //List<PlantInfoVo> allPlants = new List<PlantInfoVo>(); //foreach (UIElement c in plantsList.Children) //{ // if (c is CheckBox) // { // CheckBox cbox = c as CheckBox; // PlantInfoVo tempVo = config.PlantsInfo.Single(model => string.Format("pid_{0}", model.plantId).Equals(cbox.Name)); // tempVo.Longitude = double.Parse(findTextBox(string.Format("tboxlong_{0}", tempVo.plantId))); // tempVo.latitude = double.Parse(findTextBox(string.Format("tboxlat_{0}", tempVo.plantId))); // tempVo.height = findTextBox(string.Format("tboxhei_{0}", tempVo.plantId)); // tempVo.design_power = findTextBox(string.Format("tboxdesignpower_{0}", tempVo.plantId)); // tempVo.detailInterval = findTextBox(string.Format("tboxdetailtime_{0}", tempVo.plantId)); // tempVo.tipInterval = findTextBox(string.Format("tboxtiptime_{0}", tempVo.plantId)); // if (cbox.IsChecked == true) // { // checkedPlants.Add(tempVo); // } // allPlants.Add(tempVo); // } //} string[] pidArray = addPids.Split('|'); foreach (string pid in pidArray) { if (string.IsNullOrEmpty(pid)) { continue; } checkedPlants.Add(config.PlantsInfo.FirstOrDefault(p => p.plantId.Equals(pid))); } config.TipsPlantsInfo = checkedPlants; //config.PlantsInfo = allPlants; } //if (selected == 1) //{ //自动演示电站列表 //List<PlantInfoVo> tipscheckedPlants = new List<PlantInfoVo>(); //for (int x = 0; x < tipsplantsList.Children.Count; x++) //{ // if (tipsplantsList.Children[x] is CheckBox) // { // CheckBox check = tipsplantsList.Children[x] as CheckBox; // if (check.IsChecked == true) // { // tipscheckedPlants.Add(pvos.Single(model => string.Format("pid_{0}", model.plantId).Equals(check.Name))); // } // } //} //config.TipsPlantsInfo = tipscheckedPlants; // } //保存配置的电站到 KML 文件 plant.kml kml kml = new kml(); List <GroundOverlay> groundoverlaies = new List <GroundOverlay>(); foreach (PlantInfoVo piv in config.PlantsInfo) { String desc = ""; if (config.TipsPlantsInfo != null && config.TipsPlantsInfo.Contains(piv)) { desc = "<font size=4>装机容量:" + piv.design_power + " kW</font><hr><font size=4>" + "城市:" + piv.city + "</font><br/><font size=4>国家:" + piv.country + "</font><hr><a href='http://localhost:8111/web?plantId=" + piv.plantId + "' target='_self'><font size=4>点击查看详细信息</font></a>"; } else { desc = "<font size=4>装机容量:" + piv.design_power + " kW</font><hr><font size=4>" + "城市:" + piv.city + "</font><br/><font size=4>国家:" + piv.country + "</font><hr>"; } kml.Document.Add(new Placemark(piv.plantName, desc, "#globeIcon", "1", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt() { altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006" })); //kml.Document.Add(new Placemark(piv.plantName + "-1", desc, "#globeIcon1", "1", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt() { altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006" })); //kml.Document.Add(new Placemark(piv.plantName + "-2", desc, "#globeIcon2", "0", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt() { altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006" })); groundoverlaies.Add(new GroundOverlay { name = piv.plantName + "overlay", icon = config.domain + "/demoimg/3x.png", visibility = "0", LatLonBox = new GroundOverlay.LatLonBx { east = piv.Longitude - 1.5, rotation = 160, north = piv.latitude - 1.5, south = piv.latitude + 1.5, west = piv.Longitude + 1.5 }, LookAt = new GroundOverlay.Look { altitude = "1", heading = "124", latitude = "1", longitude = "1", range = "", tilt = "" } }); groundoverlaies.Add(new GroundOverlay { name = piv.plantName + "overlay-1", icon = config.domain + "/demoimg/3x-1.png", visibility = "0", LatLonBox = new GroundOverlay.LatLonBx { east = piv.Longitude - 1.5, rotation = 160, north = piv.latitude - 1.5, south = piv.latitude + 1.5, west = piv.Longitude + 1.5 }, LookAt = new GroundOverlay.Look { altitude = "1", heading = "124", latitude = "1", longitude = "1", range = "", tilt = "" } }); } kml.SaveToFile("plant.kml", groundoverlaies, config.domain); //config.MainInterval = this.tboxMainPage.Text; //config.DetailInterval = this.tboxDetailPage.Text; XMLHelper.SerializerXML <ConfigPara>(System.Environment.CurrentDirectory + "\\config.xml", config); MessageBox.Show("参数保存成功", "系统提示", MessageBoxButton.OK); }