Customize the MapWinGIS ActiveX Control

Hello
I would like to add the picture of a wind rose at the top right of the map control. If I add this picture in a layer, the wind rose changes when pan and zoom change.
How add this wind rose in the map control keeping its fixed size and position during user interactions ?

Hello @Gilles

I’ve done something very similar in an old VB6 program. Here’s how I did it:

  1. Set the Shapefiles Volatile property = True. This causes the layer to be drawn after data layers.
  2. Add something like the following to the AxMap.AfterLayers event. This will cause your icon to be drawn after every redraw (pan/zoom/etc). The intent is to relocate your icon to the new upper-right corner of the map. This event occurs after the data layers are drawn, and prior to the Volatile layers.

Assuming that there is only one feature in your layer (being at index 0), and that WIND_VANE_SIZE is a constant, being the size of your image (in pixels), here’s some VB6 code (hopefully you can glean what you need from this):

    ' helper function to convert roughly from pixels to a map distance in the current map units
    Private Function PixelsToDistance(ByVal pMap As MapWinGIS.Map, ByVal pixels As Integer) As Double
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
        ' lower left corner of screen
        pMap.PixelToProj 0, 0, X1, Y1
        ' x pixels to the right
        pMap.PixelToProj pixels, 0, X2, Y2
        ' get the distance (just in the x-direction)
        PixelsToDistance = Abs(X2 - X1)
    End Function

    Private Sub Map_AfterLayers(...)
        Layer = AxMap.Shapefile(windVaneLayerHandle)
        ' update the coordinates to the upper right corner of the map window
        ' this adjustment will affect the drawing of the Icon during the Volatile drawing phase
        Dim newShape As MapWinGIS.shape
        ' create Shape
        Set newShape = New MapWinGIS.shape
        newShape.Create SHP_POINT
        ' the Icon position is based on map projection coordinates
        newShape.AddPoint Map.Extents.xMax - PixelsToDistance(Map, WIND_VANE_SIZE), Map.Extents.yMax - PixelsToDistance(Map, WIND_VANE_SIZE)
        ' do the update
        Layer.StartEditingShapes
        Layer.EditUpdateShape 0, newShape
        Layer..StopEditingShapes
    End Sub

Regards,
Jerry.

1 Like

Thank you very much Jerry for your tip and code.

My object is a picture (png), thus I opened as an image object.
Could I open this picture as a Shapefile as you suggested in the first step ?
Because currently, I can’t resize my picture from MapWinGis functions.

Edit
The answer is probably here :
Layer = AxMap.Shapefile(windVaneLayerHandle)

But I need that the picture is a shapefile. What is the way to convert an image to a shapefile?

In my case, the picture was icon-sized (about 32x32 pixels). I set up a point-based layer, and in the ShapeDrawingOptions

** .PointType = tkPointSymbolType**

** .Picture = [Image reference]**

You can play with other options as well, such as PointSize and even PointRotation

Correction, I meant to say

** .PointType = tkPointSymbolType.ptSymbolPicture**