?? unitshellapis.pas
字號:
if TLayerTreeNodeRecord(ANode.Data).FtClassType=FtClassType then
begin
Result:=MyGIS.GMapTools.MapX.Layers.Item[i];
LayerNode:=ANode;
Exit;
end;
end;
end;
procedure MoveLayer(MapX:TMapXObject; const FromIndex, ToIndex: Integer);
var
SNode, DNode:TTreeNode;
iState_SNode, iState_DNode:Integer;
begin
MapX.Layers.Move(FromIndex, ToIndex);
SNode:=FindLayerNode(FromIndex);
DNode:=FindLayerNode(ToIndex);
iState_SNode:=SNode.StateIndex;
iState_DNode:=DNode.StateIndex;
SNode.MoveTo(DNode, naInsert);
DNode.StateIndex:=-1;
SNode.StateIndex:=-1;
DNode.StateIndex:=iState_DNode;
SNode.StateIndex:=iState_SNode;
end;
procedure SetLayerVisible(MapX:TMapXObject;
const Index: Integer; const Visible:Boolean);
var
ANode:TTreeNode;
iState:Integer;
aLyr:Layer;
begin
ANode:=FindLayerNode(Index);
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(TLayerTreeNodeRecord(ANode.Data).Name);
aLyr.Visible:=Visible;
if Visible then
iState:=TREENODESTATE_SUBCHECKEDALL
else
iState:=TREENODESTATE_NOTCHECKED;
SetNodeState(ANode, iState, True, nil);
end;
procedure SetLayerEditable(MapX:TMapXObject;
const Index: Integer; const Editable: Boolean);
var
i:Integer;
ANode:TTreeNode;
aLyr:Layer;
begin
ANode:=FindLayerNode(Index);
MapX.Layers.InsertionLayer:=nil;
EditLayer:=nil;
for i:=1 to MapX.Layers.Count do
begin
if IsCustomLayer(MapX.Layers.Item[i]) then
MapX.Layers.Item[i].Editable:=False;
end;
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(TLayerTreeNodeRecord(ANode.Data).Name);
if aLyr<>nil then
begin
aLyr.Editable:=Editable;
if Editable then
begin
EditLayer:=aLyr;
MapX.Layers.InsertionLayer:=aLyr;
end;
end;
end;
procedure SetLayerSelectable(MapX:TMapXObject;
const Index: Integer; const Selectable: Boolean);
var
ANode:TTreeNode;
aLyr:Layer;
begin
ANode:=FindLayerNode(Index);
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(TLayerTreeNodeRecord(ANode.Data).Name);
aLyr.Selectable:=Selectable;
end;
procedure SetLayerAutoLabel(MapX:TMapXObject; SysTreeRoot:TTreeNode;
const Index: Integer; const AutoLabel: Boolean);
var
ANode:TTreeNode;
aLyr:Layer;
begin
ANode:=FindLayerNode(Index);
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(TLayerTreeNodeRecord(ANode.Data).Name);
aLyr.AutoLabel:=AutoLabel;
end;
procedure RemoveuserLayer(MapX:TMapXObject; const Index: Integer);
var
ANode:TTreeNode;
aLayerInfo:TLayerTreeNodeRecord;
aLyr:Layer;
begin
ANode:=FindLayerNode(Index);
aLayerInfo:=ANode.Data;
if (aLayerInfo.NodeType<>LTN_LAYER)or(aLayerInfo.IsSystem) then
WarningAbort('提示', '只有用戶圖層可以被移出!');
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(aLayerInfo.Name);
if aLyr=EditLayer then EditLayer:=nil;
MyGIS.GMapTools.m_Layers.Remove(Index);
DeleteNode(ANode);
end;
procedure RemoveAllNodes;
procedure RemoveAllSubNodes(ANode:TTreeNode);
var
ASubNode:TTreeNode;
aLayerInfo:TLayerTreeNodeRecord;
aLyr:Layer;
begin
while ANode.Count>0 do
begin
ASubNode:=ANode.Item[0];
aLayerInfo:=ASubNode.Data;
if aLayerInfo.NodeType<>LTN_LAYER then
RemoveAllSubNodes(ASubNode)
else begin
aLyr:=MyGIS.GMapTools.m_Layers.FindByName(aLayerInfo.Name);
if aLyr=EditLayer then EditLayer:=nil;
MyGIS.GMapTools.m_Layers.Remove(GetLayerIndex(MyGIS.GMapTools.MapX, aLayerInfo.Name));
end;
DeleteNode(ASubNode);
end;
end;
begin
RemoveAllSubNodes(SysTreeRoot);
end;
function SetCurrentMapTool(const ToolClassName:string;
TurnEvent:TNotifyEvent):TBaseMapTool;
var
Index:Integer;
AToolObj:TBaseMapTool;
begin
MyGIS.GMapTools.m_Layer.Layer:=EditLayer;
Index:=MyGIS.GMapTools.m_Map.UserTools.IndexByClassName(ToolClassName);
if Index=-1 then
WarningAbort('錯誤', '沒有找到名稱為 "'+ToolClassName+'" 的地圖工具!!');
Result:=MyGIS.GMapTools.m_Map.UserTools.Items[Index];
Result.MsgHandle:=AppMsgHandle;
if Result is TLayerMapTool then
with TLayerMapTool(Result) do
begin
LayerManager:=MyGIS.GMapTools.m_Layer;
TrackLayer:=UserLayer;
end;
MyGIS.GMapTools.m_Map.UserTools.SetCurrentTool(Result);
Result.OnTurnTool:=TurnEvent;
end;
procedure CheckEditLayer;
begin
if EditLayer=nil then
WarningAbort('提示', '請設置編輯圖層!');
if not editlayer.Editable then
WarningAbort('提示', '圖層沒有處于編輯狀態!');
end;
function MapFieldTypeToLogicalFieldName(AFieldType:TMapFieldType):string;
begin
case AFieldType of
mftString : Result:='字符串';
mftInteger : Result:='整型';
mftSmallint : Result:='整型';
mftBoolean : Result:='布爾型';
mftFloat : Result:='浮點型';
mftBCD : Result:='浮點型';
mftDateTime : Result:='日期\時間';
mftBinary : Result:='二進制';
else Result:='';
end;
end;
function LogicalFieldNameToMapFieldType(const FieldName:string):TMapFieldType;
begin
Result:=mftUnknown;
if AnsiCompareText(FieldName, '字符串')=0 then
Result:=mftString
else if AnsiCompareText(FieldName, '整型')=0 then
Result:=mftInteger
else if AnsiCompareText(FieldName, '布爾型')=0 then
Result:=mftBoolean
else if AnsiCompareText(FieldName, '浮點型')=0 then
Result:=mftFloat
else if AnsiCompareText(FieldName, '日期\時間')=0 then
Result:=mftDateTime
else if AnsiCompareText(FieldName, '二進制')=0 then
Result:=mftBinary;
end;
const
ShapeTypeNames:array [TShapeType] of string=
(
'未知',
'標記',
'線段',
'折線',
'矩形',
'圓形',
'多邊形',
'正多邊形',
'橢圓',
'圓弧',
'文字'
);
function GetShapeTypeName(AShapeType:TShapeType):string;
begin
Result:=ShapeTypeNames[AShapeType];
end;
function GetShapeTypeByName(const TypeName:string):TShapeType;
var
i:Integer;
begin
Result:=stUnknown;
for i:=0 to 10 do
if AnsiCompareText(ShapeTypeNames[TShapeType(i)], TypeName)=0 then
begin
Result:=TShapeType(i);
Exit;
end;
end;
function GetLayerFromTreeNode(ANode:TTreeNode):Layer;
begin
Result:=nil;
if (ANode<>nil)and(ANode.Level>0) then
if TLayerTreeNodeRecord(ANode.Data).NodeType=LTN_LAYER then
Result:=MyGIS.GMapTools.m_Layers.FindByName(TLayerTreeNodeRecord(ANode.Data).Name);
end;
function IsCustomLayer(Lyr:Layer):Boolean;
begin
Result:=(Lyr.type_=miLayerTypeNormal)and(Lyr.Name<>'_YHB_SYS_TRACKLAYER');
end;
function GetCustomLayerIndex(MapX:TMapXObject; const ComboIndex:Integer):Integer;
var
i, j:Integer;
begin
Result:=-1;
j:=-1;
for i:=1 to MapX.Layers.Count do
if IsCustomLayer(MapX.Layers.Item[i]) then
begin
Inc(j);
if j=ComboIndex then
begin
Result:=i;
Break;
end;
end;
end;
function GetCustomLayerComboIndex(MapX:TMapXObject; const LayerIndex:Integer):Integer;
var
i, j:Integer;
begin
Result:=-1;
j:=-1;
for i:=1 to MapX.Layers.Count do
begin
if IsCustomLayer(MapX.Layers.Item[i]) then
Inc(j);
if i=LayerIndex then
begin
Result:=j;
Break;
end;
end;
end;
function GetBoundsString(Bounds:CMapXRectangle):string;
begin
Result:=FloatToStr(Bounds.XMin)+','+FloatToStr(Bounds.YMin)+','+
FloatToStr(Bounds.XMax)+','+FloatToStr(Bounds.YMax);
end;
function CreateBoundsUseBoundsString(const BoundsStr:string):CMapXRectangle;
var
List:TStringList;
begin
List:=TStringList.Create;
try
Trans2(BoundsStr, ',', List);
Result:=CoRectangle.Create;
Result.Set_(StrToFloat(List.Strings[0]), StrToFloat(List.Strings[1]),
StrToFloat(List.Strings[2]), StrToFloat(List.Strings[3]));
finally
List.Free;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -