/// <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.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.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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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;
                        }

                        // Á¤Á¡ ¼±ÅÃÀÌ ¹ß»ýÇÏÁö ¾Ê¾Ò½À´Ï´Ù.
                        if (!_selectedFeature.Geometry.Intersects(env.ToPolygon()))
                        {
                            // ¼±ÅÃÀ» Ãë¼ÒÇÕ´Ï´Ù.
                            DeselectFeature();
                            return;
                        }
                    }

                    if (_activeFeature != null)
                    {
                        // ´Ù°¢Çü°ú ¼±ÀÇ Á¤Á¡À» ¹Ù·Î µå·¡±×ÇÏÁö ¸¶½Ê½Ã¿À. ¸ÕÀú Á¤Á¡À» Ç¥½ÃÇÏ´Â ´Ù°¢ÇüÀ» ¼±ÅÃÇÑ ´ÙÀ½ À̵¿ÇÒ ¼ö ÀÖ½À´Ï´Ù.
                        if (_featureSet.FeatureType == FeatureType.Polygon) // ¸é
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            if (!(_selectedCategory is IPolygonCategory sc))
                            {
                                _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;
                            if (!(_selectedCategory is ILineCategory sc))
                            {
                                _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;
                            mpl?.SetVisible(_activeFeature, false);

                            if (!(_selectedCategory is IPointCategory sc))
                            {
                                if (_layer.GetCategory(_activeFeature).Symbolizer.Copy() is IPointSymbolizer ps)
                                {
                                    ps.SetFillColor(Color.Cyan);
                                    _selectedCategory = new PointCategory(ps);
                                }
                            }
                        }
                    }

                    Map.MapFrame.Initialize();
                    Map.Invalidate();
                }
            }

            base.OnMouseDown(e);
        }