地图和图层的管理设计.docx
- 文档编号:5497633
- 上传时间:2022-12-17
- 格式:DOCX
- 页数:78
- 大小:34.95KB
地图和图层的管理设计.docx
《地图和图层的管理设计.docx》由会员分享,可在线阅读,更多相关《地图和图层的管理设计.docx(78页珍藏版)》请在冰豆网上搜索。
地图和图层的管理设计
地图文档管理
PageLayout
地图管理
图层管理
Render
一、地图文档管理——LXMXDDocumentClass
接口IMapDocmentIMapControl3IPageLayoutControl2
功能:
新建、打开、保存、另存、设置保存路径(相对还是绝对路径)、
新建
publicboolCreateMapDocument(stringmxdPath)
方法功能:
新建地图文档
输入参数:
stringmxdPath地图文档的保存路径
返回参数:
bool值为True时,表示新建成功;值为False表示建立失败
打开
publicboolOpenMap(stringstrPath,boolbPageLayout)
方法功能:
在MapControl或PageLayout中打开给定的图文件
输入参数:
stringstrMXDPath打开的地图文档路径及文件名
boolbPageLayout是否用PageLayout打开地图
返回参数:
bool值为True时,表示打开成功;值为False表示打开失败
保存
publicboolSaveMapDocument(stringpSMxdFile,stringpTMxdFile)
方法功能保存MXD文件
输入参数stringpSMxdFile源MXD文件名
stringpTMxdFile目标MXD文件名
注意pSMxdFile与pTMxdFile相等
返回参数:
bool值为True时,表示保存成功;值为False表示保存失败
另存
publicboolSaveAsMapDocument(stringpSMxdFile,stringpTMxdFile)
方法功能保存MXD文件
输入参数stringpSMxdFile源MXD文件名
stringpTMxdFile目标MXD文件名
注意pSMxdFile与pTMxdFile不相等
返回参数:
bool值为True时,表示保存成功;值为False表示保存失败
设置保存路径
publicboolSetDSavePath(stringdSavePath)
方法功能:
设置文档保存路径
注意是相对还是绝对
(还是有点疑问,是否要放在系统配置中)
输入参数:
stringdSavePath文档保存路径
返回参数:
bool值为True表示设置成功;值为False表示设置失败
'地图文档打印
PrivateFunctionMapPrint()
OnErrorGoToErrorHandler
IfPageLayoutCtrl.PrinterIsNothingThen
MsgBox"没有打印机",,"提示"
ExitFunction
EndIf
DimpPrinterAsIPrinter
SetpPrinter=PageLayoutCtrl.Printer
IfpPrinter.Paper.Orientation<>PageLayoutCtrl.Page.OrientationThen
pPrinter.Paper.Orientation=PageLayoutCtrl.Page.Orientation
EndIf
DimdWidthAsDouble,dHeightAsDouble
pPrinter.QueryPaperSizedWidth,dHeight
PageLayoutCtrl.PrintPageLayout'打印
PageLayoutCtrl.MousePointer=esriPointerDefault
ExitFunction
ErrorHandler:
ErrorOperateErr.Description,Erl,c_sModuleFileName,"MapPrintSetting"
EndFunction
'地图文档打印设置
PrivateFunctionMapPrintSetting()
OnErrorGoToErrorHandler
IfNotShowPrinterSetThenExitFunction'如果取消就退出
IfPageLayoutCtrl.PrinterIsNothingThen
MsgBox"没有打印机",,"提示"
ExitFunction
EndIf
DimdWidthAsDouble,dHeightAsDouble,iUnitsAsInteger
DimpPrinterAsIPrinter
SetpPrinter=PageLayoutCtrl.Printer
pPrinter.Paper.FormID=Printer.PaperSize
pPrinter.Paper.Orientation=Printer.Orientation
dWidth=pPrinter.Paper.PrintableBounds.Envelope.Width
dHeight=pPrinter.Paper.PrintableBounds.Envelope.Height
WithPageLayoutCtrl.Page
.FormID=esriPageFormCUSTOM'自定义纸张大小(看到的)
iUnits=.Units
.Units=pPrinter.Units
.Orientation=pPrinter.Paper.Orientation
.PutCustomSizedWidth,dHeight
.StretchGraphicsWithPage=False
.QuerySizedWidth,dHeight
EndWith
DimpFrameElementAsIFrameElement
DimpElementAsIElement
DimpMapFrameAsIMapFrame
SetpFrameElement=PageLayoutCtrl.ActiveView.GraphicsContainer.FindFrame(PageLayoutCtrl.ActiveView.FocusMap)
IfNot(pFrameElementIsNothing)Then
SetpMapFrame=pFrameElement
SetpElement=pMapFrame
DimpEnvelopeAsIEnvelope
SetpEnvelope=pElement.Geometry.Envelope
WithpEnvelope
.Height=dHeight-.YMin*2'根据纸张变化重新设定地图框大小
.Width=dWidth-.XMin*2
EndWith
pElement.Geometry=pEnvelope
DimpGraphicsContainerAsIGraphicsContainer
SetpGraphicsContainer=PageLayoutCtrl.PageLayout
pGraphicsContainer.UpdateElementpElement
EndIf
PageLayoutCtrl.Page.Units=iUnits
PageLayoutCtrl.ActiveView.Refresh
ExitFunction
ErrorHandler:
IfErr.Number=32755ThenExitFunction'userpressedcancel
ErrorOperateErr.Description,Erl,c_sModuleFileName,"MapPrintSetting"
EndFunction
二、PageLayout
模版切合(Maps类)、视图切换
PublicFunctionf_PageLayout_CreateEnvelope(PageLayoutControl1AsIPageLayoutControl2,lXminAsLong,lYminAsLong,lXmaxAsLong,lYmaxAsLong)AsIEnvelope
'函数功能:
创建一个范围
'编写人helen
'编写日期2004/5/25
Setf_PageLayout_CreateEnvelope=Nothing
'GettheIPointinterfacebycreatingpointsisthecurrentpageunits
DimpPointMinAsIPoint
DimpPointMaxAsIPoint
SetpPointMin=PageLayoutControl1.ToPagePoint(lXmin,lYmin)
SetpPointMax=PageLayoutControl1.ToPagePoint(lXmax,lYmax)
'GettheIEnvelopeinterface
DimpEnvelopeAsIEnvelope
SetpEnvelope=NewEnvelope
'Settheenvelopecoordinates
pEnvelope.PutCoordspPointMin.X,pPointMin.y,pPointMax.X,pPointMax.y
Setf_PageLayout_CreateEnvelope=pEnvelope
EndFunction
PublicFunctionChangeLayout(OptionalfirstPathAsString)AsInteger
'函数功能:
切换地图模版
'编写人wufayun
'编写日期2006/04/02
'参数:
OptionalfirstPathAsString初始化打开对话框的路径
'返回值:
=-1'地图模版路径为空;=-3'您加载的地图模版文件有错误;
'=-2'用户单击的是取消;=-4'未知错误;=1'成功
OnErrorGoToErrorHandler
'firstPath初始路径
CommonDialog1.DialogTitle="打开地图模版"
CommonDialog1.Filter="地图模版(*.mxt)|*.mxt"
CommonDialog1.InitDir=firstPath
CommonDialog1.CancelError=True
CommonDialog1.ShowOpen
'Exitifnomapdocumentisselected
DimMXTFilePathAsString
MXTFilePath=CommonDialog1.FileName
IfMXTFilePath=""Then
ChangeLayout=-1'地图模版路径为空
ExitFunction
EndIf
IfNotPageLayoutCtrl.CheckMxFile(MXTFilePath)Then
ChangeLayout=-3'您加载的地图模版文件有错误
ExitFunction
EndIf
PageLayoutCtrl.LoadMxFileMXTFilePath
DimpMapsAsIMaps
SetpMaps=NewMaps
DimpMapAsIMap
SetpMap=m_pMapDocument.Map(0)
pMaps.AddpMap
PageLayoutCtrl.PageLayout.ReplaceMapspMaps
PageLayoutCtrl.ActiveView.ActivatePageLayoutCtrl.hwnd
m_pMapDocument.ReplaceContentsPageLayoutCtrl.PageLayout
TOCControl1.SetBuddyControlPageLayoutCtrl
ChangeLayout=1'成功
ExitFunction
ErrorHandler:
IfErr.Number=cdlCancelThen'判断用户单击的是取消
ChangeLayout=-2'用户单击的是取消
Else
ChangeLayout=-4'未知错误
EndIf
EndFunction
三、地图管理——LXMapClass
接口IMapIActiveView
功能:
地图输出为图片、比例尺设置、显示单位设置、地图空间参考设置
新建并添加图层组、添加图层、移去图层、图层顺序调整(功能性的)
地图输出为图片
publicboolExportMapToFile(stringpfileName)
方法功能:
把地图导出到指定格式的图象文件中(*.jpg;*.pdf;*.bmp;*.tif)
注:
使用IExporter的接口,比如用JpegExporter实例化,把地图转换成jpg
输入参数:
pFileNametypeString,图象文件全名
返回参数:
bool
'参数示例:
pFileName="d:
\\aa.bmp"(此处应该是反斜线的单线吧)
比例尺设置
publicboolSetMapScale(doublepScale)
方法功能:
地图比例尺设置
输入参数:
doublepScale比例尺大小
返回参数:
bool
要加获取比例尺么
publicISpatialReferenceGetMapPRJ(integerpZone,integerpZoneType,integeriPrj)
方法功能:
设置地图空间参考
输入参数:
integerpZone表示带号
integerpZoneType值为1表示3度带
值为2表示6度带
integeriPrjiPrj=1表示北京54iPrj=2表示西安80
返回参数:
ISpatialReference
publicISpatialReferenceGetMapPRJ(IMappMap)
方法功能:
获取地图空间参考
输入参数:
IMappMap
返回参数:
ISpatialReference
PublicFunctionf_Coordinate_GetUnitDescription(pUnitsAsesriUnits)AsString
'函数功能:
显示单位设置
OnErrorGoToeH
f_Coordinate_GetUnitDescription="未知"
SelectCasepUnits
CaseesriInches:
f_Coordinate_GetUnitDescription="英寸"
CaseesriPoints:
f_Coordinate_GetUnitDescription="点"
CaseesriFeet:
f_Coordinate_GetUnitDescription="英尺"
CaseesriYards:
f_Coordinate_GetUnitDescription="码"
CaseesriMiles:
f_Coordinate_GetUnitDescription="英里"
CaseesriNauticalMiles:
f_Coordinate_GetUnitDescription="海里"
CaseesriMillimeters:
f_Coordinate_GetUnitDescription="毫米"
CaseesriCentimeters:
f_Coordinate_GetUnitDescription="厘米"
CaseesriMeters:
f_Coordinate_GetUnitDescription="米"
CaseesriKilometers:
f_Coordinate_GetUnitDescription="公里"
CaseesriDecimalDegrees:
f_Coordinate_GetUnitDescription="度"
CaseesriDecimeters:
f_Coordinate_GetUnitDescription="度"
CaseesriUnknownUnits:
f_Coordinate_GetUnitDescription="未知"
CaseElse:
f_Coordinate_GetUnitDescription="未知"
EndSelect
eH:
EndFunction
'地图刷新
PublicFunctionMapRefresh()AsBoolean
DimpActiveViewAsIActiveView
MapRefresh=False
Ifm_MapIsNothingThenExitFunction
SetpActiveView=m_Map
pActiveView.Refresh
MapRefresh=True
EndFunction
'放大地图
PublicFunctionMapZoomIn()
Dimpoint1AsIPoint
'DimlZoomInKeyAsLong
DimpEnvelopeAsIEnvelope
'lZoomInKey=GetKeyState(vbKeyAdd)
'IflZoomInKeyAnd&H8000Then
Setpoint1=Newpoint
point1.x=MapCtrl.Extent.XMin+MapCtrl.Extent.Width/2
point1.y=MapCtrl.Extent.YMin+MapCtrl.Extent.Height/2
SetpEnvelope=MapCtrl.ActiveView.Extent
pEnvelope.Height=pEnvelope.Height/1.5
pEnvelope.Width=pEnvelope.Width/1.5
pEnvelope.CenterAtpoint1
MapCtrl.ActiveView.Extent=pEnvelope
MapCtrl.ActiveView.PartialRefreshesriViewGeography,Nothing,Nothing
MapCtrl.ActiveView.Refresh
'EndIf
'
Setpoint1=Nothing
SetpEnvelope=Nothing
EndFunction
'放大地图
PublicFunctionMapZoomOut()
Dimpoint1AsIPoint
'DimlZoomOutKeyAsLong
DimpEnvelopeAsIEnvelope
'lZoomOutKey=GetKeyState(vbKeySubtract)
'IflZoomOutKeyAnd&H8000Then
Setpoint1=Newpoint
point1.x=MapCtrl.Extent.XMin+MapCtrl.Extent.Width/2
point1.y=MapCtrl.Extent.YMin+MapCtrl.Extent.Height/2
SetpEnvelope=MapCtrl.ActiveView.Extent
pEnvelope.Height=pEnvelope.Height*1.5
pEnvelope.Width=pEnvelope.Width*1.5
pEnvelope.CenterAtpoint1
MapCtrl.ActiveView.Extent=pEnvelope
MapCtrl.ActiveView.PartialRefreshesriViewGraphics,Nothing,Nothing
MapCtrl.ActiveView.Refresh
'EndIf
'
Setpoint1=Nothing
SetpEnvelope=Nothing
EndFunction
'下移地图
PublicFunctionMapMoveDown()
Dimpoint1AsIPoint
'DimlDownKeyAsLong
DimpEnvelopeAsIEnvelope
'lDownKey=GetKeyState(vbKeyDown)
'IflDownKeyAnd&H8000Then
Setpoint1=Newpoint
point1.x=MapCtrl.Extent.XMin+MapCtrl.Extent.Width/2
point1.y=MapCtrl.Extent.YMin+MapCtrl.Extent.Height/2-MapCtrl.Extent.Height/5
MapCtrl.CenterAtpoint1
MapCtrl.ActiveView.PartialRefreshesriViewGraphics,Nothing,Nothing
'EndIf
Setpoint1=Nothing
SetpEnvelope=Nothing
EndFunction
'左移地图
PublicFunctionMapMoveLeft()
Dimpoint1AsIPoint
'DimlLeftKeyAsLong
DimpEnvelopeAsIEnvelope
'lLeftKey=GetKeyState(vbKeyLeft)
'IflLeftKeyAnd&H8000Then
Setpoint1=Newpoint
point1.x=MapCtrl.Extent.XMin+MapCtrl.Extent.Width/2-MapCtrl.Extent.Width/5
point1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 地图 管理 设计