环境delphi6+mapx4.5
意图:用CMapxLayerInfo建永久图层
//
P_Csys :CMapxCoordSys;
//
P_Fields :cmapxfields;
//自己加个索引字段,其他是用户加的字段放在列表框里
procedure TNewTableFrm.Button6Click(Sender: TObject);
var
Str :char;
Str1 :string;
LayerName,FileSpec :string;
Number,LayerPos,retn,FeatureNameLen :integer;
LayerInfo :CMapxLayerInfo;
dst1 :CmapxDataset;
lyr :CmapxLayer;
layerinfo1 : cmapxlayerinfo;
i :integer;
begin
P_Fields := cofields.Create;
//加字段
for i:=0 to ListView1.Items.Count -1do
begin
if trim(edit1.Text)='' then
begin
MessageDlg('字段名称不能为空!',mtInformation,[mbOK],0);
exit;
end;
Str1 :=edit1.Text;
Str :=Str1[1];
if ((Str in ['a'..'z'])=false)
or ((Str in ['A'..'Z'])=false) or (Str<>'_') then
begin
end;
end;
//验证字段名称是不是合法
//*******************************************
try
with SaveDialog1do
begin
Title:='保存表文件';
Filter := '表(*.tab)|*.tab';
DefaultExt:='表文件|*.tab';
if execute then
begin
if fileName='' then
exit;
FileSpec :=fileName;
end;
end;
//验证图层名称的合法性
LayerName :=edit3.Text;
FeatureNameLen :=40;
LayerPos :=1;
If FeatureNameLen <= 0 then
begin
MessageDlg('请输入大于0的数字!',mtInformation,[mbOK],0);
exit;
end;
If LayerPos <= 0 then
begin
MessageDlg('请输入大于0的数字!',mtInformation,[mbOK],0);
exit;
end;
//lyr :=Form1.Map1.Layers.CreateLayer(LayerName,FileSpec,LayerPos,FeatureNameLen,P_Csys);
//Form1.Map1.Refresh;
//将新建图层加入到数据字典和数据集
P_Fields := cofields.Create;
P_Fields.AddStringField('zqs2',40);
P_Fields.AddStringField('zqs3',40);
//怎么加索引字段 ?
layerinfo1 := colayerinfo.Create;
LayerInfo1.Type_ :=miLayerInfoTypeNewTable;
layerinfo1.AddParameter('filespec',FileSpec);
LayerInfo1.AddParameter('Name',LayerName);
layerinfo1.AddParameter('fields',P_Fields);
//加上投影
if P_Csys <> nil then
LayerInfo1.AddParameter('CoordSys',P_Csys);
lyr :=Form1.map1.layers.Add(LayerInfo1,1);
// Form1.Map1.Layers.AddGeosetLayers(LayerName)
{
try
dst1 :=Form1.map1.Datasets.Add(miDatasetLayer,lyr,EmptyParam,EmptyParam, EmptyParam,EmptyParam, EmptyParam, EmptyParam);
except
end;
//做个循环
try
dst1.AddField('sss','1');
dst1.Refresh;
except
end;
}
except
MessageDlg('是否覆盖?',mtInformation,[mbOK],0);
exit;
end;
//*******************************************
close;
end;
//设置投影
procedure TNewTableFrm.Button5Click(Sender: TObject);
var
ctype :Integer;
cunits :Integer;
vEmpty : OleVariant;
rect : CMapXRectangle;
CS : CMapXCoordsys;
begin
//投影也没有很好解决
Form1.Map1.NumericCoordSys.PickCoordSys(0,0);
//可是没有办法控制到里面呀
P_Csys := Form1.Map1.NumericCoordSys;
ctype := P_Csys.Type_;
cunits := P_Csys.Units;
//要加上边界
{
rect:= CoRectangle.Create;
rect.Set_(1, 1, 10000, 10000);
CS := CreateOleObject('Mapx.Coordsys.4') as CMapXCoordsys;
CS.Set_ (OleVariant(0),vEmpty,OleVariant(7),vEmpty,vEmpty,vEmpty,vEmpty,vEmpty,vEmpty,vEmpty,vEmpty,vEmpty,rect,vEmpty);
}
//If ctype = 0 then
//begin
// FrmRange.Show 1
//'rect的左下角不能为(0,0)
// P_Csys.Set ctype, , cunits, , , , , , , , , , rect
//end;
end;