Select to view content in your preferred language

Adding a feature layer into a Web scene already containing a Building scene layer

953
5
Jump to solution
05-16-2023 01:56 AM
Blakearc
New Contributor II

Hi all. Thank you for the help before. I successfully display a web scene with a building scene layer from the portal.

Now my next step is to render some icons indicating some spots in the view. I am trying to do it with the following steps:

1. Render the building scene layer and scene view.

2. Use buildingSceneLayer.when, get the fullExtent of building scene layer and trigger the functions below.

3. Map datas into new Graphic() items;

4. Create feature layer sourcing the graphic items, set the fullExtent as the object obtained from step 2 and set elevationInfo mode to be "relative-to-ground".

5. Add the feature layer into scene view by view.layers.add(featureLayer);

 

Problem I have:

The graphics displays correctly if I don't add the building scene layer. However it doesn't show up if I add back the building scene layer.

Again, I am sorry that I am not able to provide a workable repo due to security issue. Perhaps some sample code could help me out. Thank you for any help.

0 Kudos
1 Solution

Accepted Solutions
Blakearc
New Contributor II

I have successfully rendered the feature layer. The solution was to set the same spatial reference as the web scene on all graphic objects when mapping data with Graphic class. I think the doc should explain more on how spatial reference works in the same project among different components. In this project, the feature layer does not required to have a spatial reference but the graphic object does.

View solution in original post

0 Kudos
5 Replies
Blakearc
New Contributor II

Although I can't provide my full code, I can provide my coding structure for reference.

 

const DATA = "[...]";

// modify spatial reference
const webscene = new WebScene({
   spatialReference: {
      wkid: 102140,
      latestWkid: 2326,
   },
});

const view = new SceneView({
   container: "viewDiv",
   map: webscene,
});

const buildingLayer = new BuildingSceneLayer({
   url: building_scene_layer_url,
});

webscene.layers.add(buildingLayer);

buildingLayer.when(() => {
   const iconsLayer = renderFeatureLayer(buildingLayer.fullExtent);
   webscene.add(iconsLayer);
});

function renderFeatureLayer(_defaultLayerDimension) {
   const icons = DATA.map(
      (d) =>
         new Graphic({
            // ...other configs
            // set geometry
            geometry: new Point({ x, y, z }),
         })
   );

   const SYMBOL = {
      type: "simple-marker",
      color: "blue",
      size: "200px",
      outline: {
        width: 0.5,
        color: "darkblue",
      },
   };

   const featureLayer = new FeatureLayer({
     // ...other configs
     source: icons,
     elevationInfo: { mode: "relative-to-ground" },
      maxScale: 1,
      minScale: 1,
      // spatial reference doesn't affect the result
      spatialReference: {
        wkid: 102140,
        latestWkid: 2326,
     },
     renderer: {
        type: "simple",
        symbol: SYMBOL,
      },
      fullExtent: _defaultLayerDimension,
   });

   return featureLayer;
}
0 Kudos
dani
by Esri Contributor
Esri Contributor

I was able to get your code here working by filling in some blanks where you have your own custom data. I am using a different spatial reference, but the only other key difference I had to make to get it to work was to change or remove the 'minScale' value you have set in the feature layer. In the code above, you have minScale set to 1, which is the same as your maxScale value. minScale, if set, should always have a higher value than maxScale. Is it possible that this is causing the issue you're seeing? As the code is now, it makes sense that the graphics in the feature layer would not be visible. See this section for more info. 

I'd recommend removing minScale (so the layer's visibility is not restricted) and seeing if that resolves the issue. If not, please let us know and we can investigate further. 

0 Kudos
Blakearc
New Contributor II

Hi. Thank you for the reply.

The spatial reference on the webscene was configured for the building scene layer so that it shows up. I can't use another spatial reference here.

I also tried to comment out maxScale, minScale and spatial reference when initializing the feature layer. With the building scene layer hidden, the icon displays correctly. But it disappears when any of scaling & spatial reference is configured.

0 Kudos
Blakearc
New Contributor II

I have successfully rendered the feature layer. The solution was to set the same spatial reference as the web scene on all graphic objects when mapping data with Graphic class. I think the doc should explain more on how spatial reference works in the same project among different components. In this project, the feature layer does not required to have a spatial reference but the graphic object does.

0 Kudos
dani
by Esri Contributor
Esri Contributor

Thanks for the update, I can take a look through the documentation to see where some improvements could be made around this. 

0 Kudos