📄 application.asp
字号:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following constants define the maximum and minimum zoom levels
' (the distance across the middle of the map) that we want to assign
' for this application.
Const cMaximumZoom = 800 ' allow user to zoom out to 50,000 Meters.
Const cMinimumZoom = 0.1 ' allow user to zoom in to 0.1 Meters.
Const cInitialCenterX = 118.8
Const cInitialCenterY = 31.4
Const cInitialZoom = 200
'''''''''''''''''''''''''''''''''''''''
' SetupMappingEngine - Obtain a map object by calling InitMapEngine.
'
Sub SetupMappingEngine()
Dim nItemType
Dim strItemLayers
Dim bResult
' If this session already has a Map object, then exit.
If Not (Session(cMapXObject) Is Nothing) Then
Exit Sub
End If
' We are going to obtain a map object now; so this seems
' like a good time to initialize the error system.
InitErrorSystem ""
' Initialize the mapping engine.
bResult = InitMapEngine(OBTAIN_FROM_BROKER, Session(SESN_MAPNAME))
' Set the map object's default properties, if we obtained a map object.
If Not (Session(cMapXObject) Is Nothing) Then
bResult = SetMapAutoRedraw(False)
'''''''''''''''''''''''''''''''''''''''
' If the method is POST then the user already had a session, but it
' expired. A new session is starting in response to a form being
' submitted, so we need to try and rebuild the map to where the
' user left off by reading information stored in the form.
'
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
RebuildMap
End If
'设置图片大小
bResult = SetMapSize(980, 889)
'设置图片标题
bResult = SetMapTitleText("")
bResult = SetMapAutoRedraw(True)
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' RebuildMap - Rebuilds the map engine by reading the form fields
' and setting as many map properties and globals as possible. Called
' after a session timeout.
'
Sub RebuildMap()
Dim fCenterX
Dim fCenterY
Dim fCurrentCenterX
Dim fCurrentCenterY
Dim fZoom
Dim nItemType
Dim strItemLayers
Dim bResult
' Re-apply the selected Map tool.
If Request.Form(FRM_TOOL).Count = 1 Then
Session(SESN_TOOL) = Request.Form(FRM_TOOL)
End If
' Set the map pan/zoom to the last known settings.
If Request.Form(FRM_CX).Count = 1 Or Request.Form(FRM_CY).Count = 1 Then
' Note the map's current center x/y
bResult = GetMapCenter(fCurrentCenterX, fCurrentCenterY)
fCenterX = fCurrentCenterX
fCenterY = fCurrentCenterY
' Use the Center X from the form fields, if appropriate
If Request.Form(FRM_CX).Count = 1 Then
fCenterX = Request.Form(FRM_CX)
If Not IsNumeric(fCenterX) Then
fCenterX = fCurrentCenterX
End If
End If
' Use the Center Y from the form fields, if appropriate
If Request.Form(FRM_CY).Count = 1 Then
fCenterY = Request.Form(FRM_CY)
If Not IsNumeric(fCenterY) Then
fCenterY = fCurrentCenterY
End If
End If
' Re-center the map
bResult = SetMapCenter(fCenterX, fCenterY)
End If
If Request.Form(FRM_LAST_ZOOM).Count = 1 Then
fZoom = Request.Form(FRM_LAST_ZOOM)
If IsNumeric(fZoom) Then
bResult = SetMapZoom(fZoom)
End If
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function PrepareMapEngine()
Dim bRC
On Error Resume Next
SetupMappingEngine
If Not (Session(cMapXObject) Is Nothing) Then
'VERY IMPORTANT! We need to set the state of our MapX engine. Since
'it was just given to us from a shared pool, it is in an unknown state.
'In this sample we will restore Center and Zoom. Your application may
'need to save and restore other settings as well.
'
'However, if this is the first time that this user is creating a
'map, then we will set the map to a default view, because there are
'no "previous" settings to return to.
'
If Session(SESN_FIRST_ACCESS) = True Then
'This is the first use of the mapping engine during this ASP session.
'We may need to initialize the starting location.
'
'However, if we detect that a form submit is what caused
'this execution of MAPPAGE.ASP, then it means that the user
'displayed a map, then the user's ASP session timed out, and
'THEN the user clicked again. In this case, we can
'skip setting the map to its default view, because
'the SetupMappingEngine call already restored the
'map's view to what it was before the timeout.
'
If Request.ServerVariables("REQUEST_METHOD") <> "POST" Then
' Set the map to default view (show entire world).
bRC = SetMapCenterAndZoomTo(cInitialCenterX,cInitialCenterY,cInitialZoom)
End If
Session(SESN_FIRST_ACCESS) = False
Else
'This is not the first map the user has seen; so we should call
'RestoreState to return the map to the state it was in before.
'
'The RestoreState() method currently only saves CenterX, CenterY, and
'Zoom Properties. Any other Map Properties or settings that your application
'needs should be preserved in Session variables between pages and restored here.
'The FreeMapEngine() function is a good place to save Map Properties into
'Session variables. In future releases of MapXtreme, the SaveSettings() and
'RestoreSettings() methods of MapXcourier will be enhanced to offer more
'state maintainance functionality.
Session(cMapXCourierObject).RestoreState
End If
Else
' The map object does not exist, so return False and indicate an error.
SetError "PrepareMapEngine", Session(cMapXCourierObject).GetErrorNum, Session(cMapXCourierObject).GetErrorDesc
PrepareMapEngine = False
Exit Function
End If
If Err Then
PrepareMapEngine = False
If Not HaveError() Then
SetError "PrepareMapEngine", Err.number, Err.Description
End If
Else
PrepareMapEngine = True
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FreeMapEngine()
Dim bRC
On Error Resume Next
'VERY IMPORTANT! Before we give our instance of MapX back to the shared pool,
'We need to save any settings that we need to restore it's state on the next
'Map request. The SaveStateMethod will preserve CenterX, CenterY and Zoom.
'Any other settings that your application needs should be stored in
'Global variables at this time.
'
Session(cMapXCourierObject).SaveState
'Now we can free up MapX and send it back to the shared pool
If Not UnInitMapEngine(RETURN_TO_BROKER) Then
SetError "FreeMapEngine", Session(cMapXCourierObject).GetErrorNum, Session(cMapXCourierObject).GetErrorDesc
FreeMapEngine = False
Exit Function
End If
If Err Then
FreeMapEngine = False
If Not HaveError() Then
SetError "FreeMapEngine", Err.number, Err.Description
End If
Else
FreeMapEngine = True
End If
End Function
</SCRIPT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -