5

嗨,这是我在这里的第一篇文章..

我一直在玩谷歌地图,试图列出法国的露营地。

我已经到了读取数据的 xml 文件的地步,加载地图并对结果进行聚类,一切正常,但速度很慢。

Q1 即使使用聚类器,您可以渲染的标记数量是否有限制(目前有超过 7000 条记录)

Q2 到目前为止我的代码有什么明显的问题吗:

    <!DOCTYPE html>
<html>
 <head>
  <title>Read XML in Microsoft Browsers</title>
      <script src="http://maps.google.com/maps/api/js?sensor=false&language=en&region=GB" type="text/javascript"></script>
      <script src="scripts/markerclusterer.js" type="text/javascript"></script>
      <link rel="stylesheet" type="text/css" href="stylesheets/style_1024.css" />
   <script type="text/javascript">
       var xmlDoc;
       function loadxml() {
           xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
           xmlDoc.async = false;
           xmlDoc.onreadystatechange = readXML;
           xmlDoc.load("xml_files/France_all.xml");
       }

       function readXML() {
           if (xmlDoc.readyState == 4) {
               //alert("Loaded");
               //set up map
               var map = new google.maps.Map(document.getElementById('map'), {
                   zoom: 10,
                   center: new google.maps.LatLng(0, 0),
                   mapTypeControl: true,
                   mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
                   navigationControl: true,
                   mapTypeId: google.maps.MapTypeId.ROADMAP
               });

               var bounds = new google.maps.LatLngBounds();
               var infowindow = new google.maps.InfoWindow({ maxWidth: 100 });
               var marker, i

               var markers = [];
               var html = [];

               var x = (xmlDoc.getElementsByTagName("placemark").length);
               //for (i = 0; i < x; i++) {
               for (i = 0; i < x; i++) {
                   //document.write(xmlDoc.documentElement.childNodes[1].firstChild.tagName) + '<br>';
                   desc = xmlDoc.getElementsByTagName("description")[i].text;
                   lat = parseFloat((xmlDoc.getElementsByTagName("latitude")[i].text));
                   lon = parseFloat((xmlDoc.getElementsByTagName("longitude")[i].text));
                   myicon = (xmlDoc.getElementsByTagName("icon")[i].text);
                   //create new point
                   var point = new google.maps.LatLng(lat, lon);

                   //create new marker
                   marker = new google.maps.Marker({
                       position: point,
                       panControl: false,
                       map: map,
                       icon: myicon
                   });

                   //increae map bounds
                   bounds.extend(point);
                   //fit to bounds
                   map.fitBounds(bounds);

                   //add reference to arrays
                   markers.push(marker);
                   html.push(desc);

                   //add listener
                   google.maps.event.addListener(marker, 'click', (function (marker, i) {
                       return function () {
                           infowindow.setContent(html[i]);
                           infowindow.open(map, marker);
                       }
                   })(marker, i));

                   //alert(i + " " + desc +" added!");
               };
               //var mc = new MarkerClusterer(map);
              var mcOptions = {gridSize: 50, maxZoom: 15 };
              var mc = new MarkerClusterer(map, markers, mcOptions);
           }

       }
  </script>


 </head>

 <body onload="loadxml()">

 <div style="height:100%; width:100%">
    <div id="map" style="float:left; width:50%; height:100%">
        <!--filled via script-->
    </div>
     <div style="float:left; width:50%; height:100%">
        <h4>Select Region</h4>
       <select>
        <option value="Alsace" onclick="loadxml()">Alsace</option>
       </select>
     </div>
 </div>

 </body>
</html> 
4

1 回答 1

1

这篇文章可能会有所帮助。基于图块的解决方案(FusionTables、KmlLayer 或基于服务器的自定义地图)将比原生 Google Maps API v3 对象更快地呈现,即使使用集群也是如此。您可能会看到 xml 文件的传输和处理时间。

于 2012-10-03T16:13:22.960 回答