How do I convert a 2D map to 3D?

1266
2
10-19-2018 02:56 PM
FayuLai
New Contributor II

I was trying to convert a 2D map to 3D using the following code:

public Task<bool> Create3DView()
{
return QueuedTask.Run(async () =>
{
if (MapView.Active == null) return false;

Map pMap = MapFactory.Instance.CopyMap(MapView.Active.Map);


CIMMap pMapDef = pMap.GetDefinition();
pMapDef.MapType = MapType.Scene;
pMap.SetDefinition(pMapDef);

var pLayers = pMap.GetLayersAsFlattenedList().OfType<FeatureLayer>();
foreach (var pLayer in pLayers)
{
var lyrDefn = pLayer.GetDefinition() as CIMBasicFeatureLayer;
//setting this property moves the layer to 3D group in a scene
lyrDefn.IsFlattened = false;
//Set the definition back to the layer
pLayer.SetDefinition(lyrDefn);
}

pMap.SetName("3D Map");
await ArcGIS.Desktop.Core.ProApp.Panes.CreateMapPaneAsync(pMap, MapViewingMode.SceneLocal, null);

return true;
});
}

But I kept getting the following error:

"A 2D map cannot be opened as a 3D map. Convert the map first and then open."

I have set the map type to MapType.Scene.

Any ideas?

0 Kudos
2 Replies
FayuLai
New Contributor II

Is this a Pro API bug?  Any help will be greatly appreciated.

0 Kudos
PeterYurkosky
Esri Contributor

We don't expose this functionality in the API (converting a map between 2D and 3D), but it's a good idea, and we may be able to add it in the near future.

In the meantime, try this:

  1. Create a brand-new scene (don’t copy the existing one).
  2. Delete the default basemap layer.
  3. Copy the layers over using LayerFactory.CopyLayer. At least this way, the layers’ symbology will be maintained, and in many cases, appropriate 3D-related defaults will be set.
  4. Change the feature layers’ IsFlattened property, the way you’re already doing.

 

In lieu of a genuine ConvertMapToScene function, this should get you pretty close.

Cheers,

Pete Yurkosky

Programmer - ArcGIS Pro

0 Kudos