1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>[Google Maps API]StreetViewPanorama et Tabs Widget</title>
<meta name="Author" content="NoSmoking">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?language=fr&v=3"></script>
<style>
html, body {
height: 100%;
margin: 0px;
padding: 1em;
box-sizing:border-box;
}
#div_carte {
height:100%;
}
.infotext {
width:480px;
height:380px;
}
.tabs {
width:450px;
height:350px;
}
.pano {
width:100%;
height: 280px;
}
</style>
<script>
var tMarker = [
{ 'lat' :45.767299, 'lon' : 4.834329, 'title' :'Lyon', 'info' :'<b>Lyon<\/b><br>la suite du texte...'},
{ 'lat' :48.856667, 'lon' : 2.350987, 'title' :'Paris', 'info' :'<b>Paris<\/b><br>la suite du texte...'},
{ 'lat' :44.837368, 'lon' :-0.576144, 'title' :'Bordeaux', 'info' :'<b>Bordeaux<\/b><br>la suite du texte...'},
{ 'lat' :43.297612, 'lon' : 5.381042, 'title' :'Marseille', 'info' :'<b>Marseille<\/b><br>la suite du texte...'}
];
var oMap = null;
function initCarte () {
// création de la carte
oMap = new google.maps.Map(document.getElementById("div_carte"),{
'zoom' : 6,
'center' : new google.maps.LatLng( 46.80, 1.75),
'mapTypeId' : google.maps.MapTypeId.ROADMAP
});
for( i=0; i < tMarker.length; i++){
addMarker(tMarker[i]);
}
}
function addMarker ( data){
// get ID unique
oMap.timeID = oMap.timeID ? ++oMap.timeID : new Date().getTime();
var idPano = 'pano' + oMap.timeID;
// création marker
oMarker = new google.maps.Marker({
'position' : {lat: data.lat, lng: data.lon},
'map' : oMap,
'title' : data.title
});
var contentMarker = [
'<div class="infotext">',
'<div class ="tabs">',
'<ul>',
'<li><a href="#tab1_' +oMap.timeID +'" class="IG">General</a></li>',
'<li><a href="#tab2_' +oMap.timeID +'" class="SV">Street View</a></li>',
'</ul>',
'<div id="tab1_' +oMap.timeID +'">',
'<h3>' + data.title + '</h3>',
'<p> Coordonnées GPS : ' + oMarker.getPosition().toUrlValue(6) + '</p>',
'<p>' + data.info + '</p>',
'</div>',
'<div id="tab2_' +oMap.timeID +'">',
'<div class="pano" id="' +idPano +'"></div>',
'</div>',
'</div>',
'</div>'
].join('');
// création infobulle
var oInfo = new google.maps.InfoWindow({
'content' : contentMarker,
'idPano' : idPano,
'refPano' : null
});
// événement clic sur le marker
google.maps.event.addListener( oMarker, "click", function () {
// affichage InfoWindow
if( !oInfo.getMap()){
oInfo.open( this.getMap(), this);
}
});
// attention domready à chaque ouverture de la fenêtre
google.maps.event.addListener( oInfo, 'domready', function () {
// garde info du vrai this
var thisInfo = this;
// si 1st, création
if( ! thisInfo.refPano){
// active le système d'onglets
$(".tabs").tabs();
//Création d'un street view panorama
thisInfo.refPano = new google.maps.StreetViewPanorama(
document.querySelector( '#' +thisInfo.idPano),
{
'position' : thisInfo.getPosition()
}
);
// obligé si la création s'est fait en mode hidden (onglet caché)
$('.SV').on('click' ,function () {
thisInfo.refPano.setVisible(true);
});
}
});
}
google.maps.event.addDomListener(window,'load', initCarte);
</script>
</head>
<body>
<div id="div_carte"></div>
</body>
</html> |
Partager