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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
| <script type="text/javascript">
//Creation de Map
// Variables globales
// ------------------
var map = null;
var Table_Pins = {}; // Liste des Pins affichées
var Pos_Info = null; // Dit sur quel marker se situe l'infobulle
var Liste_Points = []; // Pour la mémorisation du tracé
var route = null;
//-----------------------------------------------------------------
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(43.665, 7.052),
mapTypeId: google.maps.MapTypeId.ROADMAP, //Type de carte
mapTypeControl: true,
panControl: true,
zoomControl: true, //Zoom
scaleControl: true, //Echelle
scaleControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM},
streetViewControl: true
} ;
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
//------------------------
// Ouverture du WebBrowser
// -----------------------
try { google.maps.event.addDomListener(window, 'load', initialize);}
catch (ex){ alert("vous devez etre connecte a l'internet...");}
// ------------------------------------------------------------------------------------
// Affichage des véhicules
// ------------------------------------------------------------------------------------
function Affiche_Pin(Lat, Long, immat, type, site, vitesse, date)
{
for ( immat in Table_Pins)
{
var myPin = Table_Pins[immat];
myPin.html ='<b>Véhicule <font color="green">' + immat + ' ' + '</font></b><br>' +
'Site : ' + site + '<br>' +
'Type : ' + type + '<br>' +
'Vitesse : ' + vitesse + ' km/h' + '<br>' +
'Date : ' + date + '<br>';
if (typeof myPin != "undefined")
{
myPin.setLatLng(new google.maps.LatLng(Lat, Long))
// La Pin est déja placée, on la déplace
// -------------------------------------
map = new google.maps.Map(document.getElementById('map'));
map.setCenter(new google.maps.LatLng(Lat, Long));
map.setZoom(15);
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
if (Pos_Info == myPin) {
var infowindow = new google.maps.InfoWindow({
content: myPin.html,
position: new google.maps.LatLng(Lat, Long) });
infowindow.open(map);
} //end if (pos_info)
}//end if (mypin)
else{
var image = {
url: 'http://maps.google.com/mapfiles/kml/pal4/icon15.png',
size: new google.maps.Size(32, 32),
anchor: new google.maps.Point(16, 32)};
var vehlatlng = new google.maps.LatLng(Lat, Long) ;
var marker = new google.maps.Marker({
map: map,
position: vehlatlng,
icon: image });
var infowindow = new google.maps.InfoWindow({
content: myPin.html,
position: vehlatlng });
}//end else
// Evenement "Click" et "infowindowopen" du marker
// ---------------------------
google.maps.event.addListener(marker, 'tilesloaded', function() {
if(lastOpenInfoWin) lastOpenInfoWin.close();
lastOpenInfoWin = infowindow;
infowindow.open(marker.get('map'), marker);
Pos_Info = marker;});
Table_Pins[immat] = marker;
marker.setMap(map);
} //end for
}//end function affiche_pin
// ------------------------------------------------------------------------------------
// On centre le véhicule
// ------------------------------------------------------------------------------------
function Centrer_Pin(immat) {
var myPin = Table_Pins[immat];
if (typeof myPin != "undefined")
{ getPosition();
map.setCenter(myPin.getPosition());
infowindow.open(map);
}*/
}
// ------------------------------------------------------------------------------------
// On Efface un parcours
// ------------------------------------------------------------------------------------
// Deletes all markers in the array by removing references to them
function Clear_Trace()
{
if (Liste_Points) {
for (var i in Liste_Points) {
Liste_Points[i].setMap(null); }
Liste_Points.length = 0;}
}
// ------------------------------------------------------------------------------------
// On trace un parcours
// ------------------------------------------------------------------------------------
function Trace_Pin(Lat, Long, immat, type, site, vitesse, date)
{ var image = {
url: 'http://maps.google.com/mapfiles/kml/pal4/icon15.png',
size: new google.maps.Size(32, 32),
anchor: new google.maps.Point(16, 32)};
var vehlatlng = new google.maps.LatLng(Lat, Long) ;
var marker = new google.maps.Marker({
map: map,
position: vehlatlng,
icon: image });
marker.tooltip = '<div class="tooltip">' + 'Date : ' + date + '<br>' + 'Vitesse : ' + vitesse + ' km/h' + '<br>' + '<\/div>';
marker.setMap(map);
Liste_Points.push(marker.getPoint());
}
// ------------------------------------------------------------------------------------
// On joint les points du parcours
// ------------------------------------------------------------------------------------
function Trace_Route() {
if (route) { map.removeOverlay(route); }
if (Liste_Points.length > 1) {
route = new google.maps.Polyline({
path: Liste_Points,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2});
route.setMap(map);
}
}
// ------------------------------------------------------------------------------------
// Gestion des tooltips
// ------------------------------------------------------------------------------------
/* function showTooltip(marker) { // Display tooltips
tooltip.innerHTML = marker.tooltip;
var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(), map.getZoom());
var anchor = marker.getIcon().iconAnchor;
var width = marker.getIcon().iconSize.width;
var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width, -offset.y + point.y + anchor.y));
pos.apply(tooltip);
tooltip.style.visibility = "visible";
} */
function createTooltip(marker, immat) {
//create a tooltip
var tooltipOptions={
marker:marker,
content:marker.tooltip,
cssClass:'tooltip' // name of a css class to apply to tooltip
};
var tooltip = new Tooltip(tooltipOptions);
}
var lastOpenInfoWin = null;
</script>
<script type="text/javascript">
// tooltips javascript
function Tooltip(options)
{// Now initialize all properties.
this.marker_ = options.marker;
this.content_ = options.content;
this.map_ = options.marker.get('map');
this.cssClass_ = options.cssClass||null;
this.div_ = null;
//Explicitly call setMap on this overlay
this.setMap(this.map_);
var me = this;
// Show tooltip on mouseover event.
google.maps.event.addListener(me.marker_, 'mouseover', function() {
me.show();});
// Hide tooltip on mouseout event.
google.maps.event.addListener(me.marker_, 'mouseout', function() {
me.hide();});
}
// Now we extend google.maps.OverlayView()
Tooltip.prototype = new google.maps.OverlayView();
// onAdd is one of the functions that we must implement,
// it will be called when the map is ready for the overlay to be attached.
Tooltip.prototype.onAdd = function()
{
// Create the DIV and set some basic attributes.
var div = document.createElement('DIV');
div.style.position = "absolute";
// Hide tooltip
div.style.visibility = "hidden";
if(this.cssClass_)
div.className += " "+this.cssClass_;
//Attach content to the DIV.
div.innerHTML = this.content_;
// Set the overlay's div_ property to this DIV
this.div_ = div;
// We add an overlay to a map via one of the map's panes.
// We'll add this overlay to the floatPane pane.
var panes = this.getPanes();
panes.floatPane.appendChild(this.div_);
}
// We here implement draw
Tooltip.prototype.draw = function()
{
// Position the overlay. We use the position of the marker
// to peg it to the correct position, just northeast of the marker.
// We need to retrieve the projection from this overlay to do this.
var overlayProjection = this.getProjection();
// Retrieve the coordinates of the marker
// in latlngs and convert them to pixels coordinates.
// We'll use these coordinates to place the DIV.
var ne = overlayProjection.fromLatLngToDivPixel(this.marker_.getPosition());
// Position the DIV.
var div = this.div_;
div.style.left = ne.x + 'px';
div.style.top = ne.y + 'px';
}
// We here implement onRemove
Tooltip.prototype.onRemove = function()
{
this.div_.parentNode.removeChild(this.div_);
}
// Note that the visibility property must be a string enclosed in quotes
Tooltip.prototype.hide = function()
{
if (this.div_)
{
this.div_.style.visibility = "hidden";
}
}
Tooltip.prototype.show = function()
{
if (this.div_)
{
this.div_.style.visibility = "visible";
}
}
</script> |
Partager