ArcEngine添加栅格后,不能闪烁问题

在做一个动画,也就是常说的闪烁吧,一开始的时候只是以矢量数据Shp为实验数据,添加闪烁后,倒是挺成功的

闪烁代码如下:

 IPictureMarkerSymbol pPicsymbol = null;

pPicsymbol = new PictureMarkerSymbolClass();
                string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                string filename = @"\SpatialAnalyst\小鹿.bmp";
                filename = ThePath + filename;
                pPicsymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, filename);
                pPicsymbol.Size = 16;

    ICursor Cursor;                       

    pSelectionSet.Search(null, false, out Cursor);(我假设选择集已经存在了)

    IFeatureCursor pfeatureCursor = Cursor as IFeatureCursor;                     

    IFeature feature = pfeatureCursor.NextFeature();                      

   while (feature != null)                  

       {                           

        map_control.FlashShape(feature.Shape, 3, 300, pPicsymbol as ISymbol);         

                    feature = pfeatureCursor.NextFeature();             

         }

但是后来我添加栅格底图后,不晓得为什么,闪烁总是显示不了,在网上也查不到原因,偶尔的操作发现:只要在加载矢量之后再加载栅格就不会有问题,但我还是不知道原因,也许各位读者能给找到答案

代码如下:

private void addShpToolStripMenuItem_Click(object sender, EventArgs e)

        {

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title = "选择Shp文件";

            openFileDialog1.Filter = "ShapeFile (*.shp)|*.shp";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)//确定按的是“确定”键

            {

                string sFilePath = openFileDialog1.FileName;

                if (sFilePath != null)

                {

                    #region//将路径E:\AE\ESRI\dezhou\road.shp 改造成 E:\AE\ESRI\dezhou

                    // char[] sFilePathTrim = { '\\' };

                    // string[] Arraydir = sFilePath.Split(sFilePathTrim);

                    // string dir2 = null;

                    // for (int i = 0; i < Arraydir.Length - 1; i++)

                    // { dir2 += Arraydir[i] + '\\'; }

                    //dir2.TrimEnd(sFilePathTrim);

                    #endregion

                    bool hasloadedShp = false;

                    int index = sFilePath.LastIndexOf("\\");//这种方法相当的好

                    string dir2 = sFilePath.Substring(0, index);

                    string filename = openFileDialog1.SafeFileName.ToLower();

                    string filenameNoextnetion = filename.Substring(0,filename.LastIndexOf(".shp"));

                    for (int i = 0; i < map_control.LayerCount; i++)

                    {

                        ILayer layer= map_control.get_Layer(i);

                        if (filenameNoextnetion == layer.Name.ToLower())

                        {

                            MessageBox.Show("该图层已经存在!");

                            hasloadedShp = true;

                            break;

                        }

                    }

                    if (hasloadedShp==false)

                    map_control.AddShapeFile(dir2, openFileDialog1.SafeFileName);

                }

                checkMaptips();

            }

        }

private void checkMaptips()

        {

            bool hasRasterlyr = false;

            for (int i = 0; i < map_control.LayerCount; i++)

            {

                ILayer layer = axMapControl1.get_Layer(i);

                if (layer is IFeatureLayer)

                {

                    IFeatureLayer featureLayer = (IFeatureLayer)layer;

                    ILayerFields fields = featureLayer as ILayerFields;

                    int indexfield = fields.FindField("LocalTime");

                    if (indexfield > 0)

                    {

                        // IField field = fields.get_Field(indexfield);

                        //featureLayer.DisplayField = field.Name;

                        featureLayer.DisplayField = "LocalTime";

                        layer.ShowTips = true;

                    }

                }

                else if (layer is IRasterLayer)

                {

                    hasRasterlyr = true;

                }

            }

            if (hasRasterlyr != true)

            {

                try

                {

                    IWorkspaceFactory workspcFac = new RasterWorkspaceFactoryClass();

                    IRasterWorkspace rasterWorkspc;

                    IRasterDataset rasterDatst = new RasterDataset();

                    IRasterLayer rasterLay = new RasterLayer();

                    string applicationPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

                    string filePath = @"\SpatialAnalyst";

                    filePath = applicationPath + filePath;

                    rasterWorkspc = workspcFac.OpenFromFile(filePath, 0) as IRasterWorkspace;

                    rasterDatst = rasterWorkspc.OpenRasterDataset("20110924.tif");

                    rasterLay.CreateFromDataset(rasterDatst);

                    //map_control.ClearLayers();

                    map_control.AddLayer(rasterLay, map_control.LayerCount);

                    map_control.ActiveView.Refresh();

                }

                catch (Exception ex)

                {

                    MessageBox.Show(string.Format( "请确认存在名字叫'{0}'的栅格图层", "20110924.tif"));

                    map_control.ClearLayers();

                    axTOCControl1.Update();

                    map_control.ActiveView.Refresh();

                }

            }

            axMapControl1.ShowMapTips = true;//只有在当前图层显示tips情况下,Map才会显示

        }

作者: 风云

出处: http://www.cnblogs.com/fengyunlishi/

本文版权归风云和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

作者: 风云 出处: http://www.cnblogs.com/fengyunlishi/ 本文版权归风云和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文地址:https://www.cnblogs.com/fengyunlishi/p/2711431.html