从asp.net生成KML

编程入门 行业动态 更新时间:2024-10-26 10:41:13
本文介绍了从asp生成KML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将SharpKML与asp(C#)一起使用,它生成的kml可以在谷歌地图上加载和工作,但问题是我不能添加一些东西,比如: 样式,开始和结束点(大黄色针脚),将线条分成块而不是连续的长线。 i尝试了一切,但它甚至不起作用文档标记未添加到输出中。

I used SharpKML with asp(C#) it generates kml which loads and works in Google Maps but problem is that i can't add few things like: Styles, Start and End points (big yellow pins), Dividing line string into chunks instead of continuous long line. i tried everything but it doesn't work even document tag is not added in output.

protected void Button1_Click(object sender, EventArgs e) { var document = new Document(); document.Id = "Document"; document.Name = "Document"; SharpKml.Dom.Style style = new SharpKml.Dom.Style(); style.Id = "yellowLineGreenPoly"; //style.Line = new LineStyle(new Color32(HexStringToColor("7f00ffff"),4)); //Color32 col = HexStringToColor("7f00ffff"); //LineStyle ls = new LineStyle(); //ls.Color = col; //style.Line = ls; //document.AddStyle(style); Description ds = new Description(); ds.Text = @"<h1>Car's Tracking</h1> "; LineString linestring = new LineString(); CoordinateCollection coordinates = new CoordinateCollection(); //Color clr = Color.FromArgb(100, 150, 75); //clr.ToArgb(); SqlConnection sqlcon = new SqlConnection(conStr); // String com = "select Latitude, Longitude from Coordinates where IMEI=@txtIMEI"; SqlCommand sqlcom = new SqlCommand("GetLatLon", sqlcon); sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.Parameters.Add("@IMEI", SqlDbType.VarChar).Value= TextBox1.Text; DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(sqlcom); sda.Fill(dt); try { sqlcon.Open(); sqlcom.ExecuteNonQuery(); foreach (DataRow dr in dt.Rows) { double lon = double.Parse(dr["Longitude"].ToString()); double lat = double.Parse(dr["Latitude"].ToString()); coordinates.Add(new Vector(lat, lon)); } linestring.Coordinates = coordinates; Placemark placemark = new Placemark(); placemark.Name = "Car's Track Record"; placemark.Description = ds; // placemark.StyleUrl = new Uri("#yellowLineGreenPoly", UriKind.Relative); placemark.Geometry = linestring; document.AddFeature(placemark); // linestring.Extrude = true; linestring.Tessellate = true; linestring.AltitudeMode = AltitudeMode.RelativeToGround; var kml = new Kml(); // kml.Feature = document; kml.Feature = placemark; KmlFile kmlFile = KmlFile.Create(kml, true); using (var stream = System.IO.File.OpenWrite("C:/"+"IMEI-"+TextBox1.Text+".kmz")) { kmlFile.Save(stream); Response.Write("KML Created"); } } catch (Exception exc) { Response.Write(exc.Message); } finally { sqlcon.Close(); } }

推荐答案

从您的代码中看,您似乎期待奇迹。您添加到kml对象的唯一项目是地标。好吧,使用地标你还可以添加 linestring 和坐标。虽然您也将地标添加到文档,但是没有直接或间接添加文档的行 - 至 kml 。 From your code, it looks like you are expecting a miracle. The only item you add to kml object is the placemark. Well, with the placemark you also add linestring and the Coordinates. Though you add the placemark also to the document, there is no line where the document gets added - directly or indirectly - to kml.

更多推荐

从asp.net生成KML

本文发布于:2023-11-11 08:03:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577835.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:asp   net   KML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!