FeatureLayer can't be added to two maps in JS API v4.0

1065
2
Jump to solution
11-29-2016 11:16 AM
Jay_Gregory
Occasional Contributor III

I'm playing around with v4.0 of the API, and noticed that a feature layer can only be added to a single Map.  My app has both a SceneView and a MapView (the views are toggled in the same div with a button), each with a separate corresponding Map object.  

I can add my FeatureLayer to my Map for my MapView, and it shows up.  

If I try to add my FeatureLayer to my Map for my SceneView, it will remove the layer from my Map/MapView and add it to my Map/SceneView.  

The only way I can add a layer to both a MapView and SceneView at the same time (i.e. syncing layers across two maps/map views) is essentially cloning the FeatureLayer (or creating a new one) and adding the second one to the second view.  Seems laborious and unnecessary because now my app has to keep track of two FeatureLayers that are exactly the same, just to get them to appear in two different views.  Is this by design or am I doing something wrong?

0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

The layer should only exist in one map, but the map can have multiple views. Have you tried creating just ONE layer in ONE map, then use that single map for both the MapView and SceneView? 

View solution in original post

2 Replies
JohnGrayson
Esri Regular Contributor

The layer should only exist in one map, but the map can have multiple views. Have you tried creating just ONE layer in ONE map, then use that single map for both the MapView and SceneView? 

Jay_Gregory
Occasional Contributor III

Thanks so much!  That worked.

Don't know why I didn't think of that myself.  The examples show two map objects instead of one (the Calcite-Maps examples at least), and that was the example I was basing my app off of, but I guess it's unnecessary to have two Map objects because a MapView doesn't break when fed a Map with a ground parameter specified.  

0 Kudos