Posts: 2
Joined: Fri Mar 26, 2010 9:32 pm
Location: United Kingdom

Map.Close not releasing/closing maplib file?

Fri Jun 18, 2010 7:08 pm

I'm trying to add map add and re-scale functionality to our VB/ActiveX application that uses GPSTools. I can create a new maplib (or add a map to an existing maplib) using zMapLib and set the scaling and save to maplib.

However, if I have opened (Map.Open) and subsequently closed (Map.Close) a maplib in the GPSViewXP component, zMapLib is not able to save to that maplib file. I get a "Could not delete file" error when trying to save to the maplib. If I remove the code related to opening/closing the maplib in the GPSViewXP component, zMapLib works correctly.

Am I doing something wrong (or missing something) or is there possibly a bug with GPSViewXP not closing the maplib file?

GPSTools version is

Code: Select all

    'Create new (uncalibrated) chart from bitmap image
    Set objzMaplib = New zMapLib
    Dim objzMapData As zMapData
    Dim intMapNum As Integer
    Dim strNewMapName As String
    strNewMapName = "test1"
    'open an existing maplib
    objzMaplib.Open (App.Path & "\test.maplib")
    'create new map data in maplib from an image file. Ensure new map name is unique within maplib
    Set objzMapData = objzMaplib.NewMapData(App.Path & "\chart.png", strNewMapName)
    'preset the map scale to arbitrary huge extents to allow lat/lon pos-dependent operations
    'top-left pixel
    Dim point1 As New zPoint       'the z prefix denotes an object in the zMapLib class (zPoint is zMapLib's equivalent to Point)
    point1.X = 0
    point1.Y = 0
    Dim pos1 As New zPosition
    pos1.Datum = 1
    pos1.Longitude = -90
    pos1.Latitude = 60
    'top-right pixel
    Dim point2 As New zPoint
    Set point2 = objzMapData.Size
    point2.Y = 0
    Dim pos2 As New zPosition
    pos2.Datum = 1
    pos2.Longitude = 90
    pos2.Latitude = 60
    'bottom-right pixel
    Dim point3 As New zPoint
    Set point3 = objzMapData.Size
    Dim pos3 As New zPosition
    pos3.Datum = 1
    pos3.Longitude = 90
    pos3.Latitude = -60
    'set map scale using defined pos/point pairs
    objzMapData.SetScale pos1, point1, pos2, point2, pos3, point3
    'and save to maplib file
    objzMaplib.Save App.Path & "\test.MapLib"
    objzMaplib.Close ' Don't forget to close the file


    'load and re-scale a maplib by picking 3 points on a viewed map
    Dim objLib As MapLib
    Dim objMapData As MapData
    'Open a MapLib in the Map control
    Map1.Open App.Path & "\test.MapLib"
    Set objLib = Map1.MapLib
    'get the newly added map data from maplib
    Set objMapData = objLib.GetMapDataByName(strNewMapName)

    'set map scale using predefined points
    'we would normally allow user to pick 3 points on chart window but this demo just uses pre-set values
    'need a Point object (as opposed to zPoint) to get points from map. These points are transferred to zPoints to do the scaling
    Dim refpoint As New Point
    'arrays of 3 points and 3 positions for map scaling
    Dim zPointScaling(3) As New zPoint
    Dim zPosScaling(3) As New zPosition
    'top-left pixel
    zPointScaling(1).X = 0
    zPointScaling(1).Y = 0
    zPosScaling(1).Datum = 1
    zPosScaling(1).Longitude = -20
    zPosScaling(1).Latitude = 20
    'top-right pixel
    Set refpoint = objMapData.Size
    zPointScaling(2).X = refpoint.X
    zPointScaling(2).Y = refpoint.Y
    zPointScaling(2).Y = 0
    zPosScaling(2).Datum = 1
    zPosScaling(2).Longitude = 20
    zPosScaling(2).Latitude = 20
    'bottom-right pixel
    Set refpoint = objMapData.Size
    zPointScaling(3).X = refpoint.X
    zPointScaling(3).Y = refpoint.Y
    zPosScaling(3).Datum = 1
    zPosScaling(3).Longitude = 20
    zPosScaling(3).Latitude = -20
    'close map so we can load it into zmaplib and modify, then re-open the re-scaled version in Map1 control
    'NB Map1.Close does NOT seem to close the maplib file - cannot subsequently save to the same file using zMapLib...
    'load the new map in zMapLib (can't save in normal MapLib, but can only view and choose points to set scale in normal MapLib)
    'Dim WithEvents objzMaplib As zMapLib (as global at top of code)
    Set objzMaplib = New zMapLib
    Dim objNewzMapData As zMapData
    objzMaplib.Open App.Path & "\test.MapLib"
    Set objNewzMapData = objzMaplib.GetMapDataByName(strNewMapName)
    'set map scale using defined pos/point pairs
    objNewzMapData.SetScale zPosScaling(1), zPointScaling(1), zPosScaling(2), zPointScaling(2), zPosScaling(3), zPointScaling(3)
    'can't save to an open maplib?? Maplib held open by Map1 (GPSView)??
    objzMaplib.Save App.Path & "\test.MapLib"
    objzMaplib.Close ' Don't forget to close the file

Return to “GpsTools”