/** * ----------------------------------------------------------------------------- * file: gmapsMarkup.js * file version: 1.1.2 * date: 2011-09-23 */ var gmapsCM=null, gmapsMM=null; function markupMaps() { 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 */ this.createMap = function (properties, gmapsIndex) { var bounds = new google.maps.LatLngBounds( new google.maps.LatLng(properties.mapBounds.south, properties.mapBounds.west), new google.maps.LatLng(properties.mapBounds.north, properties.mapBounds.east) ), map = new google.maps.Map($("#"+properties.id).get(0), { backgroundColor:'#ffffff', mapTypeId: properties.mapType, zoom: properties.zoomLevel, center: 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.bounds=bounds; map.kmlFile=kmlFile; map.markers=new Array(); map.gmapsIndex=gmapsIndex; map.width=properties.width; map.height=properties.height; map.callId=0; map.allowBubble=properties.allowBubble; map.initialized=false; properties.gMap=map; if(properties.geolocated) { if(properties.fitToBounds) { this.fitToBounds(map.bounds, gmapsIndex); } else { map.setCenter(map.bounds.getCenter()); } } if(properties.markerVisible) { this.loadMarkers(map); } else { this.initializeMapViewport(gmapsIndex); } }; /** * load markers from the server * * @param Map map : the map */ this.loadMarkers = function(map) { var __this=this; if(map.getBounds()==null) return(false); map.callId++; datas={ requestId:gmapsMarkup.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.width, height:map.height, distanceTreshold:20, loadIndex:map.gmapsIndex }; $.ajax( { type: "POST", url: "plugins/GMaps/gmaps_ajax.php", async: true, data: { ajaxfct:"public.maps.getMarkers", token:gmaps.token, datas:datas }, success: function(msg) { tmp=$.parseJSON(msg); if(gmapsMarkup.maps[tmp.loadIndex].gMap.callId==tmp.callId) { tmp.markers.sort(compareMarkers); __this.applyMarkers(gmapsMarkup.maps[tmp.loadIndex].gMap, tmp.markers); __this.initializeMapViewport(tmp.loadIndex); } } } ); }; /** * 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 */ this.applyMarkers = function(map, markers) { if(map==null) return(false); /* * deleting markers from the map only if they are not in the new list */ if(map.markers.length>0) { var i=0; while(i'+gmapsMarkup.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(gmapsMarkup.currentInfo.nbImg>1) { $('#ciGMIWC_picnum').html((index+1)+'/'+gmapsMarkup.currentInfo.nbImgTxt); $('#ciWALeft, #ciWARight').css('display', 'inline-block'); } else { $('#ciGMIWC_picnum').html(gmapsMarkup.currentInfo.nbImgTxt); $('#ciWALeft, #ciWARight').css('display', 'none'); } }; /** * */ this.displayPicturePrev=function() { gmapsMarkup.currentInfo.displayed--; if(gmapsMarkup.currentInfo.displayed<0) gmapsMarkup.currentInfo.displayed=gmapsMarkup.currentInfo.nbImg-1; this.displayPictureInfo(gmapsMarkup.currentInfo.displayed); }; /** * */ this.displayPictureNext=function() { gmapsMarkup.currentInfo.displayed++; if(gmapsMarkup.currentInfo.displayed>=gmapsMarkup.currentInfo.nbImg) gmapsMarkup.currentInfo.displayed=0; this.displayPictureInfo(gmapsMarkup.currentInfo.displayed); }; /** * check if zoomLevel */ this.fitToBounds=function(bounds, mapIndex) { gmapsMarkup.maps[mapIndex].gMap.fitBounds(bounds); if(gmapsMarkup.maps[mapIndex].zoomLevelMaxActivated && gmapsMarkup.maps[mapIndex].gMap.getZoom() > gmapsMarkup.maps[mapIndex].zoomLevel) { gmapsMarkup.maps[mapIndex].gMap.setZoom(gmapsMarkup.maps[mapIndex].zoomLevel); } }; this.initializeMapViewport=function(mapIndex) { var __this=this; if(mapIndex>-1 && !gmapsMarkup.maps[mapIndex].gMap.initialized) { // reduce copyright size... ^_^ $('#'+gmapsMarkup.maps[mapIndex].id+' span, #'+gmapsMarkup.maps[mapIndex].id+' a').css('font-size', '55.0%'); if(gmapsMarkup.maps[mapIndex].markerVisible) { google.maps.event.addListener( gmapsMarkup.maps[mapIndex].gMap, 'dragend', function() { __this.loadMarkers(this); } ); google.maps.event.addListener( gmapsMarkup.maps[mapIndex].gMap, 'zoom_changed', function() { __this.loadMarkers(this); gmapsMarkup.infoWindow.close(); } ); } if(gmapsMarkup.maps[mapIndex].kmlZoom && gmapsMarkup.maps[mapIndex].gMap.kmlFile!=null) { google.maps.event.addListenerOnce( gmapsMarkup.maps[mapIndex].gMap.kmlFile, 'defaultviewport_changed', function() { __this.fitToBounds(gmapsMarkup.maps[mapIndex].gMap.kmlFile.getDefaultViewport(), mapIndex); } ); } gmapsMarkup.maps[mapIndex].gMap.initialized=true; } }; } $(window).load( function () { initInfoWindow(); gmapsMM=new markupMaps(); // all maps have the same initials bounds gmapsMarkup.currentInfo=null; gmapsMarkup.infoWindow = new google.maps.InfoWindow(); google.maps.event.addListener( gmapsMarkup.infoWindow, 'closeclick', function () { gmapsMarkup.infoWindow.setContent(''); $('#ciGMIWC_img').unbind(); } ); /* * initialize map on the server side (call the 'public.maps.init' * function) */ $.ajax( { type: "POST", url: "plugins/GMaps/gmaps_ajax.php", async: true, data: { ajaxfct:"public.maps.init", token:gmaps.token, category:gmapsMarkup.categoryId, mapId:'y' }, success: function(msg) { gmapsMarkup.requestId=msg; for(var i=0;i