<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="从web站点访问数据" height="300">
  <Require feature="sharedmap"/>
</ModulePrefs>
<Content type="html"><![CDATA[

<small>
本例子抓取<a href="http://chinamaps.googlecode.com/svn/docs/examples/points.xml">坐标文件</a>的内容，
为每个点添加标记，并用红线将标记连接起来。
</small>

<script>
var map = new GMap2();

// 定位到北京
map.setCenter(new GLatLng(39.917, 116.397), 12);   

// 从XML文件中读出点信息，并用红线将这些点连接起来。
var url = "http://chinamaps.googlecode.com/svn/docs/examples/points.xml";
_IG_FetchXmlContent(url, function(response) {
  var polyline = [];
  var markers = response.getElementsByTagName("marker");

  for (var i = 0; i < markers.length; i++) {
    var point = markers.item(i);
    var lat  = point.getAttribute("lat");
    var lng  = point.getAttribute("lng");
    var latlng = new GLatLng(lat, lng);

    polyline.push(latlng);
    if (point.firstChild) {
      var marker = createMarker(latlng, "标记 #" + i);
      map.addOverlay(marker);
    }
  }

  var polyline = new GPolyline(polyline, "#ff0000", 3, 1);
  map.addOverlay(polyline);
});

// 在给定点创建给定名字的一个标记
function createMarker(point, name) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(name);
  });
  return marker;
}
</script>

]]></Content>
</Module>
