AnsweredAssumed Answered

moving graphics disappear on zoom

Question asked by rralbritton on May 22, 2017

I have a moving vehicles graphics layer, and the graphics will disappear when the map gets zoomed in.

The graphics are being created from an esriRequest, and a setInterval is being used to update the vehicle locations every 5 seconds. If the map remains at the home zoom level, the app works as it should. Also, I can zoom all the way out and the graphics remain, but it I zoom into a level between 18-20 the graphic disappears. I have to zoom out a level to have it reappear, but as soon as I zoom back down it disappears again. I’ve also noticed that sometimes that graphics disappear on pan as well.

There is no min or max level set for the vehicle graphics layer so it should be defaulting to 0. I have tried the following:

  • Redraw the graphics on zoom,
  • Redraw the graphics on zoom-end
  • Logged to the console to see if the layer itself was still visible after zoom (it is).


It also does not seem to matter what I set the interval at, the vehicles disappear all at about the same zoom level (18-20) after the first interval has redrawn the vehicles in their new coordinate locations.  


I’ve included, what should be all the relevant pieces of code below. I there’s something you think should be there please let me know. I may have forgotten to include it.


I’m using the 3.2 API.


app.vehiclesGraphicsLayer = new GraphicsLayer ({
    id: "vehiclesGraphicsLayer"

app.esriVehicleRequest = function (routeID) {
    return new esriRequest({
        url: "",
        content: {
            apikey: "ride1791",
            routeID: routeID
        handleAs: "json",
        callbackParamName: "method"
    }).then(function(data) {
        return data;

app.vehicleGraphicFunction= function (data,graphicsLayer) {
    var vehicleObjects = data;
    if (data.length != 0) {
        for (v = 0; v < vehicleObjects.length; v++) {

            //Define Attributes
            var attributes = {
                "RouteID": vehicleObjects[v].RouteID,
                "Name": vehicleObjects[v].Name,
                "Speed": Math.round(vehicleObjects[v].GroundSpeed),
                "ID": vehicleObjects[v].VehicleID,
                "Angle": Math.abs(vehicleObjects[v].Heading)

            //Create Symbology
            var vehiclePNG = new PictureMarkerSymbol({
                url: app.getImageURL(attributes.RouteID),
                height: 30,
                width: 30,
                angle: attributes.Angle

            //Creat InforTemplate
            var infoTemplate = new InfoTemplate("<img src=" + app.getImageURL(attributes.RouteID) + ">&nbsp<b>" + app.getLineName(attributes.RouteID) + " - ${Name}</b>");

            //Create Graphic
            var vehicleGraphic = new Graphic(new Point(vehicleObjects[v].Longitude, vehicleObjects[v].Latitude,, vehiclePNG, attributes, infoTemplate);

            //Add graphics to graphics layer
        //Create InfoTemplate Content
        app.esriVehicleInfoTemplateRequest(attributes.ID).then(function (response) {
            for (i = 0; i < response.length; i++) {
                for (gL = 0; gL <; gL++) {
                    if (response[i].VehicleID ==[gL].attributes.ID) {
                        if (response[i].Estimates.length != 0) {
                  [gL].infoTemplate.setContent("<b>" + response[i].Estimates[0].Description + ": </b>" + response[i].Estimates[0].Text + "<br><b>" + response[i].Estimates[1].Description + ": </b>" + response[i].Estimates[1].Text);
                        else {
                  [gL].infoTemplate.setContent("No Information Available");


app.setVehicleInterval = function(routeRequestType, graphicsLayer){

    var redVehicleInterval;

    routeRequestType.then(function(vehicleResponse) {
        //For each response returned from esriRequest
        for (i=0; i < vehicleResponse.length; i++){
            //loop through the graphics in the gL to find the graphic that shares the same vehicleID
            //if the vehicleID equals the gL attribute value then update the XY coordinates
            for (gL=0; gL <; gL++){
                if ([gL].attributes.ID === vehicleResponse[i].VehicleID) {
          [gL].geometry.update(vehicleResponse[i].Longitude, vehicleResponse[i].Latitude);
          [gL].attributes.Speed = vehicleResponse[i].GroundSpeed;
                    if (vehicleResponse[i].GroundSpeed > 1.0){
              [gL].symbol.url = app.getImageURL([gL].attributes.RouteID);
                    else {
              [gL].symbol.url = app.getStopImageURL([gL].attributes.RouteID);
                        //returns vehicle route estimates for that specific vehicle ID
                        //Update the infoTemplate content with the newly retrieved content
                        for(tR = 0; tR < templateResponse.length; tR++){
                            for(l=0; l <; l++){
                                if ([l].attributes.ID == templateResponse[tR].VehicleID){
                                    if (templateResponse[tR].Estimates.length != 0){
                                            "<b>"+templateResponse[0].Estimates[0].Description+": </b>"+templateResponse[0].Estimates[0].Text
                                            +"<br><b>"+templateResponse[0].Estimates[1].Description +": </b>"+templateResponse[0].Estimates[1].Text);
                              [l].infoTemplate.setContent("No Information Available");

//Shuttle switches are part of a layer visibility switch function
//I have only included this case here to limit unnecessary code

case "redShuttleSwitch":
    if (state === "on") {
        //Turn off All Active Shuttles if its currently toggled on
        //Request Vehicle Locations
        app.esriVehicleRequest(15).then(function (vehicleResponse) {
            app.vehicleGraphicFunction(vehicleResponse, app.vehiclesGraphicsLayer);
            //Request Stops
            app.esriStopRequest(15).then(function (stopResponse) {
                app.stopsGraphic(new Color([255, 0, 0]), 15, stopResponse);
                //Request Route
                app.esriRouteRequest(15).then(function (routeResponse) {
                    app.routesGraphicFunction(15, routeResponse);

        //Update vehicle positions and infotemplates
        redVehicleInterval = setInterval(function () {
            app.setVehicleInterval(app.esriVehicleRequest(15), app.vehiclesGraphicsLayer)
        }, 5000);

        //Update Stops InfoTemplate
        redStopInterval = setInterval(function(){
    else {
        app.removeGraphic(app.routesGraphicsLayer, 15);
        app.removeGraphic(app.stopsGraphicsLayer, 15);
        app.removeGraphic(app.vehiclesGraphicsLayer, 15);