// (C)opyright N-Gine Innovation 2008 - Tous droits réservés // http://www.ngine-innovation.com var DebugPoly = new Array(); var baseIconSingles = new Array(); // une icone pour chaque catégorie de lieu (musée, monument, etc.) var baseIconMultiple = null; // une seule icone pour les regroupements // variables à surcharger var ImgMarkerMultiple = 'Images/GMarker/bleu.png'; var ImgMarkerMultipleHighlight = 'Images/GMarker/bleub.png'; var MWCloseBtnAction = null; var MWZoomBtnAction = null; // ---------------------------------------------------------------------------------------------------------------------- function getImgSize(imgSrc) { Size = imgSrc.split( '_'); return new Array( Size[1], Size[2]); } // ********************************************************************************************************************** // ********************************************************************************************************************** // Classe GeoMap // ********************************************************************************************************************** // ********************************************************************************************************************** // ---------------------------------------------------------------------------------------------------------------------- // Constructeur : // DivID : id du div conteneur de la carte // Tableau des évènements // MapType : optionnel. Spécifie le type de carte. Valeurs possibles : G_NORMAL_MAP (par défaut), G_SATELLITE_MAP, G_HYBRID_MAP, G_PHYSICAL_MAP function GeoMap( DivID, Tab, MapType) { this.IDGMap = DivID; this.GMap = null; this.ZoomControlMoteur=null; this.MTControlMoteur=null; this.geocoder = null; // Tableau des marqueurs this.MarkerList = null; this.ImgMarkerSingles = new Array(); //ImgMarkerSingles; this.IconSingle = null; this.ImgMarkerSingleHighlights = new Array(); //ImgMarkerSingleHighlights; this.IconSingleH = null; this.ImgMarkerMultiple = ImgMarkerMultiple; this.IconMultiple = null; this.ImgMarkerMultipleHighlight = ImgMarkerMultipleHighlight; this.IconMultipleH = null; // 04/02/2008 // this.TabEvent = Tab; this.TabEvent = new Array; this.MouseOverMark = null; this.MouseOutMark = null; this.MouseClickMark = null; // Creation de la carte Google this.GMap = new GMap2(document.getElementById( this.IDGMap)); // Cache par défaut : la carte est doublée this.CacheX = 1; this.CacheY = 1; this.CacheBound = new GBounds; // Création de la zone d'affichage du tooltip this.GMap.TooltipDiv = document.createElement("div"); this.GMap.TooltipDiv.className = "ToolTip"; this.GMap.TooltipDiv.style.zIndex = 2; document.getElementById(this.IDGMap).appendChild(this.GMap.TooltipDiv); this.GMap.TooltipDiv.style.visibility="hidden"; // Création de la zone d'affichage de la bulle d'aide // MegaWindow appartient à GMAp pour pouvoir y accéder depuis les évènements this.GMap.MegaMarker = null; this.GMap.MegaWindowDiv = document.createElement("div"); //this.GMap.MegaWindowDiv.className = "MegaWindow"; this.GMap.MegaWindowDiv.style.zIndex = 2; this.GMap.MegaWindowDiv.innerHTML = '' + '' + '
'; this.GMap.MegaWindowContentDiv = document.getElementById("MegaWindowContent1"); document.getElementById(this.IDGMap).appendChild(this.GMap.MegaWindowDiv); //document.getElementsByTagName("body")[0].appendChild(this.GMap.MegaWindowDiv); this.GMap.MegaWindowDiv.style.visibility="hidden"; /*if (this.TabEvent) { for (var i = 0; i < this.TabEvent.TabEvt.length; i++) { if ( this.TabEvent.TabEvt[i].EventName == "onMarkerClick") this.MouseClickMark = this.TabEvent.TabEvt[i].Fonction; else { GEvent.addListener( this.GMap, this.TabEvent.TabEvt[i].EventName, this.TabEvent.TabEvt[i].Fonction); } } }*/ this.click = GEvent.addListener(this.GMap, 'click', this.OnClick); this.move = GEvent.addListener(this.GMap, 'move', this.OnMove); if (Tab) { for (var i = 0; i < Tab.TabEvt.length; i++) { if ( Tab.TabEvt[i].EventName == "onMarkerClick") this.MouseClickMark = Tab.TabEvt[i].Fonction; else { this.TabEvent.push( GEvent.addListener( this.GMap, Tab.TabEvt[i].EventName, Tab.TabEvt[i].Fonction)); } } this.GMap.addMapType(G_PHYSICAL_MAP); if (MapType) this.GMap.setMapType(MapType); else this.GMap.setMapType(G_NORMAL_MAP); } // -------------------------------------------------------------------------------------------------------------------- this.setCacheSize = function( X, Y){ // 04/02/2008 if ( this.MarkerList != null) this.MarkerList.Clear(); this.CacheX = X; this.CacheY = Y; var Lng1, Lng2, Lat1, Lat2; var X1, X2, Y1, Y2; var DeltaX, DeltaY; X1 = this.getCoordLeft(); X2 = this.getCoordRight(); Y1 = this.getCoordTop(); Y2 = this.getCoordBottom(); Lng1 = Math.min( X1, X2); Lng2 = Math.max( X1, X2); Lat1 = Math.min( Y1, Y2); Lat2 = Math.max( Y1, Y2); DeltaX = ( Lng2 - Lng1) / (1/this.CacheX); DeltaY = ( Lat2 - Lat1) / (1/this.CacheY); Lng1 -= DeltaX; Lng2 += DeltaX; Lat1 -= DeltaY; Lat2 += DeltaY; if ( this.CacheBounds != null) delete this.CacheBounds; this.CacheBounds = new GLatLngBounds(); this.CacheBounds.extend( new GLatLng( Lat1, Lng1)); this.CacheBounds.extend( new GLatLng( Lat2, Lng2)); } // -------------------------------------------------------------------------------------------------------------------- this.isViewPortInCache = function(){ if ( this.CacheBounds) return( this.CacheBounds.containsBounds( this.GMap.getBounds())); else return false; } // -------------------------------------------------------------------------------------------------------------------- this.isMarkerVisible = function(lat, lng){ return this.GMap.getBounds().containsLatLng( new GLatLng( lat, lng)); } // -------------------------------------------------------------------------------------------------------------------- this.setMouseOverMark = function (fn){ this.MouseOverMark = fn; } // -------------------------------------------------------------------------------------------------------------------- this.setMouseOutMark = function (fn){ this.MouseOutMark = fn; } // -------------------------------------------------------------------------------------------------------------------- this.setMouseClickMark = function (fn){ this.MouseClickMark = fn; } // -------------------------------------------------------------------------------------------------------------------- // Images des marqueurs this.setSingleMarkUrl = function (Category, url){ baseIconSingles[Category] = new GIcon(); var size = getImgSize( url); if ( (size[0] == 0) || ( size[1]==0)) { size[0] = 32; size[1] = 32; } baseIconSingles[Category].iconSize = new GSize(size[0], size[1]); baseIconSingles[Category].iconAnchor = new GPoint(size[0] / 2, size[1] / 2); baseIconSingles[Category].infoWindowAnchor = new GPoint(size[0] / 2, size[1] / 2); this.ImgMarkerSingles[Category] = url; } // -------------------------------------------------------------------------------------------------------------------- this.setMultipleMarkUrl = function ( url){ baseIconMultiple = new GIcon(); var size = getImgSize( url); if ( (size[0] == 0) || ( size[1]==0)) { size[0] = 32; size[1] = 32; } baseIconMultiple.iconSize = new GSize(size[0], size[1]); baseIconMultiple.iconAnchor = new GPoint(size[0] / 2, size[1] / 2); baseIconMultiple.infoWindowAnchor = new GPoint(size[0] / 2, size[1] / 2); this.ImgMarkerMultiple = url; } // -------------------------------------------------------------------------------------------------------------------- this.setSingleMarkHighlighUrl = function (Category, url){ this.ImgMarkerSingleHighlights[Category] = url; } // -------------------------------------------------------------------------------------------------------------------- this.setMultipleMarkHighlightUrl = function ( url){ this.ImgMarkerMultipleHighlight = url; } // -------------------------------------------------------------------------------------------------------------------- // Récupération des coordonnées de la carte this.getCoordLeft = function(){ if (this.GMap) return this.GMap.getBounds().getNorthEast().lng(); } // -------------------------------------------------------------------------------------------------------------------- this.getCoordTop = function(){ if (this.GMap) return this.GMap.getBounds().getNorthEast().lat(); } // -------------------------------------------------------------------------------------------------------------------- this.getCoordBottom = function(){ if (this.GMap) return this.GMap.getBounds().getSouthWest().lat(); } // -------------------------------------------------------------------------------------------------------------------- this.getCoordRight = function(){ if (this.GMap) return this.GMap.getBounds().getSouthWest().lng(); } // -------------------------------------------------------------------------------------------------------------------- this.GMap.ShowTooltip = function(MyMarker) { // on affiche un tooltip seulement : // - s'il y a du texte à afficher ET // - si la MegaWindow n'est pas visible (La MegaWindow a la priorité sur le tooltip) if ((MyMarker.TooltipContent == null) || (this.MegaWindowDiv.style.visibility == "visible")) return; this.TooltipDiv.innerHTML = MyMarker.TooltipContent; var point=this.getCurrentMapType().getProjection().fromLatLngToPixel(this.getBounds().getSouthWest(),this.getZoom()); var offset=this.getCurrentMapType().getProjection().fromLatLngToPixel(MyMarker.GMark.getPoint(),this.getZoom()); var anchor=MyMarker.GMark.getIcon().iconAnchor; var width=MyMarker.GMark.getIcon().iconSize.width; var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x, -offset.y + point.y + anchor.y)); pos.apply(this.TooltipDiv); this.TooltipDiv.style.visibility="visible"; } // -------------------------------------------------------------------------------------------------------------------- this.GMap.HideTooltip = function() { this.TooltipDiv.style.visibility="hidden"; SupprimeHierarchieDOM(this.TooltipDiv); } // -------------------------------------------------------------------------------------------------------------------- this.GMap.UpdateMegaWindowInnerHTML = function(InnerHTML) { SupprimeHierarchieDOM(this.MegaWindowContentDiv); this.MegaWindowContentDiv.innerHTML = InnerHTML; } // -------------------------------------------------------------------------------------------------------------------- this.GMap.ShowMegaWindowPrivate = function(MyMarker, InnerHTML, ZoomAction, CloseAction) { this.HideTooltip(); this.MegaMarker = MyMarker; // GDownloadUrl(Url, function(data, responseCode) { // // To ensure against HTTP errors that result in null or bad data, // // always check status code is equal to 200 before processing the data // if(responseCode == 200) { // this.MegaWindowContentDiv = document.getElementById("MegaWindowContent1"); // this.MegaWindowContentDiv.innerHTML = data; // } else if(responseCode == -1) { // this.MegaWindowContentDiv.innerHTML = "Data request timed out. Please try later."; // } else { // this.MegaWindowContentDiv.innerHTML = "Request resulted in error. Check XML file is retrievable."; // } // }); this.MegaWindowContentDiv = document.getElementById("MegaWindowContent1"); this.UpdateMegaWindowInnerHTML(InnerHTML); MWZoomBtnAction = ZoomAction; MWCloseBtnAction = CloseAction; this.UpdateMegaWindowPosition(); this.MegaWindowDiv.style.visibility="visible"; } // -------------------------------------------------------------------------------------------------------------------- this.GMap.UpdateMegaWindowPosition = function() { var point=this.getCurrentMapType().getProjection().fromLatLngToPixel(this.getBounds().getSouthWest(),this.getZoom()); var offset=this.getCurrentMapType().getProjection().fromLatLngToPixel(this.MegaMarker.getPoint(),this.getZoom()); var anchor=this.MegaMarker.getIcon().iconAnchor; var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x, -offset.y + point.y + anchor.y)); pos.apply(this.MegaWindowDiv); } // -------------------------------------------------------------------------------------------------------------------- this.GMap.ShowMegaWindow = function(MyMarker, InnerHTML, ZoomAction, CloseAction) { this.savePosition(); this.ShowMegaWindowPrivate(MyMarker, InnerHTML, ZoomAction, CloseAction); } // -------------------------------------------------------------------------------------------------------------------- // Pan sur la carte de facon à ce que le marqueur soit positionné dans la zone délimitée par (MinX, MaxX, MinY, MaxY) exprimés en % de 0 à 1 this.GMap.ShowMegaWindowAndPan = function(MyMarker, InnerHTML, ZoomAction, CloseAction, MinX, MaxX, MinY, MaxY) { var latlng = MyMarker.getLatLng(); var coord = this.fromLatLngToContainerPixel(latlng); var dim = this.getSize(); var deltaX = 0; var deltaY = 0; if (coord.x > dim.width * MaxX) deltaX = dim.width * MaxX - coord.x; else if (coord.x < dim.width * MinX) deltaX = dim.width * MinX - coord.x; if (coord.y > dim.height * MaxY) deltaY = dim.height * MaxY - coord.y; else if (coord.y < dim.height * MinY) deltaY = dim.height * MinY - coord.y; //alert (deltaX + ', ' + deltaY); this.savePosition(); this.panBy(new GSize(deltaX, deltaY)); this.ShowMegaWindowPrivate(MyMarker, InnerHTML, ZoomAction, CloseAction); } // -------------------------------------------------------------------------------------------------------------------- this.GMap.HideMegaWindow = function() { this.MegaMarker = null; this.MegaWindowDiv.style.visibility="hidden"; SupprimeHierarchieDOM(this.MegaWindowContentDiv); this.returnToSavedPosition(); } // -------------------------------------------------------------------------------------------------------------------- this.GMap.IsMegaWindowVisible = function() { return (this.MegaWindowDiv.style.visibility == "visible"); } } // ---------------------------------------------------------------------------------------------------------------------- //04/02/2008 GeoMap.prototype.Clear = function(){ // Nettoyage mémoire this.DeleteMarkers(); delete CacheBounds; delete this.Center; for (var j= this.TabEvent.length-1; j>=0; j--) { GEvent.removeListener(this.TabEvent[j]); } delete this.TabEvent; } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.OnClick = function(overlay, latlng, overlaylatlng){ //alert(overlay); if ((overlay == null) && (this.MegaWindowDiv.style.visibility == "visible")) this.HideMegaWindow(); } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.OnMove = function(){ if (this.MegaMarker == null) return; var visible = this.IsMegaWindowVisible(); var shouldBeVisible = this.getBounds().containsLatLng(this.MegaMarker.getLatLng()); if (visible && shouldBeVisible) this.UpdateMegaWindowPosition(); else if (visible && !shouldBeVisible) this.MegaWindowDiv.style.visibility = "hidden"; else if (!visible && shouldBeVisible) { this.MegaWindowDiv.style.visibility = "visible"; this.UpdateMegaWindowPosition(); } } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.GetMarker = function( ID) { if ( this.MarkerList == null) return null; return this.MarkerList.GetMarker( ID); } // ---------------------------------------------------------------------------------------------------------------------- // Tri des marqueurs du nord vers le sud GeoMap.prototype.SortMarker = function() { if ( this.MarkerList == null) return null; return this.MarkerList.SortMarker(); } // ---------------------------------------------------------------------------------------------------------------------- // Rajoute une donnée GeoMap.prototype.AddMark = function( ID, lat, lng, W, Zone, Category, TooltipContent) { // Rajoute les nouveles coordonnées var latlng = new GLatLng( lat, lng); if ( this.MarkerList == null) this.MarkerList = new MarkerList(); var iMarker = this.MarkerList.AddMarker( this, latlng, ID, Zone, Category, TooltipContent); iMarker.Weight = W; return iMarker.GMark; // 04/02/2008 delete latlng; } // ---------------------------------------------------------------------------------------------------------------------- // Positionne la carte à une adresse données // ex : // address = 75000 Paris // zoom = niveau de zoom GeoMap.prototype.SetAddress = function( address, zoom) { if ( this.geocoder == null) this.geocoder = new GClientGeocoder(); var temp = this; this.geocoder.getLatLng( address, function(point){ if (!point) alert("L'adresse spécifiée est introuvable"); else temp.GMap.setCenter(point, zoom); }); } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.DeletePolys = function() { for ( var i = 0; i < DebugPoly.length; i++) this.GMap.removeOverlay( DebugPoly[i]); while( DebugPoly.length != 0) { DebugPoly.pop(); } } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.DeleteMarkers = function() { if ( this.MarkerList != null) this.MarkerList.Clear(); delete this.MarkerList; this.MarkerList = null; } // ---------------------------------------------------------------------------------------------------------------------- // Affichage des marqueurs GeoMap.prototype.DisplayMarks = function() { if ( this.MarkerList != null) this.MarkerList.ShowMarkers(); } // ---------------------------------------------------------------------------------------------------------------------- // Création de la carte et affichage GeoMap.prototype.Show = function() { // Pour pallier au pb de redimensionnement de la carte this.GMap.checkResize(); // Rajoute le zoom à la carte if ( this.ZoomControlMoteur == null) this.ZoomControlMoteur = this.GMap.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0))); // rajoute un indicateur d'echelle sur la carte if ( this.MTControlMoteur == null) this.MTControlMoteur = new GScaleControl(); this.GMap.addControl( this.MTControlMoteur, new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(5,20))); // rajoute le choix du type de carte this.GMap.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(0,0))); this.GMap.addMapType(G_PHYSICAL_MAP); // On positionne la carte au "centre" de la france this.SetAddress( 'Bourges', 5); } // ---------------------------------------------------------------------------------------------------------------------- // Recalcule les zones de la carte, refait l'aggrégation et affiche les marqueurs GeoMap.prototype.Invalidate = function() { this.DisplayMarks(); // Affichage } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.AddPoly = function( X1, Y1, X2, Y2) { var Poly = new GPolygon( [new GLatLng( Y1, X1), new GLatLng( Y1, X2), new GLatLng( Y2, X2), new GLatLng( Y2, X1), new GLatLng( Y1, X1)], "#ff0000", 2, 1, "#ffaaaa", 0.2); DebugPoly.push( Poly); this.GMap.addOverlay( Poly); } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.SetDetail = function( lng, lat, zoom, mode, nom, url){ if (this.Center != null) delete this.Center; this.Center = new GLatLng( lat, lng); this.ZoomLevel = zoom; this.DetailName = nom; this.DetailMode = mode; this.DetailURL = url; // Positionnement this.GMap.setCenter( this.Center, this.ZoomLevel); } // ---------------------------------------------------------------------------------------------------------------------- GeoMap.prototype.DisplayDetailMap = function(){ this.GMap.checkResize(); // Changement du mode de la carte this.GMap.setMapType( this.GMap.getMapTypes()[parseInt(this.DetailMode)]); var GlobCurrentMark = new GMarker(this.Center, { draggable:false}); // Rajoute le marqueur this.GMap.addOverlay( GlobCurrentMark); // Création du texte var InfoText = '
' + this.DetailName +'

'; // InfoText = InfoText + 'Cliquez sur le lien pour visiter le site'; GlobCurrentMark.infoWindow = InfoText; GlobCurrentMark.openInfoWindowHtml(GlobCurrentMark.infoWindow, {maxWidth:250}); // 04/02/2008 delete GlobCurrentMark; } // ********************************************************************************************************************** // ********************************************************************************************************************** // Classe Marker // ********************************************************************************************************************** // ********************************************************************************************************************** // ---------------------------------------------------------------------------------------------------------------------- // Permet de matérialiser un marqueur de type GMarker function Marker(geomap, Id, Category, TooltipContent) { this.ID = Id; this.GeoMap = geomap; this.GMark = null; this.Coord = null; this.Bounds = null; this.Weight = 0; this.Category = Category; // musée, monument, etc. this.TooltipContent = null; if (TooltipContent != null) this.TooltipContent = '
' + TooltipContent + '
'; } // ---------------------------------------------------------------------------------------------------------------------- Marker.prototype.OnMouseOver = function(){ // récupère le marker (type Marker) qui encapsule le GMarker "this" var MyMarker = this.GeoMap.GetMarker(this.ID); if ( this.Weight == 1) this.setImage( this.GeoMap.ImgMarkerSingleHighlights[MyMarker.Category]); else this.setImage( this.GeoMap.ImgMarkerMultipleHighlight); this.GeoMap.GMap.ShowTooltip(MyMarker); if ( this.GeoMap.MouseOverMark != null) this.GeoMap.MouseOverMark( this); } // ---------------------------------------------------------------------------------------------------------------------- Marker.prototype.OnMouseOut = function(){ // récupère le marker (type Marker) qui encapsule le GMarker "this" var MyMarker = this.GeoMap.GetMarker(this.ID); if ( this.Weight == 1) this.setImage( this.GeoMap.ImgMarkerSingles[MyMarker.Category]); else this.setImage( this.GeoMap.ImgMarkerMultiple); this.GeoMap.GMap.HideTooltip(); if ( this.GeoMap.MouseOutMark != null) this.GeoMap.MouseOutMark( this); } // ---------------------------------------------------------------------------------------------------------------------- Marker.prototype.OnClick = function(){ if ( this.GeoMap.MouseClickMark != null) this.GeoMap.MouseClickMark( this); } // ---------------------------------------------------------------------------------------------------------------------- Marker.prototype.ShowMarker = function(){ if ( this.GMark == null) { if ( this.Weight == 1) { var Icon = new GIcon(baseIconSingles[this.Category]); Icon.image = this.GeoMap.ImgMarkerSingles[this.Category]; markerOptions = { icon:Icon }; this.GMark = new GMarker( new GPoint( this.Coord.lng(), this.Coord.lat()), markerOptions); } else { var Icon = new GIcon(baseIconMultiple); Icon.image = this.GeoMap.ImgMarkerMultiple; markerOptions = { icon:Icon }; this.GMark = new GMarker( new GPoint( this.Coord.lng(), this.Coord.lat()), markerOptions); } // Repporte les données sur le marqueur this.GMark.ID = this.ID; // ID du site touristique this.GMark.Bounds = this.Bounds; // zone englobante this.GMark.Weight = this.Weight; // Pondération this.GMark.GeoMap = this.GeoMap; // Carte google this.GeoMap.GMap.addOverlay( this.GMark, { draggable:false}); // 04/02/2008 /* GEvent.addListener( this.GMark, 'click', this.OnClick); GEvent.addListener( this.GMark, 'mouseover', this.OnMouseOver); GEvent.addListener( this.GMark, 'mouseout', this.OnMouseOut); */ this.GMark.click = GEvent.addListener( this.GMark, 'click', this.OnClick); this.GMark.mouseover = GEvent.addListener( this.GMark, 'mouseover', this.OnMouseOver); this.GMark.mouseout = GEvent.addListener( this.GMark, 'mouseout', this.OnMouseOut); } return (this.GMark); } // ---------------------------------------------------------------------------------------------------------------------- Marker.prototype.HideMarker = function(){ if ( this.GMark != null) { this.GeoMap.GMap.removeOverlay( this.GMark); // 04/02/2008 GEvent.removeListener( this.GMark.click); GEvent.removeListener( this.GMark.mouseover); GEvent.removeListener( this.GMark.mouseout); delete this.GMark; this.GMark = null; } } // ********************************************************************************************************************** // ********************************************************************************************************************** // Classe MarkerList // ********************************************************************************************************************** // ********************************************************************************************************************** // ---------------------------------------------------------------------------------------------------------------------- // Contient la totalité des marqueurs function MarkerList() { this.Index = 0; this.List = new Array; } // ---------------------------------------------------------------------------------------------------------------------- // Rajoute un marqueur aux coordoonées spécifiées MarkerList.prototype.AddMarker = function( geomap, latlng, nID, Zone, Category, TooltipContent){ var iItem = new Marker(geomap, nID, Category, TooltipContent); iItem.Coord = latlng; // Découpage de la zone englobante var Bound = Zone.split( "|"); var bounds2=new GLatLngBounds(); bounds2.extend( new GLatLng( Bound[1], Bound[0])); bounds2.extend( new GLatLng( Bound[3], Bound[2])); iItem.Bounds = bounds2; this.List.push( iItem); this.Index++; return iItem; } // ---------------------------------------------------------------------------------------------------------------------- // Affiche tous les marqueurs de la liste MarkerList.prototype.ShowMarkers = function(){ for (var i = 0; i < this.List.length; i++) this.List[i].ShowMarker(); } // ---------------------------------------------------------------------------------------------------------------------- // Affiche le marqueur d'index nIndex MarkerList.prototype.ShowMarker = function( nIndex){ if ( nIndex < this.List.length) this.List[ nIndex].ShowMarker(); } // ---------------------------------------------------------------------------------------------------------------------- // Masque les marqueurs MarkerList.prototype.HideMarkers = function(){ for (var i = 0; i < this.List.length; i++) this.List[i].HideMarker(); } // ---------------------------------------------------------------------------------------------------------------------- // Retourne un marker MarkerList.prototype.GetMarker = function( ID){ var bFound = false; for ( i = 0; i < this.List.length; i++) { if ( this.List[i].ID == ID) return this.List[i]; } return null; } // ---------------------------------------------------------------------------------------------------------------------- // Efface toute la liste MarkerList.prototype.Clear = function(){ while( this.List.length != 0) { var iMark = this.List.pop(); iMark.HideMarker(); delete iMark.Coord; this.Index--; } } // ----------------------------------------------------------------------------------------------------------------------- MegaWindowZoomClick = function() { if (MWZoomBtnAction != null) MWZoomBtnAction(); } // ----------------------------------------------------------------------------------------------------------------------- MegaWindowCloseClick = function() { if (MWCloseBtnAction != null) MWCloseBtnAction(); } // ********************************************************************************************************************** // ********************************************************************************************************************** // ********************************************************************************************************************** // ********************************************************************************************************************** // ********************************************************************************************************************** // ********************************************************************************************************************** // Marqueur Interface.inc.js // Ne pas effacer les deux premières lignes du fichier qui servent de marqueur afin de déterminer si l'interface a déjà été chargée lors d'un appel précédent // (C)opyright N-Gine Innovation 2008 - Tous droits réservés // http://www.ngine-innovation.com function AppelCrossDomain(URL) { var BaliseScript = document.createElement('script'); BaliseScript.language="JavaScript"; BaliseScript.src = URL; BaliseScript.type = 'text/javascript'; document.body.appendChild(BaliseScript); } // (C)opyright N-Gine Innovation 2008 - Tous droits réservés // http://www.ngine-innovation.com // Configuration // Si false, un clic sur un marqueur multiple zoome sur la carte. // Si true, un clic sur un marqueur multiple ouvre la liste des marqueurs dans une "megawindow" var UseMegaWindow = true; // Objets carte (globale/détail) var GlobTabCategoriesSites = new Array(); var GlobNDD = ''; var GlobURLATO = ''; var GlobClefContratAPIATO = ''; // Images des marqueurs var ATOImgMarkerCount = 11; // nombre d'images différentes pour les marqueurs var ATOImgMarkerDefault = 1; // category par défaut (quand le champ categorie1 n'est pas renseigné) -- attention : indicé à partir de 1 var ATOImgMarkerSingles = new Array( // comporte (ATOImgMarkerCount + 1) éléments : le premier est indicé 0 et n'est pas utilisé -> donc ~tableau indicé à partir de 1 'Images/ATOGMarker/mu-general-s_25_25_.png', 'Images/ATOGMarker/mu-general-s_25_25_.png', 'Images/ATOGMarker/mu-monument-s_25_25_.png', 'Images/ATOGMarker/mu-sitearcheologique-s_25_25_.png', 'Images/ATOGMarker/mu-musee-s_25_25_.png', 'Images/ATOGMarker/mu-parcatheme-s_25_25_.png', 'Images/ATOGMarker/mu-parcanimalier-s_25_25_.png', 'Images/ATOGMarker/mu-grotte-s_25_25_.png', 'Images/ATOGMarker/mu-sitenaturel-s_25_25_.png', 'Images/ATOGMarker/mu-parcjardin-s_25_25_.png', 'Images/ATOGMarker/mu-festival-s_25_25_.png', 'Images/ATOGMarker/mu-tourismeindustriel-s_25_25_.png'); var ATOImgMarkerSingleHighlights = new Array( // idem : tableau indicé à partir de 1 du fait que le premier élément est ignoré 'Images/ATOGMarker/mu-general-h_25_25_.png', 'Images/ATOGMarker/mu-general-h_25_25_.png', 'Images/ATOGMarker/mu-monument-h_25_25_.png', 'Images/ATOGMarker/mu-sitearcheologique-h_25_25_.png', 'Images/ATOGMarker/mu-musee-h_25_25_.png', 'Images/ATOGMarker/mu-parcatheme-h_25_25_.png', 'Images/ATOGMarker/mu-parcanimalier-h_25_25_.png', 'Images/ATOGMarker/mu-grotte-h_25_25_.png', 'Images/ATOGMarker/mu-sitenaturel-h_25_25_.png', 'Images/ATOGMarker/mu-parcjardin-h_25_25_.png', 'Images/ATOGMarker/mu-festival-h_25_25_.png', 'Images/ATOGMarker/mu-tourismeindustriel-h_25_25_.png'); var ATOImgMarkerMultiple = 'Images/ATOGMarker/mu-general-s_25_25_.png'; var ATOImgMarkerMultipleHighlight = 'Images/ATOGMarker/mu-general-h_25_25_.png'; var ATOMap = null; var ATOMapDetail = null; var GZZoom = null; var MegaWindow = null; // Mémorisation de la dernière position visible de la carte var Left, Right, Top, Bottom; // Nombre maxi de marqueurs à regrouper var MaxWeight = 3; // Pondération du dernier marqueur cliqué var LastWeight = MaxWeight; // Dernières données récupérées var LastJSON = null; var LastMark = null; // pour savoir si la carte a bougé et s'il faut sauvegarder les coordonnées var moved; // Pour la gestion des background images sur la liste var LastID = null; var LastAction = null; // on ou off var Urls = new Array(); // ---------------------------------------------------------------------------------------------------------------------- // Initialisation de la carte globale function InitCarte() { // detecte IE6 et modifie les png en gif si necessaire var IE6 = false var strChUserAgent = navigator.userAgent; var intSplitStart = strChUserAgent.indexOf("(",0); var intSplitEnd = strChUserAgent.indexOf(")",0); var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd); if(strChMid.indexOf("MSIE 6") != -1) IE6 = true; if (IE6) { for (var i = 0; i <= ATOImgMarkerCount; i++) ATOImgMarkerSingles[i] = ATOImgMarkerSingles[i].substring(0, ATOImgMarkerSingles[i].length - 3) + 'gif'; for (i = 0; i <= ATOImgMarkerCount; i++) ATOImgMarkerSingleHighlights[i] = ATOImgMarkerSingleHighlights[i].substring(0, ATOImgMarkerSingleHighlights[i].length - 3) + 'gif'; ATOImgMarkerMultiple = ATOImgMarkerMultiple.substring(0, ATOImgMarkerMultiple.length - 3) + 'gif'; ATOImgMarkerMultipleHighlight = ATOImgMarkerMultipleHighlight.substring(0, ATOImgMarkerMultipleHighlight.length - 3) + 'gif'; } LastWeight = MaxWeight; // Création de la carte ATOMap = new GeoMap( "MapAnnuaireTouristique", { "TabEvt":[ { "EventName":"moveend", "Fonction":Move }, { "EventName":"zoomend", "Fonction":Zoom }, { "EventName":"load", "Fonction":PrepareCarte }, { "EventName":"onMarkerClick", "Fonction":ClickMark } ] }, G_PHYSICAL_MAP); //ATOMap.MouseOverMark = MarkerOver; // commenté le 9/9/8 car la liste latérale n'est plus nécessaire //ATOMap.MouseOutMark = MarkerOut; // } // ---------------------------------------------------------------------------------------------------------------------- // Préparation de la carte // apellé une fois que la carte est initialisée function PrepareCarte() { // Images des marqueurs for (var i = 1; i <= ATOImgMarkerCount; i++) { ATOMap.setSingleMarkUrl(i, ATOImgMarkerSingles[i]); ATOMap.setSingleMarkHighlighUrl(i, ATOImgMarkerSingleHighlights[i]); } ATOMap.setMultipleMarkUrl (ATOImgMarkerMultiple ); ATOMap.setMultipleMarkHighlightUrl( ATOImgMarkerMultipleHighlight); // Gestion du zoom if (GZZoom == null) { GZZoom = new DragZoomControl({ nOpacity:.2, sBorder:"2px solid red" }, { buttonHTML:"", buttonZoomingHTML:"", buttonStartingStyle:{ width:'32px', height:'32px' }, buttonStyle:{ background:'' }, // oButtonZoomingStyle:{background:''}, overlayRemoveTime:1000, stickyZoomEnabled:false, wantZoom:true },{}); ATOMap.GMap.addControl( GZZoom, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(60,12))); } // lecture de la position sur la carte dans un cookie if (LireCookie("SavePosition") == 'true') { var centerLat = LireCookie("centerLat"); var centerLng = LireCookie("centerLng"); var zoom = LireCookie("zoom"); var scrollTop = LireCookie("scrollTop"); ATOMap.GMap.setCenter(new GLatLng(centerLat, centerLng), parseInt(zoom)); document.documentElement.scrollTop = scrollTop; EcrireCookie("SavePosition", 'false'); moved = false; } CalculeCarte(); } // ---------------------------------------------------------------------------------------------------------------------- // Déplacement de la carte function Move() { moved = true; // la carte a bougée if (!ATOMap.isViewPortInCache()) CalculeCarte(); /* else { if (LastJSON != null) MoteurRenduListeResultats( LastJSON); }*/ } // ---------------------------------------------------------------------------------------------------------------------- // Changement de zoom function Zoom( oldLevel, newLevel) { CalculeCarte(); } // ---------------------------------------------------------------------------------------------------------------------- // Mise à jour de la carte function CalculeCarte() { if (( Left == ATOMap.getCoordLeft()) && (Right == ATOMap.getCoordRight()) && (Top == ATOMap.getCoordTop()) && (Bottom == ATOMap.getCoordBottom())) return; // Définie la taille du cache et recalcule les coordonnées du cache ATOMap.setCacheSize( 1/3.0, 1/3.0); Left = ATOMap.getCoordLeft(); Right = ATOMap.getCoordRight(); Top = ATOMap.getCoordTop(); Bottom = ATOMap.getCoordBottom(); ATOMap.DeletePolys(); AppelCrossDomain('http://'+GlobURLATO+'/API/ATO/F/AffichageCarte.js-Key='+GlobClefContratAPIATO+ '%26Lng1='+ATOMap.getCoordLeft()+ '%26Lat1='+ATOMap.getCoordTop()+ '%26Lng2='+ATOMap.getCoordRight()+ '%26Lat2='+ATOMap.getCoordBottom()+ '%26IDCarte='+ATOMap.IDGMap+ '%26Width='+document.getElementById( ATOMap.IDGMap).width+ '%26Height='+document.getElementById( ATOMap.IDGMap).height+ '%26Weight='+LastWeight+ '%26MaxWeight='+MaxWeight+ '%26CacheX='+ATOMap.CacheX+ '%26CacheY='+ATOMap.CacheY+ '%26NDD='+GlobNDD+ '%26TailleTableauCategoriesSites='+GlobTabCategoriesSites.length+ '%26Charset='+ATOCharset ); } // ---------------------------------------------------------------------------------------------------------------------- function ClickMark( Mark) { if ((Mark == LastMark) && (ATOMap.GMap.IsMegaWindowVisible())) { ATOMap.GMap.HideMegaWindow(); return; } if ( Mark.Weight > 1) if (UseMegaWindow) { // marqueur mutliple avec l'utilisation des megawindow Mark.GeoMap.GMap.ShowMegaWindowAndPan(Mark, "Chargement...", ZoomMark, MegaWindowCloseBtnClick, 0, 0.75, 0.75, 1); AppelCrossDomain('http://'+GlobURLATO+'/API/ATO/F/ListeSiteRegroupement.js-Key='+GlobClefContratAPIATO+ '%26Lng1='+Mark.Bounds.getSouthWest().lng()+ '%26Lat1='+Mark.Bounds.getSouthWest().lat()+ '%26Lng2='+Mark.Bounds.getNorthEast().lng()+ '%26Lat2='+Mark.Bounds.getNorthEast().lat()+ '%26TailleTableauCategoriesSites='+GlobTabCategoriesSites.length+ '%26Charset='+ATOCharset); } else { // marqueur mutliple sans l'utilisation des megawindow ZoomMark(); } else { ATOMap.DeletePolys(); if (Urls[Mark.ID] != null) location.href = Urls[Mark.ID]; } LastMark = Mark; } // ---------------------------------------------------------------------------------------------------------------------- // Zoome sur un marqueur multiple (le dernier marqueur cliqué) function ZoomMark() { if (LastMark) { ATOMap.DeletePolys(); ATOMap.GMap.HideTooltip(); ATOMap.GMap.HideMegaWindow(); // Positionne le zoom et recentre la carte ATOMap.GMap.setCenter( LastMark.Bounds.getCenter(), ATOMap.GMap.getBoundsZoomLevel( LastMark.Bounds)); LastWeight = LastMark.Weight; // Apeller avec les coordonnées du carré "ATO" AppelCrossDomain('http://'+GlobURLATO+'/API/ATO/F/AffichageCarte.js-Key='+GlobClefContratAPIATO+ '%26Lng1='+ATOMap.getCoordLeft()+ '%26Lat1='+ATOMap.getCoordTop()+ '%26Lng2='+ATOMap.getCoordRight()+ '%26Lat2='+ATOMap.getCoordBottom()+ '%26IDCarte='+ATOMap.IDGMap+ '%26Width='+document.getElementById( ATOMap.IDGMap).width+ '%26Height='+document.getElementById( ATOMap.IDGMap).height+ '%26DivX='+ATOMap.maxX+ '%26DivY='+ATOMap.maxY+ '%26Weight='+LastMark.Weight+ '%26MaxWeight='+MaxWeight+ '%26CacheX='+ATOMap.CacheX+ '%26CacheY='+ATOMap.CacheY+ '%26NDD='+GlobNDD+ '%26TailleTableauCategoriesSites='+GlobTabCategoriesSites.length+ '%26Charset='+ATOCharset); } } // ---------------------------------------------------------------------------------------------------------------------- // Mise à jour de la classe d'un item // retourne l'élément function UpdateClassList(ID, onoff) { elt = document.getElementById('SITE' + ID); if (onoff == 'on') elt.className = 'DivOn'; else elt.className = 'DivOff'; /* if (LastID == ID) { LastId = null; } else { ApplyUpdateClassList(); LastID = ID; LastAction = onoff; setTimeout("ApplyUpdateClassList();", 50); } */ } /*function ApplyUpdateClassList() { if (LastID != null) { elt = document.getElementById('SITE' + LastID); if (LastAction == 'on') elt.className = 'DivOn'; else elt.className = 'DivOff'; LastID = null; } }*/ // ---------------------------------------------------------------------------------------------------------------------- // Fonction de synchronisation Marqueur/Liste //function MarkerOver( Marker) //{ // // n'est plus utilisée - le 9/9/8 car la liste latérale n'est plus nécessaire // var elt = UpdateClassList(Marker); // var Pos = CalculTopAbsolu( elt); // var NewPos = Pos - document.getElementById('TableauAnnuaireTouristique').offsetTop; // document.getElementById('BoiteSynchroList').scrollTop = NewPos; //} // // ---------------------------------------------------------------------------------------------------------------------- // Fonction de synchronisation Marqueur/Liste //function MarkerOut( Marker) //{ // // n'est plus utilisé - le 9/9/8 car la liste latérale n'est plus nécessaire // UpdateClassList(Marker); //} // // ---------------------------------------------------------------------------------------------------------------------- // Fonction de synchronisation Liste/Marqueur //function ListOver( ID) //{ // return; // desactivation de la fonction - le 9/9/8 // // Retrouve le bon marker // var Mark = ATOMap.GetMarker( ID); // // if ( Mark != null) // { // if ( Mark.Weight == 1) // Mark.GMark.setImage( ATOImgMarkerSingleHighlights[Mark.Category]); // else // Mark.GMark.setImage( ATOImgMarkerMultipleHighlight); // // Mark.GMark.GeoMap.ShowTooltip(Mark); // } // // UpdateClassList(Mark); //} // // ---------------------------------------------------------------------------------------------------------------------- // Fonction de synchronisation Liste/Marqueur //function ListOut( ID) //{ // return; // desactivation de la fonction - le 9/9/8 // // Retrouve le bon marker // var Mark = ATOMap.GetMarker( ID); // if (Mark != null) // { // if (Mark.Weight == 1) // Mark.GMark.setImage(ATOImgMarkerSingles[Mark.Category]); // else // Mark.GMark.setImage(ATOImgMarkerMultiple); // // Mark.GMark.GeoMap.HideTooltip(); // } // // UpdateClassList(Mark); //} // // ---------------------------------------------------------------------------------------------------------------------- // Clic sur la liste function ClickOnList(ID) { return; // desactivation de la fonction - le 9/9/8 // Retrouve le bon marker var Mark = ATOMap.GetMarker(ID); if (Mark != null) ClickMark(Mark); } // ---------------------------------------------------------------------------------------------------------------------- // Affichage de la carte principale function AfficheCarte(){ ATOMap.Show(); } // ---------------------------------------------------------------------------------------------------------------------- // Initialisation de la carte détail function InitCarteDetail(DivId, Lat, Lng, Zoom, Mode, Nom, Url){ // 04/02/2008 if (ATOMapDetail != null) { ATOMapDetail.Clear(); delete ATOMapDetail.GMap; delete ATOMapDetail; } // Création de la carte ATOMapDetail = new GeoMap(DivId, { "TabEvt":[ { "EventName":"load", "Fonction":AfficheCarteDetail } ] }); //ajoute les controles ATOMapDetail.GMap.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0))); ATOMapDetail.GMap.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(5,20))); ATOMapDetail.GMap.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(0,0))); // Positionne les informations du marqueur ATOMapDetail.SetDetail(Lng, Lat, Zoom, Mode, Nom, Url); } // ---------------------------------------------------------------------------------------------------------------------- // Affichage de la carte détail function AfficheCarteDetail(){ ATOMapDetail.DisplayDetailMap(); } // ---------------------------------------------------------------------------------------------------------------------- function AfficheSiteTouristique(SiteID) { AppelCrossDomain('http://'+GlobURLATO+'/API/ATO/F/AffichageSiteTouristique.js-Key='+GlobClefContratAPIATO+'%26SiteID='+SiteID); } // ---------------------------------------------------------------------------------------------------------------------- function RetourAnnuaireTouristique() { if (document.getElementById('BoiteRetourAnnuaire')) document.getElementById('BoiteRetourAnnuaire').style.display='none'; SupprimeHierarchieDOM("BoiteDetailSiteTouristique"); document.getElementById("BoiteCarteAnnuaireTouristique").style.display = 'block'; document.getElementById("BoiteCatalogueAnnuaireTouristique").style.display = 'block'; document.getElementById("BoiteDetailSiteTouristique").style.display = 'none'; if (!ATOMap) { InitCarte(); AfficheCarte(); } } // ---------------------------------------------------------------------------------------------------------------------- function InitAnnuaireTouristique(SiteID) { if (SiteID == 0) { InitCarte(); AfficheCarte(); } else { AfficheSiteTouristique(SiteID); } } // ---------------------------------------------------------------------------------------------------------------------- function MiseAJourAffichageSitesTouristiques(FluxJSON) { ATOMap.DeleteMarkers(); if (GlobTabCategoriesSites.length == 0) InitialisationCategoriesSites(FluxJSON); for (i=0;i 1) Tooltip = '
Cliquez pour découvrir
' + FluxJSON.Marqueurs[i].Poids + ' sites touristiques
'; else { // Marqueur unitaire Urls[FluxJSON.Marqueurs[i].ID] = FluxJSON.Marqueurs[i].URL; Tooltip = ''; Tooltip += ''; Tooltip += ''; Tooltip += '
Fiche touristique '+FluxJSON.Marqueurs[i].Nom+''+FluxJSON.Marqueurs[i].Nom+'
'; if (FluxJSON.Marqueurs[i].Cat1>= 0) { Tooltip += GlobTabCategoriesSites[FluxJSON.Marqueurs[i].Cat1][1]; if (FluxJSON.Marqueurs[i].Cat2 >= 0) Tooltip += ' / '+GlobTabCategoriesSites[FluxJSON.Marqueurs[i].Cat2][1]; } else { Tooltip += '
'; } Tooltip += '
'; Tooltip += ''+FluxJSON.Marqueurs[i].Ville + '
' + FluxJSON.Marqueurs[i].Departement+'
'; Tooltip += '
Cliquez sur le symbole pour visiter ce site
'; } ATOMap.AddMark(FluxJSON.Marqueurs[i].ID, FluxJSON.Marqueurs[i].Lat, FluxJSON.Marqueurs[i].Long, FluxJSON.Marqueurs[i].Poids, FluxJSON.Marqueurs[i].Zone, Category, Tooltip); } ATOMap.DisplayMarks(); //MoteurRenduListeResultats(FluxJSON); } // ---------------------------------------------------------------------------------------------------------------------- function MiseAJourAffichageListeSitesRegroupement(FluxJSON) { if (GlobTabCategoriesSites.length == 0) InitialisationCategoriesSites(FluxJSON); MoteurRenduListeResultats(FluxJSON); } // ---------------------------------------------------------------------------------------------------------------------- function InitialisationCategoriesSites(FluxJSON) { var TabCategorie = new Array("",""); for (i=0;i'; CodeHTML += '
'; CodeHTML += ' Fiche touristique ' + FluxJSON.Sites[i].SITNOM + '
'; CodeHTML += '
'; CodeHTML += ' ' + FluxJSON.Sites[i].SITNOM + '
'; if (FluxJSON.Sites[i].SITCATEGORIE1 >= 0 && FluxJSON.Sites[i].SITCATEGORIE1 != "") { CodeHTML += GlobTabCategoriesSites[FluxJSON.Sites[i].SITCATEGORIE1][1]; if (FluxJSON.Sites[i].SITCATEGORIE2 >= 0 && FluxJSON.Sites[i].SITCATEGORIE2 != "") CodeHTML += ' / '+GlobTabCategoriesSites[FluxJSON.Sites[i].SITCATEGORIE2][1]; } CodeHTML += ''; CodeHTML += '
'+FluxJSON.Sites[i].LOCNOM + '
' + FluxJSON.Sites[i].DEPARTEMENT+'
'; CodeHTML += '
'; CodeHTML += 'Fiche touristique ' + FluxJSON.Sites[i].SITNOM + '
'; } if (FluxJSON.PlusDeResultats) { CodeHTML += '
Zoomer pour plus de résultats
'; } LastJSON = FluxJSON; ATOMap.GMap.UpdateMegaWindowInnerHTML(CodeHTML); } } var ATOCharset = "iso-8859-1";