/// <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) { ILineCategory lc = category as ILineCategory; if (lc != null) { _categories.Insert(index, lc); } }
/// <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) { ILineCategory lc = category as ILineCategory; if (lc != null) { _categories.Add(lc); } }
/// <summary> /// Removes the specified category /// </summary> /// <param name="category">The category to insert</param> public override void RemoveCategory(ICategory category) { ILineCategory lc = category as ILineCategory; if (lc != null) { _categories.Remove(lc); } }
// This draws the individual line features private void DrawFeatures(MapArgs e, IEnumerable <IFeature> features) { Graphics g = e.Device ?? Graphics.FromImage(BackBuffer); for (int selectState = 0; selectState < 2; selectState++) { foreach (ILineCategory category in Symbology.Categories) { // Define the symbology based on the category and selection state ILineSymbolizer ls = category.Symbolizer; if (selectState == SELECTED) { ls = category.SelectionSymbolizer; } g.SmoothingMode = ls.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None; Rectangle clipRect = ComputeClippingRectangle(e, ls); // Determine the subset of the specified features that are visible and match the category ILineCategory lineCategory = category; int i = selectState; Func <IDrawnState, bool> isMember = state => state.SchemeCategory == lineCategory && state.IsVisible && state.IsSelected == (i == 1); var drawnFeatures = from feature in features where isMember(DrawingFilter[feature]) select feature; GraphicsPath graphPath = new GraphicsPath(); foreach (IFeature f in drawnFeatures) { BuildLineString(graphPath, DataSet.Vertex, f.ShapeIndex, e, clipRect); } double scale = 1; if (ls.ScaleMode == ScaleMode.Geographic) { scale = e.ImageRectangle.Width / e.GeographicExtents.Width; } foreach (IStroke stroke in ls.Strokes) { stroke.DrawPath(g, graphPath, scale); } graphPath.Dispose(); } } if (e.Device == null) { g.Dispose(); } }
public void ConvertLayerProperties_MapLineDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory() { // Setup const string metadataAttribute = "Meta"; var random = new Random(21); var theme = new MapTheme <LineCategoryTheme>("Other Meta", new[] { new LineCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(), new LineStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Width = random.Next(1, 48), DashStyle = random.NextEnum <LineDashStyle>() }) }); var lineStyle = new LineStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Width = random.Next(1, 48), DashStyle = random.NextEnum <LineDashStyle>() }; var mapLineData = new MapLineData("test", lineStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapLineLayer = new MapLineLayer(); var converter = new MapLineDataConverter(); // Call converter.ConvertLayerProperties(mapLineData, mapLineLayer); // Assert ILineSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(lineStyle); ILineScheme appliedScheme = mapLineLayer.Symbology; Assert.AreEqual(1, appliedScheme.Categories.Count); ILineCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); }
// This draws the individual line features private void DrawFeatures(MapArgs e, IEnumerable <IFeature> features, bool selected) { if (selected && !DrawingFilter.DrawnStates.Any(_ => _.Value.IsSelected)) { return; } Graphics g = e.Device ?? Graphics.FromImage(BackBuffer); var featureList = features as IList <IFeature> ?? features.ToList(); Action <GraphicsPath, Rectangle, IEnumerable <IFeature> > drawFeature = (graphPath, clipRect, featList) => { foreach (IFeature f in featList) { BuildLineString(graphPath, f.Geometry as ILineString, e, clipRect); } }; foreach (ILineCategory category in Symbology.Categories) { // Define the symbology based on the category and selection state ILineSymbolizer ls = selected ? category.SelectionSymbolizer : category.Symbolizer; // Determine the subset of the specified features that are visible and match the category ILineCategory lineCategory = category; Func <IDrawnState, bool> isMember; if (selected) { // get only selected features isMember = state => state.SchemeCategory == lineCategory && state.IsVisible && state.IsSelected; } else { // get all features isMember = state => state.SchemeCategory == lineCategory && state.IsVisible; } var drawnFeatures = from feature in featureList where isMember(DrawingFilter[feature]) select feature; DrawPath(g, ls, e, drawFeature, drawnFeatures); } if (e.Device == null) { g.Dispose(); } }
// CGX, n'est plus static /// <summary> /// Gets the indices of the features that get drawn. /// </summary> /// <param name="indices">Indices of all the features that could be drawn.</param> /// <param name="states">FastDrawnStates of the features.</param> /// <param name="category">Category the features must have to get drawn.</param> /// <param name="selected">Indicates whether only the selected features get drawn.</param> /// <returns>List of the indices of the features that get drawn.</returns> private List <int> GetFeatures(IList <int> indices, FastDrawnState[] states, ILineCategory category, bool selected) { List <int> drawnFeatures = new List <int>(); foreach (int index in indices) { if (index >= states.Length) { break; } FastDrawnState state = states[index]; if (selected) { if (state.Category == category && state.Visible && state.Selected) { // CGX if (Visibility != null && Visibility.Length > 0 && index < Visibility.Length) { bool visi = Visibility[index].Visible; if (!visi) { continue; } } // CGX END drawnFeatures.Add(index); } } else { if (state.Category == category && state.Visible) { drawnFeatures.Add(index); } } } return(drawnFeatures); }
/// <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); }
private void DrawFeatures(MapArgs e, IEnumerable <int> indices) { Graphics g = e.Device ?? Graphics.FromImage(BackBuffer); if (DrawnStatesNeeded) { FastDrawnState[] states = DrawnStates; int max = indices.Max(); if (max >= states.Length) { AssignFastDrawnStates(); states = DrawnStates; } for (int selectState = 0; selectState < 2; selectState++) { foreach (ILineCategory category in Symbology.Categories) { // Define the symbology based on the category and selection state ILineSymbolizer ls = category.Symbolizer; if (selectState == SELECTED) { ls = category.SelectionSymbolizer; } g.SmoothingMode = ls.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None; // Compute a clipping rectangle that accounts for symbology Rectangle clipRect = ComputeClippingRectangle(e, ls); // Determine the subset of the specified features that are visible and match the category ILineCategory lineCategory = category; int i = selectState; List <int> drawnFeatures = new List <int>(); foreach (int index in indices) { if (index >= states.Length) { break; } FastDrawnState state = states[index]; if (state.Category == lineCategory && state.Selected == (i == 1) && state.Visible) { drawnFeatures.Add(index); } } GraphicsPath graphPath = new GraphicsPath(); foreach (int shp in drawnFeatures) { ShapeRange shape = DataSet.ShapeIndices[shp]; BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect); } double scale = 1; if (ls.ScaleMode == ScaleMode.Geographic) { scale = e.ImageRectangle.Width / e.GeographicExtents.Width; } foreach (IStroke stroke in ls.Strokes) { stroke.DrawPath(g, graphPath, scale); } graphPath.Dispose(); } } } else { // Selection state is disabled // Category is only the very first category ILineCategory category = Symbology.Categories[0]; ILineSymbolizer ls = category.Symbolizer; g.SmoothingMode = ls.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None; Rectangle clipRect = ComputeClippingRectangle(e, ls); // Determine the subset of the specified features that are visible and match the category GraphicsPath graphPath = new GraphicsPath(); foreach (int shp in indices) { ShapeRange shape = DataSet.ShapeIndices[shp]; BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect); } double scale = 1; if (ls.ScaleMode == ScaleMode.Geographic) { scale = e.ImageRectangle.Width / e.GeographicExtents.Width; } foreach (IStroke stroke in ls.Strokes) { stroke.DrawPath(g, graphPath, scale); } graphPath.Dispose(); } if (e.Device == null) { g.Dispose(); } }
/// <summary> /// Reduces the index value of the specified category by 1 by /// exchaning it with the category before it. If there is no /// category before it, then this does nothing. /// </summary> /// <param name="category">The category to decrease the index of</param> public override bool DecreaseCategoryIndex(ICategory category) { ILineCategory pc = category as ILineCategory; return(pc != null && Categories.DecreaseIndex(pc)); }
public void ConvertLayerProperties_MapLineDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapLineLayer() { // 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 <LineCategoryTheme>(metadataAttribute, new[] { new LineCategoryTheme(equalCriterion, new LineStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Width = random.Next(1, 48), DashStyle = random.NextEnum <LineDashStyle>() }), new LineCategoryTheme(unequalCriterion, new LineStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Width = random.Next(1, 48), DashStyle = random.NextEnum <LineDashStyle>() }) }); var lineStyle = new LineStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Width = random.Next(1, 48), DashStyle = random.NextEnum <LineDashStyle>() }; var mapLineData = new MapLineData("test", lineStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapLineLayer = new MapLineLayer(); var converter = new MapLineDataConverter(); // Call converter.ConvertLayerProperties(mapLineData, mapLineLayer); // Assert ILineSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(lineStyle); ILineScheme appliedScheme = mapLineLayer.Symbology; Assert.AreEqual(3, appliedScheme.Categories.Count); ILineCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); ILineCategory equalSchemeCategory = appliedScheme.Categories[1]; string expectedFilter = $"[1] = '{equalCriterion.Value}'"; Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression); LineStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style; expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle); AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer); ILineCategory 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); }
/// <summary> /// Gets the indices of the features that get drawn. /// </summary> /// <param name="indices">Indices of all the features that could be drawn.</param> /// <param name="states">FastDrawnStates of the features.</param> /// <param name="category">Category the features must have to get drawn.</param> /// <param name="selected">Indicates whether only the selected features get drawn.</param> /// <returns>List of the indices of the features that get drawn.</returns> private static List <int> GetFeatures(IList <int> indices, FastDrawnState[] states, ILineCategory category, bool selected) { List <int> drawnFeatures = new List <int>(); foreach (int index in indices) { if (index >= states.Length) { break; } FastDrawnState state = states[index]; if (selected) { if (state.Category == category && state.Visible && state.Selected) { drawnFeatures.Add(index); } } else { if (state.Category == category && state.Visible) { drawnFeatures.Add(index); } } } return(drawnFeatures); }