代码名称:用dialog函数打开增加一个新的地图窗口

作者/收集者:zixing

开发环境:MapBasic

代码:

include "mapbasic.def"
declare sub main
declare sub newmap
declare sub addlayer
sub main
create menu "tool" as 
"(-",
"new map...." calling newmap,
"(-",
"add map...." calling addlayer
alter menu bar add "tool"
end sub
sub newmap
dim filename as string
dim tablename as string
filename=fileopendlg("","","tab","打开表")
if filename="" then
exit sub
else
tablename=pathtotablename$(filename)
open table tablename
map from tablename
end if 
end sub


sub addlayer
dim map_win_id as integer
dim filename as string
dim tablename as string
onerror goto error_trap
map_win_id=frontwindow()
if windowinfo(map_win_id,win_info_type) <> win_mapper then
note "只能在地图窗口增加图层!"
exit sub
end if
filename=fileopendlg("","","tab","打开表")
if filename="" then
exit sub
else tablename=pathtotablename$(filename)
open table tablename
end if
add map   '是加图层的语句,
window map_win_id
auto         '使用了此关键字mapinfo将自动地把该图层定位在一系列图层间的合适位置。没有则新加如的图层放置在地图的顶部。
layer tablename   '通过table参数指定加入到地图窗口中的一个或多个已经打开的表。
done:
exit sub
error_trap:
note error$()
resume done
end sub