// JavaScript Document // Copyright 2006 Jean-Marc Reymund // jeanmarc_reymund@yahoo.fr // version 1.0 (13/06/2006) /* * function de creation gmap */ function gmapTool () { var glt = 48.8563575709925; // lattitude origine var gln = 2.452869415283203; // longitude origine var gplotsUrl = "/gmap/anncities/"; // url a appeler pour les points var gcitInfUrl = "/gmap/cityinfos/"; // url contenus des popup info (city) var gcprInfUrl = "/gmap/cityinfospro/"; // url contenus des popup info (city pro) var gproInfUrl = "/gmap/proinfos/"; // url contenus des popup info (pro) var ginfoAction = "getInfosCityData"; // infoZoom / getInfosCityData / getInfosCityProData var gminimap = true; var gplotNum = 66; // nbr de points var gidRub = 4; // rubrique var glevel = 12; // niveau de zoom par defaut var gmapId = "map"; // id de la map var glnmin = null; // longitude min var glnmax = null; // longitude max var gltmin = null; // latitude min var gltmax = null; // latitude max var gplots = Array(); // liste des points (ville) var gpros = Array(); // liste des points (pro) var gproCount = 0; // nombre de pro sur la carte var gplotCount = 0; // nombre de point sur la carte var gmap = null; // instance de objet gmap var geocoder = null; // instance de objet geocodage pour localiser (lg/lt) une adresse var infoIcon = new GIcon(); infoIcon.image = "http://www.refleximmo.com/img/gmap/plot_info.png"; infoIcon.shadow = "http://www.refleximmo.com/img/gmap/plot_shadow.png"; infoIcon.iconSize = new GSize(15, 22); infoIcon.shadowSize = new GSize(33, 26); infoIcon.iconAnchor = new GPoint(7, 22); infoIcon.infoWindowAnchor = new GPoint(5, 0); var proIcon = new GIcon(); proIcon.image = "http://www.refleximmo.com/img/gmap/plot_pro.png"; proIcon.shadow = "http://www.refleximmo.com/img/gmap/plot_shadow.png"; proIcon.iconSize = new GSize(15, 22); proIcon.shadowSize = new GSize(33, 26); proIcon.iconAnchor = new GPoint(7, 22); proIcon.infoWindowAnchor = new GPoint(5, 0); /* * chargement api google et init divers */ this.load = function () { if (GBrowserIsCompatible()) { gmap = new GMap2(document.getElementById(gmapId)); geocoder = new GClientGeocoder(); GEvent.addListener(gmap, "zoomend", function() { eval(gmapId+".chgZoom();"); }); GEvent.addListener(gmap, "move", function() { eval(gmapId+".chgLgLt();"); }); gmap.addControl(new GSmallMapControl()); gmap.addControl(new GMapTypeControl()); gmap.addControl(new GScaleControl()); if (gminimap) { gmap.addControl(new GOverviewMapControl()); } gmap.setCenter(new GLatLng(glt, gln), glevel); } } /* * action lors d un changement lg lt */ this.chgLgLt = function () { var gresult = this.lnltInit(false); if (gresult) { this.getPlotsData(); } } /* * action lors d un changement de zoom */ this.chgZoom = function () { this.cleanMap(); if (gmap.getZoom() < 5) { gmap.setZoom(5); } if (gmap.getZoom() < 14) { if (ginfoAction == "getInfosCityProData") { ginfoAction = "infoZoom"; } }else { if (ginfoAction == "infoZoom") { ginfoAction = "getInfosCityProData"; } } if (gmap.getZoom() > 17) { gmap.setZoom(17); } glevel = gmap.getZoom(); this.lnltInit(true); this.getPlotsData(); } /* * recalcul les ln lt en cas de deplacement */ this.lnltInit = function (init) { var center = gmap.getCenter(); var bounds = gmap.getBounds(); var NE = bounds.getNorthEast(); var SW = bounds.getSouthWest(); var NEln = NE.lng(); var NElt = NE.lat(); var SWln = SW.lng(); var SWlt = SW.lat(); var width = Math.abs(NEln-SWln); var height = Math.abs(NElt-SWlt); gln = center.lng(); glt = center.lat(); if (gln > (glnmin+width*3/2) || gln < (glnmax-width*3/2) || glt > (gltmin+height*3/2) || glt < (gltmax-height*3/2) || init) { glnmin = 1*SWln-width/2; glnmax = 1*NEln+width/2; gltmin = 1*SWlt-height/2; gltmax = 1*NElt+height/2; return true; } return false; } /* * recuperation des donnes serveurs */ this.getAjaxData = function (url,exec) { //document.getElementById("url").innerHTML = url; var xhr = new XHR(); xhr.setUrl(url); xhr.setSync(true); xhr.setOutPut("xml"); xhr.execRequest(exec); } /* * recuperation des villes */ this.getPlotsData = function () { var crit = this.getCriteresData(); var url = gplotsUrl+"lnmin/"+glnmin+"/ltmin/"+gltmin+"/lnmax/"+glnmax+"/ltmax/"+gltmax+"/echelle/"+glevel+"/num/"+gplotNum+"/idrub/"+gidRub+"/"+crit; this.getAjaxData(url, gmapId+".dispPlots"); // recuperation des informations pour creer la map } /* * Affichage des points sur la carte */ this.dispPlots = function (data) { if (gproCount > gplotNum*5 || gplotCount > gplotNum*5) { this.cleanMap(); } var gplotsList = data.getElementsByTagName("plots"); for (i=0; i 0) { for (i=0; i" +"Ville : " +"" +"" +" " +"" +"" +"" + label + " (" + cp + ")" +"" +"" +" " +"" +"" +"Population : " +"" +"" +" " +"" +"" +"" + popul + " habitants " +"" +"" +" " +"" +"" +"" +"" +"" + total_ann + " annonce(s) dans cette ville
" +""; if (total_pro != "") { infos += "" +" " +"" +"" +"" +"" +"" + total_pro + " pro(s) dans cette ville" +""; } infos += "
"; updateLastMinutPA(id, cp); eval("gplots["+id+"].openInfoWindowHtml(\"" + infos + "\");"); } } /* * Creation de la bulle information ville pro */ this.createCityInfosProWindow = function (data) { if (data != null) { if (getValueByName("geo_prefix", data) != "") { var label = getValueByName("geo_prefix", data)+" "+getValueByName("geo_label", data); } else { var label = getValueByName("geo_label", data); } var rewrite = getValueByName("geo_rewrite", data); var cp = getValueByName("geo_cp", data); var popul = getValueByName("geo_pop", data); var id = getValueByName("id_geo", data); var total_ann = getValueByName("total_ann", data); var total_pro = getValueByName("total_pro", data); var crit = this.getCriteresData(); var pro = ""; if (data.getElementsByTagName("pros")[0].hasChildNodes()) { var pro = "
"; var items = data.getElementsByTagName("pros")[0].getElementsByTagName("item"); pro +="" +"" +"" +"" +"" +"" +"" +"" +""; for (i = 0; i" +"" +"
" +"" +"
" +"" +"" +"" +""; } pro += "
 
" +"Dans cette ville :
Pas de géolocalisation pour " + total_pro + " pro(s) :" +"
 
" +"" +"" + pro_nom + "
" +pro_adr +"
 

" } var infos = "" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"
Ville :
 
" + label + " (" + cp + ")
 
Population :
 
" + popul + " habitants
 

" +pro; eval("gplots["+id+"].openInfoWindowHtml(\""+infos+"\");"); } } /* * Creation de la bulle information ville */ this.createProInfosWindow = function (data) { var id = getValueByName("id_pro", data); var nom = getValueByName("pro_nom", data); var adresse = getValueByName("pro_adresse", data); var cp = getValueByName("pro_cp", data); var ville = getValueByName("pro_ville", data); var tel = getValueByName("pro_tel", data); var fax = getValueByName("pro_fax", data); var logo = getValueByName("pro_logo", data); var target = getValueByName("pro_style", data); if (target != "") { target = " target='blank' "; } if (logo == "") { var logo = "http://www.refleximmo.com/img/no_logo.gif"; } else{ var logo = "http://194.2.229.56/logo/" + logo; } nom = nom.replace(/\r/, " "); nom = nom.replace(/\n/, " "); adresse = adresse.replace(/\r/, " "); adresse = adresse.replace(/\n/, " "); var infos = "" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"
" + nom + "
" + adresse + "
" + ville + " (" + cp + ")
 
Tél. : " + tel + "
 
Fax : " + fax + "
 

"; if(data.getElementsByTagName("annonce")[0].hasChildNodes()) { var pa =""; var items = data.getElementsByTagName("annonce")[0].getElementsByTagName("item"); for (i = 0; i - "; } if (piece == 0 || piece == "") { piece = ""; } else { piece = ""+piece+" pièce(s) - "; } pa +="" +"" +"" +"" +"" +""; } var total = getValueByName("total", data); pa += "" +"" +"" +"" +"" +"" +"" +"" +"" +"
" +""+a_ville+" "+a_cp+" - " + piece + surface + prix +"
 
 
" +"Voir la totalité des annonces de ce professionnel" +"
 

"; var infoTabs = [ new GInfoWindowTab("Infos", infos), new GInfoWindowTab("Annonces", pa) ]; eval("gpros["+id+"].openInfoWindowTabsHtml(infoTabs);"); } else { eval("gpros["+id+"].openInfoWindowHtml(\""+infos+"\");"); } } /* * efface la map */ this.cleanMap = function () { gmap.clearOverlays(); gplots = Array(); gpros = Array(); gproCount = 0; gplotCount = 0; } /* * recuperation des criteres pour url */ this.getCriteresData = function() { var prixmin = document.getElementById("prixMin"); var prixmax = document.getElementById("prixMax"); var surfmin = document.getElementById("surfaceMin"); var surfmax = document.getElementById("surfaceMax"); var piecmin = document.getElementById("pieceMin"); var piecmax = document.getElementById("pieceMax"); var keyword = document.getElementById("key"); if (prixmin != null) {prixmin = prixmin.value;} else {prixmin = "";} if (prixmax != null) {prixmax = prixmax.value;} else {prixmax = "";} if (surfmin != null) {surfmin = surfmin.value;} else {surfmin = "";} if (surfmax != null) {surfmax = surfmax.value;} else {surfmax = "";} if (piecmin != null) {piecmin = piecmin.value;} else {piecmin = "";} if (piecmax != null) {piecmax = piecmax.value;} else {piecmax = "";} if (keyword != null) {keyword = keyword.value;} else {keyword = "";} if (prixmin == undefined) {prixmin = "";} if (prixmax == undefined) {prixmax = "";} if (surfmin == undefined) {surfmin = "";} if (surfmax == undefined) {surfmax = "";} if (piecmin == undefined) {piecmin = "";} if (piecmax == undefined) {piecmax = "";} if (keyword == undefined) {keyword = "";} return "prixMin/"+prixmin+"/prixMax/"+prixmax+"/surfaceMin/"+surfmin+"/surfaceMax/"+surfmax+"/pieceMin/"+piecmin+"/pieceMax/"+piecmax+"/keywords/"+keyword+"/"; } /* * effectue un zoom sur le clic */ this.infoZoom = function (id, lon, lat) { gmap.setCenter(new GLatLng(lat, lon), 17); } /* * definit le nom de la carte */ this.setMapName = function (data) { gmapId = data; } /* * definit le centre de la carte */ this.setLonLat = function (x, y) { gln = x; glt = y; } /* * definit plotsUrl */ this.setPlotsUrl = function (data) { gplotsUrl = data; } /* * definit infoType */ this.setInfoAction = function (data) { ginfoAction = data; } /* * definit le niveau de zoom */ this.setZLevel = function (data) { glevel = data; } /* * definit id rubrique */ this.setIdRub = function (data) { gidRub = data; } /* * nbr point sur la map */ this.setPlotNum = function (data) { gplotNum = data; } /* * minimap (true flase) */ this.setMiniMap = function (data) { gminimap = data; } } function getValueByName(name, doc) { if (doc.getElementsByTagName(name).length > 0) { if (doc.getElementsByTagName(name)[0].hasChildNodes()) { return doc.getElementsByTagName(name)[0].childNodes[0].nodeValue; } } return ""; } function deg2rad(value) { return Math.round((value*Math.PI/180)*100000)/100000; } function rad2deg(value) { return Math.round((value*180/Math.PI)*100000)/100000; }