Changeset 7308 for extensions/GMaps/js/gmapsCategory.js
- Timestamp:
- Oct 20, 2010, 10:49:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/GMaps/js/gmapsCategory.js
r7177 r7308 2 2 * ----------------------------------------------------------------------------- 3 3 * file: gmapsCategory.js 4 * file version: 1. 0.05 * date: 2010-10- 104 * file version: 1.1.0 5 * date: 2010-10-20 6 6 */ 7 7 … … 87 87 function loadMarkers(map) 88 88 { 89 gmaps.callId++; 90 89 91 datas={ 90 92 requestId:gmaps.requestId, 93 callId:gmaps.callId, 91 94 bounds:{ 92 95 north:map.getBounds().getNorthEast().lat(), … … 97 100 width:$(map.getDiv()).width(), 98 101 height:$(map.getDiv()).height(), 99 distanceTreshold:20 102 distanceTreshold:20, 100 103 }; 101 104 … … 104 107 $('#gmapsLoading').css('display', 'inline-block'); 105 108 $('#gmapsNbPhotos').html(''); 106 $('#iDialogGMapWaiting').css(107 {108 width:$('#iGMapsIcon').width()+'px',109 height:$('#iGMapsIcon').height()+'px',110 top:$('#iGMapsIcon').position().top+'px',111 left:$('#iGMapsIcon').position().left+'px',112 display:'block'113 }114 );115 109 116 110 $.ajax( … … 124 118 { 125 119 tmp=$.parseJSON(msg); 126 tmp.markers.sort(compareMarkers); 127 applyMarkers(currentMapLoad, tmp.markers); 128 $('#gmapsLoading').css('display', 'none'); 129 $('#gmapsNbPhotos').html('['+tmp.datas.nbPhotos+']'); 130 $('#iDialogGMapWaiting').css('display', 'none'); 120 if(gmaps.callId==tmp.callId) 121 { 122 tmp.markers.sort(compareMarkers); 123 applyMarkers(currentMapLoad, tmp.markers); 124 $('#gmapsLoading').css('display', 'none'); 125 $('#gmapsNbPhotos').html('['+tmp.datas.nbPhotos+']'); 126 } 131 127 } 132 128 } … … 140 136 * @param Array markers : array of markers properties 141 137 * each marker is an object with properties : 142 * latitude, longitude, nbIm ages138 * latitude, longitude, nbImg 143 139 */ 144 140 function applyMarkers(map, markers) … … 154 150 while(i<map.markers.length) 155 151 { 156 newListIndex=markerInList(map.markers[i].u niqueId, markers);152 newListIndex=markerInList(map.markers[i].uId, markers); 157 153 if(newListIndex==-1) 158 154 { … … 189 185 { 190 186 marker:marker, 191 u niqueId:markers[i].uniqueId187 uId:markers[i].uId 192 188 } 193 189 ); … … 207 203 function compareMarkers(m1,m2) 208 204 { 209 if(m1.u niqueId<m2.uniqueId)205 if(m1.uId<m2.uId) 210 206 { 211 207 return(-1); 212 208 } 213 else if(m1.u niqueId<m2.uniqueId)209 else if(m1.uId<m2.uId) 214 210 { 215 211 return(1); … … 222 218 for(var i=0;i<markerList.length;i++) 223 219 { 224 if(markerList[i].u niqueId==uniqueId) return(i)220 if(markerList[i].uId==uniqueId) return(i) 225 221 } 226 222 return(-1); … … 286 282 } 287 283 288 if(gmaps.currentInfo.nbIm ages>1)284 if(gmaps.currentInfo.nbImg>1) 289 285 { 290 286 $('#ciGMIWC_picnum').html((index+1)+'/'+gmaps.currentInfo.nbImgTxt); … … 304 300 { 305 301 gmaps.currentInfo.displayed--; 306 if(gmaps.currentInfo.displayed<0) gmaps.currentInfo.displayed=gmaps.currentInfo.nbIm ages-1;302 if(gmaps.currentInfo.displayed<0) gmaps.currentInfo.displayed=gmaps.currentInfo.nbImg-1; 307 303 displayPictureInfo(gmaps.currentInfo.displayed); 308 304 } … … 314 310 { 315 311 gmaps.currentInfo.displayed++; 316 if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbIm ages) gmaps.currentInfo.displayed=0;312 if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbImg) gmaps.currentInfo.displayed=0; 317 313 displayPictureInfo(gmaps.currentInfo.displayed); 318 314 } 319 315 320 316 317 /** 318 * check if zoomLevel 319 */ 320 function fitToBounds(bounds) 321 { 322 gmaps.maps[gmaps.currentMapLoadIndex].gMap.fitBounds(bounds); 323 324 if(gmaps.maps[gmaps.currentMapLoadIndex].zoomLevelMaxActivated && 325 gmaps.maps[gmaps.currentMapLoadIndex].gMap.getZoom() > gmaps.maps[gmaps.currentMapLoadIndex].zoomLevel) 326 { 327 gmaps.maps[gmaps.currentMapLoadIndex].gMap.setZoom(gmaps.maps[gmaps.currentMapLoadIndex].zoomLevel); 328 } 329 } 330 331 function initializeMapViewport(mode) 332 { 333 if(gmaps.currentMapLoadIndex>-1 && 334 ($('#'+gmaps.maps[gmaps.currentMapLoadIndex].id+'Content').dialog('isOpen') && mode=='loaded' || mode=='open') && 335 (gmaps.maps[gmaps.currentMapLoadIndex].viewportInitialized==false) 336 ) 337 { 338 /* 339 * if the container is not visible when map are built, they are 340 * not initialized correctly 341 * 342 * when dialog is opened for the first time, proceed to map 343 * finalization : 344 * - resize 345 * - center the map 346 * - add handlers on events 'dragend' and 'zoom_change' 347 * allowing to reload markers according to the new viewport 348 */ 349 google.maps.event.trigger(gmaps.maps[gmaps.currentMapLoadIndex].gMap, 'resize'); 350 351 352 if(gmaps.maps[gmaps.currentMapLoadIndex].fitToBounds) 353 { 354 fitToBounds(gmaps.bounds) 355 } 356 else 357 { 358 gmaps.maps[gmaps.currentMapLoadIndex].gMap.setCenter(gmaps.bounds.getCenter()); 359 } 360 361 // reduce copyright size... ^_^ 362 $('#'+gmaps.maps[gmaps.currentMapLoadIndex].id+' span, #'+gmaps.maps[gmaps.currentMapLoadIndex].id+' a').css('font-size', '55.0%'); 363 364 if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null) 365 gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.currentMapLoadIndex].gMap); 366 367 google.maps.event.addListener( 368 gmaps.maps[gmaps.currentMapLoadIndex].gMap, 369 'dragend', 370 function() 371 { 372 loadMarkers(this); 373 $('#gmapsBoundMap').css('display', 'inline'); 374 $('#gmapsBoundKml').css('display', 'inline'); 375 } 376 ); 377 378 google.maps.event.addListener( 379 gmaps.maps[gmaps.currentMapLoadIndex].gMap, 380 'zoom_changed', 381 function() 382 { 383 loadMarkers(this); 384 gmaps.infoWindow.close(); 385 $('#gmapsBoundMap').css('display', 'inline'); 386 $('#gmapsBoundKml').css('display', 'inline'); 387 } 388 ); 389 390 gmaps.maps[gmaps.currentMapLoadIndex].viewportInitialized=true; 391 } 392 393 if(gmaps.currentMapLoadIndex>-1) loadMarkers(gmaps.maps[gmaps.currentMapLoadIndex].gMap); 394 } 395 321 396 $(window).load(function () 322 397 { 323 // all maps have the same in tials bounds398 // all maps have the same initials bounds 324 399 gmaps.currentInfo=null; 400 gmaps.currentMapLoadIndex=-1; 325 401 326 402 gmaps.bounds = new google.maps.LatLngBounds( … … 351 427 $('#'+gmaps.maps[i].id).css( 352 428 { 353 width: ($(window).width()* 0.8)+'px',354 height:($(window).height()* 0.8)+'px'429 width: ($(window).width()*gmaps.popupAutomaticSize)+'px', 430 height:($(window).height()*gmaps.popupAutomaticSize)+'px' 355 431 } 356 432 ); 357 433 } 434 435 /* 436 * initialize map on the server side (call the 'public.maps.init' 437 * function 438 */ 439 $.ajax( 440 { 441 type: "POST", 442 url: "plugins/GMaps/gmaps_ajax.php", 443 async: true, 444 data: { ajaxfct:"public.maps.init", category:gmaps.categoryId }, 445 success: 446 function(msg) 447 { 448 gmaps.requestId=msg; 449 initializeMapViewport('loaded'); 450 } 451 } 452 ); 453 358 454 359 455 // initialize dialog box for maps … … 370 466 { 371 467 gmaps.currentMapLoadIndex=$(this).data('index'); 372 373 /* 374 * initialize map on the server side (call the 'public.maps.init' 375 * function 376 */ 377 $.ajax( 378 { 379 type: "POST", 380 url: "plugins/GMaps/gmaps_ajax.php", 381 async: true, 382 data: { ajaxfct:"public.maps.init", category:gmaps.categoryId }, 383 success: 384 function(msg) 385 { 386 gmaps.requestId=msg; 387 388 if(gmaps.maps[gmaps.currentMapLoadIndex].viewportInitialized==false) 389 { 390 /* 391 * if the container is not visible when map are built, they are 392 * not initialized correctly 393 * 394 * when dialog is opened for the first time, proceed to map 395 * finalization : 396 * - resize 397 * - center the map 398 * - add handlers on events 'dragend' and 'zoom_change' 399 * allowing to reload markers according to the new viewport 400 */ 401 google.maps.event.trigger(gmaps.maps[gmaps.currentMapLoadIndex].gMap, 'resize'); 402 403 404 if(gmaps.maps[gmaps.currentMapLoadIndex].fitToBounds) 405 { 406 gmaps.maps[gmaps.currentMapLoadIndex].gMap.fitBounds(gmaps.bounds); 407 } 408 else 409 { 410 gmaps.maps[gmaps.currentMapLoadIndex].gMap.setCenter(gmaps.bounds.getCenter()); 411 } 412 413 // reduce copyright size... ^_^ 414 $('#'+gmaps.maps[gmaps.currentMapLoadIndex].id+' span, #'+gmaps.maps[gmaps.currentMapLoadIndex].id+' a').css('font-size', '55.0%'); 415 416 if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null) 417 gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.currentMapLoadIndex].gMap); 418 419 google.maps.event.addListener( 420 gmaps.maps[gmaps.currentMapLoadIndex].gMap, 421 'dragend', 422 function() 423 { 424 loadMarkers(this); 425 $('#gmapsBoundMap').css('display', 'inline'); 426 $('#gmapsBoundKml').css('display', 'inline'); 427 } 428 ); 429 430 google.maps.event.addListener( 431 gmaps.maps[gmaps.currentMapLoadIndex].gMap, 432 'zoom_changed', 433 function() 434 { 435 loadMarkers(this); 436 gmaps.infoWindow.close(); 437 $('#gmapsBoundMap').css('display', 'inline'); 438 $('#gmapsBoundKml').css('display', 'inline'); 439 } 440 ); 441 442 // loads the markers 443 loadMarkers(gmaps.maps[gmaps.currentMapLoadIndex].gMap); 444 gmaps.maps[gmaps.currentMapLoadIndex].viewportInitialized=true; 445 } 446 447 } 448 } 449 ); 468 initializeMapViewport('open'); 450 469 } 451 470 } … … 453 472 454 473 $('div.gmapsPopup div.ui-dialog-titlebar') 455 .append('<a href="#" id="gmapsBoundMap" style="display:none;" onclick=" gmaps.maps[gmaps.currentMapLoadIndex].gMap.fitBounds(gmaps.bounds); $(this).css(\'display\', \'none\').blur(); return(false);">'+474 .append('<a href="#" id="gmapsBoundMap" style="display:none;" onclick="fitToBounds(gmaps.bounds); $(this).css(\'display\', \'none\').blur(); return(false);">'+ 456 475 '<span>∴</span></a>'); 457 476 $('#gmapsBoundMap').attr('title', gmaps.lang.boundmap); … … 460 479 { 461 480 $('div.gmapsPopup div.ui-dialog-titlebar') 462 .append('<a href="#" id="gmapsBoundKml" onclick=" gmaps.maps[gmaps.currentMapLoadIndex].gMap.fitBounds(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.getDefaultViewport()); $(this).css(\'display\', \'none\').blur(); return(false);">'+481 .append('<a href="#" id="gmapsBoundKml" onclick="fitToBounds(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.getDefaultViewport()); $(this).css(\'display\', \'none\').blur(); return(false);">'+ 463 482 '<span>∼</span></a>'); 464 483 $('#gmapsBoundKml').attr('title', gmaps.lang.boundkml);
Note: See TracChangeset
for help on using the changeset viewer.