[mapguide-users] Exception when setting layer Visibility

frieda ruslankutowoj at web.de
Wed Feb 6 01:04:39 PST 2019


Hello, I need help to understand the purpose of the following codeblock.

I have MapGuide Server 2.5.2 Final installed on IIS in Windows 10 64 bit.
The function is for printing the map in pdf or word document.
----------------------------------------------------------------------------------------------------------------------------------------------
Private Sub printButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles btnPrint.Click

        Dim objUtilties As New
CCommonFunctions(Request.ServerVariables("SCRIPT_NAME"))

        If Not m_objMGC.IsPlotBoxDrawn(m_objMapGuide) Then
            AddJavaScript("Print", "alert('No Plotbox');")
            Exit Sub
        End If

        Dim changedLayers As ArrayList = PrepareMapForPrinting()

        Try
            Scale = DetermineScale(Me.cboScale.SelectedValue)
            Dim ViewScale As Double = Scale

            If Me.cboScale.SelectedValue.Contains("current") Then
                Scale /= ScaleDistortion
            End If

            Dim DPI As Integer =
g_objObjHandl.NZ_Int(Me.cboDPI.SelectedValue)

            Dim objMapDraw As New MapGuideDrawing(m_objUser,
m_objUser.Project.DocumentFolder)
            objMapDraw.DPI = DPI
            objMapDraw.RegKeyPath = Application("APP_REG_PATH")

            Dim MapSize() As Double =
objMapDraw.DetermineMapExtent(Me.cboPageSize.SelectedValue,
Me.rbQuer.Checked, 0.90000000000000002)

            objMapDraw.InitializeMapImage(m_objMapGuide,
m_objMGC.GetPlotBox(m_objMapGuide, "(TYPE=1)", False), MapSize(0),
MapSize(1))
            objMapDraw.InitializeLegendImage(m_objMapGuide,
Session("PRINTOPT")(0))
            Dim MergedImage As Drawing.Image =
objMapDraw.MergeImages(m_objMapGuide.Map.Name, ViewScale,
g_objObjHandl.NZ_Boolean(Me.hdfLegend.Value), Session("PRINTOPT"))
            Dim fileDir As String = objMapDraw.CreateDocument(m_objMapGuide,
MergedImage, Me.cboPageSize.SelectedValue, Me.rbQuer.Checked,
Me.cboDownload.SelectedValue)

            objUtilties.DownloadFile(Me.Form, fileDir)

        Catch ex As Exception
            m_objUser.WriteError(ex, "")
            AddJavaScript("PrintError", "alert('" & ex.Message & "');")
        Finally
            If changedLayers Is Nothing = False Then
RepairMapAfterPrinting(changedLayers)
        End Try
    End Sub
----------------------------------------------------------------------------------------------------------------------------------
I get an Exception in the "RepairMapAfterPrinting"
----------------------------------------------------------------------------------------------------------------------------------
Sub RepairMapAfterPrinting(ByVal pv_arrChangedLayers As ArrayList)

        Dim Visibility As Boolean
        Dim objMapGuide As FRIEDAcom.MapGuide = CType(m_objMapGuide,
FRIEDAcom.MapGuide)

        objMapGuide.ConnectMapGuide(objMapGuide.SessionID,
Session("GRAPHIC").Project)

        For Each layer As OSGeo.MapGuide.MgLayer In pv_arrChangedLayers
            Visibility = layer.IsVisible()
            layer.SetVisible(Not Visibility)
        Next
End Sub
-----------------------------------------------------------------------------------------------------------------------------------
The Exception occurs here: Visibility = layer.IsVisible(). When I change it
to Visibility = layer.GetVisible(), the exception occurs in
layer.SetVisible(Not Visibility).
It's not my code and I don't really understand what's going on.

The Exception:
OSGeo.MapGuide.SWIGExceptionHelper.ThrowCustomException(String className,
IntPtr cptr) +494
   OSGeo.MapGuide.PlatformBaseApiPINVOKE.MgLayerBase_SetVisible(IntPtr
jarg1, Boolean jarg2) +0
   OSGeo.MapGuide.MgLayerBase.SetVisible(Boolean visible) +13



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html


More information about the mapguide-users mailing list