loftywaif002 / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
Apache License 2.0
0 stars 0 forks source link

No markers are made when the marker array uses non-numeric keys #266

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Demo link or sample code:

My markers aren't simply pushed into an array of markers.  Instead, I am using 
the telephone number of the place represented by that marker as its key.  
Whenever you make such a hash, the length keyword returns 0.  Therefore, line 
182 of markerclusterer.js is broken:

182   if (opt_markers && opt_markers.length) {

What steps will reproduce the problem?
1. Assume "d" is a JavaScript object with keys "phone" and "name".  Make a 
marker as such:

myLatlng = new google.maps.LatLng(lat, lng);
markerSet[d["phone"]] = new google.maps.Marker({
    position: myLatlng,
    map: myMap,
    title: d["name"],
    icon: markerImage
});

2. Invoke the markerclusterer:

markerCluster = new MarkerClusterer(map, markers);

3. Line 182 fails as mentioned above.  The if condition fails.

Expected result:

I wanted to see clusters representing multiple markers.

Actual result:

I saw a whole bunch of markers stacked on top of each other in a very small 
space.

Version: MarkerClusterer for Google Maps v3, version 1.0 (r439)

Browser / Operating System:
Chrome 28.0.1500.72 m / Windows 7

Additional comments:

I fixed this defect for myself with:
Line 182:
  if (opt_markers && (opt_markers.length || Object.keys(opt_markers).length)) {

Lines 407-415:
  if (markers.length) {
    for (var i = 0, marker; marker = markers[i]; i++) {
      this.pushMarkerTo_(marker);
    }
  } else if (Object.keys(markers).length) {
    for (var marker in markers) {
      this.pushMarkerTo_(markers[marker]);
    }
  }

Original issue reported on code.google.com by t3h.st...@gmail.com on 29 Jul 2013 at 2:09

GoogleCodeExporter commented 8 years ago
Thanks I will take a peak.

Original comment by brett.mc...@gmail.com on 10 Sep 2013 at 6:13

GoogleCodeExporter commented 8 years ago
Fixed in head (Rev r444).

Original comment by brett.mc...@gmail.com on 12 Sep 2013 at 12:03

GoogleCodeExporter commented 8 years ago

Original comment by brett.mc...@gmail.com on 12 Sep 2013 at 7:42

GoogleCodeExporter commented 8 years ago
The fix causes an error within IE 8:
The Object.keys property does not exist within that browser version:
http://forum.jquery.com/topic/object-keys-fails-in-ie8

Original comment by herrel....@gmail.com on 12 Sep 2013 at 8:00

GoogleCodeExporter commented 8 years ago
Good catch.  I will either roll an Object.keys solution for situations where it 
doesn't exist, or just back out the change entirely.

Original comment by brett.mc...@gmail.com on 12 Sep 2013 at 8:34

GoogleCodeExporter commented 8 years ago
Added a local Object.keys implementation for IE8 and created release 1.0.2.

Original comment by brett.mc...@gmail.com on 13 Sep 2013 at 3:15

GoogleCodeExporter commented 8 years ago
Works like a charm! Thanks a lot for the fast bug-bugfix :-) 

Original comment by herrel....@gmail.com on 13 Sep 2013 at 6:17