Bonjour à tous,

Je réalise une petite application ou il m'est nécessaire d'afficher en temps réel la position d'un véhicule ainsi que son trajet restant jusqu'à son point d'arriver. Pour commencer j'ai donc réaliser une petite routine qui récupère en bdd un par un tous les points nécessaire pour tracer la polyligne de mon trajet restant. Je les insert dans un tableau javascript. Puis une fois tous les points collecté, j'utilise ce tableau pour tracer ma polyligne sur la carte :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
//Represent a list of ItineraryMapPoint
var ItineraryMapPointCoordinates = [];
var ItineraryMapPointCount = 0;
 
function AddBoxItineraryPoint(_color,_lat, _lng) {
    var _LatLngCircle = new google.maps.LatLng(_lat, _lng);
 
    var _ItineraryCircle = {
      fillColor: _color,
      strokeColor: _color,
      strokeOpacity: 1,
      strokeWeight: 4,
      center: _LatLngCircle,
      map : map,
      radius : 0.2
    };
 
    var _Thecircle = new google.maps.Circle(_ItineraryCircle);
 
    ItineraryMapPointCoordinates[ItineraryMapPointCount] = _LatLngCircle;
    ItineraryMapPointCount++;
    ItineraryObject[ItinerayCmpt] = _Thecircle;
    ItinerayCmpt++;
}
 
 
 
//Display all the waypoint on the Map
function DrawItineraryMapPointPolyline(_color, _zIndex) {
 
    _zIndex = _zIndex + 10;
 
    var _ItineraryMapPointPath = new google.maps.Polyline({
        path: ItineraryMapPointCoordinates,
        strokeColor: _color,
        strokeOpacity: 1,
        strokeWeight: 4,
        zIndex: _zIndex
    });
 
    _ItineraryMapPointPath.setMap(map);
    ItineraryMapPointCount = 0;
    ItineraryMapPointCoordinates = [];
 
    ItineraryObject[ItinerayCmpt] = _ItineraryMapPointPath;
    ItinerayCmpt++;
}
Et quand je dois rafraichir mon itinéraire 5 seconde plus tard je vide mon tableau ItineraryObject afin de faire disparaitre mon trajet je recommence :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
//Remove all the itinerary Object on the Map
function RemoveItineraryDrawn() {
    for (var i = 0; i < ItinerayCmpt; i++) {
        if (ItineraryObject[i] != null) {
            ItineraryObject[i].setMap(null);
            ItineraryObject[i] = null;
        }
    }
    ItineraryObject = [];
    ItinerayCmpt = 0;
}
Déjà je trouve mon code très moche mais en plus c'est pas fluide du tout et je me dis qu'il y doit y avoir une méthode plus adapté pour faire ce que doit faire ! Si quelqu'un avait une piste sur la méthode à utiliser ?