function AdvancedGoogleMapsDirectory(cartClass, params) { this.params = params; } AdvancedGoogleMapsDirectory.prototype.run = function() { //création $maps = $('#map_canvas').goMap( { latitude: this.params.mp_coordCenterLat, longitude: this.params.mp_coordCenterLng, 'zoom' : this.params.mp_zoom_init, maptype: 'ROADMAP' }); //hook this.hook_init($maps); //ajoute les points addAllSpot(); //centrer la carte en fonction de la position du client geolocUser(); //groupement des points if( this.params.clusterer == true ) { setMarkerclusterer(); } //gestion d'action spe gestionActionSpe(); //centre if( this.params.mp_coordCenterLat == '' || this.params.mp_coordCenterLng == '' ) { $.goMap.fitBounds('visible'); } // $(document).bind("resize", function() { setTimeout(function() { // google.maps.event.trigger($.goMap.map, 'resize'); // $.goMap.fitBounds('visible'); //$maps.resize(); },100) }); }; /** * [hookInit description] * @param {[type]} goMap [description] * @return {[type]} [description] */ AdvancedGoogleMapsDirectory.prototype.hook_init = function(goMap) { } /** * [addAllSpot description] */ function addAllSpot(){ // $.each(mp_maps_datas["collection"], function(idEntry, datas) { //ico var ico = mp_default_spot_ico; //si icone if(typeof(datas.incon) != "undefined") { ico = datas.icon; } // var options = { latitude: datas.lat, longitude: datas.lng, icon: ico, id: idEntry, // group : datas.region }; //affichage description if(typeof(datas.description) == "undefined" || datas.description == '') { options.html = { content: "chargement...", ajax : datas.description_url }; } else { options.html = { content: datas.description }; } //set $.goMap.createMarker(options); }); } /** * centre la carte en fonction de la localisation du client */ function geolocUser(){ // // On vérifie que l'API soit disponible if (!navigator.geolocation){ return; } // navigator.geolocation.getCurrentPosition( function (position) { var lat = position.coords.latitude; var lng = position.coords.longitude; //set $.goMap.setMap({ 'zoom': mp_zoom_geoloc, latitude:lat, longitude:lng, }); },function (error) { // Traitement de l'erreur }, { maximumAge: 0, timeout: 10000 } ); } /** * [setMarkerclusterer description] * @param {[type]} $maps [description] */ function setMarkerclusterer($maps) { //liste marker var markers = []; for (var i in $.goMap.markers) { var temp = $($.goMap.mapId).data($.goMap.markers[i]); markers.push(temp); } // var options = { imagePath: mp_path_group_ico }; //add var markerclusterer = new MarkerClusterer($.goMap.map, markers, options); } /** * gestionActionSpe */ function gestionActionSpe() { //recherche pays $("#landsSearch").change(function(){ searchByLands(this); }); //recherche region $("#regionSearch").change(function(){ searchByRegion(this); }); //recherche ville $(".recherche-ville").on("click", ".btn-search", function(e){ zoomByVille(e.delegateTarget); e.preventDefault(); }); //si focus sur ville $("#villeSearch").focus(function(){ var field = this; //on lance la validation quand entré $("#villeSearch").keypress(function(e){ if( e.keyCode == 13 ){ zoomByVille( $(field).parent() ); e.preventDefault(); } }); }); } /** * [searchByRegion description] * @param {[type]} selecte [description] * @return {[type]} [description] */ function searchByRegion(select) { var address = $(select).find("option:selected").text(); if(address == "") { $.goMap.fitBounds('visible'); } else { $.goMap.setMap({'address': address+", France", 'zoom': mp_zoom_region_search}); } } /** * searchByLands */ function searchByLands(select) { var address = $(select).find("option:selected").text(); if(address == "") { $.goMap.fitBounds('visible'); } else { $.goMap.setMap({'address': address, 'zoom': mp_zoom_lands_search}); } } /** * [zoomByVille description] * @return {[type]} [description] */ function zoomByVille(boxSearch){ //si recherche pa ville if($(boxSearch).find("#villeSearch").val() != ""){ var address = $(boxSearch).find("#villeSearch").val()+", France"; $.goMap.setMap({'address': address, 'zoom': mp_zoom_ville_search}); } }