如何用mapbasic编写地图对象双击事件?
chenjianwei1981
2006年09月17日 21:21:31
来自于铁路工程
只看楼主

各位高手,小弟不才,请教大侠们: 1.mapinfo地图上有个村庄,用矩形表示,可以说是个块,哈. 2.我想用mapbasic编程,双击此矩形,然后弹出消息窗口. 3.消息窗口中会显示这个村庄的属性数据,如村的名称啊,距离线路中线的距离啊等等. 4.编好后,我还想放在用VB+MAPINFO做的程序中去运行.如何实现呢?


各位高手,小弟不才,请教大侠们:
1.mapinfo地图上有个村庄,用矩形表示,可以说是个块,哈.
2.我想用mapbasic编程,双击此矩形,然后弹出消息窗口.
3.消息窗口中会显示这个村庄的属性数据,如村的名称啊,距离线路中线的距离啊等等.
4.编好后,我还想放在用VB+MAPINFO做的程序中去运行.

如何实现呢?

免费打赏
chenjianwei1981
2006年09月19日 15:38:58
2楼
今天自己往前前进了一小步:可以调用表中的数据了,下一步是如何和地图对象结合起来。

以下是代码
回复
chenjianwei1981
2006年09月19日 15:39:08
3楼
include "mapbasic.def"
declare sub main
declare sub toolhandler

sub main
note "请选择mapinfo中的某一个工具,然后在地图中单击"
+"便可以在消息框中显示该处的坐标位置"
end sub

sub toolhandler
dim psum as float,i as integer
open table "E:\编程开发\GIS\数据\MAP_DATA\WORLD\WORLD"

onerror goto ERROR_TRAP

if windowinfo(frontwindow(),win_info_type)=win_mapper then
fetch first from world
i=1
do while i<=10
if world.country="Andorra" then
psum=psum+world.Pop_1994
exit do
end if
fetch next from world
i=i+1
loop

open window message
print psum
end if

done:
exit sub
ERROR_TRAP:
note error$()
resume done

end sub

回复
chenjianwei1981
2006年09月20日 19:04:37
4楼
今天又前进了一步
解决了mapbasic中的问题
不过怎么跟VB接口没有思路
回复
chenjianwei1981
2006年09月20日 19:05:02
5楼
include "mapbasic.def"
include "icons.def"

declare sub main
declare sub tool_sub

sub main
create buttonpad "查询工具" as
toolbutton calling tool_sub ID 1
icon MI_ICON_ARROW
Cursor MI_CURSOR_ARROW
drawmode DM_CUstom_POINT
helpmsg "在地图窗口中单击\n单击一位置"
separator
toolbutton calling tool_sub ID 2
icon MI_ICON_SEARCH_RECT
cursor MI_CURSOR_FINGER_LEFT
drawmode DM_CUstom_RECT
helpmsg "在地图窗口中绘制一矩形\n绘制一矩形"
width 3
print "位置查询程序现已运行!"
print "从查询工具中选择一工具!"
end sub

sub tool_sub
’当用户使用了查询工具中任一自定义按钮时,调用该子过程
dim x,y,x2,y2 as float
dim i,i_found,i_row_id,i_win_id as integer
dim s_table as alias

onerror goto ERROR_TRAP

i_win_id=frontwindow()
if windowinfo(i_win_id,WIN_INFO_TYPE)<>WIN_MAPPER then
note "这个工具只能在地图窗口中使用!"
exit sub
end if
’判断用户单击得起点
x=commandinfo(cmd_info_x)
y=commandinfo(cmd_info_y)

if commandinfo(cmd_info_toolbtn)=1 then
’用户使用的是点查询工具
’判断点查询选择的对象数目
i_found=searchpoint(i_win_id,x,y)
else
’用户使用的是矩形查询工具
’判断在矩形中有多少个对象
x2=commandinfo(cmd_info_x2)
y2=commandinfo(cmd_info_y2)
i_found=searchrect(i_win_id,x,y,x2,y2)
end if

if i_found=0 then
beep ’没有找到任何对象
else
print chr$(12)
if commandinfo(cmd_info_toolbtn)=2 then
print "矩形:x1="+x+",y1="+y
print "x2="+x2+",y2="+y2
else
print "点:x1="+x+",y1="+y
end if

’处理查询结果
for i=1 to i_found
’得到当前对象所在表的名称
s_table=searchinfo(i,search_info_table)
’得到当前对象的行号
i_row_id=searchinfo(i,search_info_row)
if left$(s_table,8)="cosmetic" then
print "对象在装饰图层中!"
else
fetch rec i_row_id from s_table
s_table=s_table+".col1"
print s_table
end if
next
end if

done:
exit sub
ERROR_TRAP:
note error$()
resume done

end sub

回复
chenjianwei1981
2006年09月23日 12:01:21
6楼
可以调用消息窗口了
不过数据传输还有待解决
回复

相关推荐

APP内打开