⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitlabelinfo.pas

📁 在delphi下基于MapX5.0的GIS程序
💻 PAS
字号:
unit UnitLabelInfo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, MapXLib_TLB, ComObj, DB, Spin;

type
  TFrmLabelInfo = class(TForm)
    BBtnExport: TBitBtn;
    BBtnCancel: TBitBtn;
    BBtnEdit: TBitBtn;
    LEditName: TLabeledEdit;
    BBtnDelete: TBitBtn;
    SEditRotation: TSpinEdit;
    LableRotation: TLabel;
    TimerLabelInfo: TTimer;
    CBoxHindLabel: TCheckBox;
    procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT; 
    procedure FillFeatureData(TableName: String);
    procedure FormShow(Sender: TObject);
    procedure NFillData();
    procedure SFillData();
    procedure BBtnExportClick(Sender: TObject);
    procedure TimerLabelInfoTimer(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure BBtnDeleteClick(Sender: TObject);
    procedure BBtnEditClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmLabelInfo: TFrmLabelInfo;
  OnShowing: Boolean;

implementation

uses UnitCommonModule, UnitMain, UnitDataModule, UnitModify,
  UnitSearchResult;

{$R *.dfm}

// 画窗体边框
procedure TFrmLabelInfo.WMNCPaint(var Msg: TWMNCPaint);
var
  dc : hDc;
  Pen : hPen;
  OldPen : hPen;
  OldBrush : hBrush;
begin
  inherited;
  dc := GetWindowDC(Handle);
  msg.Result := 1;
  Pen := CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
  OldPen := SelectObject(dc, Pen);
  OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH));
  if OnShowing and TimerLabelInfo.Enabled then Windows.Rectangle(dc, 0, 0, Width, Height+5);
  if Not TimerLabelInfo.Enabled then Windows.Rectangle(dc, 0, 0, Width, Height);
  if Not OnShowing and TimerLabelInfo.Enabled then Windows.Rectangle(dc, 0, 0, Width, Height-5);
  SelectObject(dc, OldBrush);
  SelectObject(dc, OldPen);
  DeleteObject(Pen);
  ReleaseDC(Handle, Canvas.Handle);
end;

procedure TFrmLabelInfo.FillFeatureData(TableName: String);
begin
  EditLayer.KeyField := 'ID';
  if DM.ADOQueryText.Locate('ID', infoFeature.KeyValue, [loCaseInsensitive]) then
  begin
  //  添加图元属性
    LEditName.Text := DM.ADOQueryTextName.Value;
    if DM.ADOQueryTextRotation.Value < 0
      then SEditRotation.Value := 360+DM.ADOQueryTextRotation.Value
      else SEditRotation.Value := DM.ADOQueryTextRotation.Value;
    CBoxHindLabel.Checked := DM.ADOQueryTextHideLabel.Value;
  end;
end;

procedure TFrmLabelInfo.FormShow(Sender: TObject);
begin
  TimerLabelInfo.Enabled := True;
  LEditName.Text := '';
  OnShowing := True;
  LEditName.SetFocus;

  OpenADOQueryAll(DM.ADOQueryText, '标记');
  case infFormViewType of
    NEW_FEATURE :
    begin
      IniNewFormData(FrmLabelInfo);
      // 处理没有图元绑定的标记
      SEditRotation.Value := 0;
      CBoxHindLabel.Checked := False;
      CBoxHindLabel.Enabled := False;
    end;
    SELECT_FEATURE :
    begin
      IniSelectFormData(FrmLabelInfo);
      FillFeatureData(EditLayer.Name);
    end;
    SEARCH_FEATURE :
    begin
      IniSearchFormData(FrmLabelInfo);
      FillFeatureData(EditLayer.Name);
    end;
  end;
// 记录原始图元名称
  IniFeatureName := LEditName.Text;  
end;

procedure TFrmLabelInfo.NFillData();
begin
// 修改标记属性
  DM.ADOQueryTextID.Value := PYConvert(LEditName.Text);
  DM.ADOQueryTextName.Value := LEditName.Text;
  DM.ADOQueryTextType.Value := FrmModify.CBoxFeatureType.Text;
  if DM.ADOQueryTextRotation.Value < 0
    then SEditRotation.Value := 360+DM.ADOQueryTextRotation.Value
    else SEditRotation.Value := DM.ADOQueryTextRotation.Value;
  DM.ADOQueryTextHideLabel.Value := CBoxHindLabel.Checked;
  DM.ADOQueryText.Post;
// 需要处理标注改标注内容
  if Not CBoxHindLabel.Checked then
  begin
    With FrmMain do
    begin
      Map1.DefaultStyle.TextFontRotation := DM.ADOQueryTextRotation.Value;
      SetLabelStr(LEditName.Text);
      SetFeatureRowValue('标记', LEditName.Text);
      newObj := Map1.FeatureFactory.CreateText(Pt, LabelStr, miPositionBR, Map1.Defaultstyle);
      Map1.Layers['标记'].AddFeature(newObj, RowVals);
    end;
  end;
end;

procedure TFrmLabelInfo.SFillData();
var
  Ptt: Variant;
  MoveWidth, MoveHeight: Double;
begin
// 修改标记属性
  DM.ADOQueryTextID.Value := PYConvert(LEditName.Text);
  DM.ADOQueryTextName.Value := LEditName.Text;
  if SEditRotation.Value <= 180
    then DM.ADOQueryTextRotation.Value := SEditRotation.Value
    else DM.ADOQueryTextRotation.Value := -360+SEditRotation.Value;
  DM.ADOQueryTextHideLabel.Value := CBoxHindLabel.Checked;
  DM.ADOQueryText.Post;
  if Not CBoxHindLabel.Checked then
  begin
    With FrmMain do
    begin
      // 处理标记的Text:加空格字符
      SetLabelStr(LEditName.Text);
      // 处理图元字段的初始化值
      SetFeatureRowValue('标记', LEditName.Text);
      Map1.DefaultStyle.TextFontRotation := DM.ADOQueryTextRotation.Value;
      // 处理图元的位移   ?????
      MoveWidth := Length(LabelStr)/Length(LEditName.Text)*infoFeature.Bounds.Width/2;
      MoveHeight := infoFeature.Bounds.Height/2;
      Ptt := CreateOleObject('MapX.Point.5');
      Ptt.Set(infoFeature.CenterX-MoveWidth, infoFeature.CenterY+MoveHeight);
      Map1.Layers['标记'].DeleteFeature(infoFeature);
      newObj := Map1.FeatureFactory.CreateText(Ptt, LabelStr, miPositionBR, Map1.Defaultstyle);
      Map1.Layers['标记'].AddFeature(newObj, RowVals);
      VarClear(Ptt);
    end;
  end else FrmMain.Map1.Layers['标记'].DeleteFeature(infoFeature);
end;

procedure TFrmLabelInfo.BBtnExportClick(Sender: TObject);
begin
  if LEditName.Text = '' then
  begin
    Application.MessageBox('记录名称不能为空,请输入名称!', '提示', 0);
    LEditName.SetFocus;
  end else
  begin
    case infFormViewType of
    // 无图元与之匹配情况   标注多于图元
      NEW_FEATURE:
      begin
        if Not DM.ADOQueryText.Locate('ID', PYConvert(LEditName.Text), [loCaseInsensitive]) then
        begin
          DM.ADOQueryText.Append;
          NFillData();
          EditLayer.Selection.ClearSelection;
          Close;
        end else
        begin
          Application.MessageBox('标记记录已经存在,请重新输入登记信息!', '提示', 0);
          LEditName.SetFocus;
        end;
      end;
    // 有图元与之匹配情况
      SELECT_FEATURE:
      begin
        if (DM.ADOQueryText.Locate('ID', PYConvert(LEditName.Text), [loCaseInsensitive]))
           and (IniFeatureName <> LEditName.Text)
        then
        begin
          Application.MessageBox('记录已经存在,请重新输入修改信息!', '提示', 0);
          LEditName.SetFocus;
        end else
        begin
          OpenADOQueryAll(DM.ADOQueryAll, TypeToLayer(DM.ADOQueryTextType.Value));
          // 如果有对应的图元信息就修改
          if DM.ADOQueryAll.Locate('ID', PYConvert(IniFeatureName), [loCaseInsensitive]) then
          begin
            // 改图元的属性
            FoundObj := FrmMain.Map1.Layers[TypeToLayer(DM.ADOQueryTextType.Value)].Find.Search(PYConvert(IniFeatureName), '');
            if (FoundObj.Findrc Mod 10 = 1) then
            begin
              FrmMain.Map1.Layers[TypeToLayer(DM.ADOQueryTextType.Value)].KeyField := 'ID';
              FoundObj.KeyValue := PYConvert(LEditName.Text);
              FoundObj.Update;
            end;
            // 改数据库中对应的属性
            DM.ADOQueryAll.Edit;
            DM.ADOQueryAll.FieldByName('ID').AsString := PYConvert(LEditName.Text);
            DM.ADOQueryAll.FieldByName('Name').AsString := LEditName.Text;
            DM.ADOQueryAll.Post;
          end;
          DM.ADOQueryText.Locate('ID', PYConvert(IniFeatureName), [loCaseInsensitive]);
          DM.ADOQueryText.Edit;
          SFillData();
          EditLayer.Selection.ClearSelection;
          Close;
        end;
      end;
    end;
  end;
end;

procedure TFrmLabelInfo.TimerLabelInfoTimer(Sender: TObject);
begin
  if OnShowing then
  begin
    Height := Height + 5;
    if Height > 105 then TimerLabelInfo.Enabled := False;
  end
  else
  begin
    Height := Height - 5;
    if Height < 30 then
    begin
      TimerLabelInfo.Enabled := False;
      Close;
    end;
  end;
end;

procedure TFrmLabelInfo.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if Height > 30 then
  begin
    CanClose := False;
    OnShowing := False;
    TimerLabelInfo.Enabled := True;
  end;
end;

procedure TFrmLabelInfo.BBtnDeleteClick(Sender: TObject);
begin
// 删除图元及对应的数据  标记图元及数据
  if Application.MessageBox('确实要删除吗?', '提示', MB_YESNO) = IDYES	then
    DeleteFeatureLabelData(PYConvert(IniFeatureName));
  Close;
end;

procedure TFrmLabelInfo.BBtnEditClick(Sender: TObject);
begin
  EditBtnClick(FrmLabelInfo);
  // 判断是否有对应的图元信息
  OpenADOQueryAll(DM.ADOQueryAll, TypeToLayer(DM.ADOQueryTextType.Value));
  if Not DM.ADOQueryAll.Locate('ID', PYConvert(IniFeatureName), [loCaseInsensitive]) then
    CBoxHindLabel.Enabled := False;
end;

procedure TFrmLabelInfo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  FrmSearchResult.TimerFlash.Enabled := False;
  if FrmMain.Map1.GeoSet <> '' then
    FrmMain.Map1.Layers.ClearSelection;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -