/// <summary>
        /// Create a unique value renderer based on the weather
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static CIMUniqueValueRenderer CreateRedenderer(Table table)
        {
            List <string> uniqueIconUrls = new List <string>();

            using (RowCursor cursor = table.Search())
            {
                do
                {
                    if (cursor.Current != null)
                    {
                        string url = cursor.Current["Iconurl"].ToString();
                        if (!uniqueIconUrls.Contains(url))
                        {
                            uniqueIconUrls.Add(url);
                        }
                    }
                }while (cursor.MoveNext());
            }

            CIMUniqueValueGroup uniqueValueGroup = new CIMUniqueValueGroup
            {
                Heading = "Weer type",
                Classes = CreateUniqueValueClasses(uniqueIconUrls)
            };

            CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer
            {
                Groups = new CIMUniqueValueGroup[] { uniqueValueGroup },
                Fields = new string[] { "Iconurl" }
            };

            return(uniqueValueRenderer);
        }
Esempio n. 2
0
        public static void SetShipAngle()
        {
            var task = QueuedTask.Run(() =>
            {
                //Create a list of the above two CIMUniqueValueClasses
                List <CIMUniqueValueClass> listUniqueValueClasses = new List <CIMUniqueValueClass>();
                for (int i = 0; i < 360; i++)
                {
                    List <CIMUniqueValue> listUniqueValues = new List <CIMUniqueValue>();
                    CIMUniqueValue cuv = new CIMUniqueValue {
                        FieldValues = new string[] { i.ToString() }
                    };
                    //CIMMarker cm = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlackRGB, GetShipSymbolSize(5,8,i), SetShipRotate(i));
                    CIMMarker cm = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlackRGB, GetShipSymbolSize2(10, i), SetShipRotate(i));
                    listUniqueValues.Add(cuv);
                    CIMUniqueValueClass UniqueValueClass = new CIMUniqueValueClass
                    {
                        Editable = true,
                        Patch    = PatchShape.Default,
                        Symbol   = SymbolFactory.Instance.ConstructPointSymbol(cm).MakeSymbolReference(),
                        Visible  = true,
                        Values   = listUniqueValues.ToArray()
                    };
                    listUniqueValueClasses.Add(UniqueValueClass);
                }

                //Create a list of CIMUniqueValueGroup
                CIMUniqueValueGroup uvg = new CIMUniqueValueGroup
                {
                    Classes = listUniqueValueClasses.ToArray(),
                };
                List <CIMUniqueValueGroup> listUniqueValueGroups = new List <CIMUniqueValueGroup> {
                    uvg
                };
                CIMMarker cm1 = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlackRGB, 8, SetShipRotate(0));
                //Create the CIMUniqueValueRenderer
                CIMUniqueValueRenderer uvr = new CIMUniqueValueRenderer
                {
                    UseDefaultSymbol = true,
                    DefaultSymbol    = SymbolFactory.Instance.ConstructPointSymbol(cm1).MakeSymbolReference(),
                    Groups           = listUniqueValueGroups.ToArray(),
                    Fields           = new string[] { ConstDefintion.ConstFieldName_cog }
                };
                //Set the feature layer's renderer.
                FeatureLayer featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().First() as FeatureLayer;
                featureLayer.SetRenderer(uvr);
            });
        }
        /// <summary>
        /// Warning! You must call this method on the MCT!
        /// </summary>
        /// <returns></returns>
        private CIMRenderer CreateUniqueValueRendererForUSStates()
        {
            //All of these methods have to be called on the MCT
            if (Module1.OnUIThread)
            {
                throw new CalledOnWrongThreadException();
            }

            //Create the Unique Value Renderer
            CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer()
            {
                // set the value field
                Fields = new string[] { "STATE_NAME" }
            };

            //Construct the list of UniqueValueClasses
            List <CIMUniqueValueClass> classes = new List <CIMUniqueValueClass>();

            // Alabama
            List <CIMUniqueValue> alabamaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        alabamaValue  = new CIMUniqueValue()
            {
                FieldValues = new string[] { "Alabama" }
            };

            alabamaValues.Add(alabamaValue);

            var alabamaColor = CIMColor.CreateRGBColor(255, 170, 0);

            var alabama = new CIMUniqueValueClass()
            {
                Values   = alabamaValues.ToArray(),
                Label    = "Alabama",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(alabamaColor)
                }
            };

            classes.Add(alabama);

            // Alaska
            List <CIMUniqueValue> alaskaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        alaskaValue  = new CIMUniqueValue()
            {
                FieldValues = new string[] { "Alaska" }
            };

            alaskaValues.Add(alaskaValue);

            var alaskaColor = CIMColor.CreateRGBColor(255, 0, 0);

            var alaska = new CIMUniqueValueClass()
            {
                Values   = alaskaValues.ToArray(),
                Label    = "Alaska",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(alaskaColor)
                }
            };

            classes.Add(alaska);

            // California
            List <CIMUniqueValue> californiaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        californiaValue  = new CIMUniqueValue()
            {
                FieldValues = new string[] { "California" }
            };

            californiaValues.Add(californiaValue);

            var californiaColor = CIMColor.CreateRGBColor(85, 255, 0);

            var california = new CIMUniqueValueClass()
            {
                Values   = californiaValues.ToArray(),
                Label    = "California",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(californiaColor)
                }
            };

            classes.Add(california);

            // Colorado
            List <CIMUniqueValue> coloradoValues = new List <CIMUniqueValue>();
            CIMUniqueValue        coloradoValue  = new CIMUniqueValue()
            {
                FieldValues = new string[] { "Colorado" }
            };

            coloradoValues.Add(coloradoValue);

            var coloradoColor = CIMColor.CreateRGBColor(0, 92, 230);

            var colorado = new CIMUniqueValueClass()
            {
                Values   = coloradoValues.ToArray(),
                Label    = "Colorado",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(coloradoColor)
                }
            };

            classes.Add(colorado);

            // so on and so forth for all the 51.
            //....

            //Add the classes to a group (by default there is only one group or "symbol level")
            // Unique value groups
            CIMUniqueValueGroup groupOne = new CIMUniqueValueGroup()
            {
                Heading = "State Names",
                Classes = classes.ToArray()
            };

            uniqueValueRenderer.Groups = new CIMUniqueValueGroup[] { groupOne };

            //Draw the rest with the default symbol
            uniqueValueRenderer.UseDefaultSymbol = true;
            uniqueValueRenderer.DefaultLabel     = "All other values";

            var defaultColor = CIMColor.CreateRGBColor(215, 215, 215);

            uniqueValueRenderer.DefaultSymbol = new CIMSymbolReference()
            {
                Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(defaultColor)
            };

            return(uniqueValueRenderer as CIMRenderer);
        }
        /// <summary>
        /// Warning! You must call this method on the MCT!
        /// </summary>
        /// <returns></returns>
        private CIMRenderer CreateUniqueValueRendererForUSStates() {
            //All of these methods have to be called on the MCT
            if (Module1.OnUIThread)
                throw new CalledOnWrongThreadException();

            //Create the Unique Value Renderer
            CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer();

            // set the value field
            uniqueValueRenderer.Fields = new string[] { "STATE_NAME" };

            //Construct the list of UniqueValueClasses
            List<CIMUniqueValueClass> classes = new List<CIMUniqueValueClass>();

            // Alabama
            List<CIMUniqueValue> alabamaValues = new List<CIMUniqueValue>();
            CIMUniqueValue alabamaValue = new CIMUniqueValue();
            alabamaValue.FieldValues = new string[] { "Alabama" };
            alabamaValues.Add(alabamaValue);

            var alabamaColor = CIMColor.CreateRGBColor(255, 170, 0);

            var alabama = new CIMUniqueValueClass() {
                Values = alabamaValues.ToArray(),
                Label = "Alabama",
                Visible = true,
                Editable = true,
                Symbol = new CIMSymbolReference() {Symbol = SymbolFactory.ConstructPolygonSymbol(alabamaColor)}
            };

            classes.Add(alabama);

            // Alaska
            List<CIMUniqueValue> alaskaValues = new List<CIMUniqueValue>();
            CIMUniqueValue alaskaValue = new CIMUniqueValue();
            alaskaValue.FieldValues = new string[] { "Alaska" };
            alaskaValues.Add(alaskaValue);

            var alaskaColor = CIMColor.CreateRGBColor(255, 0, 0);

            var alaska = new CIMUniqueValueClass() {
                Values = alaskaValues.ToArray(),
                Label = "Alaska",
                Visible = true,
                Editable = true,
                Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.ConstructPolygonSymbol(alaskaColor) }
            };

            classes.Add(alaska);

            // California
            List<CIMUniqueValue> californiaValues = new List<CIMUniqueValue>();
            CIMUniqueValue californiaValue = new CIMUniqueValue();
            californiaValue.FieldValues = new string[] { "California" };
            californiaValues.Add(californiaValue);

            var californiaColor = CIMColor.CreateRGBColor(85, 255, 0);

            var california = new CIMUniqueValueClass() {
                Values = californiaValues.ToArray(),
                Label = "California",
                Visible = true,
                Editable = true,
                Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.ConstructPolygonSymbol(californiaColor) }
            };

            classes.Add(california);

            // Colorado
            List<CIMUniqueValue> coloradoValues = new List<CIMUniqueValue>();
            CIMUniqueValue coloradoValue = new CIMUniqueValue();
            coloradoValue.FieldValues = new string[] { "Colorado" };
            coloradoValues.Add(coloradoValue);

            var coloradoColor = CIMColor.CreateRGBColor(0, 92, 230);

            var colorado = new CIMUniqueValueClass() {
                Values = coloradoValues.ToArray(),
                Label = "Colorado",
                Visible = true,
                Editable = true,
                Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.ConstructPolygonSymbol(coloradoColor) }
            };

            classes.Add(colorado);

            // so on and so forth for all the 51.
            //....

            //Add the classes to a group (by default there is only one group or "symbol level")
            // Unique value groups
            CIMUniqueValueGroup groupOne = new CIMUniqueValueGroup();
            groupOne.Heading = "State Names";
            groupOne.Classes = classes.ToArray();

            uniqueValueRenderer.Groups = new CIMUniqueValueGroup[] { groupOne };

            //Draw the rest with the default symbol
            uniqueValueRenderer.UseDefaultSymbol = true;
            uniqueValueRenderer.DefaultLabel = "All other values";

            var defaultColor = CIMColor.CreateRGBColor(215, 215, 215);
            uniqueValueRenderer.DefaultSymbol = new CIMSymbolReference() {
                Symbol = SymbolFactory.ConstructPolygonSymbol(defaultColor)
            };
            
            return uniqueValueRenderer as CIMRenderer;
        }
Esempio n. 5
0
        public async void Example6()
        {
            Map map = MapView.Active.Map;
            await QueuedTask.Run(() =>
            {
                StreamLayer streamLayer = null;
                //https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer

                #region Defining a unique value renderer definition

                var uvrDef = new UniqueValueRendererDefinition()
                {
                    ValueFields    = new string[] { "ACTYPE" },
                    SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(
                        ColorFactory.Instance.RedRGB, 10, SimpleMarkerStyle.Hexagon)
                                     .MakeSymbolReference(),
                    ValuesLimit = 5
                };
                //Note: CreateRenderer can only create value classes based on
                //the current events it has received
                streamLayer.SetRenderer(streamLayer.CreateRenderer(uvrDef));

                #endregion

                #region Setting a unique value renderer for latest observations

                //Define the classes by hand to avoid using CreateRenderer(...)
                CIMUniqueValueClass uvcB727 = new CIMUniqueValueClass()
                {
                    Values = new CIMUniqueValue[] { new CIMUniqueValue()
                                                    {
                                                        FieldValues = new string[] { "B727" }
                                                    } },
                    Visible = true,
                    Label   = "Boeing 727",
                    Symbol  = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(255, 0, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
                };

                CIMUniqueValueClass uvcD9 = new CIMUniqueValueClass()
                {
                    Values = new CIMUniqueValue[] { new CIMUniqueValue()
                                                    {
                                                        FieldValues = new string[] { "DC9" }
                                                    } },
                    Visible = true,
                    Label   = "DC 9",
                    Symbol  = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(0, 255, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
                };
                //Assign the classes to a group
                CIMUniqueValueGroup uvGrp = new CIMUniqueValueGroup()
                {
                    Classes = new CIMUniqueValueClass[] { uvcB727, uvcD9 }
                };
                //assign the group to the renderer
                var UVrndr = new CIMUniqueValueRenderer()
                {
                    Fields           = new string[] { "ACTYPE" },
                    Groups           = new CIMUniqueValueGroup[] { uvGrp },
                    UseDefaultSymbol = true,
                    DefaultLabel     = "Others",
                    DefaultSymbol    = SymbolFactory.Instance.ConstructPointSymbol(
                        CIMColor.CreateRGBColor(185, 185, 185), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
                };
                //set the renderer. Depending on the current events recieved, the
                //layer may or may not have events for each of the specified
                //unique value classes
                streamLayer.SetRenderer(UVrndr);

                #endregion

                #region Setting a unique value renderer for previous observations
                //The layer must be track aware and spatial
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask!
                //Define unique value classes same as we do for current observations
                //or use "CreateRenderer(...)" to assign them automatically
                CIMUniqueValueClass uvcB727Prev = new CIMUniqueValueClass()
                {
                    Values = new CIMUniqueValue[] { new CIMUniqueValue()
                                                    {
                                                        FieldValues = new string[] { "B727" }
                                                    } },
                    Visible = true,
                    Label   = "Boeing 727",
                    Symbol  = SymbolFactory.Instance.ConstructPointSymbol(
                        CIMColor.CreateRGBColor(255, 0, 0), 4, SimpleMarkerStyle.Hexagon)
                              .MakeSymbolReference()
                };

                CIMUniqueValueClass uvcD9Prev = new CIMUniqueValueClass()
                {
                    Values = new CIMUniqueValue[] { new CIMUniqueValue()
                                                    {
                                                        FieldValues = new string[] { "DC9" }
                                                    } },
                    Visible = true,
                    Label   = "DC 9",
                    Symbol  = SymbolFactory.Instance.ConstructPointSymbol(
                        CIMColor.CreateRGBColor(0, 255, 0), 4, SimpleMarkerStyle.Hexagon)
                              .MakeSymbolReference()
                };

                CIMUniqueValueGroup uvGrpPrev = new CIMUniqueValueGroup()
                {
                    Classes = new CIMUniqueValueClass[] { uvcB727Prev, uvcD9Prev }
                };

                var UVrndrPrev = new CIMUniqueValueRenderer()
                {
                    Fields           = new string[] { "ACTYPE" },
                    Groups           = new CIMUniqueValueGroup[] { uvGrpPrev },
                    UseDefaultSymbol = true,
                    DefaultLabel     = "Others",
                    DefaultSymbol    = SymbolFactory.Instance.ConstructPointSymbol(
                        CIMColor.CreateRGBColor(185, 185, 185), 4, SimpleMarkerStyle.Hexagon)
                                       .MakeSymbolReference()
                };

                #endregion

                #region Setting a simple renderer to draw track lines
                //The layer must be track aware and spatial
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask!
                //Note: only a simple renderer with solid line symbol is supported for track
                //line renderer
                var trackRenderer = new SimpleRendererDefinition()
                {
                    SymbolTemplate = SymbolFactory.Instance.ConstructLineSymbol(
                        ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.Solid)
                                     .MakeSymbolReference()
                };
                streamLayer.SetRenderer(
                    streamLayer.CreateRenderer(trackRenderer),
                    FeatureRendererTarget.TrackLines);

                #endregion

                #region Check Previous Observation and Track Line Visibility

                //The layer must be track aware and spatial for these settings
                //to have an effect
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask
                if (!streamLayer.AreTrackLinesVisible)
                {
                    streamLayer.SetTrackLinesVisibility(true);
                }
                if (!streamLayer.ArePreviousObservationsVisible)
                {
                    streamLayer.SetPreviousObservationsVisibility(true);
                }

                #endregion

                #region Make Track Lines and Previous Observations Visible
                //The layer must be track aware and spatial for these settings
                //to have an effect
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask
                //Note: Setting PreviousObservationsCount larger than the
                //"SetExpirationMaxCount()" has no effect
                streamLayer.SetPreviousObservationsCount(6);
                if (!streamLayer.AreTrackLinesVisible)
                {
                    streamLayer.SetTrackLinesVisibility(true);
                }
                if (!streamLayer.ArePreviousObservationsVisible)
                {
                    streamLayer.SetPreviousObservationsVisibility(true);
                }
                #endregion


                #region Retrieve the current observation renderer

                //Must be on QueuedTask!
                var renderer = streamLayer.GetRenderer();

                #endregion

                #region Retrieve the previous observation renderer
                //The layer must be track aware and spatial
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask!
                var prev_renderer = streamLayer.GetRenderer(
                    FeatureRendererTarget.PreviousObservations);

                #endregion

                #region Retrieve the track lines renderer
                //The layer must be track aware and spatial
                if (streamLayer.TrackType != TrackType.Spatial)
                {
                    return;
                }
                //Must be on QueuedTask!
                var track_renderer = streamLayer.GetRenderer(
                    FeatureRendererTarget.TrackLines);

                #endregion
            });
        }