source: extensions/GMaps/js/gmapsCategory.min.js @ 11798

Last change on this file since 11798 was 10551, checked in by grum, 13 years ago

bug:2148 - compatibility with piwigo 2.2
bug:2062 - compatibility with IE7

File size: 8.7 KB
Line 
1/* file: gmapsCategory.js - v1.2.1 | minified on 2011/04/21 with http://jscompress.com/ */
2var markerImgProp=[null,{w:32,h:32,x:15,y:31},{w:32,h:32,x:15,y:31},{w:32,h:32,x:10,y:31},{w:30,h:40,x:4,y:39}];function createMap(properties,gmapsIndex)
3{var map=new google.maps.Map($("#"+properties.id).get(0),{backgroundColor:'#ffffff',mapTypeId:properties.mapType,zoom:properties.zoomLevel,center:gmaps.bounds.getCenter(),navigationControl:(properties.navigationControl==-1)?false:true,scrollwheel:(properties.navigationControl==-1)?false:true,scaleControl:(properties.scaleControl=='n')?false:true,streetViewControl:(properties.streetViewControl=='n')?false:true,mapTypeControl:(properties.mapTypeControl==-1)?false:true,mapTypeControlOptions:{style:properties.mapTypeControl},markerTitle:''});if(properties.kmlFileUrl!='')
4{kmlFile=new google.maps.KmlLayer(properties.kmlFileUrl,{preserveViewport:true});kmlFile.setMap(map);}
5else
6{kmlFile=null;}
7re=/^mS(\d\d)_.*/i;iM=re.exec(properties.markerImg);if(iM!=null)iM=new Number(iM[1]);if(iM!=null)
8{map.markerImg=new google.maps.MarkerImage('plugins/GMaps/img/'+properties.markerImg,new google.maps.Size(markerImgProp[iM].w,markerImgProp[iM].h),new google.maps.Point(0,0),new google.maps.Point(markerImgProp[iM].x,markerImgProp[iM].y));}
9else
10{map.markerImg=null;}
11map.kmlFile=kmlFile;map.markers=new Array();map.gmapsIndex=gmapsIndex;map.viewportInitialized=false;map.callId=0;properties.gMap=map;}
12function loadMarkers(map)
13{map.callId++;datas={requestId:gmaps.requestId,callId:map.callId,bounds:{north:map.getBounds().getNorthEast().lat(),east:map.getBounds().getNorthEast().lng(),south:map.getBounds().getSouthWest().lat(),west:map.getBounds().getSouthWest().lng()},width:$(map.getDiv()).width(),height:$(map.getDiv()).height(),distanceTreshold:20,loadIndex:map.gmapsIndex,};$('#gmapsLoading').css('display','inline-block');$('#gmapsNbPhotos').html('');$.ajax({type:"POST",url:"plugins/GMaps/gmaps_ajax.php",async:true,data:{ajaxfct:"public.maps.getMarkers",datas:datas},success:function(msg)
14{tmp=$.parseJSON(msg);if(gmaps.maps[tmp.loadIndex].gMap.callId==tmp.callId)
15{tmp.markers.sort(compareMarkers);applyMarkers(gmaps.maps[tmp.loadIndex].gMap,tmp.markers);$('#gmapsLoading').css('display','none');$('#gmapsNbPhotos').html('['+tmp.datas.nbPhotos+']');}}});}
16function applyMarkers(map,markers)
17{if(map.markers.length>0)
18{var i=0;while(i<map.markers.length)
19{newListIndex=markerInList(map.markers[i].uId,markers);if(newListIndex==-1)
20{map.markers[i].marker.setMap(null);map.markers.splice(i,1);}
21else
22{markers.splice(newListIndex,1);i++;}}}
23for(var i=0;i<markers.length;i++)
24{var marker=new google.maps.Marker({position:new google.maps.LatLng(markers[i].lat,markers[i].lng),map:map,title:markers[i].nbImgTxt});if(map.markerImg!=null)marker.setIcon(map.markerImg);marker.info=markers[i];marker.info.displayed=0;map.markers.push({marker:marker,uId:markers[i].uId});google.maps.event.addListener(marker,'click',function()
25{displayWindowInfo(this);});for(var index=0;index<marker.info.imgTn.length;index++)
26{switch(marker.info.imgTn[index].charAt(0))
27{case'G':marker.info.imgTn[index]='./galleries/'+marker.info.imgTn[index].substr(1);break;case'U':marker.info.imgTn[index]='./upload/'+marker.info.imgTn[index].substr(1);break;}}}}
28function compareMarkers(m1,m2)
29{if(m1.uId<m2.uId)
30{return(-1);}
31else if(m1.uId<m2.uId)
32{return(1);}
33return(0);}
34function markerInList(uniqueId,markerList)
35{for(var i=0;i<markerList.length;i++)
36{if(markerList[i].uId==uniqueId)return(i)}
37return(-1);}
38function displayWindowInfo(marker)
39{gmaps.currentInfo=marker.info;gmaps.infoWindow.close();gmaps.infoWindow.setContent($('#iGMapsInfoWindowContent').clone().each(renameId).get(0));gmaps.infoWindow.open(marker.map,marker);displayPictureInfo(gmaps.currentInfo.displayed);}
40function renameId(i,e)
41{if(e.id!='')e.id='c'+e.id;$(e).children().each(renameId);}
42function displayPictureInfo(index)
43{gmaps.currentInfo.displayed=index;if(gmaps.currentInfo.imgName[index]=='')
44{$('#ciGMIWC_title').html(' ');}
45else
46{$('#ciGMIWC_title').html(gmaps.currentInfo.imgName[index]);}
47$('#ciGMIWC_img').attr('src',gmaps.currentInfo.imgTn[index]);$('#ciGMIWC_img').unbind();if(gmaps.currentInfo.imgCatsUrl[index].length==1)
48{$('#ciGMIWC_img').bind('click',function()
49{window.location=gmaps.currentInfo.imgCatsUrl[gmaps.currentInfo.displayed][0];});}
50else
51{$('#ciGMIWC_showcatList').html('');for(var i=0;i<gmaps.currentInfo.imgCatsUrl[index].length;i++)
52{$('#ciGMIWC_showcatList').append('<li><a href="'+gmaps.currentInfo.imgCatsUrl[index][i]+'">'+gmaps.currentInfo.imgCatsNames[index][i]+'</a></li>');}
53$('#ciGMIWC_img, #ciGMIWC_showcat').bind('mouseenter',function(){$('#ciGMIWC_showcat').css('display','block');}).bind('mouseleave',function(){$('#ciGMIWC_showcat').css('display','none');});}
54if(gmaps.currentInfo.nbImg>1)
55{$('#ciGMIWC_picnum').html((index+1)+'/'+gmaps.currentInfo.nbImgTxt);$('#ciWALeft, #ciWARight').css('display','inline-block');}
56else
57{$('#ciGMIWC_picnum').html(gmaps.currentInfo.nbImgTxt);$('#ciWALeft, #ciWARight').css('display','none');}}
58function displayPicturePrev()
59{gmaps.currentInfo.displayed--;if(gmaps.currentInfo.displayed<0)gmaps.currentInfo.displayed=gmaps.currentInfo.nbImg-1;displayPictureInfo(gmaps.currentInfo.displayed);}
60function displayPictureNext()
61{gmaps.currentInfo.displayed++;if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbImg)gmaps.currentInfo.displayed=0;displayPictureInfo(gmaps.currentInfo.displayed);}
62function fitToBounds(bounds,mapIndex)
63{gmaps.maps[mapIndex].gMap.fitBounds(bounds);if(gmaps.maps[mapIndex].zoomLevelMaxActivated&&gmaps.maps[mapIndex].gMap.getZoom()>gmaps.maps[mapIndex].zoomLevel)
64{gmaps.maps[mapIndex].gMap.setZoom(gmaps.maps[mapIndex].zoomLevel);}}
65function initializeMapViewport(mode,mapIndex)
66{if(mapIndex>-1&&($('#'+gmaps.maps[mapIndex].id+'Content').dialog('isOpen')&&mode=='loaded'||mode=='open')&&(gmaps.maps[mapIndex].gMap.viewportInitialized==false))
67{google.maps.event.trigger(gmaps.maps[mapIndex].gMap,'resize');$('#'+gmaps.maps[mapIndex].id+' span, #'+gmaps.maps[mapIndex].id+' a').css('font-size','55.0%');if(gmaps.geolocated)
68{if(gmaps.maps[mapIndex].fitToBounds)
69{fitToBounds(gmaps.bounds,mapIndex);}
70else
71{gmaps.maps[mapIndex].gMap.setCenter(gmaps.bounds.getCenter());}}
72else
73{fitToBounds(gmaps.maps[mapIndex].gMap.kmlFile.getDefaultViewport(),mapIndex);}
74google.maps.event.addListener(gmaps.maps[mapIndex].gMap,'dragend',function()
75{loadMarkers(this);$('#gmapsBoundMap').css('display','inline');$('#gmapsBoundKml').css('display','inline');});google.maps.event.addListener(gmaps.maps[mapIndex].gMap,'zoom_changed',function()
76{loadMarkers(this);gmaps.infoWindow.close();$('#gmapsBoundMap').css('display','inline');$('#gmapsBoundKml').css('display','inline');});gmaps.maps[mapIndex].gMap.viewportInitialized=true;loadMarkers(gmaps.maps[mapIndex].gMap);}}
77$(window).load(function()
78{gmaps.currentInfo=null;gmaps.bounds=new google.maps.LatLngBounds(new google.maps.LatLng(gmaps.bounds.south,gmaps.bounds.west),new google.maps.LatLng(gmaps.bounds.north,gmaps.bounds.east));gmaps.infoWindow=new google.maps.InfoWindow();google.maps.event.addListener(gmaps.infoWindow,'closeclick',function(){gmaps.infoWindow.setContent('');$('#ciGMIWC_img').unbind();});for(var i=0;i<gmaps.maps.length;i++)
79{createMap(gmaps.maps[i],i);if(gmaps.maps[i].sizeMode=='A')
80{$('#'+gmaps.maps[i].id).css({width:($(window).width()*gmaps.popupAutomaticSize)+'px',height:($(window).height()*gmaps.popupAutomaticSize)+'px'});}
81$('#'+gmaps.maps[i].id+'Content').dialog({autoOpen:false,width:$('#'+gmaps.maps[i].id).width(),height:'auto',modal:true,closeText:'X',dialogClass:'gmapsPopup',title:gmaps.maps[i].title,open:function()
82{$.ajax({type:"POST",url:"plugins/GMaps/gmaps_ajax.php",async:true,data:{ajaxfct:"public.maps.init",category:gmaps.categoryId,mapId:'n'},success:function(msg)
83{gmaps.requestId=msg;for(var i=0;i<gmaps.maps.length;i++)
84{initializeMapViewport('loaded',i);}}});}}).data('index',i);if(gmaps.geolocated)
85{$('div.gmapsPopup div.ui-dialog-titlebar').append('<a href="#" id="gmapsBoundMap" style="display:none;" onclick="fitToBounds(gmaps.bounds, '+i+'); $(this).css(\'display\', \'none\').blur(); return(false);">'+'<span>∴</span></a>');$('#gmapsBoundMap').attr('title',gmaps.lang.boundmap);}
86if(gmaps.maps[i].gMap.kmlFile!=null)
87{$('div.gmapsPopup div.ui-dialog-titlebar').append('<a href="#" id="gmapsBoundKml" onclick="fitToBounds(gmaps.maps['+i+'].gMap.kmlFile.getDefaultViewport(), '+i+'); $(this).css(\'display\', \'none\').blur(); return(false);">'+'<span>∼</span></a>');$('#gmapsBoundKml').attr('title',gmaps.lang.boundkml);}
88$('div.gmapsPopup div.ui-dialog-titlebar').append('<span id="gmapsLoading" style="display:none;"><img src="./plugins/GrumPluginClasses/icons/processing.gif"><span>'+gmaps.lang.loading+'</span></span>');$('#ui-dialog-title-iGMapsIconContent').append('<span id="gmapsNbPhotos"></span>');}});
Note: See TracBrowser for help on using the repository browser.