Ejemplo n.º 1
0
        /// <summary>
        /// 设置要素图片显示样式
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <param name="pictureName"></param>
        /// <param name="size"></param>
        public static void SetFeaturePictureSymbol(IFeatureLayer featureLayer, string pictureName, int size)
        {
            IGeoFeatureLayer     geoLayer     = featureLayer as IGeoFeatureLayer;
            IPictureMarkerSymbol pPicturemksb = CreatePictureSymbol(pictureName, size);
            ISimpleRenderer      simpleRender = geoLayer.Renderer as ISimpleRenderer;

            if (simpleRender == null)
            {
                simpleRender = new SimpleRendererClass();
            }
            simpleRender.Symbol = pPicturemksb as ISymbol;
            geoLayer.Renderer   = simpleRender as IFeatureRenderer;
        }
        private void ReAngleElements(IElement element2D, IElement element3D, double newAngle)
        {
            if (element2D != null)
            {
                IMarkerElement markerElement;
                markerElement = element2D as IMarkerElement;
                IPictureMarkerSymbol pictureMarkerSymbol = (IPictureMarkerSymbol)markerElement.Symbol;

                pictureMarkerSymbol.Angle = newAngle;

                markerElement.Symbol = pictureMarkerSymbol;
            }

            if (element3D != null)
            {
                IMarkerElement markerElement;
                markerElement = element3D as IMarkerElement;
                IMarker3DSymbol    pMarker3DSymbol = (IMarker3DSymbol)markerElement.Symbol;
                IMarker3DPlacement pM3DP           = (IMarker3DPlacement)pMarker3DSymbol;
                pM3DP.Angle          = newAngle;
                markerElement.Symbol = (ESRI.ArcGIS.Display.IMarkerSymbol)pMarker3DSymbol;
            }
        }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
0
        private ISymbol SetColorOfUnknownSymbol(IClone ClonedSymbol, IColor Color)
        {
            ISymbol tempSetColorOfUnknownSymbol = null;

            //
            // This function takes an IClone interface, works out the underlying coclass
            // (which should be some kind of symbol) and then sets the Color property
            // according to the passed in color.
            //
            tempSetColorOfUnknownSymbol = null;
            if (ClonedSymbol == null)
            {
                return(tempSetColorOfUnknownSymbol);
            }
            //
            // Here we figure out which kind of symbol we have. For the simple symbol
            // types, simply setting the color property is OK. However, more complex
            // symbol types require further investigation.
            //
            IFillSymbol          FillSymbol          = null;
            IMarkerFillSymbol    MarkerFillSymbol    = null;
            IMarkerSymbol        MarkerSymbol_A      = null;
            ILineFillSymbol      LineFillSymbol      = null;
            ILineSymbol          LineSymbol          = null;
            IPictureFillSymbol   PictureFillSymbol   = null;
            IMarkerSymbol        MarkerSymbol_B      = null;
            IPictureMarkerSymbol PictureMarkerSymbol = null;
            IMarkerLineSymbol    MarkerLineSymbol    = null;
            IMarkerSymbol        MarkerSymbol_C      = null;
            ILineSymbol          LineSymbol_B        = null;

            if (ClonedSymbol is ISymbol)
            {
                //
                // Check for Fill symbols.
                //
                if (ClonedSymbol is IFillSymbol)
                {
                    //
                    // Check for SimpleFillSymbols or MultiLevelFillSymbols.
                    //
                    if ((ClonedSymbol is ISimpleFillSymbol) | (ClonedSymbol is IMultiLayerFillSymbol))
                    {
                        FillSymbol = (IFillSymbol)ClonedSymbol;
                        //
                        // Here we simply change the color of the Fill.
                        //
                        FillSymbol.Color            = Color;
                        tempSetColorOfUnknownSymbol = (ISymbol)FillSymbol;
                        //
                        // Check for MarkerFillSymbols.
                        //
                    }
                    else if (ClonedSymbol is IMarkerFillSymbol)
                    {
                        MarkerFillSymbol = (IMarkerFillSymbol)ClonedSymbol;
                        //
                        // Here we change the color of the MarkerSymbol.
                        //
                        MarkerSymbol_A = (IMarkerSymbol)SetColorOfUnknownSymbol((IClone)MarkerFillSymbol.MarkerSymbol, Color);
                        MarkerFillSymbol.MarkerSymbol = MarkerSymbol_A;
                        tempSetColorOfUnknownSymbol   = (ISymbol)MarkerFillSymbol;
                        //
                        // Check for LineFillSymbols.
                        //
                    }
                    else if (ClonedSymbol is ILineFillSymbol)
                    {
                        LineFillSymbol = (ILineFillSymbol)ClonedSymbol;
                        //
                        // Here we change the color of the LineSymbol.
                        //
                        LineSymbol = (ILineSymbol)SetColorOfUnknownSymbol((IClone)LineFillSymbol.LineSymbol, Color);
                        LineFillSymbol.LineSymbol   = LineSymbol;
                        tempSetColorOfUnknownSymbol = (ISymbol)LineFillSymbol;
                        //
                        // Check for PictureFillSymbols.
                        //
                    }
                    else if (ClonedSymbol is IPictureFillSymbol)
                    {
                        PictureFillSymbol = (IPictureFillSymbol)ClonedSymbol;
                        //
                        // Here we simply change the color of the BackgroundColor.
                        //
                        PictureFillSymbol.BackgroundColor = Color;
                        tempSetColorOfUnknownSymbol       = (ISymbol)PictureFillSymbol;
                    }
                    //
                    // Check for Marker symbols.
                    //
                }
                else if (ClonedSymbol is IMarkerSymbol)
                {
                    //
                    // Check for SimpleMarkerSymbols, ArrowMarkerSymbols or
                    // CharacterMarkerSymbols.
                    //
                    if ((ClonedSymbol is IMultiLayerMarkerSymbol) | (ClonedSymbol is ISimpleMarkerSymbol) | (ClonedSymbol is IArrowMarkerSymbol) | (ClonedSymbol is ICharacterMarkerSymbol))
                    {
                        MarkerSymbol_B = (IMarkerSymbol)ClonedSymbol;
                        //
                        // For these types, we simply change the color property.
                        //
                        MarkerSymbol_B.Color        = Color;
                        tempSetColorOfUnknownSymbol = (ISymbol)MarkerSymbol_B;
                        //
                        // Check for PictureMarkerSymbols.
                        //
                    }
                    else if (ClonedSymbol is IPictureMarkerSymbol)
                    {
                        PictureMarkerSymbol = (IPictureMarkerSymbol)ClonedSymbol;
                        //
                        // Here we change the BackgroundColor property.
                        //
                        PictureMarkerSymbol.Color   = Color;
                        tempSetColorOfUnknownSymbol = (ISymbol)PictureMarkerSymbol;
                    }
                    //
                    // Check for Line symbols.
                    //
                }
                else if (ClonedSymbol is ILineSymbol)
                {
                    //
                    // Check for MarkerLine symbols.
                    //
                    if (ClonedSymbol is IMarkerLineSymbol)
                    {
                        MarkerLineSymbol = (IMarkerLineSymbol)ClonedSymbol;
                        //
                        // Here we change the color of the MarkerSymbol.
                        //
                        MarkerSymbol_C = (IMarkerSymbol)SetColorOfUnknownSymbol((IClone)MarkerLineSymbol.MarkerSymbol, Color);
                        MarkerLineSymbol.MarkerSymbol = MarkerSymbol_C;
                        tempSetColorOfUnknownSymbol   = (ISymbol)MarkerLineSymbol;
                        //
                        // Check for other Line symbols.
                        //
                    }
                    else if ((ClonedSymbol is ISimpleLineSymbol) | (ClonedSymbol is IHashLineSymbol) | (ClonedSymbol is ICartographicLineSymbol))
                    {
                        LineSymbol_B                = (ILineSymbol)ClonedSymbol;
                        LineSymbol_B.Color          = Color;
                        tempSetColorOfUnknownSymbol = (ISymbol)LineSymbol_B;
                    }
                }
            }

            return(tempSetColorOfUnknownSymbol);
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void btnadd_Click(object sender, EventArgs e)
        {
            if (superTabControl1.SelectedTabIndex == 0)
            {
                esriSimpleMarkerStyle style = new esriSimpleMarkerStyle();
                if (cbSimpleStyle.SelectedIndex == 0)
                {
                    style = esriSimpleMarkerStyle.esriSMSCircle;
                }
                else if (cbSimpleStyle.SelectedIndex == 1)
                {
                    style = esriSimpleMarkerStyle.esriSMSSquare;
                }
                else if (cbSimpleStyle.SelectedIndex == 2)
                {
                    style = esriSimpleMarkerStyle.esriSMSCross;
                }
                else if (cbSimpleStyle.SelectedIndex == 3)
                {
                    style = esriSimpleMarkerStyle.esriSMSX;
                }
                else
                {
                    style = esriSimpleMarkerStyle.esriSMSDiamond;
                }


                if (superTabControl1.SelectedTabIndex == 0)
                {
                    if (checkBoxX1.Checked == true)
                    {
                        ISimpleMarkerSymbol pSimMarSymbol = creatsimpoint(colorsimple.SelectedColor, style, sizesimple.Value, anglesimple.Value, xsimoffset.Value,
                                                                          ysimoffset.Value, outcolor.SelectedColor, outsize.Value);
                        addListBoxItem(pSimMarSymbol as ISymbol);
                    }
                    else
                    {
                        ISimpleMarkerSymbol pSimMarSymbol = creatsimpoint(colorsimple.SelectedColor, style, sizesimple.Value, anglesimple.Value, xsimoffset.Value,
                                                                          ysimoffset.Value, Color.Empty, 0);
                        addListBoxItem(pSimMarSymbol as ISymbol);
                    }
                }
            }

            else if (superTabControl1.SelectedTabIndex == 1)
            {
                if (picfilename == "")
                {
                    MessageBox.Show("请先选择图片", "提示", MessageBoxButtons.OK);
                }
                else
                {
                    IPictureMarkerSymbol pPicMarSymbol = creatpicpoint(sizepicture.Value, xpicoffset.Value, ypicoffset.Value, anglepicture.Value, backcolorpic.SelectedColor, picfilename);
                    addListBoxItem(pPicMarSymbol as ISymbol);
                }
            }

            else if (superTabControl1.SelectedTabIndex == 2)
            {
                IArrowMarkerSymbol pArrMarPoint = creatarrowpoint(colorarrow.SelectedColor, lengtharrow.Value, widtharrow.Value, anglearrow.Value, xarroffset.Value, yarroffset.Value);
                addListBoxItem(pArrMarPoint as ISymbol);
            }

            else if (superTabControl1.SelectedTabIndex == 3)
            {
                if (filename3D == "")
                {
                    MessageBox.Show("请先选择模型", "提示", MessageBoxButtons.OK);
                }
                else
                {
                    IMarker3DSymbol p3DMarSymbol = creat3dmarkerpoint(isuse3d, filename3D);
                    addListBoxItem(p3DMarSymbol as ISymbol);
                }
            }

            RePainPictureBox(Radio);
        }