?? dchymapmodule.~pas
字號(hào):
{-----------------------------------------------------------------------------
Unit Name: dchyMapModule
Author: 杜長(zhǎng)宇 du changyu changyudu@163.com ,junqilian@163.com
Purpose: 用于操作mapx控件的相關(guān)工具包
History: 創(chuàng)建: 2005-05-20
用法:
1、在需要使用該工具模塊的單元里,uses unit :dchyMapModule;
2、定義對(duì)象
var
myMapModule : TdchyMapModule;
3、myMapModule.Method();
-----------------------------------------------------------------------------}
unit dchyMapModule;
interface
uses
SysUtils,MapXLib_TLB,Variants,Activex ;
type
TdchyMapModule = class
private
public
{ Private declarations }
procedure LoadLayerFromServer(var currentMap:TMap;layerName,queryString, serverName,userName,password:string);
procedure MoveLayerToTop(var currentMap:TMap;layerName:string);
function GetLayerIndex(var currentMap:TMap;layerName:string):integer;
procedure AutoPan(var currentMap:TMap;mapX,mapY,deltaXScale,deltaYScale:double);
function CreateTempAnimationLayer(var currentMap:TMap;layerName:string):CMapXLayer;
function CreateServerLayer(var currentMap,layerName,serverName,userName,password:string):CMapXLayer;
procedure DeleteTempAnimationLayer(var currentMap:TMap;layerName:string);
function GetChineseMapUnit(var currentMap:TMap;mapUnit:TOleEnum):string;
end;
implementation
{ TdchyMapModule }
{-----------------------------------------------------------------------------
Procedure: TdchyMapModule.GetLayerIndex
Author: Administrator
Date: 20-五月-2005
Arguments: var currentMap:TMap; layerName: string
Result: integer
如果result=-1 則表示沒(méi)有找到指定的圖層。
-----------------------------------------------------------------------------}
procedure TdchyMapModule.AutoPan(var currentMap: TMap; mapX, mapY,
deltaXScale, deltaYScale: double);
var
maxX,maxY,minX,minY : double;
deltaX,deltaY : double;
begin
// 當(dāng)mapX,mapY點(diǎn)到達(dá)屏幕距邊界還有1/deltaXScale水平和1/deltaYScale垂直時(shí),自動(dòng)移動(dòng)屏幕1/deltaXScale(水平)和1/deltaYScale(垂直)
maxX:=currentMap.Bounds.XMax;
minX:=currentMap.Bounds.XMin;
maxY:=currentMap.Bounds.YMax;
minY:=currentMap.Bounds.YMin;
deltaX:=(maxX-minX)/deltaXScale;
deltaY:=(maxY-minY)/deltaYScale;
if (mapX<minX+deltaX) then currentMap.CenterX := currentMap.CenterX-(minX-mapX)-deltaX
else if (mapX>maxX-deltaX) then currentMap.CenterX := currentMap.CenterX+(mapX-maxX)+deltaX;
if (mapY<minY+deltaY) then currentMap.CenterY := currentMap.CenterY-(minY-mapY)-deltaY
else if(mapY>maxY-deltaY) then currentMap.CenterY := currentMap.CenterY+(mapY-maxY)+deltaY;
end;
function TdchyMapModule.CreateTempAnimationLayer(var currentMap: TMap;
layerName: string): CMapXLayer;
var
layerInfo:CMapXLayerInfo;
flds : CMapXFields;
begin
try
flds := CoFields.Create;
flds.AddStringField('ID',254,EmptyParam);
layerInfo := CoLayerInfo.Create;
layerInfo.type_ := miLayerInfoTypeTemp;
layerInfo.AddParameter('FileSpec',layerName);
layerInfo.AddParameter('Name',layerName);
layerInfo.AddParameter('Fields',flds);
currentMap.Layers.Add(layerInfo,1);
currentMap.Layers.AnimationLayer := currentMap.Layers.Item[layerName];
result := currentMap.Layers.Item[layerName];
except
result := nil;
end;
end;
procedure TdchyMapModule.DeleteTempAnimationLayer(var currentMap: TMap;
layerName: string);
var
index : integer;
begin
index := GetLayerIndex(currentMap,layerName);
if not index<0 then currentMap.Layers.Remove(index);
end;
function TdchyMapModule.GetChineseMapUnit(var currentMap: TMap;
mapUnit: TOleEnum): string;
begin
case mapUnit of
miUnitMile : result := '英里';
miUnitKilometer : result := '千米';
miUnitInch : result := '英寸';
miUnitFoot : result := '英尺';
miUnitYard : result := '碼';
miUnitMillimeter : result := '毫米';
miUnitCentimeter : result := '厘米';
miUnitMeter : result := '米';
miUnitSurveyFoot : result := 'SurveyFoot';
miUnitNauticalMile : result := '海里';
miUnitTwip : result := '緹';
miUnitPoint : result := '點(diǎn)';
miUnitPica : result := 'Pica';
miUnitDegree : result := '度';
miUnitLink : result := 'Link';
miUnitChain : result := 'Chain';
miUnitRod : result := 'Rod';
end;
end;
function TdchyMapModule.GetLayerIndex(var currentMap:TMap; layerName: string): integer;
var
i : integer;
begin
for i :=1 to currentMap.Layers.Count do begin
if currentMap.Layers.Item[i].Name = layerName then begin
result := i;
break;
end
else begin
//raise Exception.CreateFmt('TdchyMapModule.GetLayerIndex error: 找不到指定的圖層:%s',[layerName]);
result := -1;
end;
end;
end;
{-----------------------------------------------------------------------------
Procedure: TForm1.LoadLayerFromServer
Author: Administrator
Date: 20-五月-2005
Arguments: var currentMap:TMap;layerName,whereCondition, serverName, userName, password: string
Result: None
whereCondition 示例:" where objectId > 25 "
-----------------------------------------------------------------------------}
procedure TdchyMapModule.LoadLayerFromServer(var currentMap: TMap;
layerName, queryString, serverName, userName, password: string);
var
//QueryString:string;
LayerInfo:CMapxLayerInfo;
begin
LayerInfo := CoLayerInfo.Create;
LayerInfo.type_ := miLayerInfoTypeServer;
Layerinfo.Type_:=miLayerInfoTypeServer;
LayerInfo.AddParameter('Name',layerName);
LayerInfo.AddParameter('ConnectString','SRVR='+serverName+';UID='+userName+';PWD='+password);
LayerInfo.AddParameter('Query',queryString);
LayerInfo.AddParameter('Toolkit','ORAINET');
LayerInfo.AddParameter('Cache','OFF'); //關(guān)閉緩存,以便使客戶端及時(shí)反映服務(wù)器的變化。
//加載到圖層列表的最底端
currentMap.Layers.Add(LayerInfo,currentMap.ControlInterface.Layers.Count+1);
end;
{-----------------------------------------------------------------------------
Procedure: TForm1.MoveLayerToTop
Author: Administrator
Date: 20-五月-2005
Arguments: var currentMap: TMap; layerName:string
Result: None
把制定的圖層移動(dòng)到地圖圖層列表的最頂端
-----------------------------------------------------------------------------}
procedure TdchyMapModule.MoveLayerToTop(var currentMap: TMap;
layerName: string);
var
i : integer;
layerIndex : integer;
begin
layerIndex := self.GetLayerIndex(currentMap,layerName);
if layerIndex>=0 then
currentMap.Layers.Move(layerIndex,1)
else
raise Exception.CreateFmt('TdchyMapModule.MoveLayerToTop error: 找不到指定的圖層:%s',[layerName]);
end;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -