private ClassBreakConfigControl createNewClassBreakConfigControl(ClassBreakInfo classBreak) { ClassBreakConfigControl classBreakConfigControl = new ClassBreakConfigControl() { ClassBreak = classBreak, SymbolConfigProvider = SymbolConfigProvider, GeometryType = GeometryType, }; classBreakConfigControl.ClassBreakModified += new EventHandler <ClassBreakModificationEventArgs>(classBreakConfigControl_ClassBreakChanged); return(classBreakConfigControl); }
void symbolsConfigControl_CurrentClassBreakChanged(object sender, CurrentClassBreakChangedEventArgs e) { _classBreakInfo = e.ClassBreak; if (e.ClassBreak == null) { return; } if (SymbolConfigControl != null) { SymbolConfigControl.Symbol = e.ClassBreak.Symbol; } }
void AddRangeButton_Click(object sender, RoutedEventArgs e) { if (ClassBreaksRenderer == null) { return; } ClassBreakConfigControl classBreakConfigControl = null; if (ClassBreaksRenderer.Classes.Count < 1) // Empty class break set { // Assign a first class break and symbolize it using the first class break ClassBreakInfo newClassBreak = new ClassBreakInfo() { MinimumValue = 0, MaximumValue = 0, Symbol = ClassBreaksRenderer.DefaultSymbol != null?ClassBreaksRenderer.DefaultSymbol.CloneSymbol() : SymbolUtils.CreateDefaultSymbol(GeometryType), }; classBreakConfigControl = createNewClassBreakConfigControl(newClassBreak); ClassBreaksRenderer.Classes.Add(newClassBreak); } else { ClassBreakInfo lastClassBreak = ClassBreaksRenderer.Classes[ClassBreaksRenderer.Classes.Count - 1]; double currentMaxVal = lastClassBreak.MaximumValue; lastClassBreak.MaximumValue -= Math.Floor((currentMaxVal - lastClassBreak.MinimumValue) / 2); // split class break into two ClassBreakInfo newClassBreak = new ClassBreakInfo() { MinimumValue = lastClassBreak.MaximumValue + 1, MaximumValue = currentMaxVal, Symbol = lastClassBreak.Symbol != null?lastClassBreak.Symbol.CloneSymbol() : SymbolUtils.CreateDefaultSymbol(GeometryType), }; classBreakConfigControl = createNewClassBreakConfigControl(newClassBreak); ClassBreaksRenderer.Classes.Add(newClassBreak); } if (ClassBreakConfigItems != null) { ClassBreakConfigItems.Items.Add(classBreakConfigControl); ClassBreakConfigItems.SelectedItem = classBreakConfigControl; } }
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is SimpleLineSymbol) { return(Visibility.Visible); } ConfigurableFeatureLayer featureLayer = value as ConfigurableFeatureLayer; if (featureLayer != null) { return(featureLayer.GeometryType == GeometryType.PolyLine ? Visibility.Visible : Visibility.Collapsed); } ClassBreakInfo classBreak = value as ClassBreakInfo; if (classBreak != null) { return(classBreak.Symbol is SimpleLineSymbol ? Visibility.Visible : Visibility.Collapsed); } return(Visibility.Collapsed); }
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; } }
void symbolsConfigControl_CurrentClassBreakChanged(object sender, CurrentClassBreakChangedEventArgs e) { _classBreakInfo = e.ClassBreak; if (e.ClassBreak == null) return; if (SymbolConfigControl != null) SymbolConfigControl.Symbol = e.ClassBreak.Symbol; }
public void SetShapeRangeValues(DashboardHelper dashboardHelper, string shapeKey, string dataKey, string valueField, List <SolidColorBrush> brushList, int classCount, string missingText, string legendText, bool?showPolyLabels = false) { try { _classCount = classCount; _dashboardHelper = dashboardHelper; _shapeKey = shapeKey; _dataKey = dataKey; _valueField = valueField; _missingText = missingText; _legendText = legendText; _showPolyLabels = (bool)showPolyLabels; if (brushList != null) { _colors = brushList; } DataTable loadedData = GetLoadedData(dashboardHelper, dataKey, ref valueField); if (_valueField == "{Record Count}") { _valueField = "freq"; } GraphicsLayer graphicsLayer = GetGraphicsLayer() as GraphicsLayer; _thematicItem = GetThematicItem(classCount, loadedData, graphicsLayer); if (this.UseQuantiles == false && RangeStarts_FromControls != null && RangeStarts_FromControls.Count > 0) { _thematicItem.RangeStarts = RangeStarts_FromControls; PopulateRangeValues(); } else { PopulateRangeValues(); } GraphicCollection textGraphics = new GraphicCollection(); if (graphicsLayer.Graphics != null && graphicsLayer.Graphics.Count > 0) { for (int i = graphicsLayer.Graphics.Count - 1; i > -1; i--) { if (graphicsLayer.Graphics[i].Symbol is TextSymbol) { graphicsLayer.Graphics.RemoveAt(i); } } } bool usePoleOfInaccessibility = true; if (graphicsLayer.Graphics != null && graphicsLayer.Graphics.Count > 0) { for (int i = 0; i < graphicsLayer.Graphics.Count; i++) { Graphic graphicFeature = graphicsLayer.Graphics[i]; if (graphicFeature.Symbol is TextSymbol) { continue; } if (graphicFeature.Attributes.Count == 0) { continue; } string filterExpression = ""; if (dataKey.Contains(" ") || dataKey.Contains("$") || dataKey.Contains("#")) { filterExpression += "["; } filterExpression += dataKey; if (dataKey.Contains(" ") || dataKey.Contains("$") || dataKey.Contains("#")) { filterExpression += "]"; } filterExpression += " = '" + GetShapeValue(graphicFeature, shapeKey) + "'"; double graphicValue = Double.PositiveInfinity; try { DataRow[] postFilterExpression = loadedData.Select(filterExpression); if (postFilterExpression.Length > 0) { graphicValue = Convert.ToDouble(postFilterExpression[0][_valueField]); } } catch (Exception) { graphicValue = Double.PositiveInfinity; } int brushIndex = GetRangeIndex(graphicValue, _thematicItem.RangeStarts); if (brushList != null) { Color color = ((SolidColorBrush)brushList[brushIndex]).Color; Brush fill = new SolidColorBrush(Color.FromArgb(Opacity, color.R, color.G, color.B)); if (graphicValue == Double.PositiveInfinity) { color = ((SolidColorBrush)brushList[brushList.Count - 1]).Color; fill = new SolidColorBrush(Color.FromArgb(Opacity, color.R, color.G, color.B)); } SimpleFillSymbol symbol = new SimpleFillSymbol(); symbol.Fill = fill; symbol.BorderBrush = new SolidColorBrush(Colors.Black); symbol.BorderThickness = 1; graphicFeature.Symbol = symbol; } if (ShowPolyLabels) { TextSymbol textSymbol = new TextSymbol(); textSymbol.Foreground = new SolidColorBrush(Colors.Black); textSymbol.FontSize = 11; if (graphicFeature.Attributes[shapeKey] != null) { string sShapekey = graphicFeature.Attributes[shapeKey].ToString().Trim(); int indexShapeKey = sShapekey.LastIndexOfAny(new char[] { ' ', '-' }); int iShapeKeyLen = sShapekey.Length; // Break up label if possible and put on new line. Adjust offsets as needed. if (indexShapeKey != -1) //& iShapeKeyLen > 10) { textSymbol.Text = sShapekey.Substring(0, indexShapeKey) + "\r\n " + sShapekey.Substring(indexShapeKey + 1, (iShapeKeyLen - (indexShapeKey + 1))); textSymbol.OffsetX = iShapeKeyLen / 0.8; textSymbol.OffsetY = 6; } else { textSymbol.Text = sShapekey; textSymbol.OffsetX = iShapeKeyLen / 0.4; textSymbol.OffsetY = 3; } //Console.WriteLine(textSymbol.Text); //textSymbol.OffsetX = textSymbol.Text.Length / 0.4; textSymbol.OffsetY = textSymbol.FontSize / 2.0; Envelope extentEnvelope = graphicFeature.Geometry.Extent; MapPoint pole = extentEnvelope.GetCenter(); ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> rings = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>(); //if (graphicFeature.Attributes[shapeKey].ToString().Trim() == "Richmond Hill") usePoleOfInaccessibility = true; if (usePoleOfInaccessibility) { if (graphicFeature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon) { rings = ((ESRI.ArcGIS.Client.Geometry.Polygon)graphicFeature.Geometry).Rings; Tuple <double, double> coords; bool showDebugCells = true; if (showDebugCells) { double precision = 0.1; double denom = 64.0; precision = extentEnvelope.Width / denom < precision? extentEnvelope.Width / denom : precision; precision = extentEnvelope.Height / denom < precision ? extentEnvelope.Height / denom : precision; coords = PolyLabel.PoleOfInaccessibility(rings, precision, graphicsLayer: graphicsLayer); //Envelope extent = graphicFeature.Geometry.Extent; //Cell extentCell = new Cell(extent.XMin, extent.YMin, extent.Width / 2, rings); //PolyLabel.AddDebugGraphic(extentCell, graphicsLayer); } else { coords = PolyLabel.PoleOfInaccessibility(rings); } pole.X = coords.Item1; pole.Y = coords.Item2; } //usePoleOfInaccessibility = false; } Graphic textGraphic = new Graphic(); textGraphic.Symbol = textSymbol; textGraphic.Geometry = pole; textGraphics.Add(textGraphic); } } TextBlock t = new TextBlock(); t.Background = Brushes.White; if (graphicValue == Double.PositiveInfinity) { t.Text = GetShapeValue(graphicFeature, shapeKey) + " " + DashboardSharedStrings.DASHBOARD_MAP_NO_DATA; } else { t.Text = GetShapeValue(graphicFeature, shapeKey) + " : " + graphicValue.ToString(); } t.FontSize = 14; Border border = new Border(); border.BorderThickness = new Thickness(1); Panel panel = new StackPanel(); panel.Children.Add(t); border.Child = panel; graphicFeature.MapTip = border; if (graphicFeature.Attributes.Keys.Contains("EpiInfoValCol")) { graphicFeature.Attributes["EpiInfoValCol"] = graphicValue; } else { graphicFeature.Attributes.Add("EpiInfoValCol", graphicValue); } } graphicsLayer.Graphics.AddRange(textGraphics); if (graphicsLayer is FeatureLayer) { ClassBreaksRenderer renderer = new ClassBreaksRenderer(); renderer.Field = "EpiInfoValCol"; Color color = ((SolidColorBrush)brushList[brushList.Count - 1]).Color; Brush fill = new SolidColorBrush(Color.FromArgb(Opacity, color.R, color.G, color.B)); renderer.DefaultSymbol = new SimpleFillSymbol() { Fill = fill, BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = 1 }; for (int i = 0; i < _thematicItem.RangeStarts.Count; i++) { ClassBreakInfo classBreakInfo = new ClassBreakInfo(); classBreakInfo.MinimumValue = double.Parse(RangeValues[i, 0]); classBreakInfo.MaximumValue = double.Parse(RangeValues[i, 1]); color = ((SolidColorBrush)brushList[i]).Color; fill = new SolidColorBrush(Color.FromArgb(Opacity, color.R, color.G, color.B)); classBreakInfo.Symbol = new SimpleFillSymbol() { Fill = fill, BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = 1 }; renderer.Classes.Add(classBreakInfo); } graphicsLayer.Renderer = renderer; } } SetLegendSection(brushList, classCount, missingText, _thematicItem); } catch { } }
public Traffic() { try { traffic = GlobalLayers.TrafficLayer; traffic_lights = GlobalLayers.LightsLayer; traffic.OutFields = new OutFields { "*" }; traffic_lights.OutFields = new OutFields { "*" }; } catch (Exception) { return; } // 设定道路的流量渲染模型 ClassBreaksRenderer rTrafficRoad = new ClassBreaksRenderer(); // 流量 rTrafficRoad.Field = "SHAPE_Length"; // 指定渲染道路属性字段 // 设定红绿灯的3状态渲染 ClassBreakInfo _Normal = new ClassBreakInfo(); _Normal.MinimumValue = 0; _Normal.MaximumValue = 100; _Normal.Symbol = App.Current.Resources["NORMAL"] as ESRI.ArcGIS.Client.Symbols.Symbol; ClassBreakInfo _Middle = new ClassBreakInfo(); _Middle.MinimumValue = 101; _Middle.MaximumValue = 200; _Middle.Symbol = App.Current.Resources["MIDDLE"] as ESRI.ArcGIS.Client.Symbols.Symbol; ClassBreakInfo _High = new ClassBreakInfo(); _High.MinimumValue = 201; _High.MaximumValue = 1000; _High.Symbol = App.Current.Resources["BUSY"] as ESRI.ArcGIS.Client.Symbols.Symbol; rTrafficRoad.Classes.Add(_Normal); rTrafficRoad.Classes.Add(_Middle); rTrafficRoad.Classes.Add(_High); traffic.Renderer = rTrafficRoad; foreach (Graphic e in traffic as GraphicsLayer) { e.Attributes["SHAPE_Length"] = 0; } traffic.Visible = true; ClassBreaksRenderer rTrafficLights = new ClassBreaksRenderer(); // 红绿灯 rTrafficLights.Field = "status"; // 指定渲染的红绿灯属性字段 // 设定红绿灯的3状态渲染 ClassBreakInfo r = new ClassBreakInfo(); r.MinimumValue = 0; r.MaximumValue = 0; r.Symbol = App.Current.Resources["REDFLAG"] as ESRI.ArcGIS.Client.Symbols.Symbol; ClassBreakInfo y = new ClassBreakInfo(); y.MinimumValue = 1; y.MaximumValue = 1; y.Symbol = App.Current.Resources["YELLOWFLAG"] as ESRI.ArcGIS.Client.Symbols.Symbol; ClassBreakInfo g = new ClassBreakInfo(); g.MinimumValue = 2; g.MaximumValue = 2; g.Symbol = App.Current.Resources["GREENFLAG"] as ESRI.ArcGIS.Client.Symbols.Symbol; rTrafficLights.Classes.Add(r); rTrafficLights.Classes.Add(y); rTrafficLights.Classes.Add(g); traffic_lights.Renderer = rTrafficLights; // GlobalLayers._MainMap.Layers.Add(traffic_lights); foreach (Graphic e in traffic_lights as GraphicsLayer) { e.Attributes["status"] = 1; } traffic_lights.Visible = true; /* * road_traffic_stat.Symbol = App.Current.Resources["TRAFFIC_NORMAL"] as ESRI.ArcGIS.Client.Symbols.Symbol; * traffic.Renderer = road_traffic_stat; */ /* * ArcGISLocalFeatureLayer FLAG = new ArcGISLocalFeatureLayer("dhnew\\traffic.mpk", "FLAG"); // 道路中心线_Clip/ FLAG * SimpleRenderer traffic_stat = new SimpleRenderer(); * traffic_stat.Symbol = App.Current.Resources["REDFLAG"] as ESRI.ArcGIS.Client.Symbols.Symbol; * FLAG.Renderer = traffic_stat; * GlobalLayers._MainMap.Layers.Add(FLAG); */ try { IConnectionFactory factory; factory = new ConnectionFactory(ConfigurationManager.AppSettings["MQ"].ToString()); // 连接MQ数据发布服务器 IConnection connection = factory.CreateConnection(); connection.Start(); ISession session = connection.CreateSession(); // 连接红绿灯 主题 IMessageConsumer consumerLights = session.CreateDurableConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(ConfigurationManager.AppSettings["Topic_Traffic_lights"].ToString()), "GQY_L", null, false); consumerLights.Listener += new MessageListener(ProcessLights); IMessageConsumer consumerTraffic = session.CreateDurableConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(ConfigurationManager.AppSettings["Topic_Traffic"].ToString()), "GQY_T", null, false); consumerTraffic.Listener += new MessageListener(ProcessTraffic); } catch (Exception e) { MessageBox.Show("订阅交通信号失败" + e.ToString()); } }
private ClassBreakConfigControl createNewClassBreakConfigControl(ClassBreakInfo classBreak) { ClassBreakConfigControl classBreakConfigControl = new ClassBreakConfigControl() { ClassBreak = classBreak, SymbolConfigProvider = SymbolConfigProvider, GeometryType = GeometryType, }; classBreakConfigControl.ClassBreakModified += new EventHandler<ClassBreakModificationEventArgs>(classBreakConfigControl_ClassBreakChanged); return classBreakConfigControl; }
void AddRangeButton_Click(object sender, RoutedEventArgs e) { if (ClassBreaksRenderer == null) return; ClassBreakConfigControl classBreakConfigControl = null; if (ClassBreaksRenderer.Classes.Count < 1) // Empty class break set { // Assign a first class break and symbolize it using the first class break ClassBreakInfo newClassBreak = new ClassBreakInfo() { MinimumValue = 0, MaximumValue = 0, Symbol = ClassBreaksRenderer.DefaultSymbol != null ? ClassBreaksRenderer.DefaultSymbol.CloneSymbol() : SymbolUtils.CreateDefaultSymbol(GeometryType), }; classBreakConfigControl = createNewClassBreakConfigControl(newClassBreak); ClassBreaksRenderer.Classes.Add(newClassBreak); } else { ClassBreakInfo lastClassBreak = ClassBreaksRenderer.Classes[ClassBreaksRenderer.Classes.Count - 1]; double currentMaxVal = lastClassBreak.MaximumValue; lastClassBreak.MaximumValue -= Math.Floor((currentMaxVal - lastClassBreak.MinimumValue) / 2); // split class break into two ClassBreakInfo newClassBreak = new ClassBreakInfo() { MinimumValue = lastClassBreak.MaximumValue + 1, MaximumValue = currentMaxVal, Symbol = lastClassBreak.Symbol != null ? lastClassBreak.Symbol.CloneSymbol() : SymbolUtils.CreateDefaultSymbol(GeometryType), }; classBreakConfigControl = createNewClassBreakConfigControl(newClassBreak); ClassBreaksRenderer.Classes.Add(newClassBreak); } if (ClassBreakConfigItems != null) { ClassBreakConfigItems.Items.Add(classBreakConfigControl); ClassBreakConfigItems.SelectedItem = classBreakConfigControl; } }
private static IRenderer createNewDefaultClassBreaksRenderer(GraphicsLayer graphicsLayer, FieldInfo attributeField, double min, double max, int numOfClassBreaks, LinearGradientBrush defaultColorRampGradientBrush, IEnumerable <Symbol> existingSymbolSet) { Symbol defaultSymbol = graphicsLayer.GetDefaultSymbolClone(); ClassBreaksRenderer renderer = new ClassBreaksRenderer() { Field = attributeField != null ? attributeField.Name : null, DefaultSymbol = defaultSymbol, }; List <Symbol> symbols = new List <Symbol>(); if (numOfClassBreaks < 2) // classbreaks renderer must have atleast 2 classbreaks { numOfClassBreaks = 2; } double rangeSize = Math.Round((max - min) / numOfClassBreaks, 2); double rangeDelta = 1.0; // delta between 2 class ranges // we choose an integral size double lastRangeDeltaIncr = 1.0; // SL core api requires the last classbreak to be greater than max value of dataset bool fractionalIncrement = false; if (Math.Round(max, 0) != max)// we are dealing with a non-integeral values, so our delta's are in fractional increments { fractionalIncrement = true; rangeDelta = 0.01; lastRangeDeltaIncr = 0.01; } double startValue = min; for (int i = 0; i < numOfClassBreaks; i++) { Symbol symbol = null; if (existingSymbolSet != null) { symbol = existingSymbolSet.ElementAtOrDefault(i); } if (symbol == null) { symbol = graphicsLayer.GetDefaultSymbolClone(); } double endValue = (startValue + rangeSize) - rangeDelta; ClassBreakInfo classBreak = new ClassBreakInfo() { MinimumValue = fractionalIncrement ? startValue : Math.Floor(startValue), MaximumValue = fractionalIncrement ? endValue : Math.Floor(endValue), Symbol = symbol, }; if (i == numOfClassBreaks - 1) // last class break { classBreak.MaximumValue = max + lastRangeDeltaIncr; if (max > 1000000) // SL has a limitation on values greater than a million http://msdn.microsoft.com/en-us/library/bb412393.aspx { classBreak.MaximumValue += 2.0; // the +2 is to workaround Silverlights limitation of single precision values } } symbols.Add(symbol); renderer.Classes.Add(classBreak); startValue += rangeSize; } if (defaultColorRampGradientBrush != null) { if (existingSymbolSet == null) // apply the gradient brush, only if symbols have not been pre-defined { applyLinearGradientBrushToSymbolSet(symbols, defaultColorRampGradientBrush, defaultSymbol); } } return(renderer); }
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; } }
void classBreakConfigControl_ClassBreakChanged(object sender, ClassBreakModificationEventArgs e) { // Auto adjust adjacent class breaks if (e.ClassBreakModificationType == ClassBreakModificationType.MinValueChanged) { ClassBreakConfigControl control = sender as ClassBreakConfigControl; if (control != null) { int indexOfClassBreak = -1; ClassBreakInfo classBreak = control.ClassBreak; indexOfClassBreak = ClassBreaksRenderer.Classes.IndexOf(classBreak); if (indexOfClassBreak > 0) { // Update the previous class break in the collection if (ClassBreakConfigItems != null && ClassBreakConfigItems.Items != null) { int indexOfControl = ClassBreakConfigItems.Items.IndexOf(control); if (indexOfControl > 0)// array bounds check { ClassBreakConfigControl prevControl = ClassBreakConfigItems.Items[indexOfControl - 1] as ClassBreakConfigControl; if (prevControl != null) { ClassBreakInfo prevClassBreak = prevControl.ClassBreak; double incr = 1.0; double delta = 2 * incr; double diff = prevClassBreak.MaximumValue - prevClassBreak.MinimumValue; if (Math.Round(diff, 0) != Math.Round(diff, 4)) // dealing with precision of less than 1 integer { incr = 0.01; delta = 2 * incr; } double newValue = classBreak.MinimumValue - incr; if (classBreak.MinimumValue <= prevClassBreak.MinimumValue + delta) { // don't allow min value to drop below previous class break value // Auto audjust the class breaks newValue = prevClassBreak.MinimumValue + delta; control.UpdateMinValue(newValue); prevControl.UpdateMaxValue(newValue - incr); } else { prevControl.UpdateMaxValue(newValue); } } } } } } } else if (e.ClassBreakModificationType == ClassBreakModificationType.MaxValueChanged) { ClassBreakConfigControl control = sender as ClassBreakConfigControl; if (control != null) { int indexOfClassBreak = -1; ClassBreakInfo classBreak = control.ClassBreak; indexOfClassBreak = ClassBreaksRenderer.Classes.IndexOf(classBreak); if (indexOfClassBreak > -1 && indexOfClassBreak < ClassBreaksRenderer.Classes.Count - 1) { // Update following class break if (ClassBreakConfigItems != null && ClassBreakConfigItems.Items != null) { int indexOfControl = ClassBreakConfigItems.Items.IndexOf(control); if (indexOfControl > -1 && indexOfControl < ClassBreakConfigItems.Items.Count - 1)// array bounds check { ClassBreakConfigControl nextControl = ClassBreakConfigItems.Items[indexOfControl + 1] as ClassBreakConfigControl; if (nextControl != null) { ClassBreakInfo nextClassBreak = nextControl.ClassBreak; double incr = 1.0; double delta = 2 * incr; double diff = nextClassBreak.MaximumValue - nextClassBreak.MinimumValue; if (Math.Round(diff, 0) != Math.Round(diff, 4)) // dealing with precision of less than 1 integer { incr = 0.01; delta = 2 * incr; } double newValue = classBreak.MaximumValue + incr; // check if the max value is greater than max of next classbreak (minus the minimum spacing) if (classBreak.MaximumValue >= (nextClassBreak.MaximumValue - delta)) { // don't allow max value to go above next class break value // Auto audjust the class breaks newValue = nextClassBreak.MaximumValue - delta; control.UpdateMaxValue(newValue); nextControl.UpdateMinValue(newValue + incr); } else { nextControl.UpdateMinValue(newValue); } } } } } } } SelectedClassBreakModificationEventArgs args = new SelectedClassBreakModificationEventArgs() { ClassBreakModificationType = e.ClassBreakModificationType, IsSelectedItem = ClassBreakConfigItems.SelectedItem == sender, }; OnClassBreakRendererModified(args); }
private static IRenderer createNewDefaultClassBreaksRenderer(GraphicsLayer graphicsLayer, FieldInfo attributeField, double min, double max, int numOfClassBreaks, LinearGradientBrush defaultColorRampGradientBrush, IEnumerable<Symbol> existingSymbolSet) { Symbol defaultSymbol = graphicsLayer.GetDefaultSymbolClone(); ClassBreaksRenderer renderer = new ClassBreaksRenderer() { Field = attributeField != null ? attributeField.Name : null, DefaultSymbol = defaultSymbol, }; List<Symbol> symbols = new List<Symbol>(); if (numOfClassBreaks < 2) // classbreaks renderer must have atleast 2 classbreaks numOfClassBreaks = 2; double rangeSize = Math.Round((max - min) / numOfClassBreaks, 2); double rangeDelta = 1.0; // delta between 2 class ranges // we choose an integral size double lastRangeDeltaIncr = 1.0; // SL core api requires the last classbreak to be greater than max value of dataset bool fractionalIncrement = false; if (Math.Round(max, 0) != max)// we are dealing with a non-integeral values, so our delta's are in fractional increments { fractionalIncrement = true; rangeDelta = 0.01; lastRangeDeltaIncr = 0.01; } double startValue = min; for (int i = 0; i < numOfClassBreaks; i++) { Symbol symbol = null; if (existingSymbolSet != null) symbol = existingSymbolSet.ElementAtOrDefault(i); if (symbol == null) symbol = graphicsLayer.GetDefaultSymbolClone(); double endValue = (startValue + rangeSize) - rangeDelta; ClassBreakInfo classBreak = new ClassBreakInfo() { MinimumValue = fractionalIncrement ? startValue : Math.Floor(startValue), MaximumValue = fractionalIncrement ? endValue : Math.Floor(endValue), Symbol = symbol, }; if (i == numOfClassBreaks - 1) // last class break { classBreak.MaximumValue = max + lastRangeDeltaIncr; if (max > 1000000) // SL has a limitation on values greater than a million http://msdn.microsoft.com/en-us/library/bb412393.aspx classBreak.MaximumValue += 2.0;// the +2 is to workaround Silverlights limitation of single precision values } symbols.Add(symbol); renderer.Classes.Add(classBreak); startValue += rangeSize; } if (defaultColorRampGradientBrush != null) { if (existingSymbolSet == null) // apply the gradient brush, only if symbols have not been pre-defined { applyLinearGradientBrushToSymbolSet(symbols, defaultColorRampGradientBrush, defaultSymbol); } } return renderer; }
private FeatureLayer flRoad; //道路 public Traffic() { try { flTrafficLight = MapLayers.GetFeatureLayerByID(PublicParams.fLayerTrafficLight); flRoad = MapLayers.GetFeatureLayerByID(PublicParams.fLayerRoad); if (flTrafficLight == null || flRoad == null) { return; } } catch (Exception) { LogHelper.WriteLog("Traffic初始化错误!"); return; } flTrafficLight.OutFields = new OutFields { "*" }; flRoad.OutFields = new OutFields { "*" }; ClassBreaksRenderer cbrTrafficLight = new ClassBreaksRenderer();//红绿灯 cbrTrafficLight.Field = "DLD_STATUS"; ClassBreakInfo cbiRed = new ClassBreakInfo() { MinimumValue = 0, MaximumValue = 0, Symbol = PublicParams.symbolRedLight }; ClassBreakInfo cbiYellow = new ClassBreakInfo() { MinimumValue = 1, MaximumValue = 1, Symbol = PublicParams.symbolYellowLight }; ClassBreakInfo cbiGreen = new ClassBreakInfo() { MinimumValue = 2, MaximumValue = 2, Symbol = PublicParams.symbolGreenLight }; cbrTrafficLight.Classes.Add(cbiRed); cbrTrafficLight.Classes.Add(cbiYellow); cbrTrafficLight.Classes.Add(cbiGreen); flTrafficLight.Renderer = cbrTrafficLight; ClassBreaksRenderer cbrRoad = new ClassBreaksRenderer();//道路 cbrRoad.Field = "DL_COUNT"; ClassBreakInfo cbiFree = new ClassBreakInfo() { MinimumValue = 0, MaximumValue = 100, Symbol = PublicParams.roadFreeSymbol }; ClassBreakInfo cbiNormal = new ClassBreakInfo() { MinimumValue = 101, MaximumValue = 200, Symbol = PublicParams.roadNormalSymbol }; ClassBreakInfo cbiBusy = new ClassBreakInfo() { MinimumValue = 201, MaximumValue = 1000, Symbol = PublicParams.roadBusySymbol }; cbrRoad.Classes.Add(cbiFree); cbrRoad.Classes.Add(cbiNormal); cbrRoad.Classes.Add(cbiBusy); flRoad.Renderer = cbrRoad; Task taskInitTrafficLight = new Task(InitTrafficLight); taskInitTrafficLight.Start(); Task taskInitRoad = new Task(InitRoad); taskInitRoad.Start(); }
private void setLayerInfoColor() { if (ColorRampListBox == null) { return; } if (ColorRampListBox.Items.Count > 0) { GraphicsLayer layerInfo = DataContext as GraphicsLayer; if (layerInfo != null) { ClassBreaksRenderer classBreaksRenderer = layerInfo.Renderer as ClassBreaksRenderer; if (classBreaksRenderer != null) { // TODO:- evaluate whether this condition is valid and apply // && !layerInfo.ClassBreaks.IsUsingCustomFillSymbolColors if (classBreaksRenderer.Classes.Count > 1) { // Compare the color of the boundary classbreaks // with the start and end color gradients // and set the selected item ClassBreakInfo first = classBreaksRenderer.Classes[0]; ClassBreakInfo last = classBreaksRenderer.Classes[classBreaksRenderer.Classes.Count - 1]; if (first.Symbol is SimpleFillSymbol && last.Symbol is SimpleFillSymbol) { SimpleFillSymbol firstSymbol = first.Symbol as SimpleFillSymbol; SimpleFillSymbol lastSymbol = last.Symbol as SimpleFillSymbol; Color firstColor = (firstSymbol.Fill as SolidColorBrush).Color; Color lastColor = (lastSymbol.Fill as SolidColorBrush).Color; setSelectedColorInRamp(firstColor, lastColor); } else if (first.Symbol is SimpleLineSymbol && last.Symbol is SimpleLineSymbol) { SimpleLineSymbol firstSymbol = first.Symbol as SimpleLineSymbol; SimpleLineSymbol lastSymbol = last.Symbol as SimpleLineSymbol; Color firstColor = (firstSymbol.Color as SolidColorBrush).Color; Color lastColor = (lastSymbol.Color as SolidColorBrush).Color; setSelectedColorInRamp(firstColor, lastColor); } } else { // default to the first one ListBoxItem item = ColorRampListBox.Items[0] as ListBoxItem; if (_selectedRectangle != null) { // un-select the previous one _selectedRectangle.StrokeThickness = 1; } Rectangle rect = item.Content as Rectangle; if (rect != null) { // select the current one _selectedRectangle = rect; _selectedRectangle.StrokeThickness = 2; } ColorRampListBox.SelectedIndex = 0; } } } } }