1 function AddVehicleGraphics(){ 2 SANDY.qt.execute(SANDY.q, function(fSet){ 3 function sortGraphics(a,b){ 4 return (a.attributes.fleetID < b.attributes.fleetID) ? -1 : 1; 5 } 6 7 // record bread crumbs, if any 8 dojo.forEach(SANDY.crumbsVehicles, function(key){ 9 var crumbGraphic = dojo.filter(SANDY.avlGraphicsLayer.graphics, function(item){ 10 return item.attributes.mapKey == key; 11 })[0]; 12 SANDY.avlGraphicsLayer.remove(crumbGraphic); // required to allow appropriate refresh on history graphics layer 13 crumbGraphic.setInfoTemplate(SANDY.crumbsTipTemplate); 14 crumbGraphic.setSymbol(SANDY.crumbSymbol); 15 16 // get associate graphics layer 17 var gLayer = SANDY.mapDij.map.getLayer(key); 18 gLayer.add(crumbGraphic); 19 }); 20 21 // clear graphics layer 22 SANDY.avlGraphicsLayer.clear(); 23 SANDY.chartsDij.clearContent(); 24 25 // sort the graphics alphabetically so they are sorted when adding to active vehicles table. 26 fSet.features.sort(sortGraphics); 27 dojo.forEach(fSet.features, function(g){ 28 var symbol; 29 switch (g.attributes.defaultIcon) { 30 case "PLOW TRUCK": 31 symbol = dojo.clone(SANDY.truckSymbol); 32 break; 33 case "SWEEPER": 34 symbol = dojo.clone(SANDY.sweeperSymbol); 35 break; 36 case "SUV": 37 symbol = dojo.clone(SANDY.puSymbol); 38 break; 39 } 40 41 // rotate symbol 42 symbol.setAngle(g.attributes.headingDegrees); 43 g.setSymbol(symbol); 44 45 // round mph 46 g.attributes.speedMPH = Math.round(g.attributes.speedMPH); 47 48 // add to graphics layer 49 SANDY.avlGraphicsLayer.add(g); 50 51 // add to vehicles list / bold all vehicles that have updated in the last 30 minutes 52 var content; 53 var activeCutOff = new Date().setMinutes(new Date().getMinutes() - 30); 54 if (new Date(g.attributes.timeAtCoordinate) > activeCutOff){ 55 content = "<b>" + g.attributes.fleetID + "</b>"; 56 } else { 57 content = g.attributes.fleetID; 58 } 59 SANDY.chartsDij._addContent(content); 60 61 // update date updated text 62 var now = new Date(); 63 dojo.byId("update-date").innerHTML = now.toLocaleTimeString(); 64 dojo.style("update-date-background", "backgroundColor", "white"); 65 }); 66 67 if (fSet.features.length === 0){ 68 SANDY.chartsDij._addContent(SANDY.noVehiclesMsg); 69 } 70 }, function(error){ 71 // change background to indicate error 72 dojo.style("update-date-background", "backgroundColor", "red"); 73 }); 74 }