static public bool IsWhiteColor(CIMColor color)
        {
            CIMRGBColor rgb = color as CIMRGBColor;

            if (rgb == null)
            {
                return(false);
            }
            return(rgb.R == 255 && rgb.G == 255 && rgb.B == 255 && rgb.Alpha == 100);
        }
        static public bool IsBlackColor(CIMColor color, bool close = true)
        {
            CIMRGBColor rgb = color as CIMRGBColor;

            if (rgb == null)
            {
                return(false);
            }
            int max = close ? 45 : 0;

            return(rgb.R <= max && rgb.G <= max && rgb.B <= max && rgb.Alpha == 100);
        }
Example #3
0
        public static CIMGrayColor ToGray(this CIMRGBColor color)
        {
            const float sr = 0.299f, sg = 0.587f, sb = 0.114f;

            if (color == null)
            {
                return(null);
            }
            float level = sr * color.R + sg * color.G + sb * color.B;

            return(new CIMGrayColor {
                Level = Clip(level, 0, 255)
            });
        }
Example #4
0
        /// <summary>
        /// Upon activating the custom tool, the segment symbology is modified in this method and the regular unselected vertices symbology is also modified.
        /// </summary>
        /// <param name="active"></param>
        /// <returns></returns>
        protected override Task OnToolActivateAsync(bool active)
        {
            return(QueuedTask.Run(() =>
            {
                //Getting the current symbology options of the segment
                var segmentOptions = GetSketchSegmentSymbolOptions();
                //Modifying the primary color and the width of the segment symbology options
                var orange = new CIMRGBColor();
                orange.R = 255;
                orange.G = 165;
                orange.B = 0;
                segmentOptions.PrimaryColor = orange;
                segmentOptions.Width = 4;

                //Creating a new vertex symbol options instance with the values you want
                var vertexOptions = new VertexSymbolOptions(VertexSymbolType.RegularUnselected);
                var yellow = new CIMRGBColor();
                yellow.R = 255;
                yellow.G = 215;
                yellow.B = 0;
                var purple = new CIMRGBColor();
                purple.R = 148;
                purple.G = 0;
                purple.B = 211;
                vertexOptions.AngleRotation = 45;
                vertexOptions.Color = yellow;
                vertexOptions.MarkerType = VertexMarkerType.Star;
                vertexOptions.OutlineColor = purple;
                vertexOptions.OutlineWidth = 3;
                vertexOptions.Size = 5;

                try
                {
                    //Setting the value of the segment symbol options
                    SetSketchSegmentSymbolOptions(segmentOptions);
                    //Setting the value of the vertex symbol options of the regular unselected vertices using the vertexOptions instance created above.
                    SetSketchVertexSymbolOptions(VertexSymbolType.RegularUnselected, vertexOptions);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($@"Unexpected Exception: {ex}");
                }
            }));
        }
        static public bool IsNeutralColor(CIMColor color)
        {
            CIMRGBColor rgb = color as CIMRGBColor;

            if (rgb == null)
            {
                return(false);
            }
            // almost black
            if (rgb.R < 45 && rgb.G < 45 && rgb.B < 45 && rgb.Alpha == 100)
            {
                return(true);
            }
            // or gray
            if (rgb.R < 128 && rgb.G < 128 && rgb.B < 128 && Math.Round(rgb.R) == Math.Round(rgb.G) && Math.Round(rgb.R) == Math.Round(rgb.B) && rgb.Alpha == 100)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private Geometry CreateCircle(bool isFeedback)
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return(null);
            }

            var param = new GeometryEngine.GeodesicEllipseParameter();

            param.Center          = new Coordinate(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
            {
                param.OutGeometryType = GeometryType.Polyline;
            }
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color = new CIMRGBColor()
            {
                R = 255, B = 0, G = 0, Alpha = 25
            };

            if (isFeedback)
            {
                color = ColorFactory.GreyRGB;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.GreenRGB, true, 5.0);
            }
            AddGraphicToMap(geom, color, IsTempGraphic: isFeedback);

            return(geom as Geometry);
        }
Example #7
0
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private Geometry CreateCircle(bool isFeedback)
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return(null);
            }
            var nameConverter = new EnumToFriendlyNameConverter();
            var param         = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
            {
                param.OutGeometryType = GeometryType.Polyline;
            }
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color = new CIMRGBColor()
            {
                R = 255, B = 0, G = 0, Alpha = 25
            };

            if (isFeedback)
            {
                color = ColorFactory.Instance.GreyRGB;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            }

            // Hold onto the attributes in case user saves graphics to file later
            //CircleAttributes circleAttributes = new CircleAttributes(Point1, Distance, CircleType);
            double        dist = 0.0;
            DistanceTypes distunit;

            if (CircleType == CircleFromTypes.Diameter)
            {
                dist = Distance * 2;
            }
            else
            {
                dist = Distance;
            }

            if (IsDistanceCalcExpanded)
            {
                dist     = ConvertFromTo(LineDistanceType, RateUnit, Distance);
                distunit = RateUnit;
            }
            else
            {
                distunit = LineDistanceType;
            }

            var displayValue = nameConverter.Convert(distunit, typeof(string), new object(), CultureInfo.CurrentCulture);
            CircleAttributes circleAttributes = new CircleAttributes()
            {
                mapPoint = Point1, distance = dist, circleFromTypes = CircleType, circletype = CircleType.ToString(), centerx = Point1.X, centery = Point1.Y, distanceunit = displayValue.ToString()
            };

            if (isFeedback)
            {
                AddGraphicToMap(geom, color, (ProGraphicAttributes)circleAttributes, IsTempGraphic: isFeedback);
            }
            else
            {
                CreateCircleFeature(geom, circleAttributes);
            }

            return((Geometry)geom);
        }
        /// <summary>
        /// On activating this MapTool, the sketch segment symbology is modified along with the symbologies of the
        /// unselected current and unselected regular vertices of the sketch.
        /// The SketchSymbol property of the MapTool is also modified, which is different from the sketch segment and vertices.
        /// This property is used to customize the fixed part of the sketch, i.e. the part of the sketch that shows you what the
        /// output will look like if you finish the sketch right then without doing any more edits.
        /// </summary>
        /// <param name="active"></param>
        /// <returns></returns>
        protected override Task OnToolActivateAsync(bool active)
        {
            var darkBlue = new CIMRGBColor()
            {
                R = 0, G = 76, B = 153
            };
            var lightBlue = new CIMRGBColor()
            {
                R = 102, G = 178, B = 255
            };
            var darkGreen = new CIMRGBColor()
            {
                R = 0, G = 153, B = 0
            };
            var lightGreen = new CIMRGBColor()
            {
                R = 102, G = 255, B = 102
            };
            var red = new CIMRGBColor()
            {
                R = 153, G = 0, B = 0
            };
            var white = new CIMRGBColor()
            {
                R = 255, G = 255, B = 255
            };

            //return base.OnToolActivateAsync(active);
            return(QueuedTask.Run(() =>
            {
                //Getting the current symbology options of the segment
                var segmentOptions = GetSketchSegmentSymbolOptions();
                //Modifying the primary color, secondary color, and the width of the segment symbology options
                segmentOptions.PrimaryColor = darkBlue;
                segmentOptions.Width = 1.5;
                segmentOptions.SecondaryColor = lightBlue;

                //Creating a new vertex symbol options instances with the values you want
                //Vertex symbol options instance 1
                var vertexOptions = new VertexSymbolOptions(VertexSymbolType.RegularUnselected);
                vertexOptions.Color = darkGreen;
                vertexOptions.MarkerType = VertexMarkerType.Circle;
                vertexOptions.OutlineColor = lightGreen;
                vertexOptions.OutlineWidth = 4;
                vertexOptions.Size = 8;

                //Vertex symbol options instance 2
                var vertexOptions2 = new VertexSymbolOptions(VertexSymbolType.CurrentUnselected);
                vertexOptions2.Color = white;
                vertexOptions2.OutlineColor = red;
                vertexOptions2.MarkerType = VertexMarkerType.PushPin;
                vertexOptions2.OutlineWidth = 5;
                vertexOptions2.Size = 10;

                try
                {
                    //Setting the value of the segment symbol options
                    SetSketchSegmentSymbolOptions(segmentOptions);

                    //Setting the value of the vertex symbol options of the regular unselected vertices using the vertexOptions instance 1 created above.
                    SetSketchVertexSymbolOptions(VertexSymbolType.RegularUnselected, vertexOptions);
                    //Setting symbol options of current unselected vertex
                    SetSketchVertexSymbolOptions(VertexSymbolType.CurrentUnselected, vertexOptions2);

                    //Similarly you can set symbol options for current selected vertex and regular selected vertex
                    //SetSketchVertexSymbolOptions(VertexSymbolType.CurrentSelected, vertexOptions3);
                    //SetSketchVertexSymbolOptions(VertexSymbolType.RegularSelected, vertexOptions4);

                    //Modifying the SketchSymbol property of the MapTool
                    var yellow = CIMColor.CreateRGBColor(255, 215, 0);
                    var cimLineSymbol = SymbolFactory.Instance.ConstructLineSymbol(yellow, 4, SimpleLineStyle.DashDotDot);
                    base.SketchSymbol = cimLineSymbol.MakeSymbolReference();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($@"Unexpected Exception: {ex}");
                }
            }));
        }
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private void CreateCircle(bool isFeedback)
        {
            if (Point1 == null || Distance <= 0.0)
            {
                return;
            }

            var param = new GeometryEngine.GeodesicEllipseParameter();

            param.Center = new Coordinate(Point1);
            param.AxisDirection = 0.0;
            param.LinearUnit = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
                param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount = VertexCount;

            var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color =  new CIMRGBColor() { R=255,B=0,G=0,Alpha=25};
            if(isFeedback)
            {
                color = ColorFactory.Grey;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.Green, true, 5.0);
            }
            AddGraphicToMap(geom, color, IsTempGraphic: isFeedback);
        }