用Delphi6.0+MapObject2.0开发,真是困难重重。比如说在选定的图层上增加一条线,代码如下:
Map1MouseDown事件中:
var
ln : Line;
begin
ln := Line(CreateOleObject('MapObjects2.Line'));
With currentlayer.Records do
begin
ln := Map1.TrackLine;
AddNew;
Fields.item('Shape').Value := ln;
Fields.item('id').Value := 1;
Fields.item('name').Value := inttostr(x);
Update;
end;
end;
可是画线时没有个结束的办法,鼠标点到哪里,线就一直画到哪里。
而且线是增加到图层里了,用ArcView可以看到,但是在该图层上却看不到。
错在哪里?急盼各位高手!
Map1MouseDown事件中:
var
ln : Line;
begin
ln := Line(CreateOleObject('MapObjects2.Line'));
With currentlayer.Records do
begin
ln := Map1.TrackLine;
AddNew;
Fields.item('Shape').Value := ln;
Fields.item('id').Value := 1;
Fields.item('name').Value := inttostr(x);
Update;
end;
end;
可是画线时没有个结束的办法,鼠标点到哪里,线就一直画到哪里。
而且线是增加到图层里了,用ArcView可以看到,但是在该图层上却看不到。
错在哪里?急盼各位高手!
rect:=layer.records;
AddNew;
Fields.item('Shape').Value := ln;
Fields.item('id').Value := 1;
Fields.item('name').Value := inttostr(x);
layer.symbols.index:=*******;
layer.symbols.color:=clred;
map.reflesh;
..
图象显示主要是symbol属性
currentlayer是我选择出来的当前层。
var
ln : Line;
v : Variant;
begin
ln := Line(CreateOleObject('MapObjects2.Line'));
With currentlayer.Records do
begin
if currentlayer.shapetype = moShapeTypeLine then
begin
ln := Map1.TrackLine; AddNew; //报错AddNew Failed。
Fields.item('Shape').Value := ln;
Fields.item('id').Value := 1;
Fields.item('name').Value := inttostr(x);
Update;
end;
Map1.TrackingLayer.Refresh(True, v);
end;
我跟进去发现EditMode显示是不可编辑状态。不知是不是当前层有问题?
如何使当前层可编辑,恳请高手指点!
附:在lvLayer(Listview )中选择一个图层作为增加线的当前层:
procedure TfrmSelLayer.B_OKClick(Sender: TObject);
var
layer : IMoMapLayer;
i,j : Integer;
str : String;
begin
for i := 0 to lvLayer.Items.Count-1 do
begin
if lvLayer.Items.Item[i].Focused then
begin
for j := 0 to Map1.layers.Count-1 do
begin
layer := MapLayer(Map1.layers.Item(j));
str := layer.Name;
str := copy(str,0,pos('.',str)-1); //去掉.shp后缀名
if (lvLayer.Items.Item[i].Caption = str) then
begin
CurrentLayer := layer; //选定当前层
CurrentLayer.Visible := true;
end;
end;
Close;
end;
end;
end;