示例#1
0
        /// <summary>
        /// 反序列化点图像
        /// 从mwsr中获得点信息并翻译,应用到图层上。
        /// </summary>
        public void DeserializePointImageScheme(int newHandle, XmlElement root)
        {
            Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmLock);
            try
            {
                MapWinGIS.Utility.ImageUtils imgUtil = new MapWinGIS.Utility.ImageUtils();

                bool found = false;
                Interfaces.ShapefilePointImageScheme csh = new Interfaces.ShapefilePointImageScheme(newHandle);

                Hashtable TranslationTable = new Hashtable();

                foreach (XmlElement xe1 in root)
                {
                    if (xe1.Name == "PointImageScheme")
                    {
                        found          = true;
                        csh.FieldIndex = long.Parse(xe1.Attributes["FieldIndex"].InnerText);

                        foreach (XmlElement xe2 in xe1.ChildNodes)
                        {
                            if (xe2.Name == "ImageData")
                            {
                                foreach (XmlElement xe3 in xe2.ChildNodes)
                                {
                                    long origIndex = long.Parse(xe3.Attributes["ID"].InnerText);

                                    string imgtype;
                                    imgtype = xe3["Image"].Attributes["Type"].InnerText;
                                    System.Drawing.Image img = (System.Drawing.Image)(ConvertStringToImage(xe3["Image"].InnerText, imgtype));

                                    MapWinGIS.Image ico = new MapWinGIS.Image();
                                    ico.Picture = (stdole.IPictureDisp)imgUtil.ImageToIPictureDisp(img);
                                    if (ico != null)
                                    {
                                        ico.TransparencyColor = (uint)ico.Value[0, 0];
                                    }

                                    int newidx = System.Convert.ToInt32(Program.frmMain.MapMain.set_UDPointImageListAdd(newHandle, ico));
                                    TranslationTable.Add(origIndex, newidx);
                                    img = null;
                                }
                            }
                            else if (xe2.Name == "ItemData")
                            {
                                foreach (XmlElement xe3 in xe2.ChildNodes)
                                {
                                    if (xe3.Name == "Item")
                                    {
                                        string tag         = xe3.Attributes["MatchValue"].InnerText;
                                        long   imgIndex    = long.Parse(xe3.Attributes["ImgIndex"].InnerText);
                                        long   actualIndex = -1;
                                        if (TranslationTable.Contains(imgIndex))
                                        {
                                            actualIndex = System.Convert.ToInt64(TranslationTable[imgIndex]);
                                        }
                                        else
                                        {
                                            actualIndex = imgIndex;
                                        }

                                        if (actualIndex != -1 && tag != "")
                                        {
                                            csh.Items.Add(tag, actualIndex);
                                        }

                                        MapWinGIS.Shapefile sf;

                                        sf = (MapWinGIS.Shapefile)(Program.frmMain.m_Layers[newHandle].GetObject());
                                        if (sf == null)
                                        {
                                            Program.g_error = "获取Shapefile 对象失败。";
                                            return;
                                        }

                                        if (actualIndex != -1)
                                        {
                                            for (int j = 0; j < sf.NumShapes; j++)
                                            {
                                                if (sf.CellValue[(int)csh.FieldIndex, j].ToString() == tag)
                                                {
                                                    Program.frmMain.MapMain.set_ShapePointImageListID(newHandle, j, (int)actualIndex);
                                                    if (Program.frmMain.MapMain.get_ShapePointType(newHandle, j) != MapWinGIS.tkPointType.ptImageList)
                                                    {
                                                        Program.frmMain.MapMain.set_ShapePointType(newHandle, j, MapWinGIS.tkPointType.ptImageList);
                                                    }
                                                    Program.frmMain.MapMain.set_ShapePointSize(newHandle, j, 1);
                                                }
                                            }
                                        }

                                        sf = null;
                                    }
                                }
                            }
                            else if (xe2.Name == "ItemVisibility")
                            {
                                foreach (XmlElement xe3 in xe2.ChildNodes)
                                {
                                    if (xe3.Name == "Item")
                                    {
                                        string tag = xe3.Attributes["MatchValue"].InnerText;
                                        bool   vis = bool.Parse(xe3.Attributes["Visible"].InnerText);
                                        csh.ItemVisibility.Add(tag, vis);

                                        MapWinGIS.Shapefile sf;

                                        sf = (MapWinGIS.Shapefile)(Program.frmMain.m_Layers[newHandle].GetObject());
                                        if (sf == null)
                                        {
                                            Program.g_error = "获取Shapefile 对象失败.";
                                            return;
                                        }

                                        for (int j = 0; j < sf.NumShapes; j++)
                                        {
                                            if (sf.CellValue[(int)csh.FieldIndex, j].ToString() == tag)
                                            {
                                                Program.frmMain.MapMain.set_ShapeVisible(newHandle, j, vis);
                                            }
                                        }

                                        sf = null;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }

                if (found)
                {
                    Program.frmMain.Legend.Layers.ItemByHandle(newHandle).PointImageScheme = csh;
                }

                TranslationTable.Clear();
                GC.Collect();
            }
            catch (Exception ex)
            {
                MapWinGIS.Utility.Logger.Dbg("DEBUG: " + ex.ToString());
            }
            finally
            {
                Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmUnlock);
            }
        }
示例#2
0
        /// <summary>
        /// 更新PreviewMap的地图显示
        /// </summary>
        /// <param name="fullExtents">指示是否使用全图显示地图</param>
        public void GetPictureFromMap(bool fullExtents)
        {
            try
            {
                MapWinGIS.Extents exts;
                MapWinGIS.Image   img     = new MapWinGIS.Image();
                double            ratio   = 0;
                MapWinGIS.Extents oldExts = (MapWinGIS.Extents)Program.frmMain.MapMain.Extents;

                //锁定地图
                Program.frmMain.MapPreview.LockWindow(MapWinGIS.tkLockMode.lmLock);
                Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmLock);

                if (fullExtents) //更新为全图显示,主地图也更新为全图显示
                {
                    exts = Program.frmMain.m_View.MaxVisibleExtents;
                    if (Program.frmMain.MapPreview.Width < Program.frmMain.MapPreview.Height) //宽小于高
                    {
                        ratio = System.Convert.ToDouble(Program.frmMain.MapPreview.Width / Program.frmMain.MapMain.Width);
                    }
                    else //宽大于高
                    {
                        ratio = System.Convert.ToDouble(Program.frmMain.MapPreview.Height / Program.frmMain.MapMain.Height);
                    }
                    ratio *= 1.5; //缩放比例

                    Program.frmMain.MapMain.Extents = exts;
                    exts = (MapWinGIS.Extents)Program.frmMain.MapMain.Extents;
                }
                else
                {
                    exts = (MapWinGIS.Extents)Program.frmMain.MapMain.Extents;
                }

                img = (MapWinGIS.Image)(Program.frmMain.MapMain.SnapShot(exts));

                MapWinGIS.Utility.ImageUtils cvter  = new MapWinGIS.Utility.ImageUtils();
                System.Drawing.Image         tmpImg = MapWinGIS.Utility.ImageUtils.ObjectToImage(img.Picture, System.Convert.ToInt32(img.Width * ratio), System.Convert.ToInt32(img.Height * ratio));

                img.Picture          = (stdole.IPictureDisp)(cvter.ImageToIPictureDisp(tmpImg));
                img.dX               = (exts.xMax - exts.xMin) / img.Width;
                img.dY               = (exts.yMax - exts.yMin) / img.Height;
                img.XllCenter        = exts.xMin + 0.5 * img.dX;
                img.YllCenter        = exts.yMin + 0.5 * img.dX;
                img.DownsamplingMode = MapWinGIS.tkInterpolationMode.imHighQualityBicubic;
                img.UpsamplingMode   = MapWinGIS.tkInterpolationMode.imHighQualityBicubic;

                Program.frmMain.MapPreview.RemoveAllLayers();
                Program.frmMain.MapPreview.AddLayer(img, true);
                Program.frmMain.MapPreview.ExtentPad = 0;
                Program.frmMain.MapPreview.ZoomToMaxExtents();
                Program.frmMain.m_PreviewMap.m_ShowLocatorBox = true;
                Program.frmMain.m_PreviewMap.UpdateLocatorBox();

                Program.frmMain.mnuZoomPreviewMap.Enabled = Program.frmMain.MapMain.NumLayers > 0 && Program.frmMain.PreviewMapExtentsValid();
                if (Program.frmMain.m_Menu["mnuZoomToPreviewExtents"] != null)
                {
                    Program.frmMain.m_Menu["mnuZoomToPreviewExtents"].Enabled = Program.frmMain.MapMain.NumLayers > 0 && Program.frmMain.PreviewMapExtentsValid();
                }
            }
            catch (Exception ex)
            {
                Program.g_error = ex.ToString();
                Program.ShowError(ex);
            }
            finally
            {
                //解锁地图
                Program.frmMain.MapPreview.LockWindow(MapWinGIS.tkLockMode.lmUnlock);
                Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmUnlock);
            }
        }