예제 #1
0
 private void SetupDeviceRatio(int hDC, ESRI.ArcGIS.Display.IDisplay display)
 {
     if (display.DisplayTransformation != null)
     {
         if (display.DisplayTransformation.Resolution != 0)
         {
             m_dDeviceRatio = display.DisplayTransformation.Resolution / 72;
             //  Check the ReferenceScale of the display transformation. If not zero, we need to
             //  adjust the Size, XOffset and YOffset of the Symbol we hold internally before drawing.
             if (display.DisplayTransformation.ReferenceScale != 0)
             {
                 m_dDeviceRatio = m_dDeviceRatio * display.DisplayTransformation.ReferenceScale / display.DisplayTransformation.ScaleRatio;
             }
         }
     }
     else
     {
         // If we don't have a display transformation, calculate the resolution
         // from the actual device.
         if (display.hDC != 0)
         {
             // Get the resolution from the device context hDC.
             m_dDeviceRatio = System.Convert.ToDouble(GetDeviceCaps(hDC, LOGPIXELSX)) / 72;
         }
         else
         {
             // If invalid hDC assume we're drawing to the screen.
             m_dDeviceRatio = 1 / (TwipsPerPixelX() / 20); // 1 Point = 20 Twips.
         }
     }
 }
예제 #2
0
 void avEvents_AfterDraw(ESRI.ArcGIS.Display.IDisplay Display, esriViewDrawPhase phase)
 {
     if (phase != esriViewDrawPhase.esriViewForeground)
     {
         return;
     }
     DrawLogoStandard(Display);
 }
        private void OnActiveViewEventsAfterDraw(ESRI.ArcGIS.Display.IDisplay display, ESRI.ArcGIS.Carto.esriViewDrawPhase phase)
        {
            ESRI.ArcGIS.Carto.esriViewDrawPhase m_phase = phase;

            //if the drawing pahse geography, find all feature layer and selected feature and draw them on screen if they are polygons. Please note don't call   display::StartDrawing as it is already started by the system.
            if (m_phase == ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography)
            {
                IMap m_Map = m_MxDoc.FocusMap;
                ESRI.ArcGIS.esriSystem.UID m_UID = new ESRI.ArcGIS.esriSystem.UID();
                m_UID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
                IEnumLayer m_EnumLayer = m_Map.Layers[m_UID];
                ILayer     m_Layer     = m_EnumLayer.Next();

                //if you want to change the selection color you can change it here.
                ISimpleFillSymbol m_FillSymbol = new SimpleFillSymbol();
                m_Rgb              = new RgbColor();
                m_Rgb.Red          = 255;
                m_FillSymbol.Color = m_Rgb;
                display.SetSymbol(m_FillSymbol as ISymbol);

                do
                {
                    if (m_Layer is IFeatureLayer)
                    {
                        if (m_Layer != null)
                        {
                            IFeatureSelection m_FeatureSelection = (IFeatureSelection)m_Layer;
                            ISelectionSet     m_SelSet           = m_FeatureSelection.SelectionSet;
                            IFeatureCursor    m_FeatCur;
                            ICursor           m_Cursor;
                            m_SelSet.Search(null, false, out m_Cursor);

                            m_FeatCur = (IFeatureCursor)m_Cursor;
                            IFeature m_Feature;

                            m_Feature = m_FeatCur.NextFeature();

                            do
                            {
                                if (m_Feature != null)
                                {
                                    if (m_Feature.Shape is IPolygon)
                                    {
                                        display.DrawPolygon(m_Feature.Shape);
                                    }
                                }
                                m_Feature = m_FeatCur.NextFeature();
                            } while (m_Feature != null);
                        }
                    }
                    m_Layer = m_EnumLayer.Next();
                } while (m_Layer != null);
            }
            #endregion
        }
예제 #4
0
        private static void DrawCrossHair(ESRI.ArcGIS.Geometry.IGeometry geometry, ESRI.ArcGIS.Display.IDisplay display, IEnvelope extent, ISymbol markerSymbol, ISymbol lineSymbol)
        {
            try
            {
                var point       = geometry as IPoint;
                var numSegments = 10;

                var latitudeMid      = point.Y;//envelope.YMin + ((envelope.YMax - envelope.YMin) / 2);
                var longitudeMid     = point.X;
                var leftLongSegment  = (point.X - extent.XMin) / numSegments;
                var rightLongSegment = (extent.XMax - point.X) / numSegments;
                var topLatSegment    = (extent.YMax - point.Y) / numSegments;
                var bottomLatSegment = (point.Y - extent.YMin) / numSegments;
                var fromLeftLong     = extent.XMin;
                var fromRightLong    = extent.XMax;
                var fromTopLat       = extent.YMax;
                var fromBottomLat    = extent.YMin;
                var av = (ArcMap.Application.Document as IMxDocument).ActiveView;

                var leftPolyline   = new PolylineClass();
                var rightPolyline  = new PolylineClass();
                var topPolyline    = new PolylineClass();
                var bottomPolyline = new PolylineClass();

                leftPolyline.SpatialReference   = geometry.SpatialReference;
                rightPolyline.SpatialReference  = geometry.SpatialReference;
                topPolyline.SpatialReference    = geometry.SpatialReference;
                bottomPolyline.SpatialReference = geometry.SpatialReference;

                var leftPC   = leftPolyline as IPointCollection;
                var rightPC  = rightPolyline as IPointCollection;
                var topPC    = topPolyline as IPointCollection;
                var bottomPC = bottomPolyline as IPointCollection;

                leftPC.AddPoint(new PointClass()
                {
                    X = fromLeftLong, Y = latitudeMid
                });
                rightPC.AddPoint(new PointClass()
                {
                    X = fromRightLong, Y = latitudeMid
                });
                topPC.AddPoint(new PointClass()
                {
                    X = longitudeMid, Y = fromTopLat
                });
                bottomPC.AddPoint(new PointClass()
                {
                    X = longitudeMid, Y = fromBottomLat
                });

                for (int x = 1; x <= numSegments; x++)
                {
                    //Flash the input polygon geometry.
                    display.SetSymbol(markerSymbol);
                    display.SetSymbol(lineSymbol);

                    leftPC.AddPoint(new PointClass()
                    {
                        X = fromLeftLong + leftLongSegment * x, Y = latitudeMid
                    });
                    rightPC.AddPoint(new PointClass()
                    {
                        X = fromRightLong - rightLongSegment * x, Y = latitudeMid
                    });
                    topPC.AddPoint(new PointClass()
                    {
                        X = longitudeMid, Y = fromTopLat - topLatSegment * x
                    });
                    bottomPC.AddPoint(new PointClass()
                    {
                        X = longitudeMid, Y = fromBottomLat + bottomLatSegment * x
                    });

                    // draw
                    display.DrawPolyline(leftPolyline);
                    display.DrawPolyline(rightPolyline);
                    display.DrawPolyline(topPolyline);
                    display.DrawPolyline(bottomPolyline);

                    System.Threading.Thread.Sleep(15);
                    display.FinishDrawing();
                    av.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
                    //av.Refresh();
                    System.Windows.Forms.Application.DoEvents();
                    display.StartDrawing(display.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #5
0
        ///<summary>Flash geometry on the display. The geometry type could be polygon, polyline, point, or multipoint.</summary>
        ///
        ///<param name="geometry"> An IGeometry interface</param>
        ///<param name="color">An IRgbColor interface</param>
        ///<param name="display">An IDisplay interface</param>
        ///<param name="delay">A System.Int32 that is the time im milliseconds to wait.</param>
        ///
        ///<remarks></remarks>
        public static void FlashGeometry(ESRI.ArcGIS.Geometry.IGeometry geometry, ESRI.ArcGIS.Display.IRgbColor color, ESRI.ArcGIS.Display.IDisplay display, System.Int32 delay, IEnvelope envelope)
        {
            if (geometry == null || color == null || display == null)
            {
                return;
            }

            display.StartDrawing(display.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast

            switch (geometry.GeometryType)
            {
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
            {
                //Set the flash geometry's symbol.
                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
                symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                //Flash the input polygon geometry.
                display.SetSymbol(symbol);
                display.DrawPolygon(geometry);
                System.Threading.Thread.Sleep(delay);
                display.DrawPolygon(geometry);
                break;
            }

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
            {
                //Set the flash geometry's symbol.
                ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
                simpleLineSymbol.Width = 4;
                simpleLineSymbol.Color = color;
                ESRI.ArcGIS.Display.ISymbol symbol = simpleLineSymbol as ESRI.ArcGIS.Display.ISymbol;         // Dynamic Cast
                symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                //Flash the input polyline geometry.
                display.SetSymbol(symbol);
                display.DrawPolyline(geometry);
                System.Threading.Thread.Sleep(delay);
                display.DrawPolyline(geometry);
                break;
            }

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
            {
                //Set the flash geometry's symbol.
                ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
                simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                simpleMarkerSymbol.Size  = 12;
                simpleMarkerSymbol.Color = color;
                ESRI.ArcGIS.Display.ISymbol markerSymbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol;         // Dynamic Cast
                markerSymbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
                simpleLineSymbol.Width = 1;
                simpleLineSymbol.Color = color;
                ESRI.ArcGIS.Display.ISymbol lineSymbol = simpleLineSymbol as ESRI.ArcGIS.Display.ISymbol;         // Dynamic Cast
                lineSymbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                //Flash the input polygon geometry.
                display.SetSymbol(markerSymbol);
                display.SetSymbol(lineSymbol);

                ArcMapHelpers.DrawCrossHair(geometry, display, envelope, markerSymbol, lineSymbol);

                //Flash the input point geometry.
                display.SetSymbol(markerSymbol);
                display.DrawPoint(geometry);
                System.Threading.Thread.Sleep(delay);
                display.DrawPoint(geometry);
                break;
            }

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint:
            {
                //Set the flash geometry's symbol.
                ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
                simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                simpleMarkerSymbol.Size  = 12;
                simpleMarkerSymbol.Color = color;
                ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol;         // Dynamic Cast
                symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen;

                //Flash the input multipoint geometry.
                display.SetSymbol(symbol);
                display.DrawMultipoint(geometry);
                System.Threading.Thread.Sleep(delay);
                display.DrawMultipoint(geometry);
                break;
            }
            }

            display.FinishDrawing();
        }
예제 #6
0
        /// <summary>
        /// The dynamic layer draw method
        /// </summary>
        /// <param name="DynamicDrawPhase">the current drawphase of the dynamic drawing</param>
        /// <param name="Display">the ActiveView's display</param>
        /// <param name="DynamicDisplay">the ActiveView's dynamic display</param>
        public override void DrawDynamicLayer(ESRI.ArcGIS.Display.esriDynamicDrawPhase DynamicDrawPhase, ESRI.ArcGIS.Display.IDisplay Display, ESRI.ArcGIS.Display.IDynamicDisplay DynamicDisplay)
        {
            try
            {
                //make sure that the display is valid as well as that the layer is visible
                if (null == DynamicDisplay || null == Display || !this.m_visible)
                {
                    return;
                }

                //make sure that the current drawphase is immediate. In this sample there is no use of the
                //compiled drawPhase. Use the esriDDPCompiled drawPhase in order to draw semi-static items (items
                //which have update rate lower than the display update rate).
                if (DynamicDrawPhase != esriDynamicDrawPhase.esriDDPImmediate)
                {
                    return;
                }

                if (m_bOnce)
                {
                    //cast the DynamicDisplay into DynamicGlyphFactory
                    m_dynamicGlyphFactory = DynamicDisplay.DynamicGlyphFactory as IDynamicGlyphFactory2;
                    //cast the DynamicDisplay into DynamicSymbolProperties
                    m_dynamicSymbolProps = DynamicDisplay as IDynamicSymbolProperties;
                    //cast the compound marker symbol
                    m_dynamicCompoundMarker = DynamicDisplay as IDynamicCompoundMarker;

                    IntializeLayerData(Display.DisplayTransformation);

                    GetLayerExtent();

                    m_bOnce = false;
                }

                //get the display fitted bounds
                m_extentMaxX = Display.DisplayTransformation.FittedBounds.XMax;
                m_extentMaxY = Display.DisplayTransformation.FittedBounds.YMax;
                m_extentMinX = Display.DisplayTransformation.FittedBounds.XMin;
                m_extentMinY = Display.DisplayTransformation.FittedBounds.YMin;

                //create the dynamic symbols for the layer
                if (!m_bDynamicGlyphsCreated)
                {
                    this.CreateDynamicSymbols(m_dynamicGlyphFactory);
                    m_bDynamicGlyphsCreated = true;
                }

                double X, Y, heading;
                int    type;
                //iterate through the layers' items
                foreach (DataRow r in m_table.Rows)
                {
                    if (r[1] is DBNull || r[2] is DBNull)
                    {
                        continue;
                    }

                    //get the item's coordinate, heading and type
                    X       = Convert.ToDouble(r[1]);
                    Y       = Convert.ToDouble(r[2]);
                    heading = Convert.ToDouble(r[5]);
                    type    = Convert.ToInt32(r[6]);

                    //assign the items' coordinate to the cached point
                    m_point.PutCoords(X, Y);

                    //set the symbol's properties
                    switch (type)
                    {
                    case 0:
                        //set the heading of the current symbols' text
                        m_dynamicSymbolProps.set_Heading(esriDynamicSymbolType.esriDSymbolText, 0.0f);
                        m_dynamicSymbolProps.set_Heading(esriDynamicSymbolType.esriDSymbolMarker, 0.0f);

                        //set the symbol alignment so that it will align with the screen
                        m_dynamicSymbolProps.set_RotationAlignment(esriDynamicSymbolType.esriDSymbolMarker, esriDynamicSymbolRotationAlignment.esriDSRAScreen);

                        //set the text alignment so that it will also align with the screen
                        m_dynamicSymbolProps.set_RotationAlignment(esriDynamicSymbolType.esriDSymbolText, esriDynamicSymbolRotationAlignment.esriDSRAScreen);

                        //scale the item
                        m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 0.8f, 0.8f);
                        //set the items' color (blue)
                        m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 0.0f, 0.0f, 1.0f, 1.0f); // Blue
                        //assign the item's glyph to the dynamic-symbol
                        m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker, m_markerGlyphs[0]);
                        //set the labels text glyph
                        m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolText, m_textGlyph);
                        //set the color of the text
                        m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolText, 1.0f, 1.0f, 0.0f, 1.0f); // Yellow

                        //draw the item as a compound marker. This means that you do not have to draw the items and their
                        //accompanying labels separately, and thus allow you to write less code as well as get better
                        //performance.
                        m_dynamicCompoundMarker.DrawCompoundMarker4
                            (m_point,
                            //"TOP",
                            //"BOTTOM",
                            "Item " + Convert.ToString(r[0]),
                            heading.ToString("###.##"),
                            m_point.X.ToString("###.#####"),
                            m_point.Y.ToString("###.#####"));
                        break;

                    case 1:
                        //set the heading of the current symbol
                        m_dynamicSymbolProps.set_Heading(esriDynamicSymbolType.esriDSymbolMarker, (float)heading);

                        //set the symbol alignment so that it will align with towards the symbol heading
                        m_dynamicSymbolProps.set_RotationAlignment(esriDynamicSymbolType.esriDSymbolMarker, esriDynamicSymbolRotationAlignment.esriDSRANorth);

                        m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f);
                        m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 0.0f, 1.0f, 0.6f, 1.0f); // GREEN
                        m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker, m_markerGlyphs[1]);

                        //draw the current location
                        DynamicDisplay.DrawMarker(m_point);
                        break;

                    case 2:
                        //set the heading of the current symbol
                        m_dynamicSymbolProps.set_Heading(esriDynamicSymbolType.esriDSymbolMarker, (float)heading);

                        //set the symbol alignment so that it will align with towards the symbol heading
                        m_dynamicSymbolProps.set_RotationAlignment(esriDynamicSymbolType.esriDSymbolMarker, esriDynamicSymbolRotationAlignment.esriDSRANorth);

                        m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.1f, 1.1f);
                        m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f, 1.0f, 1.0f); // WHITE
                        m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker, m_markerGlyphs[2]);

                        //draw the current location
                        DynamicDisplay.DrawMarker(m_point);
                        break;
                    }
                }

                // by setting immediate flag to false, we signal the dynamic display that the layer is current.
                base.m_bIsImmediateDirty = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }