Select to view content in your preferred language

TypeError: Cannot call method 'moveToBack' of null

725
5
06-21-2013 07:20 AM
MichaelGlassman2
Deactivated User
I have been using the "Get driving directions" sample template with my own network analysis service. I have been having some trouble getting the graphics of the start and stop points and the route to appear. Additionally, when I changed from using an ESRI basemap to a Tiled Map Service I received this error when trying to run the sample in the JavaScript Sandbox: "TypeError: Cannot call method 'moveToBack' of null". Here is the code snippet where the error is occurring:
    //Show the result of the routing task.
    function showRoute(solveResult) {
      var data = [];
      if(grid) grid.refresh();
      
      var directions = solveResult.routeResults[0].directions;
      directionFeatures = directions.features;
      var routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([0,0,255,0.5])).setWidth(4);
      
      //Add route to the map.
      var routeGraphic = new esri.Graphic(directions.mergedGeometry, routeSymbol); 
      map.graphics.add(routeGraphic);
      routeGraphic.getDojoShape().moveToBack();
      map.setExtent(directions.extent, true);


I am not very experienced with coding with the exception of Python. When I comment out the line with "moveToBack" the error does not accur and the routing works but the graphics still do not appear. Any help anyone may be able to give would be greatly appreciated.
0 Kudos
5 Replies
JohnGravois
Deactivated User
a couple things...

1.  the graphics in the sample seem to be being pulled from our own website.  in the developer tools in the browser (or fiddler), can you confirm that you aren't having trouble downloading them?

var fromSymbol = new esri.symbol.PictureMarkerSymbol({
        ...
        "url":"http://static.arcgis.com/images/Symbols/Transportation/GreenSquareDaymark.png",


2.  the spatial reference of the returned route itself is dictated by the properties we set when we configure the route parameters.  is your new ArcGISTiledMapServiceLayer in a different coordinate system?  if so, you'll have to update the line of code below.

routeParams.outSpatialReference = new esri.SpatialReference({ wkid:102100 });


when i tested using one of our WGS84 services (and updated the SR to be "4326"), i saw the same error in the sandbox that you are describing, but not when i ran the same application on my own machine.  im not sure whats going on there.  how are you even debugging in the sandbox to determine the exact line of the error?
0 Kudos
MichaelGlassman2
Deactivated User
I know that I can access the PNG file. I have not been doing any debugging aside from making some lines comments to see which produce the errors. My data is in a different coordinate system than Web Mercator. It is in NAD_1983_StatePlane_Maryland_FIPS_1900_Feet. I have changed the Spatial Reference a few times but this has only seemed to increase my errors.
0 Kudos
JohnGravois
Deactivated User
have you tried moving outside the sandbox?  i'm not seeing the same error once i paste my code into a new HTML file.
0 Kudos
MichaelGlassman2
Deactivated User
Can I use Notepad++ for this or should I download a different program?
0 Kudos
JohnGravois
Deactivated User
plenty of options, but I personally love Notepad++...
0 Kudos