【转】Scene和Globe下的刷新问题
最近弄ArcGlobe搞的焦头烂额,果然还是资料少。。。感谢共享资源的童鞋们。。
以下为转载内容,自己看起来方便点。
AE中的三维开发,主要是SceneControl和GlobeControl,它们的表现方式和二维MapControl有比较大的差别,所以在三维下往往有些“束缚”的感觉。像在刷新这块就比较难受,可能我们更新了控件里的场景内容,但无论怎样操作都不能让更新显示出来。其实只是平常习惯了的二维下的map没有了,取而代之的是3D View,AE里也提供了一些刷新的方法,大多是刷新viewer的,基本上还是可以满足要求的。
比如我们修改了控件里某个图层的渲染,一般会调用RefreshViewers方法去刷新(Scene下面是ISceneGraph,Globe下是IGlobeDisplay),但实际上控件里的图层不会发生变化,这里就是刷新的问题,需要对图层进行刷新。下面是两个修改图层渲染的例子:
Public Sub TextureLineSymbol() 'Scene下VBA测试修改图层渲染
Dim pSxDoc As ISxDocument
Set pSxDoc = ThisDocument
Dim pTextureSym As ITextureLineSymbol
Set pTextureSym = New TextureLineSymbol
pTextureSym.CreateLineSymbolFromFile "f:\states.jpg"
pTextureSym.Width = 0.02
Dim pSimpLineSym As ISimpleLineSymbol
Set pSimpLineSym = New SimpleLineSymbol
pSimpLineSym.Style = esriSLSDashDot
Dim pLineSym As ILineSymbol
Set pLineSym = pSimpLineSym
pSimpLineSym.Width = 0.02
Dim pSimpRender As ISimpleRenderer
Set pSimpRender = New SimpleRenderer
pSimpRender.Label = "道路名称"
Set pSimpRender.Symbol = pSimpLineSym ' pTextureSym
Dim pGeoLyr As IGeoFeatureLayer
Dim pScene As IScene
Set pScene = pSxDoc.Scene
Set pGeoLyr = pScene.Layer(0)
Set pGeoLyr.Renderer = pSimpRender
pSxDoc.UpdateContents
Dim pSG As ISceneGraph
Set pSG = pScene.SceneGraph
'这样刷新是可以的
pSG.Invalidate pGeoLyr, True, False
'pScene.SceneGraph.ActiveViewer.Redraw True
pSG.RefreshViewers
'以下两种方式刷新不出错,但效果并不变
'pSG.RefreshViewers
'
'Dim pActView As IActiveView
'Set pActView = pScene
'pActView.PartialRefresh esriViewGeography, Nothing, Nothing '这个支持,但refresh方法不支持
End Sub
Globe中的刷新:
pGlobe.AddLayerType pFeatLyr, esriGlobeLayerTypeDraped, True
'Dim pSceneGraph As ISceneGraph
'Set pSceneGraph = pScene.SceneGraph '这样会出错,获取的pSceneGraph 为空
'pSceneGraph.Invalidate pFeatLyr, True, True
pGlobe.GlobeDisplay.RefreshViewers
//C#工程里测试修改Globe图层渲染
private void button1_Click(object sender, EventArgs e) //改变Globe layer的渲染
{
IScene pScene = this.axGlobeControl1.Globe as IScene;
ILayer pLayer = pScene.get_Layer(0);
MessageBox.Show(pLayer.Name);
IGeoFeatureLayer pGeoLyr = pLayer as IGeoFeatureLayer;
ISimpleLineSymbol pLineSym = new SimpleLineSymbolClass();
IRgbColor pColor=new RgbColorClass();
pColor.Blue=0;
pColor.Green=0;
pColor.Red=255;
pLineSym.Color = pColor as IColor;
ISimpleRenderer pSimpleRender = new SimpleRendererClass();
pSimpleRender.Symbol = pLineSym as ISymbol;
pGeoLyr.Renderer = pSimpleRender as IFeatureRenderer;
IGlobeDisplay pGlobeDisp = this.axGlobeControl1.GlobeDisplay;
//以下几种方式刷新都不会变化
pGlobeDisp.RefreshViewers();
IActiveView pActView = this.axGlobeControl1.Globe as IActiveView;
pActView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
//下面这种方式刷新才有效,无论是vector 3d图层,还是栅格化后的矢量图层都可以这样修改渲染
IGlobeDisplayLayers2 pGDispLyrs = pGlobeDisp as IGlobeDisplayLayers2;
pGDispLyrs.RefreshLayer(pLayer);
this.axTOCControl1.Update();
}