zoukankan      html  css  js  c++  java
  • 在GlobeControl中画面的问题

    http://wuhaodesktop.spaces.live.com/blog/cns!7222D82032DD6AB5!143.entry

    从开始学AE时就在考虑这个问题,为什么画线可以让它贴着球面,但面却不行,尝试了很多方法,但最后都没能解决。后来有一天偶然在esri的edn上看到一则提示,说二维的面元素和一维的线元素不同,它不能通过其顶点坐标来确定,其中的面还有弧度的定义。想想也是,如果只定义四个顶点,谁说它就是个弧面了?没准还是个平面呢,还有可能是中间拐很多弯的那种。

    于是又在帮助里找怎么定义弧面的方法,结果是一个也没有。再又是一个偶然的机会,我看到了与rasterize相关的一些问题,发现GlobeGraphicsLayer的属性里可以把它设为Rasterize,设置之后画出来的面马上就贴在地球上了,不过是贴在地面,不能浮空,但已经可以达到要求了,欣喜若狂,却发现无法设置图形的透明度了,画出来的一个面又大,还是纯色的,贴在上面,把下面的国界啊,省界啊,地貌什么的统统都遮住了。试了几乎所有改变透明度的方法,都不行,画出来的图形还是像个大饼一样贴在地球上。

    郁闷了,直到一天忽然想到可以单独建一个图层,通过设置图层的透明度来把图形设为半透明,这倒是个好办法。为证明这个办法的可行性,我先在程序里画了一个多边形,存成lyr文件,再在ArcGlobe里打开,贴在地球上,再调整这个图层的透明度,那鸟图形终于变成半透明了!好了,现在就想法在程序里调整图层的透明度吧,在帮助里查了好多资料,又在论坛上问了好多人,代码终于写出来了,但那鸟图形却迟迟不变透明,无奈之下我只好暂时放弃,在论坛上发了个贴子求助,几天了也没人回,我几乎绝望,心想在下面的代码里只好用边线来代替面了。

    但是似乎是老天有眼,一个星期之后我再上论坛时发现我那个帖子竟然有人回了,按那位高人的办法一试,成了!真是功夫不负有心人啊,下面就把代码和效果图记下来,做个记念吧,顺便再感谢一下那位回贴的高人。

    要在GlobeControl里画出贴在地表的多边形来,需要通过IGlobeGraphicsElementProperties设置图层的属性为Draped,并设为Rasterize,此时画上去的多边形无法设置其透明度,由于它覆盖了后面的国界,地形等重要地理信息,因此影响极坏,急需改变,可以通过设置该图层的透明度来实现,过程如下: 

    //设置透明度       
    ILayerEffects pLayerEffects = pLayer as ILayerEffects;
    pLayerEffects.Transparency = 50;
    //让设置起作用
    IGlobeDisplayLayers pGlobeLayers = m_globeDisplay as IGlobeDisplayLayers;
    IGlobeLayerProperties pGlobeLayerProps=pGlobeLayers .FindGlobeProperties (pLayer);
    //应用设置         
    pGlobeLayerProps.ApplyDisplayProperties(pLayer);

    相关代码如下:
              //添加新图层
                ILayer pLayer= new GlobeGraphicsLayerClass();
                pLayer.Name = "TraceOfSat";
                m_globe.AddLayerType(pLayer, esriGlobeLayerType.esriGlobeLayerTypeDraped, false);
                m_scene.ActiveGraphicsLayer = pLayer;

            IGlobeGraphicsLayer pGL= pLayer as IGlobeGraphicsLayer;
    //透明度
              ILayerEffects pLayerEffects = pLayer as ILayerEffects;
                pLayerEffects.Transparency = 50;

                IGlobeDisplayLayers pGlobeLayers = m_globeDisplay as IGlobeDisplayLayers;
                IGlobeLayerProperties pGlobeLayerProps=pGlobeLayers .FindGlobeProperties (pLayer);
    //应用设置         
    pGlobeLayerProps.ApplyDisplayProperties(pLayer);

    //图层的其它属性
            IGlobeGraphicsElementProperties pGEP = new GlobeGraphicsElementPropertiesClass();
             pGEP.DrapeElement = true;
                pGEP.DrapeZOffset = 1000000;
                pGEP.Rasterize = true;

    //定义多边形的四个顶点
             IPoint p1 = new PointClass();
                IPoint p2 = new PointClass();
                IPoint p3 = new PointClass();
                IPoint p4 = new PointClass();

                p1.PutCoords(0,0);
                p1.Z = 100000;
                p2.PutCoords(50,0);
                p2.Z = 1000000;
                p3.PutCoords(50,50);
                p3.Z = 1000000;
                p4.PutCoords(0,50);
                p4.Z = 1000000;

    //填充颜色
                IRgbColor pcolor = new RgbColorClass();
                pcolor.Red = 230;
                pcolor.Green = 0;
                pcolor.Blue = 0;

                  ISimpleFillSymbol pFillSym = new SimpleFillSymbol();
                pFillSym.Color = pcolor;
                ISimpleLineSymbol pLineSym = new SimpleLineSymbolClass();
                pLineSym.Color = pcolor;
    //绘制多边形
                IElement pElement = DrawPolygonWithPoints(p1, p2, p3, p4, pFillSym);
    //添加到界面中
               int index1;
                pGL.AddElement(pElement, pGEP2, out index1);
                m_pSceneview.Redraw(false);

    //根据四个顶点画多边形
          private  IElement DrawPolygonWithPoints(IPoint point1, IPoint point2, IPoint point3,
                IPoint point4, ISimpleFillSymbol pFillSym)
            {
                IElement pElement;
                IGeometry pGeometry;
                IPointCollection pPoints;
                IFillShapeElement pFillElement;
                IPoint pPoint = new PointClass();

                object Missing = Type.Missing;

                pElement = new PolygonElement();
                pGeometry = new PolygonClass();
                pPoints = pGeometry as IPointCollection;
                pPoint.PutCoords(point1.X, point1.Y);
                pPoint.Z = point1.Z;
                pPoints.AddPoint(pPoint,ref  Missing,ref Missing);

                pPoint.PutCoords(point2.X, point2.Y);
                pPoint.Z = point2.Z;
                pPoints.AddPoint(pPoint, ref Missing, ref Missing);

                pPoint.PutCoords(point3.X, point3.Y);
                pPoint.Z = point3.Z;
                pPoints.AddPoint(pPoint, ref Missing, ref Missing);

                pPoint.PutCoords(point4.X, point4.Y);
                pPoint.Z = point4.Z;
                pPoints.AddPoint(pPoint, ref Missing, ref Missing);

                pElement.Geometry = pGeometry;

                pFillElement = pElement as IFillShapeElement ;
                pFillElement.Symbol = pFillSym;

                return pElement;
            }

    效果图如下:

    图片1

  • 相关阅读:
    CF1202F You Are Given Some Letters...
    CF1178E Archaeology
    PTA (Advanced Level) 1005 Spell It Right
    PTA (Advanced Level) 1004 Counting Leaves
    Qt5——从零开始的Hello World教程(Qt Creator)
    PTA (Advanced Level) 1003 Emergency
    PTA (Advanced Level) 1002 A+B for Polynomials
    HDU 1272 小希的迷宫
    FZU 2150 Fire Game
    HihoCoder
  • 原文地址:https://www.cnblogs.com/wangzihao/p/1910122.html
Copyright © 2011-2022 走看看