/// <summary> /// Finishes the label moving operation. /// </summary> private void MapMouseUp(IMuteMap map, MouseEventArgs e) { if (!Active || _currentLabel.LayerHandle == -1) { return; } if (e.X == _currentLabel.X || e.Y == _currentLabel.Y) { Clear(); return; } // check that new position is within map if (e.X < 0 || e.Y < 0 || e.X > map.Width || e.Y > map.Height) { Clear(); return; } var fs = map.GetFeatureSet(_currentLabel.LayerHandle); if (_currentLabel.IsChart) { var chart = fs.Diagrams[_currentLabel.LabelIndex]; if (chart != null) { double x1, x2, y1, y2; map.PixelToProj(_currentLabel.X, _currentLabel.Y, out x1, out y1); map.PixelToProj(e.X, e.Y, out x2, out y2); chart.PositionX = chart.PositionX - x1 + x2; chart.PositionY = chart.PositionY - y1 + y2; fs.Diagrams.SavingMode = PersistenceType.XmlOverwrite; // .chart file should be overwritten _context.Project.SetModified(); map.Redraw(); } } else { var lb = fs.Labels.Items[_currentLabel.LabelIndex, _currentLabel.PartIndex]; if (lb != null) { double x1, x2, y1, y2; map.PixelToProj(_currentLabel.X, _currentLabel.Y, out x1, out y1); map.PixelToProj(e.X, e.Y, out x2, out y2); lb.X = lb.X - x1 + x2; lb.Y = lb.Y - y1 + y2; fs.Labels.SavingMode = PersistenceType.XmlOverwrite; // .lbl file should be overwritten _context.Project.SetModified(); map.Redraw(); } } Clear(); }
/// <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); }