/** * ----------------------------------------------------------------------------- * file: gmapsCategory.js * file version: 1.2.0 * date: 2010-11-04 */ var markerImgProp = [ null, { w:32, h:32, x:15, y:31 }, // s01 { w:32, h:32, x:15, y:31 }, // s02 { w:32, h:32, x:10, y:31 }, // s03 { w:30, h:40, x:4, y:39 }, // s04 ]; /** * create the map * * @param Object properties : map properties * @param Integer gmapsIndex : index in the map list */ function createMap(properties, gmapsIndex) { 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!='') { kmlFile = new google.maps.KmlLayer(properties.kmlFileUrl, { preserveViewport:true } ); kmlFile.setMap(map); } else { kmlFile=null; } re=/^mS(\d\d)_.*/i; iM=re.exec(properties.markerImg); if(iM!=null) iM=new Number(iM[1]); if(iM!=null) { 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)); } else { map.markerImg = null; } map.kmlFile=kmlFile; map.markers=new Array(); map.gmapsIndex=gmapsIndex; map.viewportInitialized=false; map.callId=0; properties.gMap=map; } /** * load markers from the server * * @param Map map : the map */ function loadMarkers(map) { 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) { tmp=$.parseJSON(msg); if(gmaps.maps[tmp.loadIndex].gMap.callId==tmp.callId) { tmp.markers.sort(compareMarkers); applyMarkers(gmaps.maps[tmp.loadIndex].gMap, tmp.markers); $('#gmapsLoading').css('display', 'none'); $('#gmapsNbPhotos').html('['+tmp.datas.nbPhotos+']'); } } } ); } /** * apply markers to map * * @param Map map : the google map object * @param Array markers : array of markers properties * each marker is an object with properties : * latitude, longitude, nbImg */ function applyMarkers(map, markers) { /* * deleting markers from the map only if they are not in the new list */ if(map.markers.length>0) { var i=0; while(i'+gmaps.currentInfo.imgCatsNames[index][i]+''); } $('#ciGMIWC_img, #ciGMIWC_showcat') .bind('mouseenter', function () { $('#ciGMIWC_showcat').css('display', 'block'); } ) .bind('mouseleave', function () { $('#ciGMIWC_showcat').css('display', 'none'); } ); } if(gmaps.currentInfo.nbImg>1) { $('#ciGMIWC_picnum').html((index+1)+'/'+gmaps.currentInfo.nbImgTxt); $('#ciWALeft, #ciWARight').css('display', 'inline-block'); } else { $('#ciGMIWC_picnum').html(gmaps.currentInfo.nbImgTxt); $('#ciWALeft, #ciWARight').css('display', 'none'); } } /** * */ function displayPicturePrev() { gmaps.currentInfo.displayed--; if(gmaps.currentInfo.displayed<0) gmaps.currentInfo.displayed=gmaps.currentInfo.nbImg-1; displayPictureInfo(gmaps.currentInfo.displayed); } /** * */ function displayPictureNext() { gmaps.currentInfo.displayed++; if(gmaps.currentInfo.displayed>=gmaps.currentInfo.nbImg) gmaps.currentInfo.displayed=0; displayPictureInfo(gmaps.currentInfo.displayed); } /** * check if zoomLevel */ function fitToBounds(bounds, mapIndex) { gmaps.maps[mapIndex].gMap.fitBounds(bounds); if(gmaps.maps[mapIndex].zoomLevelMaxActivated && gmaps.maps[mapIndex].gMap.getZoom() > gmaps.maps[mapIndex].zoomLevel) { gmaps.maps[mapIndex].gMap.setZoom(gmaps.maps[mapIndex].zoomLevel); } } function initializeMapViewport(mode, mapIndex) { if(mapIndex>-1 && ($('#'+gmaps.maps[mapIndex].id+'Content').dialog('isOpen') && mode=='loaded' || mode=='open') && (gmaps.maps[mapIndex].gMap.viewportInitialized==false) ) { /* * if the container is not visible when map are built, they are * not initialized correctly * * when dialog is opened for the first time, proceed to map * finalization : * - resize * - center the map * - add handlers on events 'dragend' and 'zoom_change' * allowing to reload markers according to the new viewport */ google.maps.event.trigger(gmaps.maps[mapIndex].gMap, 'resize'); // reduce copyright size... ^_^ $('#'+gmaps.maps[mapIndex].id+' span, #'+gmaps.maps[mapIndex].id+' a').css('font-size', '55.0%'); if(gmaps.geolocated) { if(gmaps.maps[mapIndex].fitToBounds) { fitToBounds(gmaps.bounds, mapIndex); } else { gmaps.maps[mapIndex].gMap.setCenter(gmaps.bounds.getCenter()); } } else { fitToBounds(gmaps.maps[mapIndex].gMap.kmlFile.getDefaultViewport(), mapIndex); } google.maps.event.addListener( gmaps.maps[mapIndex].gMap, 'dragend', function() { loadMarkers(this); $('#gmapsBoundMap').css('display', 'inline'); $('#gmapsBoundKml').css('display', 'inline'); } ); google.maps.event.addListener( gmaps.maps[mapIndex].gMap, 'zoom_changed', function() { loadMarkers(this); gmaps.infoWindow.close(); $('#gmapsBoundMap').css('display', 'inline'); $('#gmapsBoundKml').css('display', 'inline'); } ); gmaps.maps[mapIndex].gMap.viewportInitialized=true; loadMarkers(gmaps.maps[mapIndex].gMap); } } $(window).load(function () { // all maps have the same initials bounds 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 () { //$('body').append($('#iGMapsInfoWindowContent')); gmaps.infoWindow.setContent(''); $('#ciGMIWC_img').unbind(); } ); for(var i=0;i