public override void UpdateColor(Color color, int?year) { if (year != null) { var doYear = (int)year; int calcYear = doYear * 4; bool update = false; for (int i = calcYear; i < (calcYear + 4); i++) { update = (YearToColor.ContainsKey(i)) || update; } if (update) { string classValue = string.Format("{0}, {1}, {2}", doYear, false, true); for (int j = calcYear; j < calcYear + 4; j++) { if (YearToColor.ContainsKey(j)) { YearToColor[j] = color; } } ArcUtils.SetColorToLayer(Layer, color, classValue); if (YearPip.Contains(calcYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, true, true); ISymbol symbol = ArcUtils.GetPipSymbol(SizeLayer, color); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); } if (YearForbidden.Contains(calcYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, false, false); ISymbol symbol = ArcUtils.GetForbiddenSymbol(SizeLayer, color); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); if (YearPip.Contains(calcYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, true, false); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); } } Refresh(); } } }
public override void UpdateColor(Color color, int?year) { if (year != null) { var doYear = (int)year; if (YearToColor.ContainsKey(doYear)) { string classValue = string.Format("{0}, {1}, {2}", doYear, false, true); YearToColor[doYear] = color; ArcUtils.SetColorToLayer(Layer, color, classValue); if (YearPip.Contains(doYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, true, true); ISymbol symbol = ArcUtils.GetPipSymbol(SizeLayer, color); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); } if (YearForbidden.Contains(doYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, false, false); ISymbol symbol = ArcUtils.GetForbiddenSymbol(SizeLayer, color); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); if (YearPip.Contains(doYear)) { classValue = string.Format("{0}, {1}, {2}", doYear, true, false); ArcUtils.SetSymbolToLayer(Layer, symbol, classValue); } } Refresh(); } } }
protected override void PostEntryStep() { const string objectId = "RecordedAt"; const string object2Id = "PIP"; const string object3Id = "IsAuthorized"; IActiveView activeView = ArcUtils.ActiveView; IEnvelope envelope = activeView.Extent; ISpatialFilter spatialFilter = new SpatialFilterClass { Geometry = envelope, GeometryField = FeatureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelContains, SubFields = string.Format("{0},{1},{2}", objectId, object2Id, object3Id) }; var existsResult = FeatureClass.Search(spatialFilter, false); IFeature feature; var added = new List <int>(); var pipAdded = new List <int>(); var forbiddenAdded = new List <int>(); while ((feature = existsResult.NextFeature()) != null) { // ReSharper disable UseIndexedProperty int imId = existsResult.FindField(objectId); object value = feature.get_Value(imId); var dateTime = (DateTime)value; int year = dateTime.Year; if (!YearToColor.ContainsKey(year)) { YearToColor.Add(year, Color.Transparent); added.Add(year); } int pipId = existsResult.FindField(object2Id); object pipValue = feature.get_Value(pipId); if (pipValue != null) { bool pip = bool.Parse((string)pipValue); if (pip && (!YearPip.Contains(year))) { YearPip.Add(year); pipAdded.Add(year); } } int forbiddenId = existsResult.FindField(object3Id); object forbiddenValue = feature.get_Value(forbiddenId); // ReSharper restore UseIndexedProperty if (forbiddenValue != null) { bool forbidden = !bool.Parse((string)forbiddenValue); if (forbidden && (!YearForbidden.Contains(year))) { YearForbidden.Add(year); forbiddenAdded.Add(year); } } } var geoFeatureLayer = Layer as IGeoFeatureLayer; if (geoFeatureLayer != null) { IFeatureRenderer featureRenderer = geoFeatureLayer.Renderer; var uniqueValueRenderer = featureRenderer as IUniqueValueRenderer; if (uniqueValueRenderer != null) { foreach (var value in added) { // ReSharper disable CSharpWarnings::CS0612 // ReSharper disable CSharpWarnings::CS0618 var symbol = new SimpleMarkerSymbol { Color = Converter.ToRGBColor(Color.Transparent), Size = SizeLayer }; // ReSharper restore CSharpWarnings::CS0618 // ReSharper restore CSharpWarnings::CS0612 var markerSymbol = symbol as ISymbol; string classValue = string.Format("{0}, {1}, {2}", value, false, true); uniqueValueRenderer.AddValue(classValue, string.Empty, markerSymbol); // ReSharper disable UseIndexedProperty string label = value.ToString(CultureInfo.InvariantCulture); uniqueValueRenderer.set_Label(classValue, label); // ReSharper restore UseIndexedProperty } foreach (var value in pipAdded) { var rotationRenderer = uniqueValueRenderer as IRotationRenderer; if (rotationRenderer != null) { rotationRenderer.RotationField = "PIP1Yaw"; rotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic; } Color color = YearToColor.ContainsKey(value) ? YearToColor[value] : Color.Transparent; ISymbol symbol = ArcUtils.GetPipSymbol(SizeLayer, color); string classValue = string.Format("{0}, {1}, {2}", value, true, true); uniqueValueRenderer.AddValue(classValue, string.Empty, symbol); // ReSharper disable UseIndexedProperty string label = string.Format("{0} (Detail images)", value); uniqueValueRenderer.set_Label(classValue, label); // ReSharper restore UseIndexedProperty activeView.ContentsChanged(); } foreach (var value in forbiddenAdded) { Color color = YearToColor.ContainsKey(value) ? YearToColor[value] : Color.Transparent; ISymbol symbol = ArcUtils.GetForbiddenSymbol(SizeLayer, color); string classValue = string.Format("{0}, {1}, {2}", value, false, false); uniqueValueRenderer.AddValue(classValue, string.Empty, symbol); // ReSharper disable UseIndexedProperty string label = string.Format("{0} (No Authorization)", value); uniqueValueRenderer.set_Label(classValue, label); // ReSharper restore UseIndexedProperty if (pipAdded.Contains(value)) { classValue = string.Format("{0}, {1}, {2}", value, true, false); uniqueValueRenderer.AddValue(classValue, string.Empty, symbol); // ReSharper disable UseIndexedProperty label = string.Format("{0} (Detail images, No Authorization)", value); uniqueValueRenderer.set_Label(classValue, label); // ReSharper restore UseIndexedProperty } activeView.ContentsChanged(); } } } foreach (var value in added) { FrmGlobespotter.UpdateColor(this, value); } }