views:

1310

answers:

1

This is weird. I'm using the marker clusterer to bunch all my markers however the first time when the map renders and when I try to drag it or pan it - it hangs and firefox tells me the script is slowing it down so I have to stop the script. But if I zoom it out - it zooms normally and panning it from then on causes no issues - I have no idea whats going wrong here. Here is my code am I missing something here - must be something wrong with my initialisation:

var map = null;

function initializeGMaps() { 



  if (GBrowserIsCompatible())
  {
    map = new GMap2(document.getElementById("map_canvas"));


    {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
      var i = 0;
     iconBlue = new GIcon();
      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {


     iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
        iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
        iconBlue.iconSize = new GSize(12, 20);
        iconBlue.shadowSize = new GSize(22, 20);
        iconBlue.iconAnchor = new GPoint(6, 20);
        iconBlue.infoWindowAnchor = new GPoint(5, 1);

        var marker = new GMarker(point,{ icon:iconBlue, });
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[i] = marker;
        htmls[i] = html;
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }


      // create the map
      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng( 43.907787, -50.359741), 5);

     var customUI = map.getDefaultUI();
     customUI.controls.maptypecontrol = false;
     customUI.controls.menumaptypecontrol = true; 
     map.setUI(customUI);

      // A function to read the data
      function readMap() {
        var url='get-map-markers.php';
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");

            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();

            map.clearOverlays();

            // empty the array
            allmarkers = [];
      //var clusterer = new Clusterer( map );

            for (var i = 0; i < markers.length; i++) {
              // obtain the attribues of each marker
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var html = markers[i].getAttribute("html");
              var label = markers[i].getAttribute("label");
              // create the marker

              var marker = createMarker(point,label,html);
              //map.addOverlay(marker);
        allmarkers.push(marker);
        //clusterer.AddMarker( marker, html );
            }
      var markerCluster = new MarkerClusterer(map, allmarkers);
            // put the assembled side_bar_html contents into the side_bar div


          }
        }
        request.send(null);
      }

      readMap();

    }




  }
}

$(document).ready(function() { initializeGMaps(); } );
$('body').unload( function () { GUnload(); } );


UPDATE: I just noticed that the script at google.com is causing the page to be slow :( how do I fix this? WHat have I done in my code to bring this behavior.

A: 

Markerclusterer sucks. Use this one:

http://googlemapsapi.martinpearman.co.uk/clustermarker

My demo: http://www.stopdetelefoongids.nl/stats/ (source in /includes/maps.js )

SchizoDuckie