Changeset 12706 for extensions/rv_gmaps/trunk/template/data_handler.js
- Timestamp:
- Dec 8, 2011, 10:36:35 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_gmaps/trunk/template/data_handler.js
r12701 r12706 12 12 13 13 google.maps.event.bind( this._map, "click", this, this._onMapClick); 14 //google.maps.event.bind( this._infoWindow, "domready", this, this._onInfoWindowDomReady);15 14 } 16 15 … … 23 22 _navHtmlIds: ["gotoPrevImage", "gotoNextImage"], 24 23 _navHtmlHandles: [], 25 _recursionProtect: 0,26 24 _prevResult: { nb_items:0 }, 27 25 … … 70 68 if (changed) 71 69 { 72 var newMarkers = []; 70 // BEGIN NEW **************** 71 var markersToRemove=[], clustersToAdd=[], newMarkers=[]; 72 data.image_clusters.sort( function(a,b) { return PwgDataHandler.cmpll( a.position, b.position); } ); 73 for (i=0; i<data.image_clusters.length; i++) 74 { 75 var cluster = data.image_clusters[i]; 76 while(this._markers.length) 77 { 78 var marker = this._markers[0]; 79 if (PwgDataHandler.cmpll(cluster.position, marker.getPosition()) == 0) 80 { 81 marker.pwg = { 82 nb_items: cluster.nb_items, 83 images: cluster.items, 84 bounds: cluster.bounds, 85 blowup_url: cluster.blowup_url 86 }; 87 newMarkers.push(marker); 88 this._markers.shift(); 89 cluster = null; 90 break; 91 } 92 else if (PwgDataHandler.cmpll(cluster.position, marker.getPosition()) < 0) 93 { 94 break; 95 } 96 else 97 { 98 markersToRemove.push(marker); 99 this._markers.shift(); 100 } 101 } 102 103 if (cluster) 104 clustersToAdd.push(cluster); 105 } 106 107 if (document.is_debug) glog('reused ' + newMarkers.length + ' exact markers'); 108 markersToRemove = markersToRemove.concat( this._markers ); 109 110 var infoWindowMarker = this._infoWindow.getAnchor(); 111 for (i=0; i<clustersToAdd.length; i++) 112 { 113 var cluster = clustersToAdd[i]; 114 var theTitle = ""; 115 if (cluster.nb_items>1) 116 theTitle = Localization.fmt1("%d photos", cluster.nb_items); 117 else 118 theTitle = cluster.items[0].name; 119 120 var marker = markersToRemove.pop(); 121 if (marker && marker==infoWindowMarker) 122 { 123 marker.setMap(null); 124 google.maps.event.clearInstanceListeners(marker); 125 if (document.is_debug) glog('removed marker with infoWindow'); 126 marker = this._markers.pop(); 127 } 128 129 if (!marker) 130 { 131 marker = new google.maps.Marker(this.options.markerOptions); 132 marker.setPosition(cluster.position); 133 marker.setTitle(theTitle); 134 google.maps.event.addListener( marker, "click", pwgBind(this, this._onMarkerClick, marker) ); 135 google.maps.event.addListener( marker, "dblclick", pwgBind(this, this._onMarkerDblClick, marker) ); 136 marker.setMap(this._map); 137 } 138 else 139 { 140 marker.currentImageIndex=0; 141 marker.setPosition( cluster.position ); 142 marker.setTitle(theTitle); 143 } 144 145 newMarkers.push(marker); 146 147 marker.pwg = { 148 nb_items: cluster.nb_items, 149 images: cluster.items, 150 bounds: cluster.bounds, 151 blowup_url: cluster.blowup_url 152 }; 153 } 154 155 for (i=0; i<markersToRemove.length; i++) 156 { 157 markersToRemove[i].setMap(null); 158 google.maps.event.clearInstanceListeners(markersToRemove[i]); 159 } 160 161 this._markers = newMarkers; 162 this._markers.sort( function(a,b) { return PwgDataHandler.cmpll( a.getPosition(), b.getPosition()); } ); 163 // END new 164 165 /* var newMarkers = []; 73 166 var infoWindowMarker = this._infoWindow.getAnchor(); 74 167 … … 123 216 google.maps.event.clearInstanceListeners(this._markers[i]); 124 217 } 125 218 */ 126 219 this._markers = newMarkers; 127 220 this._prevResult.nb_items=data.nb_items; … … 207 300 _onInfoWindowDomReady: function() 208 301 { 209 if (this._recursionProtect)210 return;211 302 if (!this._infoWindow.getAnchor() || this._infoWindow.getAnchor().pwg.images.length<2) 212 303 return; 213 try { 214 this._recursionProtect = 1; 215 for (var i=0; i< this._navHtmlIds.length; i++) 216 { 217 var elt = document.getElementById( this._navHtmlIds[i] ); 218 if (elt) 219 this._navHtmlHandles.push( google.maps.event.addDomListener(elt, "click", pwgBind(this, this._onPictureNavigate, this._infoWindow.getAnchor(), i) ) ); 220 } 221 } 222 finally { 223 this._recursionProtect = 0; 304 for (var i=0; i< this._navHtmlIds.length; i++) 305 { 306 var elt = document.getElementById( this._navHtmlIds[i] ); 307 if (elt) 308 this._navHtmlHandles.push( google.maps.event.addDomListener(elt, "click", pwgBind(this, this._onPictureNavigate, this._infoWindow.getAnchor(), i) ) ); 224 309 } 225 310 }, … … 267 352 } 268 353 354 PwgDataHandler.cmpll = function(a,b) { 355 var d= a.lng() - b.lng(); 356 if (d < -.5e-6) 357 return -1; 358 else if (d > .5e-6) 359 return 1; 360 d= a.lat() - b.lat(); 361 if (d < -.5e-6) 362 return -1; 363 else if (d > .5e-6) 364 return 1; 365 return 0; 366 } 269 367 270 368 String.prototype.urlNoHtm = function()
Note: See TracChangeset
for help on using the changeset viewer.