コード例 #1
0
        private void ChangeRenderer()
        {
            var renderer = new UniqueValueRenderer()
            {
                Fields = new ObservableCollection <string>(new List <string> {
                    "Name"
                })
            };

            renderer.Infos = new UniqueValueInfoCollection(_states.Graphics
                                                           .Select(g => g.Attributes["Name"])
                                                           .Distinct()
                                                           .Select(obj => new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { obj }),
                Symbol = new SimpleFillSymbol()
                {
                    Outline = new SimpleLineSymbol()
                    {
                        Color = Colors.BlueViolet, Width = 6
                    }, Color = Colors.Black
                }
            }));

            _states.Renderer = renderer;
        }
コード例 #2
0
 private void RendererType_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (RendererType.SelectedIndex == 0)
     {
         if (!(Renderer is SimpleRenderer))
         {
             Renderer = new SimpleRenderer(new SimpleMarkerSymbol());
             return;
         }
     }
     else if (RendererType.SelectedIndex == 1)
     {
         if (!(Renderer is UniqueValueRenderer))
         {
             Renderer = new UniqueValueRenderer();
             return;
         }
     }
     else if (RendererType.SelectedIndex == 2)
     {
         if (!(Renderer is ClassBreaksRenderer))
         {
             Renderer = new ClassBreaksRenderer();
             return;
         }
     }
     else if (RendererType.SelectedIndex == 3)
     {
         if ((Renderer is null) || HeatMapRendererEditor.HeatMapRendererModel.FromRenderer(Renderer).type != "heatmap")
         {
             Renderer = new HeatMapRendererEditor.HeatMapRendererModel().AsRenderer();
             return;
         }
     }
 }
コード例 #3
0
 protected virtual void WriteRenderer(IRenderer renderer)
 {
     if (IsSerializable(renderer))
     {
         ClassBreaksRenderer classBreaksRenderer = renderer as ClassBreaksRenderer;
         if (classBreaksRenderer != null)
         {
             writer.WriteStartElement("GraphicsLayer.Renderer", Namespaces[Constants.esriPrefix]);
             WriteClassBreaksRenderer(classBreaksRenderer);
             writer.WriteEndElement();
         }
         else
         {
             UniqueValueRenderer uniqueValueRenderer = renderer as UniqueValueRenderer;
             if (uniqueValueRenderer != null)
             {
                 writer.WriteStartElement("GraphicsLayer.Renderer", Namespaces[Constants.esriPrefix]);
                 WriteUniqueValueRenderer(uniqueValueRenderer);
                 writer.WriteEndElement();
             }
             else
             {
                 SimpleRenderer simpleRenderer = renderer as SimpleRenderer;
                 if (simpleRenderer != null)
                 {
                     writer.WriteStartElement("GraphicsLayer.Renderer", Namespaces[Constants.esriPrefix]);
                     WriteSimpleValueRenderer(simpleRenderer);
                     writer.WriteEndElement();
                 }
             }
         }
     }
 }
コード例 #4
0
        private void WriteUniqueValueRenderer(UniqueValueRenderer uniqueValueRenderer)
        {
            writer.WriteStartElement("UniqueValueRenderer", Namespaces[Constants.esriPrefix]);
            if (!string.IsNullOrEmpty(uniqueValueRenderer.Field))
            {
                WriteAttribute("Field", uniqueValueRenderer.Field);
            }
            WriteAttribute("DefaultLabel", uniqueValueRenderer.DefaultLabel);
            if (uniqueValueRenderer.DefaultSymbol != null)
            {
                writer.WriteStartElement("UniqueValueRenderer.DefaultSymbol", Namespaces[Constants.esriPrefix]);
                (new SymbolXamlWriter(writer, Namespaces)).WriteSymbol(uniqueValueRenderer.DefaultSymbol);
                writer.WriteEndElement();
            }
            if (uniqueValueRenderer.Infos != null && uniqueValueRenderer.Infos.Count > 0)
            {
                writer.WriteStartElement("UniqueValueRenderer.Infos", Namespaces[Constants.esriPrefix]);

                foreach (ESRI.ArcGIS.Client.UniqueValueInfo uniqueValueInfo in uniqueValueRenderer.Infos)
                {
                    WriteUniqueValueInfo(uniqueValueInfo);
                }

                writer.WriteEndElement();// UniqueValueRenderer.Infos
            }
            writer.WriteEndElement();
        }
        void optionsConfigControl_NewUniqueValueCreated(object sender, NewUniqueValueInfoEventArgs e)
        {
            if (RendererSymbolSetContainerControl != null)
            {
                UniqueValueRendererSymbolsConfigControl symbolsConfigControl = RendererSymbolSetContainerControl.Content as UniqueValueRendererSymbolsConfigControl;
                if (symbolsConfigControl != null)
                {
                    FieldType     fieldType     = FieldType.Text;
                    GraphicsLayer graphicsLayer = Layer as GraphicsLayer;
                    if (graphicsLayer == null)
                    {
                        return;
                    }

                    UniqueValueRenderer uniqueValueRenderer = graphicsLayer.Renderer as UniqueValueRenderer;
                    if (uniqueValueRenderer == null)
                    {
                        return;
                    }

                    Collection <FieldInfo> fields = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetFields(graphicsLayer);
                    if (fields != null)
                    {
                        FieldInfo selectedField = fields.FirstOrDefault <FieldInfo>(f => f.Name == uniqueValueRenderer.Field);
                        if (selectedField != null)
                        {
                            fieldType = selectedField.FieldType;
                            symbolsConfigControl.AddNewUniqueValue(createNewUniqueValue(e.UniqueValue, fieldType), fieldType);
                            graphicsLayer.Refresh();
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: MapAPI.cs プロジェクト: rs-sdust/GFStatistics
        public static void UniqueValueRender(IFeatureLayer pFLayer, string fieldName)
        {
            IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();

            uniqueValueRenderer.FieldCount = 1;
            uniqueValueRenderer.set_Field(0, fieldName);

            List <string> uniqueValues = GetLayerUniqueFieldValue(pFLayer, fieldName);
            Random        rand         = new Random();

            foreach (string value in uniqueValues)
            {
                IFillSymbol fillSymbol = new SimpleFillSymbol();
                fillSymbol.Color = new RgbColor()
                {
                    Red = rand.Next(0, 255), Green = rand.Next(0, 255), Blue = rand.Next(0, 255)
                };
                uniqueValueRenderer.AddValue(value, "", (ISymbol)fillSymbol);
            }

            var featureRenderer = (IFeatureRenderer)uniqueValueRenderer;
            var geoFeatureLayer = (IGeoFeatureLayer)pFLayer;

            geoFeatureLayer.Renderer = featureRenderer;
        }
コード例 #7
0
        private void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Create uri to the used feature service
            var serviceUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");

            // Create service feature table
            ServiceFeatureTable statesFeatureTable = new ServiceFeatureTable(serviceUri);

            // Create a new feature layer using the service feature table
            FeatureLayer statesLayer = new FeatureLayer(statesFeatureTable);

            // Create a new unique value renderer
            UniqueValueRenderer regionRenderer = new UniqueValueRenderer();

            // Add the "SUB_REGION" field to the renderer
            regionRenderer.FieldNames.Add("SUB_REGION");

            // Define a line symbol to use for the region fill symbols
            SimpleLineSymbol stateOutlineSymbol = new SimpleLineSymbol(
                SimpleLineSymbolStyle.Solid, System.Drawing.Color.White, 0.7);

            // Define distinct fill symbols for a few regions (use the same outline symbol)
            SimpleFillSymbol pacificFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.Blue, stateOutlineSymbol);
            SimpleFillSymbol mountainFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.LawnGreen, stateOutlineSymbol);
            SimpleFillSymbol westSouthCentralFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.SandyBrown, stateOutlineSymbol);

            // Add values to the renderer: define the label, description, symbol, and attribute value for each
            regionRenderer.UniqueValues.Add(
                new UniqueValue("Pacific", "Pacific Region", pacificFillSymbol, "Pacific"));
            regionRenderer.UniqueValues.Add(
                new UniqueValue("Mountain", "Rocky Mountain Region", mountainFillSymbol, "Mountain"));
            regionRenderer.UniqueValues.Add(
                new UniqueValue("West South Central", "West South Central Region", westSouthCentralFillSymbol, "West South Central"));

            // Set the default region fill symbol (transparent with no outline) for regions not explicitly defined in the renderer
            SimpleFillSymbol defaultFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Null, System.Drawing.Color.Transparent, null);

            regionRenderer.DefaultSymbol = defaultFillSymbol;
            regionRenderer.DefaultLabel  = "Other";

            // Apply the unique value renderer to the states layer
            statesLayer.Renderer = regionRenderer;

            // Add created layer to the map
            myMap.OperationalLayers.Add(statesLayer);

            // Assign the map to the MapView
            _myMapView.Map = myMap;

            // Feature table initialization
            statesFeatureTable.RetryLoadAsync();
        }
コード例 #8
0
        /// <summary>
        /// Handle FeatureLayer Initialization Event
        /// </summary>
        private void FeatureLayer_Initialized(object sender, EventArgs e)
        {
            FeatureLayer     fLayer    = sender as FeatureLayer;
            EditFeatureLayer editLayer = widgetConfig.EditableLayers.FirstOrDefault(layer => fLayer.ID.Equals(string.Format("edit_{0}", layer.ID.ToString())));

            if (string.IsNullOrEmpty(editLayer.OutFields) || editLayer.OutFields == "*")
            {
                foreach (Field f in fLayer.LayerInfo.Fields)
                {
                    fLayer.OutFields.Add(f.Name);
                }
            }
            else
            {
                string[] fields = editLayer.OutFields.Split(',');
                foreach (string field in fields)
                {
                    fLayer.OutFields.Add(field);
                }
            }

            if (editLayer != null)
            {
                SymbolTypeGroup typeGroup = new SymbolTypeGroup();
                typeGroup.LayerID         = fLayer.ID;
                typeGroup.LayerName       = editLayer.Title;
                typeGroup.LayerVisibility = editLayer.VisibleInitial;
                symbolTypeGroups.Add(typeGroup);

                if (fLayer.LayerInfo.Renderer is SimpleRenderer)
                {
                    SimpleRenderer renderer   = fLayer.LayerInfo.Renderer as SimpleRenderer;
                    SymbolType     symbolType = new SymbolType(fLayer.LayerInfo.Name, null, renderer.Symbol, "");
                    typeGroup.SymbolTypes.Add(symbolType);
                }
                if (fLayer.LayerInfo.Renderer is UniqueValueRenderer)
                {
                    UniqueValueRenderer renderer = fLayer.LayerInfo.Renderer as UniqueValueRenderer;
                    foreach (UniqueValueInfo valueInfo in renderer.Infos)
                    {
                        SymbolType symbolType = new SymbolType(valueInfo.Label, valueInfo.Value, valueInfo.Symbol, valueInfo.Description);
                        typeGroup.SymbolTypes.Add(symbolType);
                    }
                }
                else if (fLayer.LayerInfo.Renderer is ClassBreaksRenderer)
                {
                    ClassBreaksRenderer renderer = fLayer.LayerInfo.Renderer as ClassBreaksRenderer;
                    foreach (ClassBreakInfo classInfo in renderer.Classes)
                    {
                        SymbolType symbolType = new SymbolType(classInfo.Label, null, classInfo.Symbol, classInfo.Description);
                        typeGroup.SymbolTypes.Add(symbolType);
                    }
                }
            }

            if (symbolTypeGroups.Count == widgetConfig.EditableLayers.Count()) // All layers are initialized
            {
                FeatureTemplateList.ItemsSource = symbolTypeGroups;
            }
        }
コード例 #9
0
 public static Symbol GetDefaultSymbol(this IRenderer renderer)
 {
     if (renderer != null)
     {
         SimpleRenderer simpleRenderer = renderer as SimpleRenderer;
         if (simpleRenderer != null)
         {
             return(simpleRenderer.Symbol);
         }
         else
         {
             ClassBreaksRenderer classBreaksRenderer = renderer as ClassBreaksRenderer;
             if (classBreaksRenderer != null)
             {
                 return(classBreaksRenderer.DefaultSymbol);
             }
             else
             {
                 UniqueValueRenderer uniqueValueRenderer = renderer as UniqueValueRenderer;
                 if (uniqueValueRenderer != null)
                 {
                     return(uniqueValueRenderer.DefaultSymbol);
                 }
             }
         }
     }
     return(null);
 }
コード例 #10
0
        private void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Create uri to the used feature service
            var serviceUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");

            // Create service feature table
            ServiceFeatureTable statesFeatureTable = new ServiceFeatureTable(serviceUri);

            // Create a new feature layer using the service feature table
            FeatureLayer statesLayer = new FeatureLayer(statesFeatureTable);

            // Create a new unique value renderer
            UniqueValueRenderer regionRenderer = new UniqueValueRenderer();

            // Add the "SUB_REGION" field to the renderer
            regionRenderer.FieldNames.Add("SUB_REGION");

            // Define a line symbol to use for the region fill symbols
            SimpleLineSymbol stateOutlineSymbol = new SimpleLineSymbol(
                SimpleLineSymbolStyle.Solid, System.Drawing.Color.White, 0.7);

            // Define distinct fill symbols for a few regions (use the same outline symbol)
            SimpleFillSymbol pacificFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.Blue, stateOutlineSymbol);
            SimpleFillSymbol mountainFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.LawnGreen, stateOutlineSymbol);
            SimpleFillSymbol westSouthCentralFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.SandyBrown, stateOutlineSymbol);

            // Add values to the renderer: define the label, description, symbol, and attribute value for each
            regionRenderer.UniqueValues.Add(
                new UniqueValue("Pacific", "Pacific Region", pacificFillSymbol, "Pacific"));
            regionRenderer.UniqueValues.Add(
                new UniqueValue("Mountain", "Rocky Mountain Region", mountainFillSymbol, "Mountain"));
            regionRenderer.UniqueValues.Add(
                new UniqueValue("West South Central", "West South Central Region", westSouthCentralFillSymbol, "West South Central"));

            // Set the default region fill symbol (transparent with no outline) for regions not explicitly defined in the renderer
            SimpleFillSymbol defaultFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Null, System.Drawing.Color.Transparent, null);
            regionRenderer.DefaultSymbol = defaultFillSymbol;
            regionRenderer.DefaultLabel = "Other";

            // Apply the unique value renderer to the states layer
            statesLayer.Renderer = regionRenderer;

            // Add created layer to the map
            myMap.OperationalLayers.Add(statesLayer);

            // Assign the map to the MapView
            _myMapView.Map = myMap;

            // Feature table initialization
            statesFeatureTable.RetryLoadAsync();
        }
コード例 #11
0
        // Adds graphics in bulk and use a renderer - Demonstrates the most efficient approach
        private void AddGraphicsInBulk_Click(object sender, RoutedEventArgs e)
        {
            // Clear the existing Graphics
            ClearGraphicsFromGraphicsLayer();
            BulkPerformanceDisplay.Text = defaultTime;

            // Create a stopwatch to time the add
            Stopwatch sw = new Stopwatch();
            sw.Start();

            // Create a instance of the Random class to generate random coordinate pairs.
            Random random = new Random();

            // Add graphics to a List<Graphic>
            var graphicsList = new List<Graphic>();
            for (int i = 0; i < 100000; i++)
            {
                var x = (random.NextDouble() * 40000000) - 20000000;
                var y = (random.NextDouble() * 40000000) - 20000000;
                var graphic = new Graphic()
                {
                    // assign each graphic a number 0, 1, 2 - we''ll use this to represent he color
                    Geometry = new MapPoint(x, y),
                    Attributes = { { "Color", i % 3 } }
                };
                graphicsList.Add(graphic);
            }

            // create a renderer with 3 symbols, rather than a symbol per graphic
            var renderer = new UniqueValueRenderer()
            {
                Field = "Color",
                Infos = {
                    new UniqueValueInfo()
                    {
                        Value = 0,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Red, Size=20  }
                    },
                    new UniqueValueInfo()
                    {
                        Value = 1,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Green, Style=SimpleMarkerSymbol.SimpleMarkerStyle.Diamond, Size=20 }
                    },
                    new UniqueValueInfo()
                    {
                        Value = 2,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Blue, Style=SimpleMarkerSymbol.SimpleMarkerStyle.Triangle, Size=20 }
                    }
                }
            };

            _graphicsLayer.Renderer = renderer;

            // Bulk add of graphics - more efficient than adding one graphic at a time
            _graphicsLayer.Graphics.AddRange(graphicsList);
            sw.Stop();
            BulkPerformanceDisplay.Text = (sw.ElapsedMilliseconds / 1000.0).ToString() + " Seconds";
        }
コード例 #12
0
        private static bool IsSerializable(IRenderer renderer)
        {
            ClassBreaksRenderer classBreaksRenderer = renderer as ClassBreaksRenderer;

            if (classBreaksRenderer != null)
            {
                if (classBreaksRenderer.Classes != null)
                {
                    foreach (ClassBreakInfo info in classBreaksRenderer.Classes)
                    {
                        if (!SymbolXamlWriter.IsSerializable(info.Symbol))
                        {
                            return(false);
                        }
                    }

                    if (!SymbolXamlWriter.IsSerializable(classBreaksRenderer.DefaultSymbol))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                UniqueValueRenderer uniqueValueRenderer = renderer as UniqueValueRenderer;
                if (uniqueValueRenderer != null)
                {
                    if (uniqueValueRenderer.Infos != null)
                    {
                        foreach (UniqueValueInfo info in uniqueValueRenderer.Infos)
                        {
                            if (!SymbolXamlWriter.IsSerializable(info.Symbol))
                            {
                                return(false);
                            }
                        }

                        if (!SymbolXamlWriter.IsSerializable(uniqueValueRenderer.DefaultSymbol))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    SimpleRenderer simpleRenderer = renderer as SimpleRenderer;
                    if (simpleRenderer != null)
                    {
                        if (!SymbolXamlWriter.IsSerializable(simpleRenderer.Symbol))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
コード例 #13
0
        public static FieldInfo ChangeRenderer(this GraphicsLayer graphicsLayer, string rendererType, FieldInfo attributeField)
        {
            IRenderer           newRenderer   = null;
            GeometryType        geometryType  = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetGeometryType(graphicsLayer);
            LinearGradientBrush gradientBrush = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetGradientBrush(graphicsLayer);
            FieldInfo           changedRenderAttributeField = null;
            List <Symbol>       existingSymbolSet           = null;

            if (Constants.ClassBreaksRenderer.Equals(rendererType))
            {
                int classBreakCount = 5;
                ClassBreaksRenderer currentRenderer = graphicsLayer.Renderer as ClassBreaksRenderer;
                if (currentRenderer != null)
                {
                    classBreakCount   = currentRenderer.Classes.Count;
                    existingSymbolSet = new List <Symbol>();
                    foreach (ClassBreakInfo classBreak in currentRenderer.Classes)
                    {
                        existingSymbolSet.Add(classBreak.Symbol);
                    }
                }
                newRenderer = createClassBreakRendererBasedOnSelectedAttribute(graphicsLayer, attributeField, gradientBrush, geometryType, classBreakCount, existingSymbolSet, out changedRenderAttributeField);
            }
            else if (Constants.UniqueValueRenderer.Equals(rendererType))
            {
                UniqueValueRenderer currentRenderer = graphicsLayer.Renderer as UniqueValueRenderer;
                if (currentRenderer != null)
                {
                    existingSymbolSet = new List <Symbol>();
                    foreach (UniqueValueInfo uniqueValue in currentRenderer.Infos)
                    {
                        existingSymbolSet.Add(uniqueValue.Symbol);
                    }
                }
                newRenderer = createUniqueValueRendererBasedOnSelectedAttribute(graphicsLayer, attributeField, gradientBrush, geometryType, existingSymbolSet, out changedRenderAttributeField);
            }
            else if (Constants.SimpleRenderer.Equals(rendererType))
            {
                newRenderer = createNewDefaultSimpleRenderer(graphicsLayer);
            }

            assignNewRendererToLayer(graphicsLayer, newRenderer);
            if (changedRenderAttributeField != null)
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, changedRenderAttributeField.DisplayName);
            }
            else if (attributeField != null)
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, attributeField.DisplayName);
            }
            else
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, null);
            }
            return(changedRenderAttributeField);
        }
		private void ChangeRenderer()
		{
			var renderer = new UniqueValueRenderer() { Fields = new ObservableCollection<string>(new string[] { "sub_region" }) };

			renderer.Infos = new UniqueValueInfoCollection(_states.Graphics
				.Select(g => g.Attributes["sub_region"])
				.Distinct()
				.Select(obj => new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { obj }), Symbol = GetRandomSymbol() }));

			_states.Renderer = renderer;
		}
コード例 #15
0
ファイル: Form1.cs プロジェクト: HazemMarawan/ArcGIS
        public void UniqueValueMultiCondition(IGeoFeatureLayer geoLayer, string aFieldName, string Value)
        {
            IUniqueValueRenderer MyIUniqueValueRenderer;

            MyIUniqueValueRenderer            = new UniqueValueRenderer();
            MyIUniqueValueRenderer.FieldCount = 1;
            MyIUniqueValueRenderer.set_Field(0, aFieldName);
            int intFieldIndex;

            intFieldIndex = geoLayer.FeatureClass.FindField(aFieldName);
            IFeatureCursor MyIFeatureCursor;
            IQueryFilter   MyQueryFilter;

            MyQueryFilter = new QueryFilter();
            int ValuesCount = ListofUniqueValues.Count;

            for (int i = 0; i < ValuesCount; i++)
            {
                MyQueryFilter.WhereClause = ListofUniqueValues[i];
                MyIFeatureCursor          = geoLayer.FeatureClass.Search(MyQueryFilter, true);
                IRandomColorRamp MyIRandomColorRamp;
                MyIRandomColorRamp      = new RandomColorRamp();
                MyIRandomColorRamp.Size = 16;
                bool CheckColor;
                MyIRandomColorRamp.CreateRamp(out CheckColor);
                if (!CheckColor)
                {
                    return;
                }
                IEnumColors MyIEnumColors;
                MyIEnumColors = MyIRandomColorRamp.Colors;
                ISimpleMarkerSymbol MyISimpleMarkerSymbol;
                IColor   MyIColor;
                IFeature MyIFeature = MyIFeatureCursor.NextFeature();
                while (MyIFeature != null)
                {
                    MyISimpleMarkerSymbol = new SimpleMarkerSymbolClass();
                    MyIColor = MyIEnumColors.Next();
                    if ((MyIColor == null))
                    {
                        MyIEnumColors.Reset();
                        MyIColor = MyIEnumColors.Next();
                    }
                    MyISimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCross;
                    MyISimpleMarkerSymbol.Color = MyIColor;
                    MyISimpleMarkerSymbol.Size  = 22;
                    MyIUniqueValueRenderer.AddValue(MyIFeature.get_Value(intFieldIndex).ToString(), "", ((ISymbol)(MyISimpleMarkerSymbol)));
                    MyIFeature = MyIFeatureCursor.NextFeature();
                }
                geoLayer.Renderer = MyIUniqueValueRenderer as IFeatureRenderer;
                axMapControl1.ActiveView.Refresh();
            }
        }
コード例 #16
0
        private static UniqueValueRenderer createUniqueValueRendererBasedOnSelectedAttribute(GraphicsLayer graphicsLayer, FieldInfo attributeField, LinearGradientBrush defaultColorRampGradientBrush, GeometryType geometryType, IEnumerable <Symbol> existingSymbolSet, out FieldInfo changedAttributeField)
        {
            changedAttributeField = attributeField;
            UniqueValueRenderer uniqueValueRenderer = graphicsLayer.Renderer as UniqueValueRenderer;

            if (uniqueValueRenderer != null)                                                    // already using unique value renderer
            {
                if (attributeField != null && attributeField.Name != uniqueValueRenderer.Field) // check if attribute has been changed
                {
                    IEnumerable <object> uniqueValues = getAllUniqueValues(graphicsLayer, attributeField);
                    uniqueValueRenderer = createNewDefaultUniqueValueRenderer(graphicsLayer, uniqueValues, attributeField, defaultColorRampGradientBrush, existingSymbolSet);
                }
            }
            else
            {
                string attributeFieldName = null;
                if (graphicsLayer.Renderer is ClassBreaksRenderer)
                {
                    // Check if the class breaks renderer had an attribute set. If so, honor that attribute name
                    ClassBreaksRenderer classBreakRenderer = graphicsLayer.Renderer as ClassBreaksRenderer;
                    if (classBreakRenderer != null)
                    {
                        attributeFieldName = classBreakRenderer.Field;
                    }
                }

                if (string.IsNullOrEmpty(attributeFieldName)) // No attribute known .. use the first non-attachment field
                {
                    FieldInfo field = null;
                    Collection <FieldInfo> layerFields = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetFields(graphicsLayer);
                    if (layerFields != null)
                    {
                        field = layerFields.FirstOrDefault <FieldInfo>(f => f.FieldType != FieldType.Attachment);
                    }
                    if (field != null)
                    {
                        changedAttributeField = field;
                        attributeField        = field;
                        attributeFieldName    = field.Name;
                    }
                }

                if (string.IsNullOrEmpty(attributeFieldName)) // An attribute name must be specified
                {
                    return(null);
                }

                IEnumerable <object> uniqueValues = getAllUniqueValues(graphicsLayer, attributeField);
                // Create a default unique value renderer
                uniqueValueRenderer = createNewDefaultUniqueValueRenderer(graphicsLayer, uniqueValues, attributeField, defaultColorRampGradientBrush, existingSymbolSet);
            }
            return(uniqueValueRenderer);
        }
コード例 #17
0
        private void CreateEndpointLayer()
        {
            var endpointLayer = new GraphicsLayer()
            {
                ID = "EndpointLayer",
                IsLabelingEnabled = true
            };

            // We are adding start and endpoints to same layer so render them differently
            var endpointLayerRenderer = new UniqueValueRenderer()
            {
                DefaultSymbol = new SimpleMarkerSymbol
                {
                    Color = Colors.Red,
                    Size  = 12
                },
                Fields = new ObservableCollection <string>()
                {
                    "PointType"
                },
                Infos = new UniqueValueInfoCollection()
                {
                    new UniqueValueInfo("EndPoint",
                                        new SimpleMarkerSymbol()
                    {
                        Color = Colors.Blue,
                        Size  = 12
                    })
                }
            };

            endpointLayer.Renderer = endpointLayerRenderer;

            // Crate labeling definition for start and end locations. Shows Address attribute as a label text.
            var labelClass = new LabelClass()
            {
                Symbol = new TextSymbol()
                {
                    Color           = Colors.Yellow,
                    BorderLineColor = Colors.Black,
                    BorderLineSize  = 2
                },
                TextExpression = "[Address]"
            };

            endpointLayer.LabelClasses = new LabelClassCollection {
                labelClass
            };

            Map.Layers.Add(endpointLayer);
            _graphicLayer = endpointLayer;
        }
        private void SetRenderers()
        {
            SimpleRenderer simpleRenderer = new SimpleRenderer()
            {
                Description = "Rivers",
                Label = "Rivers",
                Symbol = new SimpleLineSymbol() { Color = Colors.Blue, Style = SimpleLineStyle.Dash, Width = 2 }
            };
            (mapView1.Map.Layers["MyFeatureLayerSimple"] as FeatureLayer).Renderer = simpleRenderer;

            UniqueValueRenderer uvr = new UniqueValueRenderer();
            uvr.Fields = new ObservableCollection<string>(new string [] { "STATE_NAME" });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] {"New Mexico" }), Symbol = new SimpleFillSymbol() { Color = Colors.Yellow } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "Texas" }), Symbol = new SimpleFillSymbol() { Color = Colors.PaleGreen } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "Arizona" }), Symbol = new SimpleFillSymbol() { Color = Colors.YellowGreen } });

            (mapView1.Map.Layers["MyFeatureLayerUnique"] as FeatureLayer).Renderer = uvr;


            ClassBreaksRenderer CBR = new ClassBreaksRenderer()
            {
                DefaultLabel = "All Other Values",
                DefaultSymbol = new SimpleMarkerSymbol() { Color = Colors.Black, Style = SimpleMarkerStyle.Cross, Size = 10 },
                Field = "POP1990",
                Minimum = 0
            };

            CBR.Infos.Add(new ClassBreakInfo()
            {
                Maximum = 30000,
                Label = "0-30000",
                Description = "Pop between 0 and 30000",
                Symbol = new SimpleMarkerSymbol() { Color = Colors.Yellow, Size = 8, Style = SimpleMarkerStyle.Circle }
            });
            CBR.Infos.Add(new ClassBreakInfo()
            {
                Maximum = 300000,
                Label = "30000-300000",
                Description = "Pop between 30000 and 300000",
                Symbol = new SimpleMarkerSymbol() { Color = Colors.Red, Size = 10, Style = SimpleMarkerStyle.Circle }
            });

            CBR.Infos.Add(new ClassBreakInfo()
            {
                Maximum = 5000000,
                Label = "300000-5000000",
                Description = "Pop between 300000 and 5000000",
                Symbol = new SimpleMarkerSymbol() { Color = Colors.Orange, Size = 12, Style = SimpleMarkerStyle.Circle }
            });
            (mapView1.Map.Layers["MyFeatureLayerClassBreak"] as FeatureLayer).Renderer = CBR;
        }
コード例 #19
0
        // Adds graphics in an efficient way (bulk add)
        private void AddGraphics()
        {
            _graphicsLayer.Graphics.Clear();

            Random random = new Random();

            // Add graphics to a list and add in bulk (AddRange)
            var graphicsList = new List<Graphic>();
            for (int i = 0; i < 5000; i++)
            {
                var x = (random.NextDouble() * 40000000) - 20000000;
                var y = (random.NextDouble() * 40000000) - 20000000;
                var graphic = new Graphic()
                {
                    // assign each graphic a number 0, 1, 2 - we''ll use this to represent he color
                    Geometry = new MapPoint(x, y),
                    Attributes = { { "Color", i % 3 } }
                };
                graphicsList.Add(graphic);
            }

            // Create a renderer with 3 symbols (as opposed to a symbol per graphic)
            var renderer = new UniqueValueRenderer()
            {
                Field = "Color",
                Infos = {
                    new UniqueValueInfo()
                    {
                        Value = 0,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Red, Size=20  }
                    },
                    new UniqueValueInfo()
                    {
                        Value = 1,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Green, Style=SimpleMarkerSymbol.SimpleMarkerStyle.Diamond, Size=20 }
                    },
                    new UniqueValueInfo()
                    {
                        Value = 2,
                        Symbol = new SimpleMarkerSymbol() { Color = Brushes.Blue, Style=SimpleMarkerSymbol.SimpleMarkerStyle.Triangle, Size=20 }
                    }
                }
            };

            // Assign the renderer
            _graphicsLayer.Renderer = renderer;

            // Bulk add Graphics to the GraphicsLayer - more efficient than adding one graphic at a time
            _graphicsLayer.Graphics.AddRange(graphicsList);
        }
コード例 #20
0
        public void Save(string save_path)
        {
            _filepath = save_path;
            FileStream   fs = new FileStream(_filepath, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            string line = _map.MapName + " " + _Geocoordinate.ToString() + " " + _Procoordinate.ToString() + " "
                          + _ratio.ToString("F2") + " " + _scaleindex.ToString() + " " + CenterPos.X.ToString() + " " + CenterPos.Y.ToString() + " " + _map.LayerNum.ToString();

            sw.WriteLine(line);
            //对每一图层
            for (int i = 0; i < _map.LayerNum; i++)
            {
                sw.WriteLine(_map.Layers[i].FilePath);
                sw.WriteLine(_map.Layers[i].Visible.ToString());

                switch (_map.Layers[i].rendertype)
                {
                //唯一值渲染
                case RendererType.UniqueValueRenderer:
                    UniqueValueRenderer Urenderer = (UniqueValueRenderer)_map.Layers[i].Renderer;
                    string filename_uvr           = _map.Layers[i].rendertype.ToString() + " " + Urenderer.Field;
                    sw.WriteLine(filename_uvr);
                    break;

                //分级渲染
                case RendererType.ClassBreakRenderer:
                    ClassBreakRenderer Crenderer    = (ClassBreakRenderer)_map.Layers[i].Renderer;
                    string             filename_cbr = _map.Layers[i].rendertype.ToString() + " " + Crenderer.Field;
                    sw.WriteLine(filename_cbr);
                    break;

                //简单渲染
                default:
                    sw.WriteLine(_map.Layers[i].rendertype.ToString());
                    break;
                }

                //判断是否有注记信息
                bool hastext = _map.Layers[i].HasText;
                sw.WriteLine(hastext.ToString());
                if (hastext == true)
                {
                    sw.WriteLine(_map.Layers[i].Textrender.Field);
                }
            }
            sw.Close();
            fs.Close();
        }
コード例 #21
0
ファイル: MainPage.xaml.cs プロジェクト: xhe585/XArcGis
        private UniqueValueRenderer GetRenderer()
        {
            var renderer     = new UniqueValueRenderer();
            var yellowMarker = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.FromArgb(128, 0, 0, 255), 3);
            var purpleMarker = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Purple, 15);

            renderer.FieldNames.Add("symbol");
            renderer.UniqueValues.Add(new UniqueValue("", "", yellowMarker, "(#0000FF,3,0.5)"));
            renderer.UniqueValues.Add(new UniqueValue("", "", purpleMarker, "(#0000FF,5,0.5)"));


            renderer.DefaultSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Black, 10);
            renderer.DefaultLabel  = "(#00FFFF,15,0.5)";
            return(renderer);
        }
コード例 #22
0
        public static FieldInfo ChangeAttributeForRenderer(this GraphicsLayer graphicsLayer, FieldInfo newAttributeField)
        {
            IRenderer           newRenderer      = null;
            GeometryType        geometryType     = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetGeometryType(graphicsLayer);
            LinearGradientBrush gradientBrush    = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetGradientBrush(graphicsLayer);
            FieldInfo           changedAttribute = null;
            List <Symbol>       existingSymbolSet;
            ClassBreaksRenderer classBreaksRenderer = graphicsLayer.Renderer as ClassBreaksRenderer;

            if (classBreaksRenderer != null)
            {
                existingSymbolSet = new List <Symbol>();
                foreach (ClassBreakInfo classBreak in classBreaksRenderer.Classes)
                {
                    existingSymbolSet.Add(classBreak.Symbol);
                }
                newRenderer = createClassBreakRendererBasedOnSelectedAttribute(graphicsLayer, newAttributeField, gradientBrush, geometryType, classBreaksRenderer.Classes.Count, existingSymbolSet, out changedAttribute);
            }
            else
            {
                UniqueValueRenderer uniqueValueRenderer = graphicsLayer.Renderer as UniqueValueRenderer;
                if (uniqueValueRenderer != null)
                {
                    existingSymbolSet = new List <Symbol>();
                    foreach (UniqueValueInfo uniqueValue in uniqueValueRenderer.Infos)
                    {
                        existingSymbolSet.Add(uniqueValue.Symbol);
                    }
                    newRenderer = createUniqueValueRendererBasedOnSelectedAttribute(graphicsLayer, newAttributeField, gradientBrush, geometryType, existingSymbolSet, out changedAttribute);
                }
            }

            assignNewRendererToLayer(graphicsLayer, newRenderer);
            graphicsLayer.Refresh();
            if (changedAttribute != null)
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, changedAttribute.DisplayName);
            }
            else if (newAttributeField != null)
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, newAttributeField.DisplayName);
            }
            else
            {
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetRendererAttributeDisplayName(graphicsLayer, null);
            }
            return(changedAttribute);
        }
コード例 #23
0
        private void ChangeRenderer()
        {
            var renderer = new UniqueValueRenderer()
            {
                Fields = new ObservableCollection <string>(new string[] { "sub_region" })
            };

            renderer.Infos = new UniqueValueInfoCollection(_states.Graphics
                                                           .Select(g => g.Attributes["sub_region"])
                                                           .Distinct()
                                                           .Select(obj => new UniqueValueInfo {
                Values = new ObservableCollection <object>(new object[] { obj }), Symbol = GetRandomSymbol()
            }));

            _states.Renderer = renderer;
        }
コード例 #24
0
        void SymbolConfigControl_SymbolModified(object sender, SymbolSelectedEventArgs e)
        {
            // Some changes to ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleSymbols do not trigger the legendchanged event. Fix this by triggering the event by cloning the symbol.
            GraphicsLayer graphicsLayer = Layer as GraphicsLayer;

            if (graphicsLayer != null && graphicsLayer.Renderer is ILegendSupport)
            {
                SimpleRenderer simpleRenderer = graphicsLayer.Renderer as SimpleRenderer;
                if (simpleRenderer != null && (e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleLineSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleFillSymbol))
                {
                    simpleRenderer.Symbol = e.Symbol.CloneSymbol();
                }
                else
                {
                    ClassBreaksRenderer classBreaksRenderer = graphicsLayer.Renderer as ClassBreaksRenderer;
                    if (classBreaksRenderer != null && (e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleLineSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleFillSymbol))
                    {
                        if (_classBreakInfo != null)
                        {
                            _classBreakInfo.Symbol = e.Symbol.CloneSymbol();
                        }
                        else
                        {
                            classBreaksRenderer.DefaultSymbol = e.Symbol.CloneSymbol();
                        }
                    }
                    else
                    {
                        UniqueValueRenderer uniqueValueRenderer = graphicsLayer.Renderer as UniqueValueRenderer;
                        if (uniqueValueRenderer != null && (e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleLineSymbol || e.Symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleFillSymbol))
                        {
                            if (_uniqueValueInfo != null)
                            {
                                _uniqueValueInfo.Symbol = e.Symbol.CloneSymbol();
                            }
                            else
                            {
                                uniqueValueRenderer.DefaultSymbol = e.Symbol.CloneSymbol();
                            }
                        }
                    }
                }
            }
        }
コード例 #25
0
        private static UniqueValueRenderer createNewDefaultUniqueValueRenderer(GraphicsLayer graphicsLayer, IEnumerable <object> uniqueValues, FieldInfo attributeField, LinearGradientBrush defaultColorRampGradientBrush, IEnumerable <Symbol> existingSymbolSet)
        {
            Symbol defaultSymbol = graphicsLayer.GetDefaultSymbol();
            UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer()
            {
                Field         = attributeField != null ? attributeField.Name : null,
                DefaultSymbol = defaultSymbol,
            };

            if (uniqueValues != null)
            {
                List <Symbol> symbols = new List <Symbol>();
                int           i       = 0;
                foreach (object uniqueValue in uniqueValues)
                {
                    Symbol symbol = null;
                    if (existingSymbolSet != null)
                    {
                        symbol = existingSymbolSet.ElementAtOrDefault(i);
                    }
                    if (symbol == null)
                    {
                        symbol = graphicsLayer.GetDefaultSymbolClone();
                    }
                    uniqueValueRenderer.Infos.Add(new UniqueValueInfoObj()
                    {
                        Symbol          = symbol,
                        SerializedValue = uniqueValue,
                        FieldType       = attributeField.FieldType,
                    });
                    symbols.Add(symbol);
                    i++;
                }
                if (defaultColorRampGradientBrush != null)
                {
                    if (existingSymbolSet == null) // apply the gradient brush, only if symbols have not been pre-defined
                    {
                        applyLinearGradientBrushToSymbolSet(symbols, defaultColorRampGradientBrush, defaultSymbol);
                    }
                }
            }
            return(uniqueValueRenderer);
        }
コード例 #26
0
 private static void UpdateGraphicsAndRenderer(KmlGraphicsLayer layer, UniqueValueRenderer renderer, string key)
 {
     foreach (var graphic in layer.Graphics)
     {
         var f = (PlacemarkDescriptor)graphic.GetValue(FeaturePlacemarkerDescriptorProperty);
         if (f.Symbol.style.IconHref != null && f.Symbol.style.IconHref.ToLower() == key)
         {
             graphic.Symbol = PointSymbolDescriptor.GetDefaultSymbol();
             ComputeIconTranslationValues(f.Symbol.style, graphic.Symbol as KmlPlaceMarkerSymbol, ((graphic.Symbol as KmlPlaceMarkerSymbol).Fill as ImageBrush).ImageSource as BitmapImage);
             string l = null, d = null;
             GetRendererInfo(f, f.Symbol.style, out l, out d);
             var info = renderer.Infos.FirstOrDefault(i => i.Label == l);
             if (info != null)
             {
                 info.Symbol = graphic.Symbol;
             }
         }
     }
 }
コード例 #27
0
        public static void SpecialLineRenderer2(ILayer layer, string field, string value, ILineSymbol lineSymbol)
        {
            var geoFeaLayer = layer as IGeoFeatureLayer;
            IUniqueValueRenderer uniValueRender = new UniqueValueRenderer();

            IQueryFilter2 queryFilter = new QueryFilterClass();

            uniValueRender.FieldCount = 1;
            uniValueRender.Field[0]   = field;
            queryFilter.AddField(field);
            if (geoFeaLayer != null)
            {
                var fieldIndex = geoFeaLayer.FeatureClass.Fields.FindField(field);

                var customSymbol = (ISymbol)lineSymbol;

                var featureCursor = geoFeaLayer.FeatureClass.Search(queryFilter, true);
                var feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    var sValue = Convert.ToString(feature.Value[fieldIndex]);
                    if (sValue == value)
                    {
                        uniValueRender.AddValue(sValue, "", customSymbol);
                    }
                    else
                    {
                        var defaultSymbol = geoFeaLayer.Renderer.SymbolByFeature[feature];
                        uniValueRender.AddValue(sValue, "", defaultSymbol);
                    }

                    feature = featureCursor.NextFeature();
                }
            }

            ComReleaser.ReleaseCOMObject(null);
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);  //释放指针
            if (geoFeaLayer != null)
            {
                geoFeaLayer.Renderer = uniValueRender as IFeatureRenderer;
            }
        }
コード例 #28
0
        public void AddUniqueValues(List <PointDTO> pointDTOList, List <UniqueValueInfoDTO> uniqueValueInfoDTOList)
        {
            Queue <SimpleMarkerSymbol> markerSymbolQueue = this.CreateSimpleMarkerSymbolQueue();

            markerSymbolQueue.Reverse <SimpleMarkerSymbol>();

            try
            {
                List <Graphic> graphicsList = new List <Graphic>();

                // First create a list of graphics from the DTO
                foreach (PointDTO pointDTO in pointDTOList)
                {
                    Graphic graphic = this.createStratifiedGraphic(pointDTO);

                    this.graphicsLayer.Graphics.Add(graphic);
                }

                UniqueValueRenderer r = new UniqueValueRenderer();
                r.Field = "StrataValue";

                foreach (UniqueValueInfoDTO dto in uniqueValueInfoDTOList)
                {
                    UniqueValueInfo x = new UniqueValueInfo();

                    SimpleMarkerSymbol simpleMarkerySymbol = markerSymbolQueue.Dequeue();

                    //  x.Symbol = 7777

                    x.Symbol = simpleMarkerySymbol;
                    x.Value  = dto.Value;

                    r.Infos.Add(x);
                }

                this.graphicsLayer.Renderer = r;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Problem with EwavMap.AddPoints \n{0}\n{1}", ex.Message, ex.StackTrace));
            }
        }
コード例 #29
0
        public static Renderer CreateIconRenderer()
        {
            var values = new List <UniqueValue>
            {
                new UniqueValue("Normal", "Normal", CreateEntityCompositeSymbol("-", false), Values(1, 0)),
                new UniqueValue("Grayed", "Grayed", CreateEntityCompositeSymbol("-", true), Values(1, 1)),
                new UniqueValue("Normal2", "Normal2", CreateEntityCompositeSymbol("-\n-", false), Values(2, 0)),
                new UniqueValue("Grayed2", "Grayed2", CreateEntityCompositeSymbol("-\n-", true), Values(2, 1)),
                new UniqueValue("Normal3", "Normal3", CreateEntityCompositeSymbol("-\n-\n-", false), Values(3, 0)),
                new UniqueValue("Grayed3", "Grayed3", CreateEntityCompositeSymbol("-\n-\n-", true), Values(3, 1)),
            };
            var uvr = new UniqueValueRenderer(
                new[] { Form1.LineCountAttribute, Form1.IsGrayedAttribute }, // attributes used to select the symbol
                values,
                defaultLabel: values[0].Label,
                defaultSymbol: values[0].Symbol
                );

            return(uvr);
        }
コード例 #30
0
        /// <summary>
        ///  单一值渲染(多字段)
        /// </summary>
        /// <param name="layerName">图层名</param>
        /// <param name="RenderField">多字段名</param>
        /// <param name="FillStyle">样式</param>
        /// <param name="valueCount">每个字段中唯一值的个数</param>
        public void CreateUniqueValueRander(ILayer pLayer, string[] RenderField, esriSimpleFillStyle FillStyle,
                                            int[] valueCount)
        {
            IGeoFeatureLayer geoFeatureLayer;

            geoFeatureLayer = pLayer as IGeoFeatureLayer;
            IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();

            //可以设置多个字段
            uniqueValueRenderer.FieldCount = RenderField.Length; //0-3个
            for (int i = 0; i < RenderField.Length; i++)
            {
                uniqueValueRenderer.set_Field(i, RenderField[i]);
            }

            //简单填充符号
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol();

            simpleFillSymbol.Style = FillStyle;

            IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false);
            IFeature       feature;

            if (featureCursor != null)
            {
                for (int i = 0; i < RenderField.Length; i++)
                {
                    IEnumColors enumColors = CreateAlgorithmicColorRamp();
                    int         fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField(RenderField[i]);
                    for (int j = 0; j < valueCount[i]; j++)
                    {
                        feature = featureCursor.NextFeature();
                        string nameValue = feature.get_Value(fieldIndex).ToString();
                        simpleFillSymbol       = new SimpleFillSymbol();
                        simpleFillSymbol.Color = enumColors.Next();
                        uniqueValueRenderer.AddValue(nameValue, RenderField[i], simpleFillSymbol as ISymbol);
                    }
                }
            }
            geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;
        }
コード例 #31
0
        private void changeCursorForRenderer(bool isClickableCursor)
        {
            SimpleRenderer simpleRenderer = Renderer as SimpleRenderer;

            if (simpleRenderer != null)
            {
                changeCursorForSymbol(simpleRenderer.Symbol, isClickableCursor);
            }
            else
            {
                ClassBreaksRenderer classBreaksRenderer = Renderer as ClassBreaksRenderer;
                if (classBreaksRenderer != null)
                {
                    changeCursorForSymbol(classBreaksRenderer.DefaultSymbol, isClickableCursor);
                    if (classBreaksRenderer.Classes != null)
                    {
                        foreach (ClassBreakInfo classBreak in classBreaksRenderer.Classes)
                        {
                            changeCursorForSymbol(classBreak.Symbol, isClickableCursor);
                        }
                    }
                }
                else
                {
                    UniqueValueRenderer uniqueValueRenderer = Renderer as UniqueValueRenderer;
                    if (uniqueValueRenderer != null)
                    {
                        changeCursorForSymbol(uniqueValueRenderer.DefaultSymbol, isClickableCursor);
                        if (uniqueValueRenderer.Infos != null)
                        {
                            foreach (UniqueValueInfo uniqueValue in uniqueValueRenderer.Infos)
                            {
                                changeCursorForSymbol(uniqueValue.Symbol, isClickableCursor);
                            }
                        }
                    }
                }
            }
        }
コード例 #32
0
        private string getRendererAttributeName()
        {
            GraphicsLayer graphicsLayer = Layer as GraphicsLayer;

            if (graphicsLayer != null)
            {
                ClassBreaksRenderer classBreaksRenderer = graphicsLayer.Renderer as ClassBreaksRenderer;
                if (classBreaksRenderer != null)
                {
                    return(classBreaksRenderer.Field);
                }
                else
                {
                    UniqueValueRenderer uniqueValueRenderer = graphicsLayer.Renderer as UniqueValueRenderer;
                    if (uniqueValueRenderer != null)
                    {
                        return(uniqueValueRenderer.Field);
                    }
                }
            }
            return(null);
        }
コード例 #33
0
        public static void SpecialLineRenderer(ILayer layer, int id, ILineSymbol lineSymbol)
        {
            var geoFeaLayer = layer as IGeoFeatureLayer;
            IUniqueValueRenderer uniValueRender = new UniqueValueRenderer();

            uniValueRender.FieldCount = 1;
            uniValueRender.Field[0]   = "OBJECTID";
            var customSymbol = (ISymbol)lineSymbol;

            //选择某个字段作为渲染符号值
            if (geoFeaLayer != null)
            {
                var featureCursor = geoFeaLayer.FeatureClass.Search(null, true);
                var feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    var nowId = feature.OID;

                    if (nowId == id)
                    {
                        uniValueRender.AddValue(feature.OID.ToString(), "", customSymbol);
                    }
                    else
                    {
                        var defaultSymbol = geoFeaLayer.Renderer.SymbolByFeature[feature];
                        uniValueRender.AddValue(feature.OID.ToString(), "", defaultSymbol);
                    }

                    feature = featureCursor.NextFeature();
                }
            }

            if (geoFeaLayer != null)
            {
                geoFeaLayer.Renderer = uniValueRender as IFeatureRenderer;
            }
        }
コード例 #34
0
        private void ApplyUniqueValueClick(object sender, RoutedEventArgs e)
        {
            UniqueValueRenderer newUniqueValueRenderer = new UniqueValueRenderer()
            {
                DefaultSymbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Gray)
                },
                Field = "SUB_REGION"
            };

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "Pacific",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Purple),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "W N Cen",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Green),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "W S Cen",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Cyan),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "E N Cen",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Yellow),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "Mtn",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Blue),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "N Eng",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Red),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "E S Cen",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Brown),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "Mid Atl",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Magenta),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
            {
                Value = "S Atl",
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Colors.Orange),
                    BorderBrush = new SolidColorBrush(Colors.Transparent)
                }
            });

            LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            layerDrawOptions.LayerID = 2;
            layerDrawOptions.Renderer = newUniqueValueRenderer;

            (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions =
                new LayerDrawingOptionsCollection() { layerDrawOptions };
            (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = new int[] { 2 };
            // Changing VisibleLayers will refresh the layer, otherwise an explicit call to Refresh is needed.
            //(MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).Refresh();
        }
コード例 #35
0
        // Creates the renderers in code
        private void initializeRenderers()
        {
            // Create simple renderer with one symbol for rivers layer
            SimpleRenderer simpleRenderer = new SimpleRenderer()
            {
                Description = "Rivers",
                Label = "Rivers",
                Symbol = new SimpleLineSymbol() { Color = Colors.Blue, Style = SimpleLineStyle.Dash, Width = 2 }
            };
            RiversRenderer = simpleRenderer;

            // Create a unique value renderer that defines different symbols for New Mexico, Texas, 
            // and Arizona
            UniqueValueRenderer uvr = new UniqueValueRenderer();
            uvr.Fields = new ObservableCollection<string>(new string[] { "STATE_NAME" });
            SimpleLineSymbol stateOutline = new SimpleLineSymbol() { Color = Colors.Black };
            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[] { "New Mexico" }), 
                Symbol = new SimpleFillSymbol() { Color = Colors.Yellow, Outline = stateOutline } 
            });
            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[] { "Texas" }),
                Symbol = new SimpleFillSymbol() { Color = Colors.Green, Outline = stateOutline }
            });
            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[] { "Arizona" }),
                Symbol = new SimpleFillSymbol() { Color = Colors.LightGray, Outline = stateOutline }
            });
            StatesRenderer = uvr;

            // Create a class breaks renderer to symbolize cities of different sizes
            ClassBreaksRenderer cbr = new ClassBreaksRenderer()
            {
                DefaultLabel = "All Other Values",
                DefaultSymbol = new SimpleMarkerSymbol() { Color = Colors.Black, 
                    Style = SimpleMarkerStyle.Cross, Size = 10 },
                Field = "POP1990",
                Minimum = 0
            };

            // Create and add symbols
            SimpleLineSymbol cityOutline = new SimpleLineSymbol() { Color = Colors.White };
            cbr.Infos.Add(new ClassBreakInfo()
            {
                Minimum = 100000,
                Maximum = 200000,
                Label = "100000 - 200000",
                Description = "Population between 100000 and 200000",
                Symbol = new SimpleMarkerSymbol() 
                { 
                    Color = Color.FromArgb(255, 0, 210, 0), 
                    Outline = cityOutline,
                    Size = 4, 
                    Style = SimpleMarkerStyle.Circle 
                }
            });
            cbr.Infos.Add(new ClassBreakInfo()
            {
                Minimum = 200001,
                Maximum = 1000000,
                Label = "200001 - 1000000",
                Description = "Population between 200001 and 1000000",
                Symbol = new SimpleMarkerSymbol() 
                { 
                    Color = Color.FromArgb(255, 0, 127, 0), 
                    Outline = cityOutline,
                    Size = 8, 
                    Style = SimpleMarkerStyle.Circle 
                }
            });

            cbr.Infos.Add(new ClassBreakInfo()
            {
                Minimum = 1000001,
                Maximum = 10000000,
                Label = "1000001 - 10000000",
                Description = "Population between 1000001 and 10000000",
                Symbol = new SimpleMarkerSymbol() 
                { 
                    Color = Color.FromArgb(255, 0, 50, 0), 
                    Outline = cityOutline,
                    Size = 12, 
                    Style = SimpleMarkerStyle.Circle 
                }
            });
            CitiesRenderer = cbr;
        }
コード例 #36
0
        public static void SpecialLineRenderer(ILayer layer, int id, ILineSymbol lineSymbol)
        {
            var geoFeaLayer = layer as IGeoFeatureLayer;
            IUniqueValueRenderer uniValueRender = new UniqueValueRenderer();

            uniValueRender.FieldCount = 1;
            uniValueRender.Field[0] = "OBJECTID";
            var customSymbol = (ISymbol)lineSymbol;

            //选择某个字段作为渲染符号值
            if (geoFeaLayer != null)
            {
                var featureCursor = geoFeaLayer.FeatureClass.Search(null, true);
                var feature = featureCursor.NextFeature();
                while (feature != null)
                {
                    var nowId = feature.OID;

                    if (nowId == id)
                    {
                        uniValueRender.AddValue(feature.OID.ToString(), "", customSymbol);
                    }
                    else
                    {
                        var defaultSymbol = geoFeaLayer.Renderer.SymbolByFeature[feature];
                        uniValueRender.AddValue(feature.OID.ToString(), "", defaultSymbol);
                    }

                    feature = featureCursor.NextFeature();
                }
            }

            if (geoFeaLayer != null) geoFeaLayer.Renderer = uniValueRender as IFeatureRenderer;
        }
コード例 #37
0
        // Shows states by sub-region when the Unique Values button is clicked
        private void UniqueValueButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a unique value renderer
            UniqueValueRenderer uvr = new UniqueValueRenderer();

            // Symbolize based on the sub-region field
            uvr.Fields        = new ObservableCollection <string>(new string[] { "SUB_REGION" });
            uvr.DefaultSymbol = new SimpleFillSymbol()
            {
                Color = Colors.Gray
            };

            SimpleLineSymbol outline = new SimpleLineSymbol()
            {
                Color = Colors.LightGray, Width = 2
            };

            #region Define Unique Values

            // Create unique value info for each sub-region
            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "Pacific" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Purple,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "W N Cen" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Green,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "W S Cen" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Cyan,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "E N Cen" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Yellow,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "Mtn" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Blue,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "N Eng" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Red,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "E S Cen" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Brown,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "Mid Atl" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Magenta,
                    Outline = outline
                }
            });

            uvr.Infos.Add(new UniqueValueInfo
            {
                Values = new ObservableCollection <object>(new object[] { "S Atl" }),
                Symbol = new SimpleFillSymbol()
                {
                    Color   = Colors.Orange,
                    Outline = outline
                }
            });

            #endregion

            // Get the USA layer and apply the unique values renderer to the states layer
            var layer = map1.Layers["USA"] as ArcGISDynamicMapServiceLayer;
            if (layer.LayerDrawingOptions == null)
            {
                layer.LayerDrawingOptions = new LayerDrawingOptionCollection();
            }
            layer.LayerDrawingOptions.Add(new LayerDrawingOptions()
            {
                LayerID  = 2, // The states layer has an ID of 2
                Renderer = uvr
            });

            // Make the states layer the only visible one
            layer.VisibleLayers = new ObservableCollection <int>(new int[] { 2 });
        }
コード例 #38
0
        private void ApplyUniqueValueClick(object sender, RoutedEventArgs e)
        {
            UniqueValueRenderer newUniqueValueRenderer = new UniqueValueRenderer()
            {
                DefaultSymbol = new SimpleFillSymbol()
                {
                    Color = Colors.Gray
                },
                Fields = new string[] { "SUB_REGION" }
            };

            var Infos = new List<UniqueValueInfo>();
            Infos.Add(new UniqueValueInfo()
             {
                 Values = new object[] { "Pacific" },
                 Symbol = new SimpleFillSymbol()
                 {
                     Color = Colors.Purple,
                     Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                 }
             });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "W N Cen" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Green,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "W S Cen" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Cyan,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "E N Cen" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Yellow,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "Mtn" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Blue,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "N Eng" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Red,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "E S Cen" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Brown,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "Mid Atl" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Magenta,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });

            Infos.Add(new UniqueValueInfo()
            {
                Values = new object[] { "S Atl" },
                Symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Orange,
                    Outline = new SimpleLineSymbol() { Color = Colors.Transparent }
                }
            });
            newUniqueValueRenderer.Infos = Infos;
            var layer = MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer;
            layer.LayerDrawingOptions.Add(new LayerDrawingOptions()
            {
                LayerID = 2,
                Renderer = newUniqueValueRenderer
            });
            layer.VisibleLayers = new int[] { 2 };
        }
コード例 #39
0
 private static UniqueValueRenderer createNewDefaultUniqueValueRenderer(GraphicsLayer graphicsLayer, IEnumerable<object> uniqueValues, FieldInfo attributeField, LinearGradientBrush defaultColorRampGradientBrush, IEnumerable<Symbol> existingSymbolSet)
 {
     Symbol defaultSymbol = graphicsLayer.GetDefaultSymbol();
     UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer()
     {
         Field = attributeField != null ? attributeField.Name : null,
         DefaultSymbol = defaultSymbol,
     };
     if (uniqueValues != null)
     {
         List<Symbol> symbols = new List<Symbol>();
         int i = 0;
         foreach (object uniqueValue in uniqueValues)
         {
             Symbol symbol = null;
             if (existingSymbolSet != null)
                 symbol = existingSymbolSet.ElementAtOrDefault(i);
             if (symbol == null)
                 symbol = graphicsLayer.GetDefaultSymbolClone();
             uniqueValueRenderer.Infos.Add(new UniqueValueInfoObj()
             {
                 Symbol = symbol,
                 SerializedValue = uniqueValue,
                 FieldType = attributeField.FieldType,
             });
             symbols.Add(symbol);
             i++;
         }
         if (defaultColorRampGradientBrush != null)
         {
             if (existingSymbolSet == null) // apply the gradient brush, only if symbols have not been pre-defined
             {
                 applyLinearGradientBrushToSymbolSet(symbols, defaultColorRampGradientBrush, defaultSymbol);
             }
         }
     }
     return uniqueValueRenderer;
 }
コード例 #40
0
 public static IRenderer CloneRenderer(this IRenderer renderer)
 {
     if (renderer == null)
         return null;
     SimpleRenderer simpleRenderer = renderer as SimpleRenderer;
     if (simpleRenderer != null)
     {
         return new SimpleRenderer()
         {
             Symbol = simpleRenderer.Symbol != null ? simpleRenderer.Symbol.CloneSymbol() : null,
         };
     }
     else
     {
         ClassBreaksRenderer classBreaksRenderer = renderer as ClassBreaksRenderer;
         if (classBreaksRenderer != null)
         {
             ClassBreaksRenderer clone = new ClassBreaksRenderer() { 
                  Field = classBreaksRenderer.Field,
                  DefaultSymbol = classBreaksRenderer.DefaultSymbol != null ? classBreaksRenderer.DefaultSymbol.CloneSymbol() : null,
             };
             if (classBreaksRenderer.Classes != null)
             {
                 foreach (ClassBreakInfo classBreak in classBreaksRenderer.Classes)
                 {
                     clone.Classes.Add(new ClassBreakInfo() { 
                          Description = classBreak.Description,
                          Label = classBreak.Label,
                          MaximumValue = classBreak.MaximumValue,
                          MinimumValue = classBreak.MinimumValue,
                          Symbol = classBreak.Symbol != null ? classBreak.Symbol.CloneSymbol() : null,
                     });
                 }
             }
             return clone;
         }
         else
         {
             UniqueValueRenderer uniqueValueRenderer = renderer as UniqueValueRenderer;
             if (uniqueValueRenderer != null)
             {
                 UniqueValueRenderer clone = new UniqueValueRenderer() { 
                      Field = uniqueValueRenderer.Field,
                      DefaultSymbol = uniqueValueRenderer.DefaultSymbol != null ? uniqueValueRenderer.DefaultSymbol.CloneSymbol() : null,
                 };
                 if (uniqueValueRenderer.Infos != null)
                 {
                     foreach (UniqueValueInfo uniqueValue in uniqueValueRenderer.Infos)
                     {
                         clone.Infos.Add(new UniqueValueInfo()
                         {
                             Description = uniqueValue.Description,
                             Label = uniqueValue.Label,
                             Value = uniqueValue.Value,
                             Symbol = uniqueValue.Symbol != null ? uniqueValue.Symbol.CloneSymbol() : null,
                         });
                     }
                 }
                 return clone;
             }
         }
     }
     return null;
 }
コード例 #41
0
        void queryTaskPolygon_ExecuteCompleted(object sender, QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features returned from query");
                return;
            }

            GraphicsLayer graphicsLayer = MyMap.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer;

            Random random = new Random();

            // Random switch between class breaks and unique value renderers
            if (random.Next(0, 2) == 0)
            {
                ClassBreaksRenderer classBreakRenderer = new ClassBreaksRenderer();
                classBreakRenderer.Field = "POP2000";
                int classCount = 6;

                List<double> valueList = new List<double>();
                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    graphicsLayer.Graphics.Add(graphic);
                    valueList.Add((int)graphic.Attributes[classBreakRenderer.Field]);
                }

                // LINQ
                IEnumerable<double> valueEnumerator =
                   from aValue in valueList
                   orderby aValue
                   select aValue;

                int increment = Convert.ToInt32(Math.Ceiling(args.FeatureSet.Features.Count / classCount));
                int rgbFactor = 255 / classCount;
                int j = 255;

                for (int i = increment; i < valueList.Count; i += increment)
                {
                    ClassBreakInfo classBreakInfo = new ClassBreakInfo();

                    if (i == increment)
                        classBreakInfo.MinimumValue = 0;
                    else
                        classBreakInfo.MinimumValue = valueEnumerator.ElementAt(i - increment);

                    classBreakInfo.MaximumValue = valueEnumerator.ElementAt(i);

                    SimpleFillSymbol symbol = new SimpleFillSymbol()
                    {
                        Fill = new SolidColorBrush(Color.FromArgb(192, (byte)j, (byte)j, (byte)j)),
                        BorderBrush = new SolidColorBrush(Colors.Transparent),
                        BorderThickness = 1
                    };

                    classBreakInfo.Symbol = symbol;
                    classBreakRenderer.Classes.Add(classBreakInfo);

                    j = j - rgbFactor;
                }

                // Set maximum value for largest class break
                classBreakRenderer.Classes[classBreakRenderer.Classes.Count - 1].MaximumValue = valueEnumerator.ElementAt(valueList.Count - 1) + 1;

                graphicsLayer.Renderer = classBreakRenderer;

            }
            else
            {
                UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();
                uniqueValueRenderer.DefaultSymbol = LayoutRoot.Resources["RedFillSymbol"] as Symbol;
                uniqueValueRenderer.Field = "STATE_NAME";

                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    graphicsLayer.Graphics.Add(graphic);
                    UniqueValueInfo uniqueValueInfo = new UniqueValueInfo();

                    SimpleFillSymbol symbol = new SimpleFillSymbol()
                    {
                        Fill = new SolidColorBrush(Color.FromArgb(192, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255))),
                        BorderBrush = new SolidColorBrush(Colors.Transparent),
                        BorderThickness = 1
                    };

                    uniqueValueInfo.Symbol = symbol;
                    uniqueValueInfo.Value = graphic.Attributes["STATE_NAME"];
                    uniqueValueRenderer.Infos.Add(uniqueValueInfo);
                }

                graphicsLayer.Renderer = uniqueValueRenderer;
            }
        }
        // Shows states by sub-region when the Unique Values button is clicked
        private void UniqueValueButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a unique value renderer 
            UniqueValueRenderer uvr = new UniqueValueRenderer();

            // Symbolize based on the sub-region field
            uvr.Fields = new ObservableCollection<string>(new string[] { "SUB_REGION" });
            uvr.DefaultSymbol = new SimpleFillSymbol() { Color = Colors.Gray };

            SimpleLineSymbol outline = new SimpleLineSymbol() { Color = Colors.LightGray, Width = 2 };

            #region Define Unique Values

            // Create unique value info for each sub-region
            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "Pacific" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Purple, 
                    Outline = outline 
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "W N Cen" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Green, 
                    Outline = outline
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "W S Cen" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Cyan, 
                    Outline = outline 
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "E N Cen" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Yellow, 
                    Outline = outline 
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "Mtn" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Blue, 
                    Outline = outline 
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "N Eng" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Red, 
                    Outline = outline 
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "E S Cen" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Brown, 
                    Outline = outline
                } 
            });

            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "Mid Atl" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Magenta, 
                    Outline = outline
                } 
            });
            
            uvr.Infos.Add(new UniqueValueInfo 
            { 
                Values = new ObservableCollection<object>(new object[]{ "S Atl" }), 
                Symbol = new SimpleFillSymbol() 
                { 
                    Color = Colors.Orange, 
                    Outline = outline 
                } 
            });

            #endregion

            // Get the USA layer and apply the unique values renderer to the states layer
            var layer = map1.Layers["USA"] as ArcGISDynamicMapServiceLayer;
            if (layer.LayerDrawingOptions == null)
                layer.LayerDrawingOptions = new LayerDrawingOptionCollection();
            layer.LayerDrawingOptions.Add(new LayerDrawingOptions()
            {
                LayerID = 2, // The states layer has an ID of 2
                Renderer = uvr
            });

            // Make the states layer the only visible one
            layer.VisibleLayers = new ObservableCollection<int>(new int[] { 2 });
        }
        private void ApplyUniqueValueClick(object sender, RoutedEventArgs e)
        {

            UniqueValueRenderer uvr = new UniqueValueRenderer();
            uvr.Fields = new ObservableCollection<string>(new string[] { "SUB_REGION" });
            uvr.DefaultSymbol = new SimpleFillSymbol() { Color = Colors.Gray };

            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "Pacific"}), Symbol = new SimpleFillSymbol() { Color = Colors.Purple, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "W N Cen"}), Symbol = new SimpleFillSymbol() { Color = Colors.Green, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "W S Cen"}), Symbol = new SimpleFillSymbol() { Color = Colors.Cyan, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "E N Cen"}), Symbol = new SimpleFillSymbol() { Color = Colors.Yellow, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "Mtn"}), Symbol = new SimpleFillSymbol() { Color = Colors.Blue, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "N Eng"}), Symbol = new SimpleFillSymbol() { Color = Colors.Red, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "E S Cen"}), Symbol = new SimpleFillSymbol() { Color = Colors.Brown, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "Mid Atl"}), Symbol = new SimpleFillSymbol() { Color = Colors.Magenta, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });
            uvr.Infos.Add(new UniqueValueInfo { Values = new ObservableCollection<object>(new object[] { "S Atl" }), Symbol = new SimpleFillSymbol() { Color = Colors.Orange, Outline = new SimpleLineSymbol() { Color = Colors.Transparent } } });

          

            var layer = mapView1.Map.Layers["USA"] as ArcGISDynamicMapServiceLayer;
            LayerDrawingOptionCollection layerDrawingOptionCollection = new LayerDrawingOptionCollection()
            {
                new LayerDrawingOptions()
            {
                LayerID = 2,
                Renderer = uvr
            }
            };

            layer.LayerDrawingOptions = layerDrawingOptionCollection;

            layer.VisibleLayers = new ObservableCollection<int> { 2 };
        }
    	/// <summary>
    	/// Creates graphic elements and adds them to the graphics layer.
    	/// </summary>
    	/// <param name="layer">Graphics layer that will have features added to it.</param>
    	/// <param name="images">Dictionary of images coming from kmz content or from previous parsing</param>
    	public void CreateGraphics(KmlGraphicsLayer layer, IDictionary<string, ImageBrush> images)
        {
			if (layer == null) return;

    		GraphicCollection graphics = new GraphicCollection();
    		UniqueValueRenderer renderer = new UniqueValueRenderer(); // dummy renderer used to create the legend items (since creation of the swatches from the symbol is not that obvious) 

            // Process each metadata feature in the list
            foreach (PlacemarkDescriptor feature in placemarks)
            {
                KMLStyle style = feature.Symbol.style;

                if (style.ZipFile != null)
                {
                    // Look for the image in the zip file
                    if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
                    {
                        style.IconImage = GetIconImage(style.ZipFile, style.IconHref.ToLower());
                    }

                    style.ZipFile.Dispose();
                    style.ZipFile = null;
                }

                // If the style has an HREF then it is associated with an image
                if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
                {
                    // If the image is already loaded in the image dictionary, use it
                    if (images.ContainsKey(style.IconHref.ToLower()))
                        style.IconImage = images[style.IconHref.ToLower()];
                    else
                    {
                        // Get the image using the HREF and store the image in the images dictionary so that if
                        // other features reference it, it is cached
                        style.IconImage = GetIconImage(style.IconHref);
                        images.Add(style.IconHref.ToLower(), style.IconImage);
                    }
                }

                // Create a new graphic from the metadata and construct the symbol using polymorphism
                Graphic g = new Graphic()
                {
                    Geometry = feature.Geometry,
                    Symbol = feature.Symbol.CreateSymbol()
                };

				// Create legend entry
            	string label = null;
				string description = null;
				if (string.IsNullOrEmpty(style.StyleId))
				{
					//if the feature is not using a shared style -> create an entry by graphic with the name as ident
					if (feature.Attributes.ContainsKey("name"))
						label = feature.Attributes["name"].ToString();
					if (feature.Attributes.ContainsKey("description"))
						description = feature.Attributes["description"].ToString();
				}
				else
				{
					//if the feature is using a shared style -> create an entry for the style
					label = style.StyleId;
				}

				if (!string.IsNullOrEmpty(label) && !renderer.Infos.Any(info => info.Label == label))
					renderer.Infos.Add(new UniqueValueInfo { Label = label, Description = description, Symbol = g.Symbol });


                // Adjust and assign picture marker symbol properties
                if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint && g.Symbol is KmlPlaceMarkerSymbol)
                {
                    try
                    {

#if SILVERLIGHT
						string ext = style.IconHref.Substring(style.IconHref.LastIndexOf(".")).ToLower();
                        switch (ext)
                        {
                            case ".jpg":
                            case ".jpeg":
                            case ".png":
                                break;
                            default:
                                throw new System.Exception(string.Format(Properties.Resources.FeatureDefinition_ImageTypeNotSupported, ext));
                        }
#endif
                        KmlPlaceMarkerSymbol ms = g.Symbol as KmlPlaceMarkerSymbol;

                        // To match sizing of Google Earth, default size of point images is 40x40
                        ms.Height = 40;
                        ms.Width = 40;

                        ms.Fill = style.IconImage as ImageBrush;

                        // Default to half the pixel size (width and height) if symbol offsets are 0 (supported in wpf and sl3)
                        ImageBrush ib = ms.Fill;
                        BitmapImage bi = ib.ImageSource as BitmapImage;

#if SILVERLIGHT
                        if (bi.PixelHeight == 0 || bi.PixelWidth == 0)
                        {
                            EventHandler<RoutedEventArgs> completed = null;
                            completed = (s, e) =>
                                {
                                    bi.ImageOpened -= completed;

                                    ComputeIconTranslationValues(style, ms, bi);
                                };
                            bi.ImageOpened += completed;
                        }
#else
                        if (bi.IsDownloading)
                        {
                            EventHandler completed = null;
                            completed = (s, e) =>
                                {
                                    bi.DownloadCompleted -= completed;

                                    ComputeIconTranslationValues(style, ms, bi);
                                };
                            bi.DownloadCompleted += completed;
                        }
#endif
                        else
                        {
                            ComputeIconTranslationValues(style, ms, bi);
                        }

                    }
                    catch
                    {
                        g.Symbol = new SimpleMarkerSymbol();
                    }
                }                    

                // Copy attributes values from metadata to graphic
                foreach (var attribute in feature.Attributes)
                {
                    g.Attributes.Add(attribute.Key, attribute.Value);
                }

                // If the balloontext property has been assigned a value in the style associated with this
                // graphic feature, then add it to the attributes collection.
                if (!String.IsNullOrEmpty(style.BalloonText))
                {
                    g.Attributes.Add("balloonText", style.BalloonText);
                }

                // Add graphic to graphics layer
                graphics.Add(g);
            }

			layer.Graphics = graphics;

			// Use the renderer to create the legend itens (asynchronously since creating a swatch from a symbol is asynchronous)
    		renderer.QueryLegendInfos(layerLegendInfo => { layer.LegendInfo = layerLegendInfo;}, null);
        }
コード例 #45
0
        /// <summary>
        /// ����Ҫ�ط��Ż�
        /// </summary>
        /// <params name="layer"></params>
        /// <params name="field"></params>
        /// <params name="value"></params>
        /// <params name="pBitmap"></params>
        public static void SpecialPointRenderer(ILayer layer, string field, string value, Bitmap pBitmap)
        {
            IGeoFeatureLayer geoFeaLayer;
            IFeatureRenderer featureRenderer;
            ISymbol defaultSymbol;
            IUniqueValueRenderer uniValueRender;

            geoFeaLayer = layer as IGeoFeatureLayer;
            featureRenderer = geoFeaLayer.Renderer;
            uniValueRender = new UniqueValueRenderer();

            ///ѡ��ij���ֶ���Ϊ��Ⱦ����ֵ
            IQueryFilter2 queryFilter = new QueryFilterClass();
            int fieldIndex;
            uniValueRender.FieldCount = 1;
            uniValueRender.Field[0] = field;
            queryFilter.AddField(field);
            fieldIndex = geoFeaLayer.FeatureClass.Fields.FindField(field);//����ֶε�index

            ///��ȡ�Զ������
            ISymbol customSymbol;
            IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass();
            pictureMarkerSymbol.Size = 55;
            string strFilePath = Application.StartupPath.ToString() + "\\temp.bmp";

            pBitmap.Save(strFilePath);
            pictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG,
              strFilePath);
            customSymbol = (ISymbol)pictureMarkerSymbol;

            ///������Ⱦ���Ž�����Ⱦ
            string sValue;
            IFeature feature = null;
            IFeatureCursor featureCursor;
            featureCursor = geoFeaLayer.FeatureClass.Search(queryFilter, true);
            feature = featureCursor.NextFeature();
            while (feature != null)
            {
                sValue = Convert.ToString(feature.get_Value(fieldIndex));
                if (sValue == value)
                {
                    uniValueRender.AddValue(sValue, "", customSymbol);
                }
                else
                {
                    ///�ǵ�ǰ��ѡҪ�أ�����ű��ֲ���
                    defaultSymbol = geoFeaLayer.Renderer.get_SymbolByFeature(feature);
                    uniValueRender.AddValue(sValue, "", defaultSymbol);
                }

                feature = featureCursor.NextFeature();
            }

            if (featureCursor != null)
            {
                featureCursor = null;
                ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);
            }

            geoFeaLayer.Renderer = uniValueRender as IFeatureRenderer;
        }
コード例 #46
0
		private static void UpdateGraphicsAndRenderer(KmlGraphicsLayer layer, UniqueValueRenderer renderer, string key)
		{
			foreach (var graphic in layer.Graphics)
			{
				var f = (PlacemarkDescriptor)graphic.GetValue(FeaturePlacemarkerDescriptorProperty);
				if (f.Symbol.style.IconHref != null && f.Symbol.style.IconHref.ToLower() == key)
				{
					graphic.Symbol = PointSymbolDescriptor.GetDefaultSymbol();
					ComputeIconTranslationValues(f.Symbol.style, graphic.Symbol as KmlPlaceMarkerSymbol, ((graphic.Symbol as KmlPlaceMarkerSymbol).Fill as ImageBrush).ImageSource as BitmapImage);
					string l = null, d = null;
					GetRendererInfo(f, f.Symbol.style, out l, out d);
					var info = renderer.Infos.FirstOrDefault(i => i.Label == l);
					if (info != null)
					{
						info.Symbol = graphic.Symbol;
					}
				}
			}
		}
コード例 #47
0
    	/// <summary>
    	/// Creates graphic elements and adds them to the graphics layer.
    	/// </summary>
    	/// <param name="layer">Graphics layer that will have features added to it.</param>
    	/// <param name="images">Dictionary of images coming from kmz content or from previous parsing</param>
		public void CreateGraphics(KmlGraphicsLayer layer, IDictionary<string, ImageBrush> images)
		{
			if (layer == null) return;

			GraphicCollection graphics = new GraphicCollection();
			UniqueValueRenderer renderer = new UniqueValueRenderer(); // dummy renderer used to create the legend items (since creation of the swatches from the symbol is not that obvious) 
			
			// Process each metadata feature in the list
			foreach (PlacemarkDescriptor feature in placemarks)
			{
				KMLStyle style = feature.Symbol.style;

				if (style.ZipFile != null)
				{
					// Look for the image in the zip file
					if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
					{
						style.IconImage = GetIconImage(style.ZipFile, style.IconHref.ToLower());
					}

					style.ZipFile.Dispose();
					style.ZipFile = null;
				}

                //Define handlers upfront so we can unhook from them
#if SILVERLIGHT
                EventHandler<RoutedEventArgs>
#else
                EventHandler
#endif
 imageCompleted = null;
#if SILVERLIGHT
                EventHandler<ExceptionRoutedEventArgs> 		
#else
                EventHandler<ExceptionEventArgs>
#endif
 imageFailed = null;

				// If the style has an HREF then it is associated with an image
				if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
				{
					// If the image is already loaded in the image dictionary, use it
					if (images.ContainsKey(style.IconHref.ToLower()))
						style.IconImage = images[style.IconHref.ToLower()];
					else
					{
						// Get the image using the HREF and store the image in the images dictionary so that if
						// other features reference it, it is cached
                        style.IconImage = GetIconImage(style.IconHref);
                        if (style.IconImage != null && (style.IconImage as ImageBrush).ImageSource != null)
							{
                            var bi = (style.IconImage as ImageBrush).ImageSource as BitmapImage;
                            if (bi != null)
                            {
                                imageFailed = (s, e) =>
                                {
                                    var b = s as BitmapImage;
#if SILVERLIGHT           
                                    if (imageCompleted != null) b.ImageOpened -= imageCompleted;
                                    if(imageFailed != null) b.ImageFailed -= imageFailed;
#else
                                    if (imageCompleted != null) b.DownloadCompleted -= imageCompleted;
                                    if (imageFailed != null) b.DownloadFailed -= imageFailed;
#endif
                                    var key = b.GetValue(BitmapImageKeyProperty) as string;
								layer.Dispatcher.BeginInvoke((Action)delegate
								{								
									UpdateGraphicsAndRenderer(layer, renderer, key);
								});
                                };

#if SILVERLIGHT                                    
                                bi.ImageFailed += imageFailed;
#else
                                bi.DownloadFailed += imageFailed;
#endif
                            }
                        }
						images.Add(style.IconHref.ToLower(), style.IconImage);
					}
				}

				// Create a new graphic from the metadata and construct the symbol using polymorphism
				Graphic g = new Graphic()
				{
					Geometry = feature.Geometry,
					Symbol = feature.Symbol.CreateSymbol(),
					TimeExtent = feature.TimeExtent
				};
				g.SetValue(FeaturePlacemarkerDescriptorProperty, feature);
				// Create legend entry
				string label;
				string description;
				GetRendererInfo(feature, style, out label, out description);

				if (!string.IsNullOrEmpty(label) && !renderer.Infos.Any(info => info.Label == label))
					renderer.Infos.Add(new UniqueValueInfo { Label = label, Description = description, Symbol = g.Symbol });

				// Adjust and assign picture marker symbol properties
				if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint && g.Symbol is KmlPlaceMarkerSymbol)
				{
					try
					{
						KmlPlaceMarkerSymbol ms = g.Symbol as KmlPlaceMarkerSymbol;

						// To match sizing of Google Earth, default size of point images is 40x40
						ms.Height = 40;
						ms.Width = 40;

                        ms.Fill = style.IconImage;
                        ms.IconColor = style.IconColor;

						// Default to half the pixel size (width and height) if symbol offsets are 0 (supported in wpf and sl3)
						ImageBrush ib = ms.Fill;
						BitmapImage bi = ib.ImageSource as BitmapImage;
#if SILVERLIGHT
						if (bi.PixelHeight == 0 || bi.PixelWidth == 0)
#else
						if (bi.IsDownloading)
#endif
						{
                            imageCompleted = (s, e) =>
							{
                                var b = s as BitmapImage;
#if SILVERLIGHT                                    
                                if (imageCompleted != null) b.ImageOpened -= imageCompleted;
                                if(imageFailed != null) b.ImageFailed -= imageFailed;
#else
                                if (imageCompleted != null) b.DownloadCompleted -= imageCompleted;
                                if (imageFailed != null) b.DownloadFailed -= imageFailed;
#endif
                                ComputeIconTranslationValues(style, ms, b);
							};
#if SILVERLIGHT   
                            bi.ImageOpened += imageCompleted;
#else
                            bi.DownloadCompleted += imageCompleted;
#endif
                        }
						else
						{
							ComputeIconTranslationValues(style, ms, bi);
						}

					}
					catch
					{
						g.Symbol = PointSymbolDescriptor.GetDefaultSymbol();
						ComputeIconTranslationValues(style, g.Symbol as KmlPlaceMarkerSymbol, ((g.Symbol as KmlPlaceMarkerSymbol).Fill as ImageBrush).ImageSource as BitmapImage);
						var info = renderer.Infos.FirstOrDefault(i => i.Label == label);
						if (info != null)
						{
							info.Symbol = g.Symbol;
						}
					}
				}

				// Copy attributes values from metadata to graphic
				foreach (var attribute in feature.Attributes)
				{
					g.Attributes.Add(attribute.Key, attribute.Value);
				}

				// If the balloontext property has been assigned a value in the style associated with this
				// graphic feature, then add it to the attributes collection.
				if (!String.IsNullOrEmpty(style.BalloonText))
				{
					g.Attributes.Add("balloonText", style.BalloonText);
				}

				// Add graphic to graphics layer
				graphics.Add(g);
			}

			layer.Graphics = graphics;

			// keep the renderer for further usage (when QueryLegendInfos is called)
			layer.RendererBasedOnStyle = renderer;
		}
コード例 #48
0
        void queryTaskPolygon_ExecuteCompleted(object sender, QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features returned from query");
                return;
            }

            GraphicsLayer graphicsLayer = MyMap.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer;

            Random random = new Random();

            // Random switch between class breaks and unique value renderers
            if (random.Next(0, 2) == 0)
            {
                ClassBreaksRenderer classBreakRenderer = new ClassBreaksRenderer();
                classBreakRenderer.Field = "POP2000";
                int classCount = 6;

                List <double> valueList = new List <double>();
                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    graphicsLayer.Graphics.Add(graphic);
                    valueList.Add((int)graphic.Attributes[classBreakRenderer.Field]);
                }

                // LINQ
                IEnumerable <double> valueEnumerator =
                    from aValue in valueList
                    orderby aValue
                    select aValue;

                int increment = Convert.ToInt32(Math.Ceiling(args.FeatureSet.Features.Count / classCount));
                int rgbFactor = 255 / classCount;
                int j         = 255;

                for (int i = increment; i < valueList.Count; i += increment)
                {
                    ClassBreakInfo classBreakInfo = new ClassBreakInfo();

                    if (i == increment)
                    {
                        classBreakInfo.MinimumValue = 0;
                    }
                    else
                    {
                        classBreakInfo.MinimumValue = valueEnumerator.ElementAt(i - increment);
                    }

                    classBreakInfo.MaximumValue = valueEnumerator.ElementAt(i);

                    SimpleFillSymbol symbol = new SimpleFillSymbol()
                    {
                        Fill            = new SolidColorBrush(Color.FromArgb(192, (byte)j, (byte)j, (byte)j)),
                        BorderBrush     = new SolidColorBrush(Colors.Transparent),
                        BorderThickness = 1
                    };

                    classBreakInfo.Symbol = symbol;
                    classBreakRenderer.Classes.Add(classBreakInfo);

                    j = j - rgbFactor;
                }

                // Set maximum value for largest class break
                classBreakRenderer.Classes[classBreakRenderer.Classes.Count - 1].MaximumValue = valueEnumerator.ElementAt(valueList.Count - 1) + 1;

                graphicsLayer.Renderer = classBreakRenderer;
            }
            else
            {
                UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();
                uniqueValueRenderer.DefaultSymbol = LayoutRoot.Resources["RedFillSymbol"] as Symbol;
                uniqueValueRenderer.Field         = "STATE_NAME";

                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    graphicsLayer.Graphics.Add(graphic);
                    UniqueValueInfo uniqueValueInfo = new UniqueValueInfo();

                    SimpleFillSymbol symbol = new SimpleFillSymbol()
                    {
                        Fill            = new SolidColorBrush(Color.FromArgb(192, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255))),
                        BorderBrush     = new SolidColorBrush(Colors.Transparent),
                        BorderThickness = 1
                    };

                    uniqueValueInfo.Symbol = symbol;
                    uniqueValueInfo.Value  = graphic.Attributes["STATE_NAME"];
                    uniqueValueRenderer.Infos.Add(uniqueValueInfo);
                }

                graphicsLayer.Renderer = uniqueValueRenderer;
            }
        }
コード例 #49
0
        private void CreateEndpointLayer()
        {
            var endpointLayer = new GraphicsLayer()
            {
                ID = "EndpointLayer", 
                IsLabelingEnabled = true
            };

			// We are adding start and endpoints to same layer so render them differently
            var endpointLayerRenderer = new UniqueValueRenderer()
            {
                DefaultSymbol = new SimpleMarkerSymbol
                {
                    Color = Colors.Red,
                    Size = 12
                },
                Fields = new ObservableCollection<string>() { "PointType" },
                Infos = new UniqueValueInfoCollection()
                                {
                                    new UniqueValueInfo("EndPoint", 
                                        new SimpleMarkerSymbol() 
                                            { 
                                                Color = Colors.Blue, 
                                                Size = 12 
                                            })
                                }
            };

            endpointLayer.Renderer = endpointLayerRenderer;

			// Crate labeling definition for start and end locations. Shows Address attribute as a label text.
            var labelClass = new LabelClass()
            {
                Symbol = new TextSymbol()
                {
                    Color = Colors.Yellow,
                    BorderLineColor = Colors.Black,
                    BorderLineSize = 2
                },
                TextExpression = "[Address]" 
            };

            endpointLayer.LabelClasses = new LabelClassCollection { labelClass };

            Map.Layers.Add(endpointLayer);
            _graphicLayer = endpointLayer;
        }
コード例 #50
0
        private void WriteUniqueValueRenderer(UniqueValueRenderer uniqueValueRenderer)
        {
            writer.WriteStartElement("UniqueValueRenderer", Namespaces[Constants.esriPrefix]);
			if (!string.IsNullOrEmpty(uniqueValueRenderer.Field))
                WriteAttribute("Field", uniqueValueRenderer.Field);
			WriteAttribute("DefaultLabel", uniqueValueRenderer.DefaultLabel);
            if (uniqueValueRenderer.DefaultSymbol != null)
            {
                writer.WriteStartElement("UniqueValueRenderer.DefaultSymbol", Namespaces[Constants.esriPrefix]);
                (new SymbolXamlWriter(writer, Namespaces)).WriteSymbol(uniqueValueRenderer.DefaultSymbol);
                writer.WriteEndElement();
            }
            if (uniqueValueRenderer.Infos != null && uniqueValueRenderer.Infos.Count > 0)
            {
                writer.WriteStartElement("UniqueValueRenderer.Infos", Namespaces[Constants.esriPrefix]);

                foreach (ESRI.ArcGIS.Client.UniqueValueInfo uniqueValueInfo in uniqueValueRenderer.Infos)
                {
                    WriteUniqueValueInfo(uniqueValueInfo);
                }

                writer.WriteEndElement();// UniqueValueRenderer.Infos
            }
            writer.WriteEndElement();
        }
コード例 #51
0
        public static void SpecialLineRenderer2(ILayer layer, string field, string value, ILineSymbol lineSymbol)
        {
            var geoFeaLayer = layer as IGeoFeatureLayer;
            IUniqueValueRenderer uniValueRender = new UniqueValueRenderer();

            IQueryFilter2 queryFilter = new QueryFilterClass();
            uniValueRender.FieldCount = 1;
            uniValueRender.Field[0] = field;
            queryFilter.AddField(field);
            if (geoFeaLayer != null)
            {
                var fieldIndex = geoFeaLayer.FeatureClass.Fields.FindField(field);

                var customSymbol = (ISymbol)lineSymbol;

                var featureCursor = geoFeaLayer.FeatureClass.Search(queryFilter, true);
                var feature = featureCursor.NextFeature();
                while (feature != null)
                {
                    var sValue = Convert.ToString(feature.Value[fieldIndex]);
                    if (sValue == value)
                    {
                        uniValueRender.AddValue(sValue, "", customSymbol);
                    }
                    else
                    {
                        var defaultSymbol = geoFeaLayer.Renderer.SymbolByFeature[feature];
                        uniValueRender.AddValue(sValue, "", defaultSymbol);
                    }

                    feature = featureCursor.NextFeature();
                }
            }

            ComReleaser.ReleaseCOMObject(null);
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);  //释放指针
            if (geoFeaLayer != null) geoFeaLayer.Renderer = uniValueRender as IFeatureRenderer;
        }