AnsweredAssumed Answered

Feature Layer not showing up when adding an automatic rotation function to SceneView

Question asked by mvilla_geek on Aug 20, 2018

I am building a simple web application using the ArcGIS API for JavaScript (4.x). I created a map with an associated FeatureLayer and then a SceneView and everything works fine. However, I'm trying to make the scene rotate automatically. When I implement a function using scheduling the rotation works but the FeatureLayer dissapears and only the basemap is visible. Has anyone experienced the same problem or does someone know an approach to this issue?

Here is my code. The function that makes rotate the scene is at the end, inside scheduling.addFrameTask. I took it from an example in http://proceedings.esri.com/library/userconf/devsummit16/papers/dev_int_204.pdf (page 21).

 

  1. <!DOCTYPE html>  
  2. <html>  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">  
  6.       <title>App</title>  
  7.       <style>  
  8.          html,  
  9.          body,  
  10.          #viewDiv {  
  11.          padding: 0;  
  12.          margin: 0;  
  13.          height: 100%;  
  14.          width: 100%;  
  15.          }  
  16.       </style>  
  17.       <link rel="stylesheet" href="https://js.arcgis.com/4.8/esri/css/main.css">  
  18.       <script src="https://js.arcgis.com/4.8/"></script>  
  19.       <script>  
  20.          require([  
  21.              "esri/Map",  
  22.              "esri/views/SceneView",  
  23.              "esri/layers/SceneLayer",  
  24.              "esri/layers/FeatureLayer",  
  25.              "esri/core/scheduling",  
  26.              "esri/geometry/Point",  
  27.            
  28.              "dojo/domReady!"  
  29.          ], function(Map, SceneView, SceneLayer, FeatureLayer, scheduling, Point) {  
  30.            
  31.              const countries = new FeatureLayer({  
  32.                  url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Countries_(Generalized)/FeatureServer"  
  33.              });  
  34.            
  35.              // Create Map  
  36.              const map = new Map({  
  37.                  basemap: "gray",  
  38.                  layers: [countries]  
  39.              });  
  40.            
  41.              // Create the SceneView  
  42.              const view = new SceneView({  
  43.                  container: "viewDiv",  
  44.                  map: map,  
  45.                  center: [-74, 1],  
  46.                  scale: 75000000  
  47.              });  
  48.            
  49.              var scale = view.scale;  
  50.              var center = view.center.clone();  
  51.            
  52.              scheduling.addFrameTask({  
  53.                  update: function(ev) {  
  54.                      var pt = new Point({  
  55.                          x: center.longitude + ev.spendInTask / 1000 * 5,  
  56.                          y: center.latitude  
  57.                      });  
  58.            
  59.                      view.goTo({  
  60.                          target: pt,  
  61.                          scale: scale  
  62.                      });  
  63.                  }  
  64.              });  
  65.            
  66.          });  
  67.            
  68.       </script>  
  69.    </head>  
  70.    <body>  
  71.       <div id="viewDiv"></div>  
  72.    </body>  
  73. </html>  

 

Outcomes