[esri.views.3d.state.ViewStateManager] #camera= Invalid camera

545
3
05-10-2023 08:03 PM
Blakearc
New Contributor II

Hi all, I am trying to display a scene layer shared on ArcGIS online. I encountered a problem when I initiated the SceneView with camera property. The source code is as below,

const bSceneLayer = new BuildingSceneLayer({
  url: my_url,
});

const basemap = new Basemap({
  baseLayers: [bSceneLayer],
});

var map = new Map({
  basemap: basemap,
});

const view = new SceneView({
  container: "viewDiv",
  map: map,
  camera: {
    heading: 90,
    tilt: 45,
    position: [ -122, 38, 20000 ]
  }
});
 
(The reason of initiating the map in this way is stated in another post)
The scene layer displays but the console shows me an error
Screenshot 2023-05-11 at 10.54.19 AM.png
 
The same error appeared when I tried to assign a new or cloned camera. And no effects when I tried to do view.goTo(...).
Why is this happened and how can I solve this error?
Thanks for helping
Tags (3)
3 Replies
ReneRubalcava
Frequent Contributor

Do you have a repro application in codepen or stackblitz? Using your camera properties in this Sample App works, so it could be something else, maybe an issue with the scene layer and basemap.

 

I just saw you have this other question here related to your scenelayer, so I'm going to guess it's probably related to that.

Blakearc
New Contributor II

Hi. Thank you for the reply.

Due to security issue, I am not able to provide a repo with my current model(layer), and I can't find any similar layer public on the internet. But yes, I think the error is related to the basemap. Everything works fine if I render only the basemap with a default string value from the doc. I am struggling because there is no specification of this error in the doc.

0 Kudos
ArnoFiva
Esri Contributor

If you create a new camera object like this, the position of the camera defaults to WGS84: 

camera: {
  heading: 90, 
  tilt: 45,
  position: [ -122, 38, 20000 ]
}

This is most likely incompatible with the spatial reference of your building scene layer, which is why scene view throws an error. Granted, the error message could provide a bit more information.

You can create a valid camera object like this:

camera: {
  position: {
    x: -122,  /* replace with projected coordinate */
    y: 38, /* replace with projected coordinate */
    z: 20000,
    spatialReference: { wkid: 28992 /* Replace with wkid of your scene layer */ }
  },
  heading: 90,
  tilt: 45
}

 

Also, instead of adding your building scene layer as a basemap, better add it as a layer to your map. This will make sure widgets like the layer list and legend work properly out-of-the-box: 

const bSceneLayer = new BuildingSceneLayer({
  url: my_url,
 });

var map = new Map({
  layers: [bSceneLayer],
});

 

Hope this helps! Otherwise as Rene already pointed out, it would be good to have a running sample app you can share.