以下小段代码达到的效果是kml利用networklink不断去执行服务器上的phython代码,动态改变点的经纬度坐标。
首先在Internet信息服务下默认网站下新建虚拟目录,然后在该目录下的“虚拟目录”选项卡中创建应用程序,再点击“配置”,进入“应用程序配置”,点击添加(如下图),最后确定。
在该目录的资源管理器下新建randomPlacemark.py文件,代码如下:
#!C:/Python25/python.exe#!以上更改为自己的python安装路径
import random
latitude = random.randrange(-90, 90)
longitude = random.randrange(-180, 180)
kml = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<kml xmlns="http://www.opengis.net/kml/2.2">\n'
'<Placemark>\n'
'<name>Random Placemark</name>\n'
'<Point>\n'
'<coordinates>%d,%d</coordinates>\n'
'</Point>\n'
'</Placemark>\n'
'</kml>'
) %(longitude, latitude)
print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml
然后新建文件test.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Folder>
<name>Network Links</name>
<visibility>1</visibility>
<open>0</open>
<description>Network link example 1</description>
<NetworkLink>
<name>Random Placemark</name>
<visibility>1</visibility>
<refreshVisibility>1</refreshVisibility>
<open>0</open>
<description>A simple server-side script that generates a new random
placemark on each call</description>
<refreshVisibility>0</refreshVisibility>
<flyToView>1</flyToView>
<Link>
<href>http://computername/虚拟目录名/randomPlacemark.py</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>5</refreshInterval>
<viewRefreshMode>onStart</viewRefreshMode>
<viewRefreshTime>4</viewRefreshTime>
</Link>
</NetworkLink>
</Folder>
</kml>