Simple basic question

Jun 27, 2012 at 8:39 AM

Hi,

I'm trying to open the basic world shapefile "world_adm0.shp" and set the view, for example, on the Italy.

After opening the shapefile, the zoom level can be set using the property CurrentScale.

Then, how can I move the map automatically to view the Italy?

Below, my code

    Dim sf As MapWinGIS.Shapefile, handle As Long
    
    Set sf = New MapWinGIS.Shapefile
    If sf.Open(FileName) = True Then
       
        handle = MapW.AddLayer(sf, True)
        If handle < 0 Then Exit Function

        MapW.CurrentScale=40

        '???? Move left view to 14 (Longitude) ????

        '???? Move top view to 40 (Latitude) ????
        
    endif

Thank you

Gianluca

Jun 27, 2012 at 4:17 PM
Edited Jul 2, 2012 at 5:13 PM

Hi Gianluca,

I'm a beginner with MapWinGIS myself, so bare with me ...  :-)

I just wrote a routine that seems to accomplish what you have in mind:

Private Sub CenterAt(Map As MapWinGIS.Map, x As Double, y As Double)
Dim e As MapWinGIS.Extents
Dim xMin As Double, yMin As Double, zMin As Double
Dim xMax As Double, yMax As Double, zMax As Double
Dim xC As Double, yC As Double
Dim xOffset As Double, yOffset As Double

Set e = Map.Extents
e.GetBounds xMin, yMin, zMin, xMax, yMax, zMax
xC = xMin + ((xMax - xMin) / 2)  'x value of current center
yC = yMin + ((yMax - yMin) / 2)  'y value of current center
xOffset = x - xC
yOffset = y - yC
e.SetBounds xMin + xOffset, yMin + yOffset, zMin, xMax + xOffset, yMax + yOffset, zMax
Set Map.Extents = e
End Sub

Let me know if this helps.

Wolfgang

Jul 5, 2012 at 1:42 PM

Hello Wolfgang,

it works fine!!!! thank you

Gianluca