MapWinGIS:SampleCode-VB Net:ChangePointTypeByZoom

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Use Custom Icons when Zoomed In

 '   Example Code Created by Ted Dunsford on April 25, 2008
 '   This example illustrates how to change a point type
 '   between an icon and a simple point based on the zoom level.
 '
 Public Class Form1
 
     Dim layer As Integer
     Dim sf As MapWinGIS.Shapefile
     Dim img As MapWinGIS.Image
 
     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
 
         ' Dimension a new shapefile
         sf = New MapWinGIS.Shapefile
 
         ' Open the shapfile
         Dim ofd As New OpenFileDialog
         ofd.Filter = "Shapefiles (*.shp) |*.shp"
         If Not ofd.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then Return
         sf.Open(ofd.FileName)
 
         ' Add the shapefile data to the map so that you can see it
         layer = AxMap1.AddLayer(sf, True)
         AxMap1.set_ShapeLayerPointSize(layer, 10)
         If Not img Is Nothing Then SetIcons()
         UpdateIcon()
     End Sub
 
     Private Sub AxMap1_ExtentsChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMap1.ExtentsChanged
         UpdateIcon()
     End Sub
 
     Private Sub UpdateIcon()
         ' Test the extents.  The value used here of 1000 was appropriate for the projection I was using.
         ' If you were using latitude/longitude, you would probably want a number more like .5 or smaller.
 
         Dim ext As MapWinGIS.Extents = AxMap1.Extents
         If (ext.xMax - ext.xMin < 1000) Then
             ' we are zoomed in
             If AxMap1.get_ShapeLayerPointType(layer) = MapWinGIS.tkPointType.ptSquare Then
                 Dim shp As Integer
                 For shp = 0 To sf.NumShapes - 1
                     ' Set each shape to match the image index from the list
                     AxMap1.set_ShapePointType(layer, shp, MapWinGIS.tkPointType.ptImageList)
                     ' I use 0 here, but as you add more images, this number identifies the image you want
                     AxMap1.set_ShapePointImageListID(layer, shp, 0)
                 Next shp
 
             End If
             ' Setting to size 1 will use the unscaled size of the image
             AxMap1.set_ShapeLayerPointSize(layer, 1)
         Else
             AxMap1.set_ShapeLayerPointType(layer, MapWinGIS.tkPointType.ptSquare)
             ' Setting hte size to 10 means each point will be 10 pixels wide & tall
             AxMap1.set_ShapeLayerPointSize(layer, 10)
         End If
     End Sub
 
     ' When a new image is loaded for the 'detailed' car, set the icons on an existing shapefile if it is loaded.
     Private Sub LoadImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadImageToolStripMenuItem.Click
         Dim ofd As New OpenFileDialog
         img = New MapWinGIS.Image
         ofd.Filter = img.CdlgFilter
         If Not ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then Return
 
         img.Open(ofd.FileName, MapWinGIS.ImageType.USE_FILE_EXTENSION, True)
 
         If Not sf Is Nothing Then
 
             SetIcons()
         End If
 
     End Sub
 
     ' Iterates through the points and assigns the integer index of the image to associate it with
     Private Sub SetIcons()
         AxMap1.set_UDPointImageListAdd(layer, img)
         Dim shp As Integer
         For shp = 0 To sf.NumShapes - 1
             AxMap1.set_ShapePointType(layer, shp, MapWinGIS.tkPointType.ptImageList)
             AxMap1.set_ShapePointImageListID(layer, shp, 0)
 
         Next shp
 
         UpdateIcon()
     End Sub
 End Class

Posted by Ted Dunsford 4/25/2008

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-VB_Net:ChangePointTypeByZoom"

This page has been accessed 1,919 times. This page was last modified on 25 April 2008, at 22:59.