SaveLayerOptions

Sep 1, 2016 at 5:03 AM
I am not sure if my approach is correct, but I am trying to use
Dim xx = AxMap1.SaveLayerOptions(lh2, "C:\testing\layerstate", True, Nothing)
to store category settings so I can apply the same settings to other layers using
Dim description As String = Nothing
AxMap1.LoadLayerOptions(lh3, layeroptionspath, description)

The savelayeroptions fails. I also tried Dim xx = AxMap1.SaveLayerOptions(lh2, "layerstate", True, Nothing) with same result. No .mwsymb either?? I used as reference the AddCategoryRange.cs from the 4.9 examples...

I have also tried savemapstate with success.

Any pointers appreciated....
Coordinator
Sep 2, 2016 at 9:17 AM
Did you try looking at the error message that might be returned by AxMap1: http://www.mapwindow.org/documentation/mapwingis4.9/class_ax_map.html#ac1273a7f1a6c7a3c2f214bc60abd8fb0
Sep 5, 2016 at 9:41 PM
ok so now I have modified to

Dim xx = AxMap1.SaveLayerOptions(lh2, "C:\testing\layerstate", True, Nothing)
MsgBox(xx.ToString & " - " & AxMap1.LastErrorCode & vbCrLf & AxMap1.get_ErrorMsg(AxMap1.LastErrorCode))
which return false - 0 NoError

Total code is

Structure ll
    Dim lat As Double
    Dim lon As Double
End Structure

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim numlayers = AxMap1.NumLayers
    AxMap1.LockWindow(tkLockMode.lmLock)
    Try
        Dim lh As Integer = -1
        Dim sfbp As New Shapefile()
        If sfbp.Open("E:\my_bpoly\my_bpoly_region.shp", Nothing) Then
            lh = AxMap1.AddLayer(sfbp, True)
        Else
            MsgBox(sfbp.ErrorMsg(sfbp.LastErrorCode))
        End If

        If lh <> -1 Then
            AxMap1.set_LayerName(lh, "bp")



            Dim FillColor As UInt32
            Dim LineColor As UInt32
            Dim LineWidth As Single

            AxMap1.set_ShapeLayerDrawFill(lh, True)
            FillColor = Convert.ToUInt32(RGB(Color.SpringGreen.R, Color.SpringGreen.G, Color.SpringGreen.B))
            LineColor = Convert.ToUInt32(RGB(0, 0, 255))
            LineWidth = 1.0
            AxMap1.set_ShapeLayerFillColor(lh, FillColor)
            AxMap1.set_ShapeLayerLineColor(lh, LineColor)
            AxMap1.set_ShapeLayerLineWidth(lh, LineWidth)


        End If
    Finally
        AxMap1.LockWindow(tkLockMode.lmUnlock)
        Debug.Print("Layers added to the map: " & AxMap1.NumLayers.ToString)
    End Try

    Dim sf = New Shapefile()

    Dim result = sf.CreateNew("C:\testing\cattest.shp", ShpfileType.SHP_POINT)

    Dim field As New MapWinGIS.Field
    field.Name = "Type"
    field.Width = 4
    field.Type = MapWinGIS.FieldType.STRING_FIELD
    Dim success = sf.EditInsertField(field, 0)



    'sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsCircle)

    'Dim options = sf.DefaultDrawingOptions
    'options.PointType = tkPointSymbolType.ptSymbolPicture
    'Dim ico As New MapWinGIS.Image
    'ico.Open("E:\version_x\mwgworkingagain\file_jpg.png")

    'options.Picture = ico
    sf.CollisionMode = tkCollisionMode.AllowCollisions

    Dim pointts(4) As ll
    pointts(0).lat = 145.2401681
    pointts(0).lon = -15.47420602
    pointts(1).lat = 145.2428984
    pointts(1).lon = -15.47490434
    pointts(2).lat = 145.2422367
    pointts(2).lon = -15.47732303
    pointts(3).lat = 145.2414149
    pointts(3).lon = -15.47763495
    pointts(4).lat = 145.2393785
    pointts(4).lon = -15.47711322

    Dim res As Boolean = False

    For i = 0 To 4
        res = False

        Dim pnt = New Point()
        Dim ddlat = pointts(i).lat
        Dim ddlon = pointts(i).lon
        Dim projx As Double = 0.0
        Dim projy As Double = 0.0

        AxMap1.DegreesToProj(ddlat, ddlon, projx, projy)

        pnt.x = projx
        pnt.y = projy

        Dim shp = New Shape()
        shp.Create(ShpfileType.SHP_POINT)

        res = shp.InsertPoint(pnt, 0)

        res = False
        res = sf.EditInsertShape(shp, i)
    Next

    success = sf.EditCellValue(0, sf.NumShapes - 1, "cp10")
    success = sf.EditCellValue(0, sf.NumShapes - 2, "xp20")
    success = sf.EditCellValue(0, sf.NumShapes - 3, "cp10")
    success = sf.EditCellValue(0, sf.NumShapes - 4, "xp20")
    success = sf.EditCellValue(0, sf.NumShapes - 5, "cp10")

    Dim val0 = sf.CellValue(0, 0)
    Dim val1 = sf.CellValue(0, 1)
    Dim val2 = sf.CellValue(0, 2)
    Dim val3 = sf.CellValue(0, 3)
    Dim val4 = sf.CellValue(0, 4)

    '// adds shapefile to the map
    Dim lh2 = AxMap1.AddLayer(sf, True)



    Dim ct = sf.Categories.Add("cp10")
    ct.Expression = "[Type] = ""cp10"""
    Dim opt = ct.DrawingOptions
    opt.PointType = tkPointSymbolType.ptSymbolStandard
    opt.PointShape = tkPointShapeType.ptShapeCircle
    opt.FillColor = Convert.ToUInt32(RGB(Color.White.R, Color.White.G, Color.White.B))
    opt.PointSize = 10


    ct = sf.Categories.Add("xp20")
    ct.Expression = "[Type] = ""xp20"""
    opt = ct.DrawingOptions
    opt.PointType = tkPointSymbolType.ptSymbolStandard
    opt.PointShape = tkPointShapeType.ptShapeCross
    opt.FillColor = Convert.ToUInt32(RGB(Color.Red.R, Color.Red.G, Color.Red.B))
    opt.PointSize = 10

    sf.DefaultDrawingOptions.Visible = False 
    sf.Categories.ApplyExpressions()

    AxMap1.Redraw()

    Dim aa = AxMap1.SaveMapState("C:\testing\mapstate", True, True) ' this works
    Dim xx = AxMap1.SaveLayerOptions(lh2, "C:\testing\layerstate", True, Nothing) ' this does not work ???
    MsgBox(xx.ToString & " - " & AxMap1.LastErrorCode & vbCrLf & AxMap1.get_ErrorMsg(AxMap1.LastErrorCode))