Use C # To dynamically refresh kml

Source: Internet
Author: User

First, create a new project and add a timer control and button. When you click the button, the content in dynamic. kml is dynamically updated, so that the coordinates of the point are changed in real time. The Code is as follows:

private double xx=100;private double yy=30;private void timer1_Tick(object sender, EventArgs e){            xx +=0.03;            yy +=0.03;                        FileStream fs = new FileStream("products.kml", FileMode.Create);            XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);             // Start the document.            w.WriteStartDocument();            w.WriteStartElement("kml", "http://earth.google.com/kml/2.1");            w.WriteStartElement("Document");            w.WriteStartElement("name");            w.WriteString("zy's KML");            w.WriteEndElement();            w.WriteStartElement("open");            w.WriteString("1");            w.WriteEndElement();            //style            w.WriteStartElement("Style");            w.WriteAttributeString("id", "normalPlacemark");            w.WriteStartElement("IconStyle");            w.WriteStartElement("Icon");            w.WriteStartElement("href");            w.WriteString("F:/img/web.gif");            w.WriteEndElement();//style            w.WriteEndElement();//iconStyle            w.WriteEndElement();//icon            w.WriteEndElement();//href             //stylemap            w.WriteStartElement("StyleMap");            w.WriteAttributeString("id", "exampleStyleMap");            w.WriteStartElement("Pair");            w.WriteStartElement("key");            w.WriteString("normal");            w.WriteEndElement();            w.WriteStartElement("styleUrl");            w.WriteString("#normalPlacemark");            w.WriteEndElement();//styleUrl            w.WriteEndElement();//pair            w.WriteEndElement();//StyleMap             w.WriteStartElement("Placemark");            w.WriteStartElement("Name");            w.WriteString("zy's KML");            w.WriteEndElement();            // Write Point element             w.WriteStartElement("Point");            w.WriteStartElement("coordinates");            w.WriteString(xx.ToString ()+","+yy.ToString ());            w.WriteEndElement();            w.WriteEndElement();             w.WriteEndElement(); // Placemark            w.WriteEndElement();//document            w.WriteEndElement(); // kml             // Ends the document.            w.WriteEndDocument();             // close writer            w.Close(); } 

Create the realtimenetlink. kml file and call the dynamic. kml content again each time the kml is refreshed. The Code is as follows:

 

 <?xml version="1.0" encoding="UTF-8"?>

<kml xmlns="http://earth.google.com/kml/2.2">

<Document>

<name>RealtimeNetlink </name>

<visibility>1</visibility>

<open>1</open>

<NetworkLink>

<visibility>1</visibility>

<refreshVisibility>1</refreshVisibility>

<flyToView>0</flyToView>

<LookAt>

<longitude>114.12022</longitude>

<latitude>22.55841667</latitude>

<altitude>2000</altitude>

<range>1000</range>

<tilt>0</tilt>


<altitudeMode>relativeToGround</altitudeMode>

</LookAt>

<Link>


<refreshMode>onInterval</refreshMode>

<refreshInterval>3</refreshInterval>

<viewRefreshMode>onStart</viewRefreshMode>

<viewRefreshTime>3</viewRefreshTime>

</Link>

</NetworkLink>

</Document>

</kml>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.