You are on page 1of 22

Include "mapbasic.

def"
Include "icons.def"
Include "menu.def"

Declare Sub Main


Declare Sub open
Declare Sub billion
Declare Sub semi_billion
Declare Sub input_billion
Declare Sub input_semibillion
Declare Sub Ye_dialog
'Declare Sub Ye_listbox
Declare Sub listbox_handler
Declare Sub go_to_view
Declare Sub okhandler
Declare Sub okhandler1
Declare Sub okhandlerb
Declare Sub okhandlerb1
Declare Sub Ye_about
Declare Sub billion1
Declare Sub semi_billion1
Declare Sub Ye_buttonpad
Declare SUB Button_Test
Declare SUB Ye_Button1
Declare SUB Ye_Button2
Declare SUB Ye_longitude
Declare SUB billionl
Declare SUB semi_billionl
' *************************
' 建立主菜单
' *************************

Sub Main

Note "声明:"+CHR$(10)+"这只是一个演示程序,实现地图交互查
询!"+CHR$(10)+"程序中会有细节性误差,请见谅!"
onerror goto sub_err
Create MENU "文件" AS
"新建" Calling M_FILE_NEW,
"打开……" Calling open,
"关闭" Calling M_FILE_CLOSE ,
"保存" Calling M_FILE_SAVE,
"另存……" Calling M_FILE_SAVE_COPY_AS ,
"(-",
"页面设置" Calling M_FILE_PAGE_SETUP,
"打印……" Calling M_FILE_PRINT,
"(-",
"退出" Calling M_FILE_EXIT
Create MENU "按比例尺查询" AS
"1 比 1 百万" Calling billion1,
"1 比 50 万" Calling semi_billion1
Create MENU "输入查询" AS
"输入 1 比 1 百万图幅号" Calling input_billion,
"输入 1 比 50 万图幅号" Calling input_semibillion

Create MENU "查询" AS


"按比例尺查询" AS "按比例尺查询",
"输入查询" as "输入查询",
"(-",
"按地区查询" Calling Ye_dialog,
"经纬度查询" Calling Ye_longitude

Create MENU "编辑" AS


"撤消" Calling M_EDIT_UNDO,
"剪切" Calling M_EDIT_CUT,
"复制" Calling M_EDIT_COPY,
"粘贴" Calling M_EDIT_PASTE
Create MENU "对象" AS
"直线" Calling M_FORMAT_PICK_LINE,
''"椭圆" Calling Make_ellipse,
"区域" Calling M_FORMAT_PICK_FILL,
"标识符" Calling M_FORMAT_PICK_SYMBOL,
"标签" Calling M_TOOLS_LABELER
Create MENU "窗口" AS
"新浏览窗口" Calling M_WINDOW_BROWSE,
"建立新窗口" Calling M_WINDOW_MAP,
"窗口设计" Calling M_WINDOW_LAYOUT,
"(-",
"刷新窗口" Calling M_WINDOW_REDRAW,
"窗口平铺" Calling M_WINDOW_TILE
Create MENU "帮助" AS
"主题索引" Calling M_HELP_CONTENTS,
"WEB 页搜索" Calling M_HELP_CONNECT_MIFORUM,
"(-",
"关于" Calling Ye_about

Create Menu Bar AS


"文件","编辑","对象","查询","窗口","帮助"
ALTER BUTTONPAD "绘图" HIDE
ALTER BUTTONPAD "ODBC" HIDE
ALTER BUTTONPAD "主" HIDE
ALTER BUTTONPAD "常用" HIDE

MENU BAR SHOW


Open Table "china"
Open Table "newlayer" As customers
Open Table "newlay" As customers1
Open Table "province"

Map from customers,customers1,province,china


Position (0,0) Units "degree"
Width 75 Units "degree" Height 35 Units "degree"

Set Window FrontWindow() Max ScrollBars Off Autoscroll On


Set Map
CoordSys Earth Projection 1,0
Center(105,36)
Zoom 50 Units "degree"
Preserve Zoom Display Zoom
XY Units "degree" Distance Units "km" Area Units "sq km"
Set Map
Layer province
Selectable On
Display Graphic
Label Line None Position Center Font("宋体",1,16,BLACK)
Pen(1,2,0)
With Character_Name
Parallel On Auto On Overlap On Duplicates On Offset 2
Visibility On

Create ButtonPad "用户" AS


ToolButton
Icon MI_ICON_ARROW
Calling M_TOOLS_SELECTOR
HelpMsg "Select objects for editing\n 选择"

ToolButton
Icon MI_ICON_ZOOM_IN
Calling M_TOOLS_EXPAND
HelpMsg "工具按钮\n 放大"

ToolButton
Icon MI_ICON_ZOOM_OUT
Calling M_TOOLS_SHRINK
HelpMsg "工具按钮\n 缩小"

ToolButton
Icon MI_ICON_ZOOM_QUESTION
HelpMsg "工具按钮\n 问题"

ToolButton
Icon MI_ICON_GRABBER
Calling M_TOOLS_RECENTER
HelpMsg "工具按钮\n 平移"

ToolButton
Icon MI_ICON_INFO
Calling M_TOOLS_PNT_QUERY
HelpMsg "工具按钮\n 信息"

PushButton
Icon MI_ICON_MISC_31
Calling Ye_Button1
HelpMsg "用户开关按钮\n 百万查询"

PushButton
Icon MI_ICON_MAPSYMB_15
Calling Ye_Button2
HelpMsg "用户触发式按钮\n 50 万查询"
Show

Set window FrontWindow() title "一个地图查询的演示示例"


Exit Sub

sub_err:
note Error$()
exit sub

End Sub

' *************************
' 文件菜单
' *************************
Sub Open
Dim s_filename As String
s_filename = FileOpenDlg(".\1200114","","TAB","Open Table")
If s_filename<>"" Then
Run Menu Command 104
Open Table s_filename As 选择表
Map From 选择表
Else
Note "没有文件被选择"
End If
End Sub
'**********************************
'按钮盒
'**********************************
SUB Ye_buttonpad
CREATE BUTTONPAD "用户按钮" AS
ToolButton
Icon MI_ICON_ARROW_3
Cursor MI_CURSOR_CROSSHAIR
Calling Button_Test
id 1001
HelpMsg "工具按钮\n 工具按钮"

PUSHBUTTON
Icon MI_ICON_HELP
Calling Button_Test
id 1002
HelpMsg "触发式按钮\n 触发式按钮"

ToggleButton
Icon MI_ICON_MAPSYMB_16
Calling Button_Test
id 1003
HelpMsg "开关式按钮\n 开关式按钮"
SHOW
FIXED
End Sub
'' ***************************
'' 按钮盒测试
'' ***************************
SUB Button_Test
onerror goto sub_err
Do Case Int(CommandInfo(CMD_INFO_TOOLBTN))
Case 1001
if numwindows()=0 then
NOTE "工具型按钮盒"+CHR$(10)+"请在地图窗口中使用"
exit sub
ElseIf WindowInfo(FrontWindow(),WIN_INFO_TYPE)<>WIN_MAPPER
then
NOTE "工具型按钮盒"+CHR$(10)+"请在地图窗口中使用"
exit sub
else
note "当前光标位置"+CHR$(10)+"x:"+str$
(CommandInfo(CMD_INFO_X))+
Chr$(10)+"y:"+str$(CommandInfo(CMD_INFO_Y))
end if
Case 1002
Note "触发型按钮盒"
Case 1003
Note "按压型按钮盒"
End Case
exit sub

sub_err:
note Error$()
exit sub

End Sub

Sub Ye_Button1
dim cntrl_val as integer
dialog
title "choosing the way of querying"
position 100,100
width 300
height 150
'Control GroupBox
'Position 10 , 5
'Width 90
'Height 90
'Title "choose the way of querying"

Control radiogroup
title "querying according to the clicking position;
querying according to the longitude and the latitude;querying
according to the province name;querying of inputing the number of map
"
value 1
into cntrl_val
ID 2
position 15,20
'Control ListBox
'Position 15 , 50
'Height 80
'Title From Variable var
'Value 1
'into character
'id 1
'Calling listbox_handler

Control OkButton
Title "OK"
Calling okhandlerb
Control CancelButton
Title "Cancel"
End Sub

Sub okhandlerb
If ReadControlValue(2) = 1 Then
Dialog Remove
Call billion1
'''''''''''' act on user's choice.
End If
If ReadControlValue(2) = 2 Then
Dialog Remove
Call Ye_longitude
End If
If ReadControlValue(2) =3 Then
Dialog Remove
Call Ye_dialog
End If
If ReadControlValue(2) =4 Then
Dialog Remove
Call input_billion
End If
End Sub

'Note "按压型按钮盒"

Sub Ye_Button2
dialog
title "choosing the way of querying"
position 100,100
width 300
height 150

Control radiogroup
title "querying according to the clicking position;
querying according to the longitude and the latitude;querying
according to the province name;querying of inputing the number of map
"
value 1
'into cntrl_val
ID 2
position 15,20
'Control ListBox
'Position 15 , 50
'Height 80
'Title From Variable var
'Value 1
'into character
'id 1
'Calling listbox_handler

Control OkButton
Title "OK"
Calling okhandlerb1
Control CancelButton
Title "Cancel"
end sub

Sub okhandlerb1
If ReadControlValue(2) = 1 Then
Dialog Remove
Call semi_billion1
'''''''''''' act on user's choice.
End If
If ReadControlValue(2) = 2 Then
Dialog Remove
Call Ye_longitude
End If
If ReadControlValue(2) =3 Then
Dialog Remove
Call Ye_dialog
End If
If ReadControlValue(2) =4 Then
Dialog Remove
Call input_semibillion
End If

End Sub

' 'Note "触发型按钮盒"

'*********************************
'查询菜单
'*********************************
Sub billion1
Set Map
Layer province
Selectable On
Display Off
call billion
Run Menu Command 1707
end sub

Sub billion

Set Map
Layer customers1
Display Off
'Layer ttt
'Display Off
'Layer sss
'Display Off
Layer customers
Editable On
Selectable On
Display Graphic
dim i,j,x,i1,j1 as Integer
i = 66
j = 16
x = 1
Do While j<53 and x < 200
Do While i<138
create region
1
5(i,j)(i+6,j)(i+6,j+4)(i,j+4)(i,j)
pen makepen(2,2,black)
brush makebrush(1,white,white)
Center ( i+3, j+2 )
i1 = i + 6
j1 = j + 4
dim no, out as string, mid_no as Integer
no = "E31A001001"
mid_no = Mid$(no, 2, 2)
dim m,n,a as Integer
m = i / 6
n = m + mid_no
out = Mid$(no, 1, 1) + n + Mid$(no, 4, 7)
a = m - 10

dim letter,edl as string, l,e,b,c as Integer


letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
l = j/4
e = l + 1
c = l - 4
b = 12 * c
edl = Mid$(letter, e, 1)
Update customers
set MapNO = edl + Mid$(out, 2, 9), ID = x, cenlong = i + 3,
cenlat = j + 2, longitude = Str$(i) + "~" + Str$(i1), latitude = Str$
(j) + "~" + Str$(j1)
Where RowID = a + b
x = x + 1
i=i+6
loop
i = 66
j=j+4
Loop

End Sub

Sub semi_billion1
Set Map
Layer province
Selectable On
Display Off
'Visibility Off
call semi_billion
Run Menu Command 1707
end sub

Sub semi_billion '''以下是按 1:


50,0000 比例尺将图分割并将其各自图幅号写入数据库
Set Map
Layer customers
Selectable On
Display Off
'Layer ttt
'Display Off
'Layer sss
'Display Off
Layer customers1
Editable On
Selectable On
Display Graphic
dim p,q as float
dim w,p1,q1 as integer
w = 1
p = 66
q = 16
Do While q<53 and w < 400 '''循环
语句完成分割图层任务
Do While p<138
create region
1
5(p,q)(p+3,q)(p+3,q+2)(p,q+2)(p,q)
pen makepen(2,2,black)
brush makebrush(1,white,white)
Center ( p+1.5, q+1 )
p1 = p + 3
q1 = q + 2
'''以下是完成写入图幅号的任务
dim num, to,num1, num2 as string, pick_num as Integer
dim letter1,edl1 as string, l1,e1,b1,c1,c2,b2 as Integer
dim m1,n1,a1,a2,m2,n2,l2,e2 as Integer
letter1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
num = "E31B002001"
pick_num = Mid$(num, 2, 2)
num1 = Mid$(num, 5, 3)
num2 = Mid$(num, 8, 3)
m1 = p \ 6 '''反斜杠是取整
的除法
l1 = q \ 4
e1 = l1 + 1
a1 = p mod 6
c2 = q mod 4
a2 = p / 3
l2 = q / 2
n1 = m1 + pick_num
edl1 = Mid$(letter1, e1, 1)
c1 = l2 - 8
m2 = a2 - 21
e2 = 24 * c1

If a1 = 0 and c2 = 0 then '''嵌入循环


语句
to = edl1 + n1 + Mid$(num, 4, 1) + num1 + num2
Update customers1
set MapNO = to,cenlong = p + 1.5, cenlat = q + 1, ID = w,
longitude = Str$(p) + "~" + Str$(p1), latitude = Str$(q) + "~" + Str$
(q1)
Where RowID = m2 + e2
ElseIf a1 = 3 and c2 = 0 then
to = edl1 + n1 + Mid$(num, 4, 1) + num1 + num1
Update customers1
set MapNO = to,cenlong = p + 1.5, cenlat = q + 1, ID = w,
longitude = Str$(p) + "~" + Str$(p1), latitude = Str$(q) + "~" + Str$
(q1)
Where RowID = m2 + e2
ElseIf a1 = 0 and c2 = 2 then
to = edl1 + n1 + Mid$(num, 4, 1) + num2 + num2
Update customers1
set MapNO = to,cenlong = p + 1.5, cenlat = q + 1, ID = w,
longitude = Str$(p) + "~" + Str$(p1), latitude = Str$(q) + "~" + Str$
(q1)
Where RowID = m2 + e2
Else
to = edl1 + n1 + Mid$(num, 4, 1) + num2 + num1
Update customers1
set MapNO = to,cenlong = p + 1.5, cenlat = q + 1, ID =
w,longitude = Str$(p) + "~" + Str$(p1), latitude = Str$(q) + "~" +
Str$(q1)
Where RowID = m2 + e2
End If
w = w + 1
p=p+3
loop
p = 66
q=q+2
Loop

End Sub

Sub input_billion
dim str_val as string
Dialog Title "input billion dialog" ''' "输入查询对话框"
Control StaticText
Title "Input map NO.:"
Position 5,25
Control EditText
Position 65,25
'Width 15
'Height 5
Value "E42A001001"
Into str_val
position 65,25
Control OkButton
Title "OK"
Control CancelButton
Title "Cancel"
If CommandInfo(CMD_INFO_DLG_OK) Then
Call billion
Select MapNO From customers
Where MapNO = str_val into new
'Open table "new1"
'Open table "china"
'Map From new, china
Map From new
'Add map auto layer china
'Position (0,0)
Width 120 Units "mm" Height 110 Units "mm"
Add map auto layer china
'Set Window FrontWindow() Max ScrollBars Off
Autoscroll On
'Set Map
'CoordSys Earth Projection 1,0

'Browse * From new


End If
End sub

Sub input_semibillion
dim str_val as string

Dialog Title "input semibillion dialog" ''' "输入查询对话


框"
Control StaticText
Title "Input map NO.:"
Position 5,25
Control EditText
Position 65,25
'Width 15
'Height 5
Value "E41B001001"
Into str_val
position 65,25
Control OkButton
Title "OK"
Control CancelButton
Title "Cancel"
If CommandInfo(CMD_INFO_DLG_OK) Then
Call semi_billion
Select MapNO From customers1
Where MapNO = str_val into new1
Map From new1
Width 120 Units "mm" Height 110 Units "mm"
Add map auto layer china
'Browse * From new1
'note "1"
End If
end sub

Sub Ye_dialog
Run menu command 1701
Set Map
Layer province
'Selectable On
Display Graphic
'open table "province"
dim cntrl_val as integer
dim var as string
'dim character as object
var = "北京市;天津市;河北省;山西省;内蒙古自治区;辽宁省;吉林省;黑龙江
省;上海市;江苏省;浙江省;安徽省;福建省;江西省;山东省;河南省;湖北省;湖
南省;广东省;广西壮族自治区;海南省;四川省;贵州省;云南省;西藏自治区;陕
西省;甘肃省;青海省;宁夏回族自治区;新疆维吾尔自治区;台湾地区;香港;澳
门"
dialog
title "choosing character_name to query"
position 10,10
width 150
height 150

Control radiogroup
title "1:100,0000;1:50,0000"
value 1
into cntrl_val
ID 2
position 15,20
Control ListBox
Position 15 , 50
Height 40
Title From Variable var
Value 1
'into character
id 1
Calling listbox_handler
Control OkButton
Title "OK"
Calling okhandler
Control CancelButton
Title "Cancel"

End sub

Sub listbox_handler
If CommandInfo(CMD_INFO_DLG_DBL) = TRUE AND ReadControlValue(2) = 1
Then
Dialog Remove
Call go_to_view
'''''''''''' act on user's choice.
Call okhandler
End If
If CommandInfo(CMD_INFO_DLG_DBL) = TRUE AND ReadControlValue(2) = 2
Then
Dialog Remove
Call go_to_view
Call okhandler1
End If
End Sub

dim character as string


sub go_to_view
'DIM I AS INTEGER
'I =
if ReadControlValue(1) = 1 then
character = "北京市"
elseif ReadControlValue(1) = 2 then
character = "天津市"
elseif ReadControlValue(1) = 3 then
character = "河北省"
elseif ReadControlValue(1) = 4 then
character = "山西省"
elseif ReadControlValue(1) = 5 then
character = "内蒙古自治区"
elseif ReadControlValue(1) = 6 then
character = "辽宁省"
elseif ReadControlValue(1) = 7 then
character = "吉林省"
elseif ReadControlValue(1) = 8 then
character = "黑龙江省"
elseif ReadControlValue(1) = 9 then
character = "上海市"
elseif ReadControlValue(1) = 10 then
character = "江苏省"
elseif ReadControlValue(1) = 11 then
character = "浙江省"
elseif ReadControlValue(1) = 12 then
character = "安徽省"
elseif ReadControlValue(1) = 13 then
character = "福建省"
elseif ReadControlValue(1) = 14 then
character = "江西省"
elseif ReadControlValue(1) = 15 then
character = "山东省"
elseif ReadControlValue(1) = 16 then
character = "河南省"
elseif ReadControlValue(1) = 17 then
character = "湖北省"
elseif ReadControlValue(1) = 18 then
character = "湖南省"
elseif ReadControlValue(1) = 19 then
character = "广东省"
elseif ReadControlValue(1) = 20 then
character = "广西壮族自治区"
elseif ReadControlValue(1) = 21 then
character = "海南省"
elseif ReadControlValue(1) = 22 then
character = "四川省"
elseif ReadControlValue(1) = 23 then
character = "贵州省"
elseif ReadControlValue(1) = 24 then
character = "云南省"
elseif ReadControlValue(1) = 25 then
character = "西藏自治区"
elseif ReadControlValue(1) = 26 then
character = "陕西省"
elseif ReadControlValue(1) = 27 then
character = "甘肃省"
elseif ReadControlValue(1) = 28 then
character = "青海省"
elseif ReadControlValue(1) = 29 then
character = "宁夏回族自治区"
elseif ReadControlValue(1) = 30 then
character = "新疆维吾尔自治区"
elseif ReadControlValue(1) = 31 then
character = "台湾地区"
elseif ReadControlValue(1) = 32 then
character = "香港"
else '''ReadControlValue(1) = 33 then
character = "澳门"
'elseif ReadControlValue = 34 then
'character = "宁夏回族自治区"
'elseif ReadControlValue = 35 then
'character = "宁夏回族自治区"
End if

End sub
Sub okhandler
call go_to_view
call billion
Select * From customers, province
Where customers.obj Intersects province.obj And
province.Character_Name = character
into ttt
Map From ttt
Width 170 Units "mm" Height 150 Units "mm"

Add map auto layer province, china, customers, customers1

Set Map
Layer ttt
Selectable On
Display Graphic
Label Line None Position Center Font("宋体",1,16,BLACK)
Pen(1,2,0)
With MapNO
Parallel On Auto On Overlap On Duplicates On Offset 2
Visibility On
Layer customers
Display Off
Layer customers1
Display Off

End sub

Sub okhandler1
call go_to_view
call semi_billion
Select * From customers1, province
Where customers1.obj Intersects province.obj And
province.Character_Name = character
into sss
Map From sss
Width 170 Units "mm" Height 150 Units "mm"

Add map auto layer province, china, customers


Set Map
Layer sss
Selectable On
Display Graphic
Label Line None Position Center Font("宋体",1,16,BLACK)
Pen(1,2,0)
With MapNO
Parallel On Auto On Overlap On Duplicates On Offset 2
Visibility On
Layer customers
Display Off
'Layer customers1
'Display Off
End sub

sub Ye_about
note "介绍:"+CHR$(10)+"这是一个小的查询程序,在有些细节上仍存在一些
问题,望见谅!"+CHR$(10)+"程序中的图幅编号均为新的图幅编
号。"+CHR$(10)+" 作者:陈婷 "
end sub

dim str_val, str_vala as float

SUB Ye_longitude
'dim str_val, str_val1 as string
dim cntrl_val as integer
dialog
title "Input longitude and latitude to query"
position 100,100
width 200
height 150
Control GroupBox
Position 10 , 5 Width 90 Height 50
Title "choose the scale of map"
'Hide
Control radiogroup
Position 15,20
title "1:100,0000;1:50,0000"
value 1
into cntrl_val
ID 2
Control StaticText
Title "Input longitude:"
Position 5,60
Control EditText
Position 5,70
Value "66.00"
Into str_val
Control StaticText
Title "Input latitude:"
Position 90,60
Control EditText
Position 90,70
Value "16.00"
Into str_vala
Control OkButton
Title "OK"
Position 25,95
'Calling okhandler
Control CancelButton
Title "Cancel"
Position 110,95
If CommandInfo(CMD_INFO_DLG_OK) and cntrl_val = 1 Then
call billionl
elseIf CommandInfo(CMD_INFO_DLG_OK) and cntrl_val = 2 Then
call semi_billionl
end if
end sub

SUB billionl
dim long,lat as integer
'dim calu as string
long = str_val \ 1
lat = str_vala \ 1

call billion

Select * From customers


Where long - customers.cenlong < 3 and long - customers.cenlong > -
4 and lat - customers.cenlat < 2 and lat - customers.cenlat > -3
into yyy
Map From yyy
Width 170 Units "mm" Height 150 Units "mm"
Add map auto layer province, china,
customers,customers1

Set Map
Layer yyy
Selectable On
Display Graphic
Label Line None Position Center Font("宋体",1,16,BLACK)
Pen(1,2,0)
With MapNO
Parallel On Auto On Overlap On Duplicates On Offset 2
Visibility On
Layer customers
Display Off
Layer customers1
Display Off
end sub

sub semi_billionl

dim long1,lat1 as integer


'dim long2,lat2 as float

long1 = (str_val / 0.1) \ 1


lat1 = (str_vala / 0.1 ) \ 1
'long2 = long1 / 10
'lat2 = lat1 / 10
call semi_billion

Select * From customers1


Where long1 - (customers1.cenlong * 10) < 15 And long1 -
(customers1.cenlong* 10) > -16 and lat1 - (customers1.cenlat* 10) <
10 and lat1 - (customers1.cenlat* 10) > -11
into aaa
Map From aaa
Width 170 Units "mm" Height 150 Units "mm"
Add map auto layer province, china,
customers1,customers

Set Map
Layer aaa
Selectable On
Display Graphic
Label Line None Position Center Font("宋体",1,16,BLACK)
Pen(1,2,0)
With MapNO
Parallel On Auto On Overlap On Duplicates On Offset 2
Visibility On
Layer customers
Display Off
Layer customers1
Display Off
end sub

You might also like