Exemple #1
0
        public void SelectByLine(int IndexOfLayer, RubberLineClass Line)
        {
            int            ConstantNum      = 255;
            IActiveView    CurrentView      = axMapControl1.ActiveView;
            IScreenDisplay CurScreenDisplay = CurrentView.ScreenDisplay;

            CurScreenDisplay.StartDrawing(CurScreenDisplay.hDC, (System.Int16)esriScreenCache.esriNoScreenCache);
            IRgbColor RGBCOLORS = new ESRI.ArcGIS.Display.RgbColorClass();

            RGBCOLORS.Red = ConstantNum;
            IColor            MyColor            = RGBCOLORS;
            ISimpleFillSymbol MySimpleFillSymbol = new SimpleFillSymbolClass();

            MySimpleFillSymbol.Color = MyColor;
            ISymbol     MySymbol      = MySimpleFillSymbol as ISymbol;
            IRubberBand MyIRubberBand = Line;
            IGeometry   MyGeometry    = MyIRubberBand.TrackNew(CurScreenDisplay, MySymbol);

            CurScreenDisplay.SetSymbol(MySymbol);
            CurScreenDisplay.DrawPolygon(MyGeometry);
            CurScreenDisplay.FinishDrawing();
            ISpatialFilter MySpatialFilter = new SpatialFilterClass();

            MySpatialFilter.Geometry   = MyGeometry;
            MySpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            IFeatureLayer     SelectedLayer    = axMapControl1.ActiveView.FocusMap.get_Layer(IndexOfLayer) as IFeatureLayer;
            IFeatureSelection SelectedFeatures = SelectedLayer as IFeatureSelection;

            SelectedFeatures.SelectFeatures(MySpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
            ISelectionSet FinalSelection = SelectedFeatures.SelectionSet;

            axMapControl1.ActiveView.Refresh();
        }
Exemple #2
0
 internal void AddGraphicToMap(IGeometry geom, bool isTemp)
 {
     ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
     rgbColor.Red = 255;
     //ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
     AddGraphicToMap(geom, rgbColor, isTemp);
 }
Exemple #3
0
        public static ESRI.ArcGIS.Display.IColor TransColorToAEColor(Color color)
        {
            IRgbColor rgb = new ESRI.ArcGIS.Display.RgbColorClass();

            rgb.RGB = color.R + color.G * 256 + color.B * 65536;
            return(rgb as IColor);
        }
 public static IRgbColor MakeRGBColor(byte R, byte G, byte B)
 {
     ESRI.ArcGIS.Display.RgbColor RgbClr = new ESRI.ArcGIS.Display.RgbColorClass();
     RgbClr.Red   = R;
     RgbClr.Green = G;
     RgbClr.Blue  = B;
     return(RgbClr);
 }
        // ArcGIS Snippet Title:
        // Create RGBColor
        //
        // Long Description:
        // Generate an RgbColor by specifying the amount of Red, Green and Blue.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (Standard, Advanced, Basic)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Generate an RgbColor by specifying the amount of Red, Green and Blue.</summary>
        ///
        ///<param name="myRed">A byte (0 to 255) used to represent the Red color. Example: 0</param>
        ///<param name="myGreen">A byte (0 to 255) used to represent the Green color. Example: 255</param>
        ///<param name="myBlue">A byte (0 to 255) used to represent the Blue color. Example: 123</param>
        ///
        ///<returns>An IRgbColor interface</returns>
        ///
        ///<remarks></remarks>
        public ESRI.ArcGIS.Display.IRgbColor CreateRGBColor(System.Byte myRed, System.Byte myGreen, System.Byte myBlue)
        {
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red   = myRed;
            rgbColor.Green = myGreen;
            rgbColor.Blue  = myBlue;
            rgbColor.UseWindowsDithering = true;
            return(rgbColor);
        }
Exemple #6
0
        internal void AddGraphicToMap(IGeometry geom)
        {
            var rgbColor = new ESRI.ArcGIS.Display.RgbColorClass()
            {
                Red = 255
            };

            AddGraphicToMap(geom, rgbColor);
        }
Exemple #7
0
        public ESRI.ArcGIS.Display.IRgbColor ConvertColor(System.Drawing.Color Color)
        {
            // Zet de default waarden
            ESRI.ArcGIS.Display.IRgbColor RgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            RgbColor.Red   = Color.R;
            RgbColor.Green = Color.G;
            RgbColor.Blue  = Color.B;

            return(RgbColor);
        }
 public void DrawRectangle(ESRI.ArcGIS.Carto.IActiveView activeView)
 {
     if (activeView == null)
     {
         return;
     }
     ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
     screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
     ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
     rgbColor.Red = 255;
     ESRI.ArcGIS.Display.IColor            color            = rgbColor; // Implicit Cast
     ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
     simpleFillSymbol.Color = color;
     ESRI.ArcGIS.Display.ISymbol     symbol     = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
     ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberEnvelopeClass();
     ESRI.ArcGIS.Geometry.IGeometry  geometry   = rubberBand.TrackNew(screenDisplay, symbol);
     screenDisplay.SetSymbol(symbol);
     screenDisplay.DrawRectangle(geometry as ESRI.ArcGIS.Geometry.IEnvelope); // Dynamic Cast
     screenDisplay.FinishDrawing();
 }
        private void DrawLegend(IEnvelope Envelope)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double BoxX = 0.4; //Width
            double BoxY = 0.3; //Height
            double Text2BoxY= 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double ColumnX = 0.5; //Space between columns

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();
            BlackInsides.Blue = 0;
            BlackInsides.Red = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();
            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument Doc = ArcMap.Document;
            IPageLayout pageLayout = Doc.ActiveView as IPageLayout;
            IGraphicsContainer GraphicsContainer = pageLayout as IGraphicsContainer;
            double Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double IndentTerm = 0;
            IPoint Point = null;
            double StringLength = 0;
            string LegendText = "";
            string ItemName = "";
            string ItemDesc = "";
            IElement Ele = null;
            IEnvelope TempEnv = null;
            IRgbColor BoxColr = null;
            ISimpleFillSymbol FillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement FillEle = null;
            IEnvelope FillEnv = new EnvelopeClass();
            WKSEnvelope Patch = new WKSEnvelope();
            IGeometry Geo = null;
            string LabelText = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint = new ESRI.ArcGIS.Geometry.PointClass();
            #endregion

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            // Loop through legend records
            foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
            {
                // Grab the DMU entry itself
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));

                // Find out how far to indent the legend item
                // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                // Get the coordinates of the text for the legend entry - upper left corner
                // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                Point = new PointClass();
                double xAdditions = 0;
                if (isHeading)
                {
                    // Xcoord plus (indentation), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1);
                }
                else
                {
                    //Xcoord plus (indentation) + (Box width and margin), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                }
                Point.PutCoords(Xcoord + xAdditions, Ycoord);

                // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                StringLength = 72 * (Envelope.Width - xAdditions);

                // Fix a couple of special characters in the legend string.
                // Then amalgamate item name and description
                ItemName = FixLegendTextCharacters(aDescription.Name);
                if (!isHeading)
                {
                    LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                }
                else
                {
                    LegendText = ItemName;
                }

                // Format the legend text if it is not a heading. If it is, we're fine.
                if (!isHeading)
                {
                    LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                }

                // Boldify the ItemName
                LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                // See if this legend item should be placed on a new column
                Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                TempEnv = new EnvelopeClass();
                Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                // If the height of the formatted text is larger than the box + space specified
                if (TempEnv.Height > BoxY + Text2BoxY)
                {
                    // If the text will spill out below the envelope drawn by the user
                    if (Ycoord - TempEnv.Height < Envelope.YMin)
                    {
                        // Move to a new column - the last number is a fudge factor, looks like it is in inches
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }
                else // The height of the formatted text is not larfer than the box + space defined
                {
                    // If the box itself will spill out below the envelope drawn by the user
                    if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                    {
                        // Move to a new column
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }

                // Add the text to the map
                GraphicsContainer.AddElement(Ele, 0);

                if (!isHeading)
                {
                    FillEnv = new EnvelopeClass();

                    Patch.XMin = Point.X - BoxX - Text2BoxX;
                    Patch.YMax =  Point.Y;
                    Patch.XMax = Point.X - Text2BoxX;
                    Patch.YMin = Point.Y - BoxY;
                    FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                    Geo = FillEnv as IGeometry;

                    // Get the color of the box
                    BoxColr = new RgbColorClass();
                    if (aDescription.AreaFillRGB == null)
                    {
                        BoxColr.Red = 255;
                        BoxColr.Green = 0;
                        BoxColr.Blue = 0;
                    }
                    else
                    {
                        BoxColr.Red = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                        BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                        BoxColr.Blue = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                    }

                    // Draw the fill
                    FillSym = new SimpleFillSymbolClass();
                    FillSym.Color = BoxColr;
                    FillSym.Style = esriSimpleFillStyle.esriSFSSolid;
                    FillSym.Outline = BlackOutsides;

                    FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                    // Label the box
                    LabelText = aDescription.Label;

                    // Subscripting!!

                    for (int i = 0; i < LabelText.Length; i++)
                    {
                        string thisBit = LabelText.Substring(i, 1);
                        int num;
                        if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                        {
                            LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                            i = i + 5;
                        }
                    }
                    LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                    LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                    // Center the label
                    LabelPoint = new PointClass();
                    LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                    LabelPoint.Y = Point.Y - BoxY / 2;

                    //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                    Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                    // Add the box and label
                    GraphicsContainer.AddElement(FillEle as IElement, 0);
                    GraphicsContainer.AddElement(Ele, 0);
                }

                // Do a partial refresh
                //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                // Setup the Y coordinates for the next entry
                // if the height of this item's text is bigger than the minimum distance between text and box
                if (TempEnv.Height > Text2BoxY)
                {
                    // Subtract the box height and the text height to get the new ycoord
                    Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                }
                else
                {
                    if (isHeading)
                    {
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        Ycoord = Ycoord - (BoxY + Text2BoxY);
                    }
                }
            }

            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }
Exemple #10
0
 public static ESRI.ArcGIS.Display.IColor TransColorToAEColor(Color color)
 {
     IRgbColor rgb = new ESRI.ArcGIS.Display.RgbColorClass();
     rgb.RGB = color.R + color.G * 256 + color.B * 65536;
     return rgb as IColor;
 }
 public static ESRI.ArcGIS.Display.IRgbColor MakeRGBColor(byte R, byte G, byte B)
 {
     ESRI.ArcGIS.Display.RgbColor RgbClr = new ESRI.ArcGIS.Display.RgbColorClass();
     RgbClr.Red = R;
     RgbClr.Green = G;
     RgbClr.Blue = B;
     return RgbClr;
 }
 internal void AddGraphicToMap(IGeometry geom)
 {
     var rgbColor = new ESRI.ArcGIS.Display.RgbColorClass() { Red = 255 };
     AddGraphicToMap(geom, rgbColor);
 }
        private static void DrawMapUnits(IEnvelope Envelope, bool showText, double ColumnX)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double Text2BoxY = 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double BoxX      = 0.4; //Width
            double BoxY      = 0.3; //Height

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();

            BlackInsides.Blue  = 0;
            BlackInsides.Red   = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();

            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument        Doc = ArcMap.Document;
            IPageLayout        pageLayout = Doc.ActiveView as IPageLayout;
            IGraphicsContainer GraphicsContainer = pageLayout as IGraphicsContainer;
            double             Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double                      IndentTerm   = 0;
            IPoint                      Point        = null;
            double                      StringLength = 0;
            string                      LegendText   = "";
            string                      ItemName     = "";
            string                      ItemDesc     = "";
            IElement                    Ele          = null;
            IEnvelope                   TempEnv      = null;
            IRgbColor                   BoxColr      = null;
            ISimpleFillSymbol           FillSym      = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement           FillEle      = null;
            IEnvelope                   FillEnv      = new EnvelopeClass();
            WKSEnvelope                 Patch        = new WKSEnvelope();
            IGeometry                   Geo          = null;
            string                      LabelText    = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint   = new ESRI.ArcGIS.Geometry.PointClass();

            // Get the transparency of the MapUnitPolys Layer
            double transparency = 100;
            try
            {
                IFeatureLayer polyLayer    = commonFunctions.FindFeatureLayer(ArcMap.Editor.EditWorkspace, "MapUnitPolys");
                ILayerEffects layerEffects = polyLayer as ILayerEffects;
                transparency = layerEffects.Transparency;
            }
            catch { }

            #endregion

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            // Loop through legend records
            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
            {
                // Grab the DMU entry itself
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));


                // Find out how far to indent the legend item
                // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                // Get the coordinates of the text for the legend entry - upper left corner
                // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                Point = new PointClass();
                double xAdditions = 0;
                if (isHeading)
                {
                    // Xcoord plus (indentation), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1);
                }
                else
                {
                    //Xcoord plus (indentation) + (Box width and margin), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                }
                Point.PutCoords(Xcoord + xAdditions, Ycoord);

                // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                StringLength = 72 * (Envelope.Width - xAdditions);

                // Fix a couple of special characters in the legend string.
                // Then amalgamate item name and description
                ItemName = FixLegendTextCharacters(aDescription.Name);
                if (!isHeading)
                {
                    LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                }
                else
                {
                    LegendText = ItemName;
                }



                // Format the legend text if it is not a heading. If it is, we're fine.
                if (!isHeading)
                {
                    LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                }

                // Boldify the ItemName
                LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                // If the StratCorDiagram is being drawn
                if (showText == false)
                {
                    LegendText   = ".";     // placeholder
                    StringLength = 1;
                }

                // See if this legend item should be placed on a new column
                Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;

                TempEnv = new EnvelopeClass();
                Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                // If the height of the formatted text is larger than the box + space specified
                if (TempEnv.Height > BoxY + Text2BoxY)
                {
                    // If the text will spill out below the envelope drawn by the user
                    if (Ycoord - TempEnv.Height < Envelope.YMin)
                    {
                        // Move to a new column - the last number is a fudge factor, looks like it is in inches
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }
                else     // The height of the formatted text is not larger than the box + space defined
                {
                    // If the box itself will spill out below the envelope drawn by the user
                    if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                    {
                        // Move to a new column
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }

                // Only write the legend text if the legend is being drawn (not the StratCorDiagram)
                if (showText == true)
                {
                    GraphicsContainer.AddElement(Ele, 0);
                }

                if (!isHeading)
                {
                    FillEnv = new EnvelopeClass();

                    Patch.XMin = Point.X - BoxX - Text2BoxX;
                    Patch.YMax = Point.Y;
                    Patch.XMax = Point.X - Text2BoxX;
                    Patch.YMin = Point.Y - BoxY;
                    FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                    Geo = FillEnv as IGeometry;

                    // Get the color of the box
                    BoxColr = new RgbColorClass();
                    if (aDescription.AreaFillRGB == null)
                    {
                        BoxColr.Red   = 255;
                        BoxColr.Green = 0;
                        BoxColr.Blue  = 0;
                    }
                    else
                    {
                        BoxColr.Red   = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                        BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                        BoxColr.Blue  = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                    }

                    // Set the transparency for the legend color boxes
                    BoxColr.Red   = (int)((255 - BoxColr.Red) * transparency / 100 + BoxColr.Red);
                    BoxColr.Green = (int)((255 - BoxColr.Green) * transparency / 100 + BoxColr.Green);
                    BoxColr.Blue  = (int)((255 - BoxColr.Blue) * transparency / 100 + BoxColr.Blue);

                    // Draw the fill
                    FillSym         = new SimpleFillSymbolClass();
                    FillSym.Color   = BoxColr;
                    FillSym.Style   = esriSimpleFillStyle.esriSFSSolid;
                    FillSym.Outline = BlackOutsides;

                    FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                    // Label the box
                    LabelText = aDescription.Label;

                    // Subscripting!!

                    for (int i = 0; i < LabelText.Length; i++)
                    {
                        string thisBit = LabelText.Substring(i, 1);
                        int    num;
                        if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                        {
                            LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                            i         = i + 5;
                        }
                    }
                    LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                    LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                    // Center the label
                    LabelPoint   = new PointClass();
                    LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                    LabelPoint.Y = Point.Y - BoxY / 2;

                    //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                    Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                    // Add the box and label
                    IGroupElement3 group = new GroupElementClass();
                    group.AddElement(FillEle as IElement);
                    group.AddElement(Ele);
                    GraphicsContainer.AddElement(group as IElement, 0);
                }

                // Do a partial refresh
                //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                // Setup the Y coordinates for the next entry
                // if the height of this item's text is bigger than the minimum distance between text and box
                if (TempEnv.Height > Text2BoxY)
                {
                    // Subtract the box height and the text height to get the new ycoord
                    Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                }
                else
                {
                    if (isHeading)
                    {
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        Ycoord = Ycoord - (BoxY + Text2BoxY);
                    }
                }
            }

            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }
 internal void AddGraphicToMap(IGeometry geom, bool isTemp)
 {
     ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
     rgbColor.Red = 255;
     //ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
     AddGraphicToMap(geom, rgbColor, isTemp);
 }
Exemple #15
0
        protected override void OnClick()
        {
            // Get the min/max zoom from user input
            int minzoom = 0;
            int maxzoom = 6;
            Ecotrust.Form1 form1 = new Ecotrust.Form1();
            if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                minzoom = (int)form1.numericUpDown1.Value;
                maxzoom = (int)form1.numericUpDown2.Value;
            }
            else
            {
                return; //TODO
            }

            // Use the FolderBrowserDialog Class to choose export folder
            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
            folderDialog.Description = "Select output folder for map tiles...";
            string exportDir = "";
            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp"
                exportDir = folderDialog.SelectedPath;
                if (exportDir == "")
                    return;  // TODO raise error
            }
            else
            {
                return; //TODO
            }

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView;
            ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;

            ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent;

            // Set up export object and tile pixel coordinates
            int tileSizeX = 256;
            int tileSizeY = 256;

            // set up exporter with transparent background
            ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass();
            ESRI.ArcGIS.Display.IColor tcolor = new ESRI.ArcGIS.Display.RgbColorClass();
            // Warning: 254,254,254 will be set to transparent; don't use in any of map styling
            ((IRgbColor)tcolor).Red = 254;
            ((IRgbColor)tcolor).Green = 254;
            ((IRgbColor)tcolor).Blue = 254;
            ((ExportPNG)pngexport).BackgroundColor = tcolor;
            pngexport.TransparentColor = tcolor;
            ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport;

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT;
            exportRECT.left = 0;
            exportRECT.top = 0;
            exportRECT.right = tileSizeX;
            exportRECT.bottom = tileSizeY;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            map.DelayDrawing(true);

            // Turn off all layers
            for (int i = 0; i < map.LayerCount; i++)
                map.get_Layer(i).Visible = false;

            // Calculate total number of tiles needed
            GlobalMercator mercator = new GlobalMercator();
            GlobalMercator.Coords tempmins;
            GlobalMercator.Coords tempmaxs;
            Double numTiles = 0;
            for (int tz = minzoom; tz <= maxzoom; tz++)
            {
                tempmins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                tempmaxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);
                numTiles += ((tempmaxs.y - tempmins.y)+1) * ((tempmaxs.x - tempmins.x)+1);
            }
            numTiles *= map.LayerCount;

            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
            statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles");

            // Create a CancelTracker
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

            // Set the properties of the Step Progressor
            System.Int32 int32_hWnd = ArcMap.Application.hWnd;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
            stepProgressor.MinRange = 0;
            stepProgressor.MaxRange = (int)numTiles;
            stepProgressor.StepValue = 1;
            stepProgressor.Message = "Calculating " + numTiles.ToString() + " tiles";

            // Create the ProgressDialog. This automatically displays the dialog
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

            // Set the properties of the ProgressDialog
            progressDialog2.CancelEnabled = true;
            progressDialog2.Description = "Rendering " + numTiles.ToString() + " map tiles";
            progressDialog2.Title = "Creating map tiles...";
            progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
            System.Boolean boolean_Continue = true;

            int tileCount = 0;

            for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++)
            {
                // Turn on the layer of interest
                ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum);
                layer.Visible = true;

                // Set extents
                //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest;
                ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass();

                // Create layer directory if it doesn't exist
                DirectoryInfo dir = new DirectoryInfo(exportDir  + "\\" + layer.Name);
                if (!dir.Exists)
                    dir.Create();

                DateTime startTime = DateTime.Now;

                // Loop through zoom levels, rows, cols
                for (int tz = minzoom; tz <= maxzoom; tz++)
                {
                    GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                    GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);

                    // Create zoom directory if it doesn't exist
                    DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz);
                    if (!dir2.Exists)
                        dir2.Create();

                    for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++)
                    {
                        // Create X directory if it doesn't exist
                        DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx);
                        if (!dir3.Exists)
                            dir3.Create();

                        for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++)
                        {

                            // Flip y-axis for output tile name
                            int invertTy = (int) ((Math.Pow(2, tz) - 1) - ty);

                            tileCount += 1;

                            // TODO Calculate time and set new message
                            // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1));
                            // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds;
                            //(" + ((int)timeRemaining).ToString() +" remaining)";

                            stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy +
                                ".png (" + tileCount + " of " + numTiles + ")";

                            export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png";

                            GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz);
                            aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy);
                            aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator?
                            // Use FullExtent instead of Extent to make the extent independent of the activeView ratio
                            activeView.FullExtent = aoi;

                            // Export
                            System.Int32 hDC = export.StartExporting();
                            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                            export.FinishExporting();
                            export.Cleanup();

                            stepProgressor.Position = tileCount;

                            //Check if the cancel button was pressed. If so, break out of row
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                                break;
                        }
                        //Check if the cancel button was pressed. If so, break out of col
                        boolean_Continue = trackCancel.Continue();
                        if (!boolean_Continue)
                            break;
                    }
                    //Check if the cancel button was pressed. If so, break out of layers
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                        break;

                    // Write log
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter( exportDir + "\\log.txt", true))
                    {
                        file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" +
                          mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y);
                    }

                }
                // Turn it off
                layer.Visible = false;
            }

            map.DelayDrawing(false);

            // Turn ON all layers
            for (int i = 0; i < map.LayerCount; i++)
                map.get_Layer(i).Visible = true;

            // restore extent
            activeView.FullExtent = mapaoi;
            activeView.Refresh();

            // Done
            trackCancel = null;
            stepProgressor = null;
            progressDialog2.HideDialog();
            progressDialog2 = null;
        }
Exemple #16
0
        public IFeatureClass CreateStandAloneAnnotationClass(IWorkspace ws, string annoname)
        {
            #region 创建Anno图层
            IFeatureClass featureClass = null;
            try
            {
                //ILayer pLayer = m_pmap.get_Layer(0);
                //IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                //ILayer pSrcLayer = pLayer;
                //IFeatureClass featureClass = pFeatureLayer.FeatureClass;

                //IDataset dataset = (IDataset)featureClass;//cast for the feature workspace from the workspace
                //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)dataset.Workspace;
                IFeatureWorkspaceAnno featureWorkspaceAnno = (IFeatureWorkspaceAnno)ws;//set up the reference scale
                ESRI.ArcGIS.Carto.IGraphicsLayerScale graphicLayerScale = new ESRI.ArcGIS.Carto.GraphicsLayerScaleClass();
                //IGeoDataset geoDataset = (IGeoDataset)dataset;
                graphicLayerScale.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
                graphicLayerScale.ReferenceScale = 500;//set up symbol collection
                ESRI.ArcGIS.Display.ISymbolCollection symbolCollection = new ESRI.ArcGIS.Display.SymbolCollectionClass();
                #region "MakeText"
                ESRI.ArcGIS.Display.IFormattedTextSymbol myTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();        //set the font for myTextSymbol
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                myFont.Name = "Courier New";
                myFont.Size = 9;
                myTextSymbol.Font = myFont;//set the Color for myTextSymbol to be Dark Red
                ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                rgbColor.Red = 150;
                rgbColor.Green = 0;
                rgbColor.Blue = 0;
                myTextSymbol.Color = (ESRI.ArcGIS.Display.IColor)rgbColor;//Set other properties for myTextSymbol
                myTextSymbol.Angle = 0;
                myTextSymbol.RightToLeft = false;
                myTextSymbol.VerticalAlignment = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline;
                myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHAFull;
                myTextSymbol.CharacterSpacing = 200;
                myTextSymbol.Case = ESRI.ArcGIS.Display.esriTextCase.esriTCNormal;
                #endregion
                symbolCollection.set_Symbol(0, (ESRI.ArcGIS.Display.ISymbol)myTextSymbol);//set up the annotation labeling properties including the expression
                ESRI.ArcGIS.Carto.IAnnotateLayerProperties annoProps = new ESRI.ArcGIS.Carto.LabelEngineLayerPropertiesClass();
                annoProps.FeatureLinked = false;//这里控制是不是关联的注记层
                annoProps.AddUnplacedToGraphicsContainer = false;
                annoProps.CreateUnplacedElements = true;
                annoProps.DisplayAnnotation = true;
                annoProps.UseOutput = true;
                ESRI.ArcGIS.Carto.ILabelEngineLayerProperties layerEngineLayerProps = (ESRI.ArcGIS.Carto.ILabelEngineLayerProperties)annoProps;
                ESRI.ArcGIS.Carto.IAnnotationExpressionEngine annoExpressionEngine = new ESRI.ArcGIS.Carto.AnnotationVBScriptEngineClass();
                layerEngineLayerProps.ExpressionParser = annoExpressionEngine;
                layerEngineLayerProps.Expression = "[RefName]";
                layerEngineLayerProps.IsExpressionSimple = true;
                layerEngineLayerProps.Offset = 0;
                layerEngineLayerProps.SymbolID = 0;
                layerEngineLayerProps.Symbol = myTextSymbol;
                ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties annoLayerTransProp =
                    (ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties)annoProps;
                annoLayerTransProp.ReferenceScale = graphicLayerScale.ReferenceScale;
                annoLayerTransProp.Units = graphicLayerScale.Units;
                annoLayerTransProp.ScaleRatio = 1;
                ESRI.ArcGIS.Carto.IAnnotateLayerPropertiesCollection annoPropsColl = new ESRI.ArcGIS.Carto.AnnotateLayerPropertiesCollectionClass();
                annoPropsColl.Add(annoProps);//use the AnnotationFeatureClassDescription to get the list of required
                //fields and the default name of the shape field
                IObjectClassDescription oCDesc = new ESRI.ArcGIS.Carto.AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription fCDesc = (IFeatureClassDescription)oCDesc;//create the new class

                featureClass = featureWorkspaceAnno.CreateAnnotationClass(annoname, oCDesc.RequiredFields, oCDesc.InstanceCLSID, oCDesc.ClassExtensionCLSID,
                    fCDesc.ShapeFieldName, "", null, null, annoPropsColl, graphicLayerScale, symbolCollection, true);
                //给新建的图层添加子层
                ISubtypes subtypes = (ISubtypes)featureClass;
                subtypes.SubtypeFieldName = "AnnotationClassID";
                subtypes.AddSubtype(1, "GCD");
                subtypes.AddSubtype(2, "DLDW");
                subtypes.AddSubtype(3, "JMD");
                subtypes.AddSubtype(4, "SXSS");
                subtypes.AddSubtype(5, "DLSS");
                subtypes.AddSubtype(6, "ZBTZ");
                subtypes.AddSubtype(7, "TK");
                subtypes.DefaultSubtypeCode = 1;
                return featureClass;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return featureClass;
            }
            #endregion
        }
Exemple #17
0
        public IFeatureClass CreateStandAloneAnnotationClass(IWorkspace ws, string annoname)
        {
            #region 创建Anno图层
            IFeatureClass featureClass = null;
            try
            {
                //ILayer pLayer = m_pmap.get_Layer(0);
                //IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                //ILayer pSrcLayer = pLayer;
                //IFeatureClass featureClass = pFeatureLayer.FeatureClass;

                //IDataset dataset = (IDataset)featureClass;//cast for the feature workspace from the workspace
                //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)dataset.Workspace;
                IFeatureWorkspaceAnno featureWorkspaceAnno = (IFeatureWorkspaceAnno)ws;//set up the reference scale
                ESRI.ArcGIS.Carto.IGraphicsLayerScale graphicLayerScale = new ESRI.ArcGIS.Carto.GraphicsLayerScaleClass();
                //IGeoDataset geoDataset = (IGeoDataset)dataset;
                graphicLayerScale.Units          = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
                graphicLayerScale.ReferenceScale = 500;//set up symbol collection
                ESRI.ArcGIS.Display.ISymbolCollection symbolCollection = new ESRI.ArcGIS.Display.SymbolCollectionClass();
                #region "MakeText"
                ESRI.ArcGIS.Display.IFormattedTextSymbol myTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();        //set the font for myTextSymbol
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                myFont.Name       = "Courier New";
                myFont.Size       = 9;
                myTextSymbol.Font = myFont;//set the Color for myTextSymbol to be Dark Red
                ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                rgbColor.Red                     = 150;
                rgbColor.Green                   = 0;
                rgbColor.Blue                    = 0;
                myTextSymbol.Color               = (ESRI.ArcGIS.Display.IColor)rgbColor;//Set other properties for myTextSymbol
                myTextSymbol.Angle               = 0;
                myTextSymbol.RightToLeft         = false;
                myTextSymbol.VerticalAlignment   = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline;
                myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHAFull;
                myTextSymbol.CharacterSpacing    = 200;
                myTextSymbol.Case                = ESRI.ArcGIS.Display.esriTextCase.esriTCNormal;
                #endregion
                symbolCollection.set_Symbol(0, (ESRI.ArcGIS.Display.ISymbol)myTextSymbol); //set up the annotation labeling properties including the expression
                ESRI.ArcGIS.Carto.IAnnotateLayerProperties annoProps = new ESRI.ArcGIS.Carto.LabelEngineLayerPropertiesClass();
                annoProps.FeatureLinked = false;                                           //这里控制是不是关联的注记层
                annoProps.AddUnplacedToGraphicsContainer = false;
                annoProps.CreateUnplacedElements         = true;
                annoProps.DisplayAnnotation = true;
                annoProps.UseOutput         = true;
                ESRI.ArcGIS.Carto.ILabelEngineLayerProperties layerEngineLayerProps = (ESRI.ArcGIS.Carto.ILabelEngineLayerProperties)annoProps;
                ESRI.ArcGIS.Carto.IAnnotationExpressionEngine annoExpressionEngine  = new ESRI.ArcGIS.Carto.AnnotationVBScriptEngineClass();
                layerEngineLayerProps.ExpressionParser   = annoExpressionEngine;
                layerEngineLayerProps.Expression         = "[RefName]";
                layerEngineLayerProps.IsExpressionSimple = true;
                layerEngineLayerProps.Offset             = 0;
                layerEngineLayerProps.SymbolID           = 0;
                layerEngineLayerProps.Symbol             = myTextSymbol;
                ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties annoLayerTransProp =
                    (ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties)annoProps;
                annoLayerTransProp.ReferenceScale = graphicLayerScale.ReferenceScale;
                annoLayerTransProp.Units          = graphicLayerScale.Units;
                annoLayerTransProp.ScaleRatio     = 1;
                ESRI.ArcGIS.Carto.IAnnotateLayerPropertiesCollection annoPropsColl = new ESRI.ArcGIS.Carto.AnnotateLayerPropertiesCollectionClass();
                annoPropsColl.Add(annoProps);//use the AnnotationFeatureClassDescription to get the list of required
                //fields and the default name of the shape field
                IObjectClassDescription  oCDesc = new ESRI.ArcGIS.Carto.AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription fCDesc = (IFeatureClassDescription)oCDesc;//create the new class

                featureClass = featureWorkspaceAnno.CreateAnnotationClass(annoname, oCDesc.RequiredFields, oCDesc.InstanceCLSID, oCDesc.ClassExtensionCLSID,
                                                                          fCDesc.ShapeFieldName, "", null, null, annoPropsColl, graphicLayerScale, symbolCollection, true);
                //给新建的图层添加子层
                ISubtypes subtypes = (ISubtypes)featureClass;
                subtypes.SubtypeFieldName = "AnnotationClassID";
                subtypes.AddSubtype(1, "GCD");
                subtypes.AddSubtype(2, "DLDW");
                subtypes.AddSubtype(3, "JMD");
                subtypes.AddSubtype(4, "SXSS");
                subtypes.AddSubtype(5, "DLSS");
                subtypes.AddSubtype(6, "ZBTZ");
                subtypes.AddSubtype(7, "TK");
                subtypes.DefaultSubtypeCode = 1;
                return(featureClass);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(featureClass);
            }
            #endregion
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                //get access to the document and the active view
                pMxDocument = (IMxDocument)clsAgrcArcMapExtension.m_application.Document;
                pMap        = pMxDocument.FocusMap;
                pActiveView = pMxDocument.ActiveView;                  //pActiveView = (IActiveView)pMap;

                //get the map's graphics layer
                ICompositeGraphicsLayer2 pComGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer2;
                ICompositeLayer          pCompositeLayer   = pComGraphicsLayer as ICompositeLayer;
                ILayer pLayer;

                //loop through all graphic layers in the map and check for the 'PolyVertices' layer, if found, delete it, in order to start fresh
                for (int i = 0; i < pCompositeLayer.Count; i++)
                {
                    pLayer = pCompositeLayer.get_Layer(i);
                    if (pLayer.Name == "PolyVertices")
                    {
                        pComGraphicsLayer.DeleteLayer("PolyVertices");
                        break;
                    }
                }


                if (bolVerticesOn == false)
                {
                    IGraphicsLayer pGraphicsLayer = pComGraphicsLayer.AddLayer("PolyVertices", null);
                    pMap.ActiveGraphicsLayer = (ILayer)pGraphicsLayer;
                    IGraphicsContainer pGraphicsContainer = pComGraphicsLayer.FindLayer("PolyVertices") as IGraphicsContainer;


                    //make sure the user has selected a polygon or polyline layer
                    if (pMxDocument.SelectedLayer == null)
                    {
                        MessageBox.Show("Please select a layer.", "Select Layer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (!(pMxDocument.SelectedLayer is IFeatureLayer))
                    {
                        MessageBox.Show("Please select a polygon or line layer.", "Polygon or Line", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    //cast the selected layer as a feature layer
                    IGeoFeatureLayer pGFlayer = (IGeoFeatureLayer)pMxDocument.SelectedLayer;

                    //check if the feaure layer is a polygon or line layer
                    if (pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon & pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
                    {
                        MessageBox.Show("Please select a polygon or line layer.", "Polygon or Line", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }


                    //setup marker symbol
                    ISimpleMarkerSymbol pSimpleMarker = new SimpleMarkerSymbol();
                    ISymbol             pSymbolMarker = (ISymbol)pSimpleMarker;
                    IRgbColor           pRgbColor     = new ESRI.ArcGIS.Display.RgbColorClass();
                    pRgbColor.Red       = 223;
                    pRgbColor.Green     = 155;
                    pRgbColor.Blue      = 255;
                    pSimpleMarker.Color = pRgbColor;
                    pSimpleMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond;
                    pSimpleMarker.Size  = 8;

                    //setup line symbol
                    ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();
                    ISymbol           pSymbolLine       = (ISymbol)pSimpleLineSymbol;
                    pRgbColor               = new ESRI.ArcGIS.Display.RgbColor();
                    pRgbColor.Red           = 0;
                    pRgbColor.Green         = 255;
                    pRgbColor.Blue          = 0;
                    pSimpleLineSymbol.Color = pRgbColor;
                    pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                    pSimpleLineSymbol.Width = 1;

                    //setup simplefill symbol
                    ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();
                    ISymbol           pSymbolPolygon    = (ISymbol)pSimpleFillSymbol;
                    pRgbColor               = new ESRI.ArcGIS.Display.RgbColor();
                    pRgbColor.Red           = 0;
                    pRgbColor.Green         = 0;
                    pRgbColor.Blue          = 255;
                    pSimpleFillSymbol.Color = pRgbColor;
                    pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;

                    //get all the polygons in the current map extent ina cursor
                    IEnvelope      pMapExtent = pActiveView.Extent;
                    ISpatialFilter pQFilter   = new SpatialFilter();
                    pQFilter.GeometryField = "SHAPE";
                    pQFilter.Geometry      = pMapExtent;
                    pQFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                    IFeatureCursor pFCursor = pGFlayer.Search(pQFilter, true);


                    //draw each polygon and then each polygon's point collection
                    IFeature  pFeature = pFCursor.NextFeature();
                    IGeometry pGeometry;

                    while (pFeature != null)
                    {
                        pGeometry = pFeature.Shape;
                        //draw the polygon
                        //draw each vertex on the polygon
                        IPointCollection pPointCollection = pGeometry as IPointCollection;
                        for (int i = 0; i < pPointCollection.PointCount; i++)
                        {
                            IGeometry pPtGeom  = pPointCollection.get_Point(i);
                            IElement  pElement = new MarkerElement();
                            pElement.Geometry = pPtGeom;
                            IMarkerElement pMarkerElement = pElement as IMarkerElement;
                            pMarkerElement.Symbol = pSimpleMarker;
                            pGraphicsContainer.AddElement(pElement, 0);
                        }
                        pFeature = pFCursor.NextFeature();
                    }

                    bolVerticesOn = true;
                }
                else                 //if (bolVerticesOn == true)
                {
                    bolVerticesOn = false;
                }

                //refresh the map
                pActiveView.Refresh();
                pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "AGRC Custom Tools ArcMap Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    // ArcGIS Snippet Title:
    // Create RGBColor
    // 
    // Long Description:
    // Generate an RgbColor by specifying the amount of Red, Green and Blue.
    // 
    // Add the following references to the project:
    // ESRI.ArcGIS.Display
    // ESRI.ArcGIS.System
    // 
    // Intended ArcGIS Products for this snippet:
    // ArcGIS Desktop (Standard, Advanced, Basic)
    // ArcGIS Engine
    // ArcGIS Server
    // 
    // Applicable ArcGIS Product Versions:
    // 9.2
    // 9.3
    // 9.3.1
    // 10.0
    // 
    // Required ArcGIS Extensions:
    // (NONE)
    // 
    // Notes:
    // This snippet is intended to be inserted at the base level of a Class.
    // It is not intended to be nested within an existing Method.
    // 

    ///<summary>Generate an RgbColor by specifying the amount of Red, Green and Blue.</summary>
    /// 
    ///<param name="myRed">A byte (0 to 255) used to represent the Red color. Example: 0</param>
    ///<param name="myGreen">A byte (0 to 255) used to represent the Green color. Example: 255</param>
    ///<param name="myBlue">A byte (0 to 255) used to represent the Blue color. Example: 123</param>
    ///  
    ///<returns>An IRgbColor interface</returns>
    ///  
    ///<remarks></remarks>
    public ESRI.ArcGIS.Display.IRgbColor CreateRGBColor(System.Byte myRed, System.Byte myGreen, System.Byte myBlue)
    {
      ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
      rgbColor.Red = myRed;
      rgbColor.Green = myGreen;
      rgbColor.Blue = myBlue;
      rgbColor.UseWindowsDithering = true;
      return rgbColor;
    }
Exemple #20
0
        public static void FlashGeometria(IGeometry pGeo, IActiveView activeView)
        {
            ILineSymbol pSimpleLineSymbol = default(ILineSymbol);
            ISimpleFillSymbol pSimpleFillSymbol = default(ISimpleFillSymbol);
            ISimpleMarkerSymbol pSimpleMarkersymbol = default(ISimpleMarkerSymbol);
            IActiveView pActive = default(IActiveView);
            ISymbol pSymbol = default(ISymbol);
            IScreenDisplay pDisplay = default(IScreenDisplay);
            IRgbColor pColor = default(IRgbColor);

            int sleepValue = 500;
            pColor = new ESRI.ArcGIS.Display.RgbColorClass();
            pColor.Red = 255;
            pActive = activeView;
            pDisplay = activeView.ScreenDisplay;
            pDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
            switch (pGeo.GeometryType)
            {
                case esriGeometryType.esriGeometryPolyline:
                    pSimpleLineSymbol = new SimpleLineSymbol();
                    pSymbol = pSimpleLineSymbol as ISymbol;
                    pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
                    pSimpleLineSymbol.Width = 4;
                    pSimpleLineSymbol.Color = pColor;
                    pDisplay.SetSymbol(pSimpleLineSymbol as ISymbol);
                    pDisplay.DrawPolyline(pGeo);
                    Thread.Sleep(sleepValue);
                    break;
                case esriGeometryType.esriGeometryPolygon:
                    pSimpleFillSymbol = new SimpleFillSymbol();
                    pSymbol = pSimpleFillSymbol as ISymbol;
                    pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
                    pSimpleFillSymbol.Color = pColor;
                    pDisplay.SetSymbol(pSimpleFillSymbol as ISymbol);
                    pDisplay.DrawPolygon(pGeo);
                    Thread.Sleep(sleepValue);
                    break;
                case esriGeometryType.esriGeometryPoint:
                    pSimpleMarkersymbol = new SimpleMarkerSymbol();
                    pSymbol = pSimpleMarkersymbol as ISymbol;
                    pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
                    pSimpleMarkersymbol.Color = pColor;
                    pSimpleMarkersymbol.Size = 12;
                    pDisplay.SetSymbol(pSimpleMarkersymbol as ISymbol);
                    pDisplay.DrawPoint(pGeo);
                    Thread.Sleep(sleepValue);
                    break;
                case esriGeometryType.esriGeometryMultipoint:
                    pSimpleMarkersymbol = new SimpleMarkerSymbol();
                    pSymbol = pSimpleMarkersymbol as ISymbol;
                    pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
                    pSimpleMarkersymbol.Color = pColor;
                    pSimpleMarkersymbol.Size = 12;
                    pDisplay.SetSymbol(pSimpleMarkersymbol as ISymbol);
                    pDisplay.DrawMultipoint(pGeo);
                    pDisplay.DrawMultipoint(pGeo);
                    Thread.Sleep(sleepValue);
                    break;
                default:
                    break;
            }
            pDisplay.Invalidate(null, true, 0);

            pDisplay.FinishDrawing();
        }
Exemple #21
0
        private void _drawPolygon()
        {
            if (this._axMapCtrl.ActiveView == null)
            {
                return;
            }

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = this._axMapCtrl.ActiveView.ScreenDisplay;

            // Constant.
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
                ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast.
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
            ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
                ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            simpleFillSymbol.Color = color;
            

            ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
                ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new
                ESRI.ArcGIS.Display.RubberPolygonClass();
            ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
                symbol);
            screenDisplay.SetSymbol(symbol);

            //screenDisplay.DrawPolygon(geometry);
            screenDisplay.FinishDrawing();
            
            PolygonElementClass element = new PolygonElementClass();
            element.Geometry = geometry;
            // Create lineSymbol
            ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
            // set color & style,....
            ESRI.ArcGIS.Display.IRgbColor lineColor = new ESRI.ArcGIS.Display.RgbColorClass();
            lineColor.Red = 255;
            lineSymbol.Color = lineColor;
            lineSymbol.Width = 3;

            // Create fillSymbol
            ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
            fillSymbol.Outline = lineSymbol;
            ESRI.ArcGIS.Display.IRgbColor fillColor = new ESRI.ArcGIS.Display.RgbColorClass();
            fillColor.Red = 255;
            fillColor.Green = 255;
            fillSymbol.Color = fillColor;
            fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
            element.Symbol = fillSymbol;

            this._axMapCtrl.ActiveView.GraphicsContainer.AddElement(element, 0);
            
            //((IGraphicsContainerSelect)(this._axMapCtrl.ActiveView.GraphicsContainer)).SelectElement(element);
            this._axMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            if (this._polygonName != "")
            {
                element.Name = this._polygonName;
                this._polygonName = "";
            }
            /*
            else
            {
                int count = 0;
                IGraphicsContainer container = this._axMapCtrl.ActiveView.GraphicsContainer;
                container.Reset();
                while (container.Next() != null)
                {
                    count++;
                }
                element.Name = "Element " + count;
            }
            */
            if (PolygonDrawn != null)
            {
                PolygonDrawn(element.Name);
            }
        }
Exemple #22
0
        protected override void OnClick()
        {
            // Get the min/max zoom from user input
            int minzoom = 0;
            int maxzoom = 6;

            Ecotrust.Form1 form1 = new Ecotrust.Form1();
            if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                minzoom = (int)form1.numericUpDown1.Value;
                maxzoom = (int)form1.numericUpDown2.Value;
            }
            else
            {
                return; //TODO
            }

            // Use the FolderBrowserDialog Class to choose export folder
            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
            folderDialog.Description = "Select output folder for map tiles...";
            string exportDir = "";

            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp"
                exportDir = folderDialog.SelectedPath;
                if (exportDir == "")
                {
                    return;  // TODO raise error
                }
            }
            else
            {
                return; //TODO
            }

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView    activeView = mxDocument.ActiveView;
            ESRI.ArcGIS.Carto.IMap           map        = activeView.FocusMap;

            ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent;

            // Set up export object and tile pixel coordinates
            int tileSizeX = 256;
            int tileSizeY = 256;

            // set up exporter with transparent background
            ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass();
            ESRI.ArcGIS.Display.IColor    tcolor    = new ESRI.ArcGIS.Display.RgbColorClass();
            // Warning: 254,254,254 will be set to transparent; don't use in any of map styling
            ((IRgbColor)tcolor).Red   = 254;
            ((IRgbColor)tcolor).Green = 254;
            ((IRgbColor)tcolor).Blue  = 254;
            ((ExportPNG)pngexport).BackgroundColor = tcolor;
            pngexport.TransparentColor             = tcolor;
            ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport;

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT;
            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = tileSizeX;
            exportRECT.bottom = tileSizeY;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            map.DelayDrawing(true);

            // Turn off all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = false;
            }

            // Calculate total number of tiles needed
            GlobalMercator mercator = new GlobalMercator();

            GlobalMercator.Coords tempmins;
            GlobalMercator.Coords tempmaxs;
            Double numTiles = 0;

            for (int tz = minzoom; tz <= maxzoom; tz++)
            {
                tempmins  = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                tempmaxs  = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);
                numTiles += ((tempmaxs.y - tempmins.y) + 1) * ((tempmaxs.x - tempmins.x) + 1);
            }
            numTiles *= map.LayerCount;

            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
            statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles");

            // Create a CancelTracker
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

            // Set the properties of the Step Progressor
            System.Int32 int32_hWnd = ArcMap.Application.hWnd;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
            stepProgressor.MinRange  = 0;
            stepProgressor.MaxRange  = (int)numTiles;
            stepProgressor.StepValue = 1;
            stepProgressor.Message   = "Calculating " + numTiles.ToString() + " tiles";

            // Create the ProgressDialog. This automatically displays the dialog
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

            // Set the properties of the ProgressDialog
            progressDialog2.CancelEnabled = true;
            progressDialog2.Description   = "Rendering " + numTiles.ToString() + " map tiles";
            progressDialog2.Title         = "Creating map tiles...";
            progressDialog2.Animation     = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
            System.Boolean boolean_Continue = true;

            int tileCount = 0;

            for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++)
            {
                // Turn on the layer of interest
                ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum);
                layer.Visible = true;

                // Set extents
                //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest;
                ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass();

                // Create layer directory if it doesn't exist
                DirectoryInfo dir = new DirectoryInfo(exportDir + "\\" + layer.Name);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                DateTime startTime = DateTime.Now;

                // Loop through zoom levels, rows, cols
                for (int tz = minzoom; tz <= maxzoom; tz++)
                {
                    GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                    GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);

                    // Create zoom directory if it doesn't exist
                    DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz);
                    if (!dir2.Exists)
                    {
                        dir2.Create();
                    }

                    for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++)
                    {
                        // Create X directory if it doesn't exist
                        DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx);
                        if (!dir3.Exists)
                        {
                            dir3.Create();
                        }

                        for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++)
                        {
                            // Flip y-axis for output tile name
                            int invertTy = (int)((Math.Pow(2, tz) - 1) - ty);

                            tileCount += 1;

                            // TODO Calculate time and set new message
                            // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1));
                            // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds;
                            //(" + ((int)timeRemaining).ToString() +" remaining)";

                            stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy +
                                                     ".png (" + tileCount + " of " + numTiles + ")";


                            export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png";

                            GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz);
                            aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy);
                            aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator?
                            // Use FullExtent instead of Extent to make the extent independent of the activeView ratio
                            activeView.FullExtent = aoi;

                            // Export
                            System.Int32 hDC = export.StartExporting();
                            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                            export.FinishExporting();
                            export.Cleanup();

                            stepProgressor.Position = tileCount;

                            //Check if the cancel button was pressed. If so, break out of row
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                            {
                                break;
                            }
                        }
                        //Check if the cancel button was pressed. If so, break out of col
                        boolean_Continue = trackCancel.Continue();
                        if (!boolean_Continue)
                        {
                            break;
                        }
                    }
                    //Check if the cancel button was pressed. If so, break out of layers
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        break;
                    }

                    // Write log
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(exportDir + "\\log.txt", true))
                    {
                        file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" +
                                       mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y);
                    }
                }
                // Turn it off
                layer.Visible = false;
            }

            map.DelayDrawing(false);

            // Turn ON all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = true;
            }

            // restore extent
            activeView.FullExtent = mapaoi;
            activeView.Refresh();

            // Done
            trackCancel    = null;
            stepProgressor = null;
            progressDialog2.HideDialog();
            progressDialog2 = null;
        }
        private ESRI.ArcGIS.Display.IPictureMarkerSymbol CreatePictureMarkerSymbol(ESRI.ArcGIS.Display.esriIPictureType pictureType, System.String filename, System.Double markerSize)
        {
            // Set the Transparent background color for the Picture Marker symbol to white.
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;
            rgbColor.Green = 255;
            rgbColor.Blue = 255;

            // Create the Marker and assign properties.
            ESRI.ArcGIS.Display.IPictureMarkerSymbol pictureMarkerSymbol = new ESRI.ArcGIS.Display.PictureMarkerSymbolClass();
            pictureMarkerSymbol.CreateMarkerSymbolFromFile(pictureType, filename);
            pictureMarkerSymbol.Angle = 0;
            pictureMarkerSymbol.BitmapTransparencyColor = rgbColor;
            pictureMarkerSymbol.Size = markerSize;
            pictureMarkerSymbol.XOffset = 0;
            pictureMarkerSymbol.YOffset = 0;

            return pictureMarkerSymbol;
        }
        public ESRI.ArcGIS.Display.IRgbColor ConvertColor(System.Drawing.Color Color)
        {
            // Zet de default waarden
            ESRI.ArcGIS.Display.IRgbColor RgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            RgbColor.Red = Color.R;
            RgbColor.Green = Color.G;
            RgbColor.Blue = Color.B;

            return RgbColor;
        }
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if(pFlag==1)//缓冲区空间查询
               {
               IActiveView pActView = axMapControl1.Map as IActiveView;

               IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               ITopologicalOperator pTopo = pPoint as ITopologicalOperator;

               IGeometry pGeo = pTopo.Buffer(500);

               ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
               rgbColor.Red = 255;

               ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
               ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
               simpleFillSymbol.Color = color;

               ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol;

               pActView.ScreenDisplay.SetSymbol(symbol);

               pActView.ScreenDisplay.DrawPolygon(pGeo);

               axMapControl1.Map.SelectByShape(pGeo, null, false);

               axMapControl1.FlashShape(pGeo, 1000, 2, symbol);

               axMapControl1.ActiveView.Refresh();
               }
               if (pFlag == 2)
               {
               pNetMap = axMapControl1.Map;

               pGC = pNetMap as IGraphicsContainer;

               IActiveView pActView = pNetMap as IActiveView;

               IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               object o = Type.Missing;
               object o1 = Type.Missing;

               pPointC.AddPoint(pPoint, ref o, ref o1);

               IElement Element;

               ITextElement Textelement = new TextElementClass();

               Element = Textelement as IElement;

               pClickedCount++;

               Textelement.Text = pClickedCount.ToString();

               Element.Geometry = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               pGC.AddElement(Element, 0);

               pActView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

               IFeatureClass pFeatureClass = pNaContext.NAClasses.get_ItemByName("Stops") as IFeatureClass;

               NASolve(pNaContext, pFeatureClass, pPointC, 5000);

               IGPMessages gpMessages = new GPMessagesClass();

               bool pBool = pNASolveClass.Solve(pNaContext, gpMessages, null);

               }

               if (pFlag == 3)//有向网络
               {
               IWorkspace pWs = GetMDBWorkspace(@".\data\Geometric.mdb");

               IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;

               IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset("work");

               double s = 0;

               IPolyline pPolyline = new PolylineClass();

               SolvePath(axMapControl1.Map, GetGeometricNetwork(pFtDataset, "TestGeometric"), "Weight", pPointC, 1000, ref pPolyline, ref s);

               IRgbColor pColor = new RgbColorClass();
               pColor.Red = 255;
               IElement pElement = new LineElementClass();
               ILineSymbol linesymbol = new SimpleLineSymbolClass();
               linesymbol.Color = pColor as IColor;
               linesymbol.Width = 100;

               pElement.Geometry = pPolyline;

               pGC.AddElement(pElement, 2);

               axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
               }
               if (pFlag == 4)
               {
               if(axMapControl1.Map.get_Layer(0)!=null)
               {
                   IRasterLayer pRasterLayer = axMapControl1.Map.get_Layer(0) as IRasterLayer;

                   IRasterSurface pRasterSurface = new RasterSurfaceClass();

                   pRasterSurface.PutRaster(pRasterLayer.Raster, 0);

                   ISurface pSurface = pRasterSurface as ISurface;

                  IPolyline pPolyline = axMapControl1.TrackLine() as  IPolyline;

                   IPoint pPoint =null ;

                    IPolyline pVPolyline =null;

                   IPolyline pInPolyline= null;

                   object pRef=0.13;

                   bool pBool =true;

                   double pZ1 = pSurface.GetElevation(pPolyline.FromPoint);

                   double pZ2= pSurface.GetElevation(pPolyline.ToPoint);

                   IPoint pPoint1 = new PointClass();

                   pPoint1.Z = pZ1;

                   pPoint1.X = pPolyline.FromPoint.X;

                   pPoint1.Y = pPolyline.FromPoint.Y;

                   IPoint pPoint2 = new PointClass();

                   pPoint2.Z = pZ2;

                   pPoint2.X = pPolyline.ToPoint.X;

                   pPoint2.Y = pPolyline.ToPoint.Y;

                   pSurface.GetLineOfSight(pPoint1, pPoint2, out pPoint, out pVPolyline,
                       out pInPolyline, out pBool, false, false, ref pRef);//大爷的,设置为true居然通不过bApplyCurvature和bApplyRefraction两项设置为true,surface必须定义成具有ZUnits的投影坐标

                   //This member should not be used in .NET. As a substitute, .NET developers must use IGeoDatabaseBridge2.GetLineOfSight.

                         //楼主,用IGeoDatabaseBridge2.GetLineOfSight.方法试试
                   if (pVPolyline != null)
                   {

                       IElement pLineElementV = new LineElementClass();

                       pLineElementV.Geometry = pVPolyline;

                       ILineSymbol pLinesymbolV = new SimpleLineSymbolClass();

                       pLinesymbolV.Width = 2;

                       IRgbColor pColorV = new RgbColorClass();

                       pColorV.Green =255;

                       pLinesymbolV.Color = pColorV;

                       ILineElement pLineV = pLineElementV as ILineElement;

                       pLineV.Symbol = pLinesymbolV;

                       axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementV, 0);
                   }

                   if (pInPolyline != null)
                   {

                       IElement pLineElementIn = new LineElementClass();

                       pLineElementIn.Geometry = pInPolyline;

                       ILineSymbol pLinesymbolIn = new SimpleLineSymbolClass();

                       pLinesymbolIn.Width = 2;

                       IRgbColor pColorIn = new RgbColorClass();
                       pColorIn.Red = 255;

                       pLinesymbolIn.Color = pColorIn;
                       ILineElement pLineIn = pLineElementIn as ILineElement;

                       pLineIn.Symbol = pLinesymbolIn;

                       axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementIn, 1);

                   }

                   axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                   axMapControl1.TrackCancel.Cancel();

               }
               }
        }