Ejemplo n.º 1
0
        private LabelMoveData FindMovableItem(int x, int y)
        {
            // Actually, collision avoidance is turned on for all layers now
            // and Labels.Select, Charts.Select return only visible objects
            // so it's not possible to have 2 candidate labels for draging
            // so we can have much easier code here, but better still to consider
            // thу more difficult situation in case somebody will turn off collision
            // avoidance form plugin

            // 1 - vpAboveAll layers (considered first)
            // 0 - above current layer

            var data = new LabelMoveData()
            {
                X = x, Y = y
            };

            for (int z = 1; z >= 0; z--)        // Considering position above the layer and above all layers
            {
                int layerCount = _map.Layers.Count;

                for (int i = layerCount - 1; i >= 0; i--)    // we are starting from the layers which were drawn last
                {
                    var layer = _map.Layers[i];
                    if (layer == null || !layer.IsVector || layer.FeatureSet == null)
                    {
                        continue;
                    }

                    var fs = layer.FeatureSet;

                    var env = new Envelope();
                    env.SetBounds(x, x, y, y);

                    var position = (VerticalPosition)z;

                    int chartIndex = FindChart(fs, env, position);
                    if (chartIndex != -1)
                    {
                        data.LayerHandle = layer.Handle;
                        data.LabelIndex  = chartIndex;
                        data.IsChart     = true;
                        return(data);
                    }

                    var info = FindLabel(fs, env, position);
                    if (info != null)
                    {
                        data.LayerHandle = layer.Handle;
                        data.LabelIndex  = info.LabelIndex;
                        data.PartIndex   = info.PartIndex;
                        data.IsChart     = false;
                        return(data);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the dragging operation.
        /// </summary>
        private void MapMouseDown(IMuteMap map, MouseEventArgs e)
        {
            if (!Active)
            {
                return;
            }

            var data = FindMovableItem(e.X, e.Y);

            if (data == null)
            {
                return;
            }

            _currentLabel = data;

            var fs = _map.GetFeatureSet(_currentLabel.LayerHandle);

            if (fs == null)
            {
                return;
            }

            IEnvelope env = null;

            if (_currentLabel.IsChart)
            {
                var chart = fs.Diagrams[_currentLabel.LabelIndex];
                env = chart.ScreenExtents;
            }
            else
            {
                var label = fs.Labels.Items[_currentLabel.LabelIndex, _currentLabel.PartIndex];
                env = label.ScreenExtents;
            }

            _currentLabel.Rect = env.ToRectangle();

            DrawLabelRectangle(_currentLabel.Rect);
        }