从asp.net生成KML [英] Generating KML from asp.net
本文介绍了从asp.net生成KML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将SharpKML与asp.net(C#)一起使用,它生成的kml可以在谷歌地图上加载和工作,但问题是我不能添加一些东西,比如:
样式,开始和结束点(大黄色针脚),将线条分成块而不是连续的长线。
i尝试了一切,但它甚至不起作用文档标记未添加到输出中。
I used SharpKML with asp.net(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 addlinestring
and the Coordinates. Though you add the placemark also to thedocument
, there is no line where thedocument
gets added - directly or indirectly - tokml
.
这篇关于从asp.net生成KML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文