Ignore:
Timestamp:
Oct 20, 2010, 10:49:29 PM (14 years ago)
Author:
grum
Message:

fix bug and implement new features
bug:1926, bug:1927, bug:1929, bug:1930, bug:1931, bug:1939, bug:1946

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/GMaps/js/gmapsCategory.js

    r7177 r7308  
    22 * -----------------------------------------------------------------------------
    33 * file: gmapsCategory.js
    4  * file version: 1.0.0
    5  * date: 2010-10-10
     4 * file version: 1.1.0
     5 * date: 2010-10-20
    66 */
    77
     
    8787function loadMarkers(map)
    8888{
     89  gmaps.callId++;
     90
    8991  datas={
    9092    requestId:gmaps.requestId,
     93    callId:gmaps.callId,
    9194    bounds:{
    9295        north:map.getBounds().getNorthEast().lat(),
     
    97100    width:$(map.getDiv()).width(),
    98101    height:$(map.getDiv()).height(),
    99     distanceTreshold:20
     102    distanceTreshold:20,
    100103  };
    101104
     
    104107  $('#gmapsLoading').css('display', 'inline-block');
    105108  $('#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   );
    115109
    116110  $.ajax(
     
    124118        {
    125119          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          }
    131127        }
    132128    }
     
    140136 * @param Array markers : array of markers properties
    141137 *                        each marker is an object with properties :
    142  *                          latitude, longitude, nbImages
     138 *                          latitude, longitude, nbImg
    143139 */
    144140function applyMarkers(map, markers)
     
    154150    while(i<map.markers.length)
    155151    {
    156       newListIndex=markerInList(map.markers[i].uniqueId, markers);
     152      newListIndex=markerInList(map.markers[i].uId, markers);
    157153      if(newListIndex==-1)
    158154      {
     
    189185      {
    190186        marker:marker,
    191         uniqueId:markers[i].uniqueId
     187        uId:markers[i].uId
    192188      }
    193189    );
     
    207203function compareMarkers(m1,m2)
    208204{
    209   if(m1.uniqueId<m2.uniqueId)
     205  if(m1.uId<m2.uId)
    210206  {
    211207    return(-1);
    212208  }
    213   else if(m1.uniqueId<m2.uniqueId)
     209  else if(m1.uId<m2.uId)
    214210  {
    215211    return(1);
     
    222218  for(var i=0;i<markerList.length;i++)
    223219  {
    224     if(markerList[i].uniqueId==uniqueId) return(i)
     220    if(markerList[i].uId==uniqueId) return(i)
    225221  }
    226222  return(-1);
     
    286282  }
    287283
    288   if(gmaps.currentInfo.nbImages>1)
     284  if(gmaps.currentInfo.nbImg>1)
    289285  {
    290286    $('#ciGMIWC_picnum').html((index+1)+'/'+gmaps.currentInfo.nbImgTxt);
     
    304300{
    305301  gmaps.currentInfo.displayed--;
    306   if(gmaps.currentInfo.displayed<0) gmaps.currentInfo.displayed=gmaps.currentInfo.nbImages-1;
     302  if(gmaps.currentInfo.displayed<0) gmaps.currentInfo.displayed=gmaps.currentInfo.nbImg-1;
    307303  displayPictureInfo(gmaps.currentInfo.displayed);
    308304}
     
    314310{
    315311  gmaps.currentInfo.displayed++;
    316   if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbImages) gmaps.currentInfo.displayed=0;
     312  if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbImg) gmaps.currentInfo.displayed=0;
    317313  displayPictureInfo(gmaps.currentInfo.displayed);
    318314}
    319315
    320316
     317/**
     318 * check if zoomLevel
     319 */
     320function 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
     331function 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
    321396$(window).load(function ()
    322397  {
    323     // all maps have the same intials bounds
     398    // all maps have the same initials bounds
    324399    gmaps.currentInfo=null;
     400    gmaps.currentMapLoadIndex=-1;
    325401
    326402    gmaps.bounds = new google.maps.LatLngBounds(
     
    351427        $('#'+gmaps.maps[i].id).css(
    352428          {
    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'
    355431          }
    356432        );
    357433      }
     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
    358454
    359455      // initialize dialog box for maps
     
    370466            {
    371467              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');
    450469            }
    451470        }
     
    453472
    454473      $('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);">'+
    456475              '<span>&there4;</span></a>');
    457476      $('#gmapsBoundMap').attr('title', gmaps.lang.boundmap);
     
    460479      {
    461480        $('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);">'+
    463482                  '<span>&sim;</span></a>');
    464483        $('#gmapsBoundKml').attr('title', gmaps.lang.boundkml);
Note: See TracChangeset for help on using the changeset viewer.