/// <summary> /// Highlighting shapes with a mouse over is something that also needs to be undone when the /// mouse leaves. This test handles changing the colors back to normal when the mouse leaves a shape. /// </summary> /// <param name="e">The GeoMouseArgs parameter contains information about the mouse location and geographic coordinates.</param> /// <returns>Boolean, true if mapframe initialize (or visual change) is necessary.</returns> private bool ShapeRemoveHighlight(GeoMouseArgs e) { // If no shapes have ever been highlighted, this is meaningless. if (_oldCategory == null) { return(false); } Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6); Extent ext = Map.PixelToProj(mouseRect); MapPointLayer mpl = _layer as MapPointLayer; bool requiresInvalidate = false; IPolygon env = ext.ToEnvelope().ToPolygon(); if (mpl != null) { int w = 3; int h = 3; PointCategory pc = mpl.GetCategory(_activeFeature) as PointCategory; if (pc != null) { if (pc.Symbolizer.ScaleMode != ScaleMode.Geographic) { w = (int)pc.Symbolizer.GetSize().Width; h = (int)pc.Symbolizer.GetSize().Height; } } Rectangle rect = new Rectangle(e.Location.X - (w / 2), e.Location.Y - (h / 2), w * 2, h * 2); if (!rect.Contains(Map.ProjToPixel(_activeFeature.Geometry.Coordinates[0]))) { mpl.SetCategory(_activeFeature, _oldCategory); _activeFeature = null; requiresInvalidate = true; } } else { if (!_activeFeature.Geometry.Intersects(env)) { _layer.SetCategory(_activeFeature, _oldCategory); _activeFeature = null; requiresInvalidate = true; } } return(requiresInvalidate); }
/// <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); }