Rotating all labels of a layer

Hello,

I know of course how to AddLabel with rotation, but once drawn can I change the angle without clearing them all and redraw ?

This code I tried in VB6 does not produce any result (even lbl.text returns empty):

Public Sub RotateAllLabels(ByVal azimuth As Double)
Dim hndl As Long
Dim sf As New MapWinGIS.Shapefile
Dim lbl As New MapWinGIS.Label
Dim i As Long
hndl = Map1.LayerHandle(gHndlGuidance)
Set sf = Map1.Shapefile(hndl)
With Map1
.LockWindow lmLock
For i = 0 To UBound(arrOpl)
Set lbl = sf.Labels.Label(i, 0)
If Not lbl Is Nothing Then
lbl.Rotation = azimuth
lbl.x = lbl.x + 10#
lbl.y = lbl.y + 5#
.Redraw
End If
DoEvents
Next i
.LockWindow lmUnlock
End With
End Sub

Is there another way to achieve this goal ?
Thank you,

Hello Bob.

I loaded your code into a test app (with just a couple changes necessary) and I was able to rotate the labels (this is an Address point layer). Here’s the result:

Here’s my code, in VB.NET.
a. I changed the handle to get my layer (the zeroeth layer), and
b. I didn’t have the array named arrOpl, so I simply iterated all of the Shapes in my file, rotating the labels.
Where is it breaking down on your end?
Is the array (arrOpl) synchronized with Shapes in the layer that have Labels?
Is it not able to fetch the Labels in the first place, or just not able to rotate them?

    Dim azimuth As Double = 20
    Dim hndl As Long
    Dim sf As New MapWinGIS.Shapefile
    Dim lbl As New MapWinGIS.Label
    Dim i As Long
    hndl = AxMap1.get_LayerHandle(0) ' (gHndlGuidance)
    sf = AxMap1.get_Shapefile(hndl)
    With AxMap1
        .LockWindow(tkLockMode.lmLock)
        For i = 0 To sf.NumShapes - 1 ' UBound(arrOpl)
            lbl = sf.Labels.Label(i, 0)
            If Not lbl Is Nothing Then
                lbl.Rotation = azimuth
                lbl.x = lbl.x + 10.0#
                lbl.y = lbl.y + 5.0#
                .Redraw()
            End If
            Application.DoEvents()
        Next i
        .LockWindow(tkLockMode.lmUnlock)
    End With

Regards,
Jerry.

Hello Jerry,
I thought that was just not working, so I was already working on alternative solutions…
And now it works for me too, all I did was cleaning-up my code into subs & functions after I posted this topic
I don’t need the lbl.x & lbl.y offset, it was just here for debug. I had to get rid of it, as my labels were drawn 10° (1000 km) from where I was (scale of 30 m) - probably the reason why I missed it, two problems in one (Don’t know why it worked for you, your scale is at 400 m, must be a reason for it)
For information, I rotated 120000 labels in 0.99 sec, not bad as I need to do it only on azimuth changed.
Thank you again, hope I did not waste your time much, sure next time as I gained confidence in the OCX I will suspect my code first !
Now I will work on the last part of this project, rotate the whole thing to have my azimuth pointing up (seems not too difficult, did some testing already), but for sure I can’t wait to a next version of the OCX implemented with that method… I wanted to implement it myself, but the source code does not run on VS2019, missing MFC & other librairies…

Hello.

Glad it is working for you.

FYI, the layer I loaded was in meters, so the label offset was negligible.

I’m just curious what you mean when you say you “can’t wait for the next version of the OCX implemented with that method”. What is “that method”? I hope you don’t mean full map rotation, do you? Because someone started to implement that feature long ago, but it was never completed.

Hello Jerry,
Yes, it is exactly what I mean. It should not be complicated, just having to rotate X/Y between the screen and and the map ? Looks to me just a class to implement.
And yes I saw of course all the exchanges about this topic, it started roughly a year ago. Don’t know how I could help, as I can’t even build the project in VS2019.
So for now I will just rotate the ViewPort, enough for my use…

Thanks for the reply, Bob.

I thought at one point that I would take it on, but there have been so many higher priority features/fixes that I never got back to it. If you don’t mind, let me know what you end up doing; I’d be curious to see how it goes.

Regards,
Jerry.

Well, I succeeded in rotating the map, in real time while updating my GPS position (standard Windows API’s - 10 of them)
Good enough for what I need.
Had a limitation, labels can only rotate from -90° to 90°, so on my rotated map I had to leave them slanted roughly from -45° to 45°, no way to have them 0° at all time (like they appear on the OCX)
Of course as well I had to get rid of what doesn’t rotate, like the zoombar & coordinates, that I show to the user on another form nearby.
Thanks for your help, second project completed!