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_custon_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 "点: x="+x+", y= "+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