private void SetDefaultSymbol(ILineElement elem)
        {
            ILineSymbol          defaultLineSym = null;
            String               esriStylePath;
            IStyleGallery        styleGallery = new StyleGalleryClass();
            IStyleGalleryStorage styleStor    = (IStyleGalleryStorage)styleGallery;

            esriStylePath = styleStor.DefaultStylePath + "ESRI.style";

            IEnumStyleGalleryItem styleItems = styleGallery.get_Items("Line Symbols", esriStylePath, "Dashed");

            styleItems.Reset();
            IStyleGalleryItem styleGalleryItem = styleItems.Next();

            while (!(styleGalleryItem == null))
            {
                if (styleGalleryItem.Name == "Dashed 4:4")
                {
                    defaultLineSym       = (ILineSymbol)styleGalleryItem.Item;
                    defaultLineSym.Width = 1.50;
                    IRgbColor rgbColor = new RgbColorClass();
                    rgbColor.Red          = 255;
                    rgbColor.Blue         = 0;
                    rgbColor.Green        = 0;
                    rgbColor.Transparency = 50;
                    defaultLineSym.Color  = rgbColor;
                    break;
                }
                else
                {
                    styleGalleryItem = styleItems.Next();
                }
            }
            elem.Symbol = defaultLineSym;
        }
Esempio n. 2
0
        private void styleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IStyleGallery        pStyleGlry    = new ServerStyleGalleryClass();
            IStyleGalleryStorage pStyleStorage = pStyleGlry as IStyleGalleryStorage;

            IRgbColor pRgbColor = new RgbColorClass();

            pRgbColor.Red   = 255;
            pRgbColor.Green = 1;
            pRgbColor.Blue  = 2;

            IStyleGalleryItem pStyleItem = new ServerStyleGalleryItemClass();

            pStyleItem.Name     = "Red";
            pStyleItem.Category = "Default";
            pStyleItem.Item     = pRgbColor;

            string pOldFile = pStyleStorage.TargetFile;

            pStyleStorage.TargetFile = @"E:\test.style";
            pStyleGlry.AddItem(pStyleItem);
            pStyleStorage.TargetFile = pOldFile;
            IColor color = pRgbColor as IColor;

            this.Text = color.RGB.ToString();
        }
Esempio n. 3
0
        private void DrawColorRamp()
        {
            string               sInstall            = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;
            string               styleFilePath       = sInstall + "\\Styles\\ESRI.ServerStyle";
            IStyleGallery        styleGallery        = new ServerStyleGalleryClass();
            IStyleGalleryItem    styleGalleryItem    = null;
            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.AddFile(styleFilePath);

            IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items("Color Ramps", styleFilePath, "");

            enumStyleGalleryItem.Reset();

            styleGalleryItem = enumStyleGalleryItem.Next();

            while (styleGalleryItem != null)
            {
                m_ColorRamp = (IColorRamp)styleGalleryItem.Item;
                EnumStyleItem.Add(m_ColorRamp);
                m_FillSymbol = new GradientFillSymbol();
                m_FillSymbol.GradientAngle = 0;
                m_FillSymbol.ColorRamp     = m_ColorRamp;
                pictureBox1.Image          = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                imageList1.Images.Add(pictureBox1.Image);
                comboBoxColor.Items.Add(pictureBox1.Image);
                styleGalleryItem = enumStyleGalleryItem.Next();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(enumStyleGalleryItem);
        }
Esempio n. 4
0
        private void menuItemAddStyleSet1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (this.m_pSG is ESRI.ArcGIS.esriSystem.IPersistStream)
            {
                dialog.Filter = "符号库 (*.ServerStyle)|*.ServerStyle";
            }
            else
            {
                dialog.Filter = "符号库 (*.Style)|*.Style";
            }
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                IStyleGalleryStorage pSG = (IStyleGalleryStorage)this.m_pSG;
                int fileCount            = pSG.FileCount;
                pSG.AddFile(dialog.FileName);
                if (fileCount == pSG.FileCount)
                {
                    pSG = null;
                }
                else
                {
                    pSG = null;
                    this.AddSymbol(dialog.FileName);
                }
            }
        }
Esempio n. 5
0
        // 从符号
        public static ISymbol FetchSymbol(string name)
        {
            string               strStartPath         = System.Windows.Forms.Application.StartupPath;
            IStyleGallery        pStyleGallery        = new ServerStyleGalleryClass();
            IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;

            pStyleGalleryStorage.AddFile(strStartPath + "\\mlb.ServerStyle");

            IEnumStyleGalleryItem pEnumStyleGalleryItem = pStyleGallery.get_Items("Marker Symbols", strStartPath + "\\mlb.ServerStyle", null);

            ISymbol pSymbol = null;

            pEnumStyleGalleryItem.Reset();
            IStyleGalleryItem pStyleGalleryItem = pEnumStyleGalleryItem.Next();


            while (pStyleGalleryItem != null)
            {
                if (pStyleGalleryItem.Name == name)
                {
                    //获取符号
                    pSymbol = pStyleGalleryItem.Item as ISymbol;
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleGalleryItem);
                    break;
                }

                pStyleGalleryItem = pEnumStyleGalleryItem.Next();
            }

            return(pSymbol);
        }
Esempio n. 6
0
        private void DrawColorRamp()
        {
            string               strDefaultStyleFileName = string.Format("{0}\\CNUStyles\\ESRI.ServerStyle", Application.StartupPath);
            IStyleGallery        styleGallery            = new ServerStyleGalleryClass();
            IStyleGalleryItem    styleGalleryItem        = new ServerStyleGalleryItemClass();
            IStyleGalleryStorage styleGalleryStorage     = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.AddFile(strDefaultStyleFileName);
            IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items("Color Ramps", strDefaultStyleFileName, "");

            enumStyleGalleryItem.Reset();
            styleGalleryItem = enumStyleGalleryItem.Next();
            while (styleGalleryItem != null)
            {
                m_ColorRamp = (IColorRamp)styleGalleryItem.Item;
                EnumStyleItem.Add(m_ColorRamp);
                //新建m_FillSymbol和m_colorRamp
                m_FillSymbol = new GradientFillSymbol();
                m_FillSymbol.GradientPercentage = 1;
                m_FillSymbol.IntervalCount      = 255;
                m_FillSymbol.GradientAngle      = 0;
                m_FillSymbol.ColorRamp          = m_ColorRamp;
                pictureBox1.Image = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                pictureBox2.Image = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                imageList1.Images.Add(m_ColorRamp.Name, pictureBox1.Image);
                imageList2.Images.Add(m_ColorRamp.Name, pictureBox1.Image);
                colorComboBox.Items.Add(pictureBox1.Image);
                colorComboBox1.Items.Add(pictureBox2.Image);
                styleGalleryItem = enumStyleGalleryItem.Next();
            }
        }
Esempio n. 7
0
        private void btnBrowStyle_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter           = "符号库 (*.Style)|*.Style",
                RestoreDirectory = true
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                IStyleGalleryStorage pSG = (IStyleGalleryStorage)this.m_pSG;
                int fileCount            = pSG.FileCount;
                pSG.AddFile(dialog.FileName);
                if (fileCount == pSG.FileCount)
                {
                    pSG = null;
                }
                else
                {
                    pSG = null;
                    this.cboLookupStyleset.Properties.Items.Add(dialog.FileName);
                    this.cboLookupStyleset.Text = dialog.FileName;
                }
            }
        }
Esempio n. 8
0
 private void btnMoreSymbol_Click(object sender, EventArgs e)
 {
     if (this.m_pSG != null)
     {
         try
         {
             this.popupMenu1.ClearLinks();
             this.barManager1.Items.Clear();
             this.barManager1.Items.Add(this.menuItemAddStyleSet);
             IStyleGalleryStorage pSG = (IStyleGalleryStorage)this.m_pSG;
             for (int i = 0; i < pSG.FileCount; i++)
             {
                 string path   = pSG.get_File(i);
                 int    length = path.LastIndexOf(@"\");
                 if (length != -1)
                 {
                     path = path.Substring(length + 1);
                 }
                 length = path.LastIndexOf(".");
                 if (length != -1)
                 {
                     path = path.Substring(0, length);
                 }
                 string        fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
                 BarButtonItem item = this.barManager1.Items[fileNameWithoutExtension] as BarButtonItem;
                 if (item == null)
                 {
                     item = new BarButtonItem
                     {
                         Name    = fileNameWithoutExtension,
                         Caption = path,
                         Id      = this.barManager1.GetNewItemId()
                     };
                     this.barManager1.Items.Add(item);
                     item.ItemClick += new ItemClickEventHandler(this.item_ItemClick);
                 }
                 item.ButtonStyle = BarButtonStyle.Check;
                 this.popupMenu1.AddItem(item);
             }
             pSG = null;
             if (this.popupMenu1.ItemLinks.Count == 0)
             {
                 this.popupMenu1.AddItem(this.menuItemAddStyleSet);
             }
             else
             {
                 this.popupMenu1.AddItem(this.menuItemAddStyleSet).BeginGroup = true;
             }
             Point p = new Point(this.btnMoreSymbol.Location.X,
                                 this.btnMoreSymbol.Location.Y + this.btnMoreSymbol.Height);
             p = base.PointToScreen(p);
             this.popupMenu1.ShowPopup(p);
         }
         catch (Exception exception)
         {
             Logger.Current.Error("", exception, "");
         }
     }
 }
Esempio n. 9
0
        ///<summary>
        ///获取符号库中符号
        ///</summary>
        ///<param name="sServerStylePath">符号库全路径名称</param>
        ///<param name="sGalleryClassName">GalleryClass名称</param>
        ///<param name="symbolName">符号名称</param>
        ///<returns>符号</returns>
        private ISymbol GetSymbol(string sServerStylePath, string sGalleryClassName, string symbolName)
        {
            try
            {
                //ServerStyleGallery对象
                IStyleGallery        pStyleGaller         = new ServerStyleGalleryClass();
                IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage;

                IEnumStyleGalleryItem pEnumSyleGalleryItem = null;
                IStyleGalleryItem     pStyleGallerItem     = null;
                IStyleGalleryClass    pStyleGalleryClass   = null;
                //使用IStyleGalleryStorage接口的AddFile方法加载ServerStyle文件
                pStyleGalleryStorage.AddFile(sServerStylePath);
                //遍历ServerGallery中的Class
                for (int i = 0; i < pStyleGaller.ClassCount; i++)
                {
                    pStyleGalleryClass = pStyleGaller.get_Class(i);
                    if (pStyleGalleryClass.Name != sGalleryClassName)
                    {
                        continue;
                    }
                    //获取EnumStyleGalleryItem对象
                    pEnumSyleGalleryItem = pStyleGaller.get_Items(sGalleryClassName, sServerStylePath, "");
                    pEnumSyleGalleryItem.Reset();
                    //遍历pEnumSyleGalleryItem
                    pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    while (pStyleGallerItem != null)
                    {
                        if (pStyleGallerItem.Name == symbolName)
                        {
                            //获取符号
                            ISymbol pSymbol = pStyleGallerItem.Item as ISymbol;
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                            return(pSymbol);
                        }
                        pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                return(null);
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 获取指定种类,指定符号id的符号
        /// </summary>
        /// <param name="sGallery">符号种类(e.g.填充颜色)</param>
        /// <param name="id">符号id</param>
        /// <returns>符号</returns>
        public static ISymbol GetStyleSymbol(string sGallery, int id)
        {
            try
            {
                IStyleGallery        pStyleGallery        = new ServerStyleGalleryClass();
                IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;

                for (int i = pStyleGalleryStorage.FileCount - 1; i >= 0; i--)
                {
                    pStyleGalleryStorage.RemoveFile(pStyleGalleryStorage.get_File(i));
                }

                pStyleGalleryStorage.AddFile(_STYLEFILE);
                IEnumStyleGalleryItem pEnumStyleItem = pStyleGallery.get_Items(sGallery, _STYLEFILE, "");
                pEnumStyleItem.Reset();
                IStyleGalleryItem  mStyleItem  = pEnumStyleItem.Next();
                IStyleGalleryClass mStyleClass = null;
                for (int i = 0; i < pStyleGallery.ClassCount; i++)
                {
                    mStyleClass = pStyleGallery.get_Class(i);
                    string str = mStyleClass.Name;
                    if (str == sGallery)
                    {
                        break;
                    }
                }

                ISymbol result = null;
                while (mStyleItem != null)
                {
                    if (mStyleItem.ID == id)
                    {
                        result = mStyleItem.Item as ISymbol;
                        break;
                    }
                    mStyleItem = pEnumStyleItem.Next();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleItem);
                return(result);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 11
0
        /*从文件获取符号
         *
         */
        private ISymbol getSymbolByName(string symbolstyle, string name)
        {
            ISymbol result    = null;
            string  stylepath = System.Configuration.ConfigurationSettings.AppSettings["SymbolPath"];
            //符号管理对象
            IStyleGallery pStyleGallery = new StyleGalleryClass();
            //符号文件管理, 设定符号文件
            IStyleGalleryStorage  pStyleStorage = pStyleGallery as IStyleGalleryStorage;
            IEnumStyleGalleryItem pEnumStyleGall;
            IStyleGalleryItem     pStyleItem;
            string pp = pStyleStorage.DefaultStylePath;

            pStyleStorage.AddFile(stylepath);
            //根据类型取得不同符号集
            if (symbolstyle == "1")
            {
                pEnumStyleGall = pStyleGallery.get_Items("Marker Symbols", stylepath, "");
            }
            else if (symbolstyle == "2")
            {
                pEnumStyleGall = pStyleGallery.get_Items("Line Symbols", stylepath, "");
            }
            else if (symbolstyle == "3")
            {
                pEnumStyleGall = pStyleGallery.get_Items("Fill Symbols", stylepath, "");
            }
            else
            {
                return(null);
            }
            pEnumStyleGall.Reset();
            pStyleItem = pEnumStyleGall.Next();

            while (pStyleItem != null)       //Loop through and access each marker
            {
                if (pStyleItem.Name == name) //根据符号名称获取符号
                {
                    result = pStyleItem.Item as ISymbol; break;
                }

                pStyleItem = pEnumStyleGall.Next();
            }
            return(result);
        }
Esempio n. 12
0
        private void item_ItemClick(object sender, ItemClickEventArgs e)
        {
            IStyleGalleryStorage pSG = (IStyleGalleryStorage)this.m_pSG;

            if (pSG.FileCount != 1)
            {
                try
                {
                    pSG.RemoveFile(e.Item.Tag.ToString());
                    this.comboBoxEdit.Properties.Items.Clear();
                    this.comboBoxEdit.Properties.Items.Add("全部");
                    this.comboBoxEdit.SelectedIndex = 0;
                    this.m_Category = "";
                    this.ReadCategories(this.m_ClassName);
                    this.ReadSymbol();
                }
                catch
                {
                }
            }
        }
Esempio n. 13
0
        private static void ConvertVectorPicturesToRepresentationMarkers(string stylePath)
        {
            IStyleGallery        styleGallery        = GetStyleGallery(stylePath);
            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.TargetFile = stylePath;
            IEnumStyleGalleryItem enumItems = styleGallery.get_Items("Marker Symbols", stylePath, "Vector");

            IStyleGalleryItem3 originalItem = null;
            IStyleGalleryItem3 newItem      = null;

            enumItems.Reset();

            originalItem = enumItems.Next() as IStyleGalleryItem3;
            while (originalItem != null)
            {
                newItem = ConvertMarkerItemToRep(originalItem);
                styleGallery.AddItem(newItem);
                originalItem = enumItems.Next() as IStyleGalleryItem3;
            }
        }
Esempio n. 14
0
        private static void ConvertVectorPicturesToRepresentationMarkers(string stylePath)
        {
            if (!System.IO.File.Exists(stylePath))
            {
                Console.WriteLine("StylePath does NOT exist: " + stylePath);
                return;
            }

            IStyleGallery        styleGallery        = GetStyleGallery(stylePath);
            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.TargetFile = stylePath;
            IEnumStyleGalleryItem enumItems = styleGallery.get_Items("Marker Symbols", stylePath, "");

            IStyleGalleryItem3 originalItem = null;
            IStyleGalleryItem3 newItem      = null;

            enumItems.Reset();

            originalItem = enumItems.Next() as IStyleGalleryItem3;
            while (originalItem != null)
            {
                IPictureMarkerSymbol pictureMS = originalItem.Item as IPictureMarkerSymbol;
                if (pictureMS != null)
                {
                    // check if it requires conversion to rep marker?
                    // TODO: perhaps make this an option if user doesn't need rep's
                    if (containsVectorTag(originalItem.Tags))
                    {
                        newItem = ConvertMarkerItemToRep(originalItem);
                        Console.WriteLine("Converting symbol " + newItem.Name + " to a representation marker");
                        styleGallery.AddItem(newItem);
                    }
                    originalItem = enumItems.Next() as IStyleGalleryItem3;
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 读取ServerStyle中的文件并显示
        /// </summary>
        /// <param name="StyleGalleryClass">符号文件的种类</param>
        /// <param name="CategoryClass">符号的种类</param>
        /// <param name="cbxCategory">符号文件的种类的容器</param>
        /// <param name="lvSymbol">符号位图的容器</param>
        public static void ReadServerStyle(string StyleGalleryClass, string CategoryClass, ComboBox cbxCategory, ListView lvSymbol)
        {
            lvSymbol.Items.Clear();
            lvSymbol.LargeImageList.Images.Clear();
            IStyleGallery        pStyleGallery        = new ServerStyleGalleryClass();
            IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;

            // 增加符号文件
            //pStyleGalleryStorage.TargetFile = _STYLEFILE;
            for (int i = pStyleGalleryStorage.FileCount - 1; i >= 0; i--)
            {
                pStyleGalleryStorage.RemoveFile(pStyleGalleryStorage.get_File(i));
            }
            pStyleGalleryStorage.AddFile(_STYLEFILE);
            // 根据当前符号的类别和文件得到符号的枚举循环子,符号类别包括Fill Symbol,Line Symbol等
            IEnumStyleGalleryItem pEnumStyleItem = pStyleGallery.get_Items(StyleGalleryClass, _STYLEFILE, "");

            // 得到符号文件类别的各个条目,增加到一个Combox中
            if (cbxCategory != null)
            {
                cbxCategory.Items.Clear();
                cbxCategory.Items.Add(_ALLSYMBOLS);
                IEnumBSTR pEnumBSTR = pStyleGallery.get_Categories(StyleGalleryClass);
                pEnumBSTR.Reset();
                string Category = "";
                Category = pEnumBSTR.Next();
                while (Category != null)
                {
                    cbxCategory.Items.Add(Category);
                    Category = pEnumBSTR.Next();
                }
            }

            pEnumStyleItem.Reset();
            IStyleGalleryItem  mStyleItem  = pEnumStyleItem.Next();
            IStyleGalleryClass mStyleClass = null;

            for (int i = 0; i < pStyleGallery.ClassCount; i++)
            {
                mStyleClass = pStyleGallery.get_Class(i);
                string str = mStyleClass.Name;
                if (str == StyleGalleryClass)
                {
                    break;
                }
            }

            // 得到各个符号并转化为图片
            int       ImageIndex = 0;
            ImageList Largeimage = lvSymbol.LargeImageList;

            if (CategoryClass == "" || CategoryClass == _ALLSYMBOLS)
            {
                while (mStyleItem != null)
                {
                    // 调用另一个类的方法将符号转化为图片
                    Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem);
                    Largeimage.Images.Add(bmpB);
                    ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex);
                    lvSymbol.Items.Add(lvItem);
                    ImageIndex++;
                    mStyleItem = pEnumStyleItem.Next();
                }
            }
            else
            {
                while (mStyleItem != null)
                {
                    if (CategoryClass == mStyleItem.Category)
                    {
                        // 调用另一个类的方法将符号转化为图片
                        Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem);
                        Largeimage.Images.Add(bmpB);
                        ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex);
                        lvSymbol.Items.Add(lvItem);
                        ImageIndex++;
                    }
                    mStyleItem = pEnumStyleItem.Next();
                }
            }
            // 必须采用此方式进行释放,第二次才能正常读取
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleItem);
        }
Esempio n. 16
0
        static void ImportCSV(string csvPath, string stylePath)
        {
            //the expected field names for this util
            string filePath          = "filePath";
            string pointSize         = "pointSize";
            string styleItemName     = "styleItemName";
            string styleItemCategory = "styleItemCategory";
            string styleItemTags     = "styleItemTags";

            IStyleGallery styleGallery = GetStyleGallery(stylePath);

            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.TargetFile = stylePath;

            ITable             table = OpenCSVAsTable(csvPath);
            IRow               row = null;
            int                filePathIdx, styleItemNameIdx, pointSizeIdx, styleItemCategoryIdx, styleItemTagsIdx;
            IStyleGalleryItem3 styleGalleryItem = null;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                // Create the cursor.
                ICursor cursor = table.Search(null, false);
                comReleaser.ManageLifetime(cursor);
                filePathIdx          = cursor.FindField(filePath);
                styleItemNameIdx     = cursor.FindField(styleItemName);
                pointSizeIdx         = cursor.FindField(pointSize);
                styleItemCategoryIdx = cursor.FindField(styleItemCategory);
                styleItemTagsIdx     = cursor.FindField(styleItemTags);

                int rowCount = 0;
                while ((row = cursor.NextRow()) != null)
                {
                    rowCount++;

                    try
                    {
                        String itemFilePath = (string)row.get_Value(filePathIdx);
                        IPictureMarkerSymbol pictureMarkerSymbol = MakeMarkerSymbol(itemFilePath, Convert.ToDouble(row.get_Value(pointSizeIdx)));

                        if (pictureMarkerSymbol == null)
                        {
                            Console.WriteLine("Image not found: Row: " + rowCount + ", Image: " + itemFilePath);
                            continue;
                        }

                        styleGalleryItem          = new StyleGalleryItemClass();
                        styleGalleryItem.Item     = pictureMarkerSymbol;
                        styleGalleryItem.Name     = row.get_Value(styleItemNameIdx) as string;
                        styleGalleryItem.Category = row.get_Value(styleItemCategoryIdx) as string;
                        object obj = row.get_Value(styleItemTagsIdx);

                        // set a default tag, just in case tags field is empty
                        string tags = styleGalleryItem.Category + ";" + styleGalleryItem.Name;

                        // Make sure tags are set & a valid string type before converting to string
                        if (!((obj == null) || (obj is DBNull)))
                        {
                            tags = obj as string;
                        }

                        const int MAX_TAG_LENGTH = 255;

                        int tagsLength = tags.Length;
                        if (tagsLength > MAX_TAG_LENGTH)
                        {
                            // WORKAROUND if length > 255 (a hard limit), trim from the front (last most important)
                            tags = tags.Substring(tagsLength - MAX_TAG_LENGTH, MAX_TAG_LENGTH);
                        }

                        // Note: Tag vector symbols for later (see: containsVectorTag)
                        // + switch to disable if desired
                        const bool TAG_EMFS_WITH_VECTOR_TAG = true;
                        if (TAG_EMFS_WITH_VECTOR_TAG &&
                            (itemFilePath.Substring(itemFilePath.Length - 4) == ".emf") &&
                            (!tags.ToUpper().Contains("VECTOR")))
                        {
                            tags = tags + ";vector";
                        }

                        styleGalleryItem.Tags = tags;

                        //we want tags for search. If they weren't specified, use the default tags
                        if (styleGalleryItem.Tags == "")
                        {
                            styleGalleryItem.Tags = styleGalleryItem.DefaultTags;
                        }

                        Console.WriteLine("Importing symbol " + rowCount + " : " + styleGalleryItem.Name);
                        styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem);
                    }
                    catch (Exception ex)
                    {
                        // Catch-all exception for row processing, just so 1 bad row doesn't abort the whole process
                        Console.WriteLine("Skipping bad row: " + rowCount + ", Exception : " + ex.Message);
                        continue;
                    }
                }
            }
        }
Esempio n. 17
0
        static void ImportMaki(string jsonPath, string stylePath, string renderPath, string emfPath)
        {
            IStyleGallery styleGallery = GetStyleGallery(stylePath);

            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            File.Delete(stylePath); //delete the existing Style to start from scratch
            styleGalleryStorage.TargetFile = stylePath;

            Icon[] icons = Deserialize(jsonPath);
            System.Array.Sort(icons); //sort by name

            IStyleGalleryItem2 styleGalleryItem       = null;
            IStyleGalleryItem2 styleGalleryItemVector = null;
            string             tags = "";

            int[] sizes    = { 16, 24, 32 };
            int[] displays = { 1, 2 };

            //the order here is mainly to produce a pleasing experience in ArcMap.  Add 96 dpi images at each size first
            //then add retina, finally add vector

            foreach (int display in displays) // do regular first, the retina
            {
                foreach (Icon icon in icons)
                {
                    if (icon.tags[0] == "deprecated")
                    {
                        continue;
                    }
                    foreach (int size in sizes)
                    {
                        //raster version
                        IPictureMarkerSymbol rasterPictureMarkerSymbol = MakeMarkerSymbol(renderPath, icon.icon, size, display, false);
                        styleGalleryItem      = new StyleGalleryItemClass();
                        styleGalleryItem.Item = rasterPictureMarkerSymbol;
                        styleGalleryItem.Name = icon.name + " " + size + "px";

                        string displayDescrip = (display == 2) ? "Retina" : "";
                        styleGalleryItem.Category = "Picture " + displayDescrip;

                        tags = string.Join(";", icon.tags); //make array into string

                        styleGalleryItem.Tags = tags + ";png" + ";" + size;
                        styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem);
                    }
                }
            }

            //now add vector versions to the end of the list
            //vector version
            foreach (Icon icon in icons)
            {
                if (icon.tags[0] == "deprecated")
                {
                    continue;
                }
                foreach (int size in sizes)
                {
                    IPictureMarkerSymbol vectorPictureMarkerSymbol = MakeMarkerSymbol(emfPath, icon.icon, size, 1, true);
                    styleGalleryItemVector          = new StyleGalleryItemClass();
                    styleGalleryItemVector.Item     = vectorPictureMarkerSymbol;
                    styleGalleryItemVector.Name     = icon.name + " " + size + "px";
                    styleGalleryItemVector.Category = "Vector";
                    tags = string.Join(";", icon.tags); //make array into string
                    styleGalleryItemVector.Tags = tags + ";emf" + ";" + size;
                    styleGallery.AddItem((IStyleGalleryItem)styleGalleryItemVector);
                }
            }
        }