Just a small Demo, which demonstrates a Mapping for Latitude/Longitude based Coords into
a Mercator-Projected MapImage (the Background-image of a VB-PictureBox).
What's often preferred (in case one has to handle a lot of "Sub-Objects" or "Sub-Regions"
on such a Container-Control) - is normal VB-Labels or VB-Shape-Objects - usually "inherited"
from an Index-Zero Member of VBs Control-Arrays.
Though Control-Arrays behave a bit clumsy as far as dynamic removing/adding in-between
an existing List of Objects goes... so - that's the reason why I made this post, to break a lance
for a Collection-based approach which takes up and holds the instances of small alternative
ShapeClasses (any of VBs Shape-Like Controls can be replaced by a Class and a few Drawing-Commands).
Here's the complete Class-Code for the alternative Label-Shape which is used in the Demo.
The approach in the Zip below is fast, behaves flickerfree - it reports the current MousePos
in both Coord-Systems (Pixels - and Lat/Lng) - it supports hovered highlighting of the current
Shape-Object under the Cursor - as well as dynamic ToolTips for each of the Shape-Objects separately.
It does that in a quite small CodeBase, so for those who have Label-based approaches out there -
compare carefully if that's not something to switch over - even if it's a bit out of your comfort-zone. ;)
![]()
Mercator.zip
Olaf
a Mercator-Projected MapImage (the Background-image of a VB-PictureBox).
What's often preferred (in case one has to handle a lot of "Sub-Objects" or "Sub-Regions"
on such a Container-Control) - is normal VB-Labels or VB-Shape-Objects - usually "inherited"
from an Index-Zero Member of VBs Control-Arrays.
Though Control-Arrays behave a bit clumsy as far as dynamic removing/adding in-between
an existing List of Objects goes... so - that's the reason why I made this post, to break a lance
for a Collection-based approach which takes up and holds the instances of small alternative
ShapeClasses (any of VBs Shape-Like Controls can be replaced by a Class and a few Drawing-Commands).
Here's the complete Class-Code for the alternative Label-Shape which is used in the Demo.
Code:
Option Explicit
Private Declare Function Rectangle& Lib "gdi32" (ByVal hDC&, ByVal X1&, ByVal Y1&, ByVal X2&, ByVal Y2&)
Public Key As String 'a unique Key for identification (we are added into a Collection under it)
Public Longitude As Single, Latitude As Single 'centerpoint of the Label in Lat/Lng-coords
Public cx As Single, cy As Single 'Pixel-centerpoint of the Label on the PicBox
Public Radius As Long, Color As Long, ToolTipText As String, Hovered As Boolean
Friend Sub Init(Key, cx, cy, Lat, Lng, Optional ByVal Radius& = 3, Optional ByVal Color&, Optional ToolTipText$)
Me.Key = Key
Me.cx = cx: Longitude = Lng
Me.cy = cy: Latitude = Lat
Me.Radius = Radius
Me.Color = Color
Me.ToolTipText = ToolTipText
End Sub
Public Sub DrawOn(Cont As PictureBox)
Cont.ForeColor = vbYellow
Cont.FillColor = IIf(Hovered, vbCyan, Color)
Rectangle Cont.hDC, cx - Radius, cy - Radius, cx + Radius, cy + Radius 'GDI is a bit faster than VBs Line-Method
End Sub
in both Coord-Systems (Pixels - and Lat/Lng) - it supports hovered highlighting of the current
Shape-Object under the Cursor - as well as dynamic ToolTips for each of the Shape-Objects separately.
It does that in a quite small CodeBase, so for those who have Label-based approaches out there -
compare carefully if that's not something to switch over - even if it's a bit out of your comfort-zone. ;)

Mercator.zip
Olaf