private void BuildPaths(MapArgs e, IEnumerable <IFeature> features, out List <GraphicsPath> borderPaths) { borderPaths = new List <GraphicsPath>(); Rectangle clipRect = ComputeClippingRectangle(e); Extent drawExtents = e.PixelToProj(clipRect); SoutherlandHodgman shClip = new SoutherlandHodgman(clipRect); for (int selectState = 0; selectState < 2; selectState++) { foreach (IPolygonCategory category in Symbology.Categories) { // Determine the subset of the specified features that are visible and match the category IPolygonCategory polygonCategory = category; int i = selectState; Func <IDrawnState, bool> isMember = state => state.SchemeCategory == polygonCategory && state.IsVisible && state.IsSelected == (i == 1); var drawnFeatures = from feature in features where isMember(DrawingFilter[feature]) select feature; GraphicsPath borderPath = new GraphicsPath(); foreach (IFeature f in drawnFeatures) { BuildPolygon(DataSet.Vertex, f.ShapeIndex, borderPath, e, drawExtents.Contains(f.Envelope) ? null : shClip); } borderPaths.Add(borderPath); } } }
/// <summary> /// Removes the specified category /// </summary> /// <param name="category">The category to remove</param> public override void RemoveCategory(ICategory category) { IPolygonCategory pc = category as IPolygonCategory; if (pc != null) { _categories.Remove(pc); } }
/// <summary> /// Inserts the category at the specified index /// </summary> /// <param name="index">The integer index where the category should be inserted</param> /// <param name="category">The category to insert</param> public override void InsertCategory(int index, ICategory category) { IPolygonCategory pc = category as IPolygonCategory; if (pc != null) { _categories.Insert(index, pc); } }
/// <summary> /// Adds a new scheme, assuming that the new scheme is the correct type. /// </summary> /// <param name="category">The category to add</param> public override void AddCategory(ICategory category) { IPolygonCategory pc = category as IPolygonCategory; if (pc != null) { _categories.Add(pc); } }
public void ConvertLayerProperties_MapPolygonDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory() { // Setup const string metadataAttribute = "Meta"; var random = new Random(21); var theme = new MapTheme <PolygonCategoryTheme>("Other Meta", new[] { new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(), new PolygonStyle { FillColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }) }); var polygonStyle = new PolygonStyle { FillColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }; var mapPolygonData = new MapPolygonData("test", polygonStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapPolygonLayer = new MapPolygonLayer(); var converter = new MapPolygonDataConverter(); // Call converter.ConvertLayerProperties(mapPolygonData, mapPolygonLayer); // Assert IPolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle); IPolygonScheme appliedScheme = mapPolygonLayer.Symbology; Assert.AreEqual(1, appliedScheme.Categories.Count); IPolygonCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnMouseDoubleClick(MouseEventArgs e) { _wasDoubleClick = true; Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top); foreach (LegendBox lb in _legendBoxes) { if (!lb.Bounds.Contains(loc) || lb.CheckBox.Contains(loc)) { continue; } ILineCategory lc = lb.Item as ILineCategory; if (lc != null) { DetailedLineSymbolDialog lsDialog = new DetailedLineSymbolDialog(lc.Symbolizer); lsDialog.ShowDialog(); ILineSymbolizer sel = lc.Symbolizer.Copy(); sel.SetFillColor(Color.Cyan); lc.SelectionSymbolizer = sel; } IPointCategory pc = lb.Item as IPointCategory; if (pc != null) { DetailedPointSymbolDialog dlg = new DetailedPointSymbolDialog(pc.Symbolizer); dlg.ShowDialog(); IPointSymbolizer ps = pc.Symbolizer.Copy(); ps.SetFillColor(Color.Cyan); pc.SelectionSymbolizer = ps; } IPolygonCategory polyCat = lb.Item as IPolygonCategory; if (polyCat != null) { DetailedPolygonSymbolDialog dlg = new DetailedPolygonSymbolDialog(polyCat.Symbolizer); dlg.ShowDialog(); IPolygonSymbolizer ps = polyCat.Symbolizer.Copy(); ps.SetFillColor(Color.Cyan); ps.OutlineSymbolizer.SetFillColor(Color.DarkCyan); polyCat.SelectionSymbolizer = ps; } IFeatureLayer fl = lb.Item as IFeatureLayer; if (fl != null) { LayerDialog layDialog = new LayerDialog(fl, new FeatureCategoryControl()); layDialog.ShowDialog(); } IRasterLayer rl = lb.Item as IRasterLayer; if (rl != null) { LayerDialog dlg = new LayerDialog(rl, new RasterCategoryControl()); dlg.ShowDialog(); } IColorCategory cb = lb.Item as IColorCategory; if (cb != null) { _tabColorDialog = new TabColorDialog(); _tabColorDialog.ChangesApplied += TabColorDialogChangesApplied; _tabColorDialog.StartColor = cb.LowColor; _tabColorDialog.EndColor = cb.HighColor; _editCategory = cb; _tabColorDialog.ShowDialog(this); } } base.OnMouseDoubleClick(e); }
/// <summary> /// Before a shape is selected, moving the mouse over a shape will highlight that shape by changing /// its appearance. This tests features to determine the first feature to qualify as the highlight. /// </summary> /// <param name="e">The GeoMouseArgs parameter contains information about the mouse location /// and geographic coordinates.</param> /// <returns>A value indicating whether the shape was successfully highlighted.</returns> private bool ShapeHighlight(GeoMouseArgs e) { if (e == null) { throw new ArgumentNullException("e", "e is null."); } Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6); Extent ext = Map.PixelToProj(mouseRect); IPolygon env = ext.ToEnvelope().ToPolygon(); bool requiresInvalidate = false; foreach (IFeature feature in _featureSet.Features) { if (_featureSet.FeatureType == FeatureType.Point || _featureSet.FeatureType == FeatureType.MultiPoint) { MapPointLayer mpl = _layer as MapPointLayer; if (mpl != null) { int w = 3; int h = 3; PointCategory pc = mpl.GetCategory(feature) as PointCategory; if (pc != null) { if (pc.Symbolizer.ScaleMode != ScaleMode.Geographic) { Size2D size = pc.Symbolizer.GetSize(); w = (int)size.Width; h = (int)size.Height; } } _imageRect = new Rectangle(e.Location.X - (w / 2), e.Location.Y - (h / 2), w, h); if (_imageRect.Contains(Map.ProjToPixel(feature.Geometry.Coordinates[0]))) { _activeFeature = feature; _oldCategory = mpl.GetCategory(feature); if (_selectedCategory == null) { _selectedCategory = _oldCategory.Copy(); _selectedCategory.SetColor(Color.Red); _selectedCategory.LegendItemVisible = false; } mpl.SetCategory(_activeFeature, _selectedCategory); } } requiresInvalidate = true; } else { if (feature.Geometry.Intersects(env)) { _activeFeature = feature; _oldCategory = _layer.GetCategory(_activeFeature); if (_featureSet.FeatureType == FeatureType.Polygon) { IPolygonCategory pc = _activeCategory as IPolygonCategory; if (pc == null) { _activeCategory = new PolygonCategory(Color.FromArgb(55, 255, 0, 0), Color.Red, 1) { LegendItemVisible = false }; } } if (_featureSet.FeatureType == FeatureType.Line) { ILineCategory pc = _activeCategory as ILineCategory; if (pc == null) { _activeCategory = new LineCategory(Color.Red, 3) { LegendItemVisible = false }; } } _layer.SetCategory(_activeFeature, _activeCategory); requiresInvalidate = true; } } } return(requiresInvalidate); }
/// <inheritdoc /> protected override void OnMouseDown(GeoMouseArgs e) { if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { _mousePosition = e.Location; if (_dragging) { if (e.Button == MouseButtons.Right) { _dragging = false; Map.Invalidate(); Map.IsBusy = false; } } else { if (_selectedFeature != null) { Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6); Envelope env = Map.PixelToProj(mouseRect).ToEnvelope(); if (CheckForVertexDrag(e)) { return; } // No vertex selection has occured. if (!_selectedFeature.Geometry.Intersects(env.ToPolygon())) { // We are clicking down outside of the given polygon, so clear our selected feature DeselectFeature(); return; } } if (_activeFeature != null) { // Don't start dragging a vertices right away for polygons and lines. // First you select the polygon, which displays the vertices, then they can be moved. if (_featureSet.FeatureType == FeatureType.Polygon) { _selectedFeature = _activeFeature; _activeFeature = null; IPolygonCategory sc = _selectedCategory as IPolygonCategory; if (sc == null) { _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1) { LegendItemVisible = false }; } _layer.SetCategory(_selectedFeature, _selectedCategory); } else if (_featureSet.FeatureType == FeatureType.Line) { _selectedFeature = _activeFeature; _activeFeature = null; ILineCategory sc = _selectedCategory as ILineCategory; if (sc == null) { _selectedCategory = new LineCategory(Color.Cyan, 1) { LegendItemVisible = false }; } _layer.SetCategory(_selectedFeature, _selectedCategory); } else { _dragging = true; Map.IsBusy = true; _dragCoord = _activeFeature.Geometry.Coordinates[0]; MapPointLayer mpl = _layer as MapPointLayer; if (mpl != null) { mpl.SetVisible(_activeFeature, false); } IPointCategory sc = _selectedCategory as IPointCategory; if (sc == null) { IPointSymbolizer ps = _layer.GetCategory(_activeFeature).Symbolizer.Copy() as IPointSymbolizer; if (ps != null) { ps.SetFillColor(Color.Cyan); _selectedCategory = new PointCategory(ps); } } } } Map.MapFrame.Initialize(); Map.Invalidate(); } } base.OnMouseDown(e); }
/// <summary> /// Re-orders the specified member by attempting to exchange it with the next higher /// index category. If there is no higher index, this does nothing. /// </summary> /// <param name="category">The category to increase the index of</param> public override bool IncreaseCategoryIndex(ICategory category) { IPolygonCategory pc = category as IPolygonCategory; return(pc != null && Categories.IncreaseIndex(pc)); }
public void ConvertLayerProperties_MapPolygonDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapPolygonLayer() { // Setup const string metadataAttribute = "Meta"; var random = new Random(21); var unequalCriterion = new ValueCriterion(ValueCriterionOperator.UnequalValue, "unequal value"); var equalCriterion = new ValueCriterion(ValueCriterionOperator.EqualValue, "equal value"); var theme = new MapTheme <PolygonCategoryTheme>(metadataAttribute, new[] { new PolygonCategoryTheme(equalCriterion, new PolygonStyle { FillColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }), new PolygonCategoryTheme(unequalCriterion, new PolygonStyle { FillColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }) }); var polygonStyle = new PolygonStyle { FillColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }; var mapPolygonData = new MapPolygonData("test", polygonStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapPolygonLayer = new MapPolygonLayer(); var converter = new MapPolygonDataConverter(); // Call converter.ConvertLayerProperties(mapPolygonData, mapPolygonLayer); // Assert PolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle); IPolygonScheme appliedScheme = mapPolygonLayer.Symbology; Assert.AreEqual(3, appliedScheme.Categories.Count); IPolygonCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); IPolygonCategory equalSchemeCategory = appliedScheme.Categories[1]; string expectedFilter = $"[1] = '{equalCriterion.Value}'"; Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression); PolygonStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style; expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle); AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer); IPolygonCategory unEqualSchemeCategory = appliedScheme.Categories[2]; expectedFilter = $"NOT [1] = '{unequalCriterion.Value}'"; Assert.AreEqual(expectedFilter, unEqualSchemeCategory.FilterExpression); expectedCategoryStyle = theme.CategoryThemes.ElementAt(1).Style; expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle); AssertAreEqual(expectedSymbolizer, unEqualSchemeCategory.Symbolizer); }