SceneControl中如何添加图形Element?

SceneControl中如何添加图形Element?
已邀请:

刘峥 - ArcGIS多面手

赞同来自:

【解决办法】:
如果是打开sxd时可以直接通过获取IScene.BasicGraphicsLayer后添加element,但是如果是从数据源添加了数据的话,需要创建并添加IGraphicsLayer ,参考代码:

IGraphicsLayer graphicsLayer = null;
IGraphicsContainer3D graphicsContainer3D = null;

private void AddData_Click(object sender, EventArgs e)
{
IWorkspaceFactory factory = new FileGDBWorkspaceFactoryClass();
IWorkspace wksp = factory.OpenFromFile(@D:\Data.gdb, 0);
IEnumDataset enumDS = wksp.get_Datasets(esriDatasetType.esriDTFeatureClass);
IFeatureClass FC = enumDS.Next() as IFeatureClass;
IFeatureLayer feaLayer = new FeatureLayerClass();
feaLayer.FeatureClass = FC;
feaLayer.Name = 3D Data;
axSceneControl1.Scene.AddLayer(feaLayer as ILayer, false);
axSceneControl1.Scene.SpatialReference = ((IGeoDataset)FC).SpatialReference;

graphicsLayer = axSceneControl1.Scene.BasicGraphicsLayer;
graphicsLayer.Activate(axSceneControl1.Scene as IScreenDisplay);
axSceneControl1.Scene.AddLayer(graphicsLayer as ILayer, true);
}

private void axSceneControl1_OnMouseDown(object sender, ISceneControlEvents_OnMouseDownEvent e)
{
double ValueZ = 0.0;
ICamera pCamara = this.axSceneControl1.Camera;
IRay pRay = pCamara.GetIdentifyRay(e.x, e.y);
IVector3D pVecotor3D = pRay.Vector;
pVecotor3D.Normalize();
double a = (ValueZ - pRay.Origin.Z) / pVecotor3D.ZComponent;
IPoint Pnt = new PointClass();
Pnt.Z = ValueZ;
Pnt.X = pRay.Origin.X + pVecotor3D.XComponent * a;
Pnt.Y = pRay.Origin.Y + pVecotor3D.YComponent * a;
(Pnt as IZAware).ZAware = true;

IElement pElement = new MarkerElementClass();
IRgbColor pColor = new RgbColorClass();
ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();
pMarkerSymbol.Size = 30;
pMarkerSymbol.Color = pColor;
(pElement as IMarkerElement).Symbol = pMarkerSymbol;
pElement.Geometry = Pnt;

if (graphicsLayer != null)
{
graphicsContainer3D = graphicsLayer as IGraphicsContainer3D;
graphicsContainer3D.DeleteAllElements();
graphicsContainer3D.AddElement(pElement);
}
else
{
graphicsLayer = axSceneControl1.Scene.BasicGraphicsLayer;
graphicsContainer3D = graphicsLayer as IGraphicsContainer3D;
graphicsContainer3D.DeleteAllElements();
graphicsContainer3D.AddElement(pElement);
}

axSceneControl1.SceneGraph.RefreshViewers();
}

要回复问题请先登录注册