Rotate map and markers?

Dec 21, 2009 at 6:38 AM

First off, great maps!!

I tried to rotate the map using RenderTransform, but the markers are no longer oriented correctly. Is there a better way to rotate the map or should I try to do it in code?

 

Thanks

Coordinator
Dec 21, 2009 at 9:24 AM

currently there is no rotation functionality, but it will be ;}

Dec 21, 2009 at 10:17 PM

Let me know if I can contribute. I am not knowledgeable about mapping and GPS but I am good with Windows and 2D/3D. Can you suggest a starting point or do you have some code that I can continue with...

 

G

Coordinator
Dec 21, 2009 at 10:46 PM

yes you can,  there is MapRenderTransform in windows forms and RenderTransform in wpf, but you need to synchronize markers with it, quite complex but possible...

Dec 22, 2009 at 5:37 AM

I might assign a new dependency property to something like MapDirection or DirectionVector so the Markers can rotate themselves around their respective origins (the text as well). Also if the map is rotated using MapRenderTransform this should return the corrected LatLong in function FromLocaltoLatLong and the reverse? How about the Copyright info? I'll look into these in the next 2 days.

Coordinator
Dec 22, 2009 at 7:57 AM

feel free to experiment ;}

Jan 11, 2010 at 4:51 PM

radioman, I now have some proto code that successfully rotates the map and markers. I changed MapRenderTransform from type Transform to TransformGroup. I added two member transforms - MapRotateTransform and MapScaleTransform (to support the prior zooming functionality) - to the MapRenderTransform in the ctor. I modified the set accessor of Zoom so the intermediate zoom levels are put into the MapRotateTransform. I also call Core_OnMapZoom... to force repositioning of all markers. Now I need some support for one issue I ran into... I need to increase the bounds of the map to sqrt((largest_map dimension)^2) - I'll try to use the patch for continuous maps....

Separately, is there a way to zoom a given set of markers, and center on another? ZoomandCenterMarkers(<ObservableCollection zoom_markers, GMapMarker center_marker)

 

 

Coordinator
Jan 11, 2010 at 5:46 PM

just perfect!

on zooming markers, you can set map position immediately after using function ZoomandCenterMarkers, or just overload with new params... The default action is to set center of these markers.

Jan 12, 2010 at 12:36 AM

So I tried increasing the bounds of the map in GMapControl_SizeChanged. It works but... my map center is off by 1/2 of the increase in width. I messed with increasing the offset in DrawWPF still having issues. Can you give me any tips?

Jan 12, 2010 at 3:14 AM

Done. How do you want it. It's got a lot of hackification in it.

Coordinator
Jan 12, 2010 at 5:39 AM

please upload a patched solution zip. I'll try to test and fix things if it really works.

Coordinator
Jan 12, 2010 at 9:28 AM

perfect! testing now...

Jan 16, 2010 at 11:13 PM

radioman, I came back to this today and it doesn't work properly anymore. Must have been a problem with my test code... Obviously you got the same result. Can you give me a heads up?

Coordinator
Jan 16, 2010 at 11:20 PM

well your code works basically, just need to put all parts right ;} if have some stable code, please share any time

Jan 17, 2010 at 2:07 AM

Found a couple of offsetting bugs in the test code and seem to have it working. I'll continue to test before I make my next pass.

Coordinator
Jan 17, 2010 at 2:58 AM

great, i'll port rotation functionality to windows forms too, would be quitly wonderful to have it in windows mobile using digital compass as bearing!

Jan 20, 2010 at 4:50 PM

Posted another attempt. It's been stable for 3 days.... Let me know.

Coordinator
Jan 20, 2010 at 4:57 PM

can you remove machine specific configs, i can't even build your demo ;{

Jan 21, 2010 at 10:00 PM

Try putting GMapControl into your own environment and building it. If I'm not mistaken, that's the only file I changed.

Apr 19, 2010 at 10:36 PM

Hi, did you implement this code into the currant projet?

 

or is there any place I can download the code for rotation?

 

 

Apr 21, 2010 at 1:37 AM

let me know, I really want to do this too

Apr 21, 2010 at 8:41 PM

radioman, this thread/projet is dead?

 

Coordinator
Apr 21, 2010 at 8:49 PM

try contact gvenkat_00

Apr 21, 2010 at 9:19 PM

radioman, good point, but if he's not replying, do you still have his "demo"? maybe I can continue the projet?

Coordinator
Apr 21, 2010 at 10:18 PM

the stuff i've managed to build http://cid-e8bbd1bbd58dbc88.skydrive.live.com/self.aspx/.Public/Stuff/GMaps^_Rotation^_GV.zip

Apr 21, 2010 at 11:03 PM

thank you, I'm pretty sure I'll be able to work with that, but even if we have a  "stable" version, we'll have the problem of the road name... I don't think we can't rotate them?

Coordinator
Apr 22, 2010 at 5:44 AM

yeah ;} we can't, but usually there is no need to rotate the map

Apr 22, 2010 at 5:46 AM

I don't agree :) I need the "gps" feature on my application, since it's a incar device, I need to rotate the map when the car move...

Coordinator
Apr 22, 2010 at 6:52 AM

mm, that's cool ;} sounds like my next quest ;]

Apr 22, 2010 at 6:56 AM

:)

 

maybe I'll try to explore to render the tile myself and render them twice, one reverse and one normal.. so when I rotate I'll "load" the "reverse" tile

Coordinator
Apr 22, 2010 at 8:12 AM

..interesting, i wonder how it will look ;}

Apr 22, 2010 at 4:54 PM

hmm, maybe we can just have the road name into another layer and have title without roadname

 

Coordinator
Sep 8, 2010 at 10:59 AM

windows forms now has integrated rotation

Apr 4, 2013 at 1:52 PM
radioman,

You said windows forms now has integrated rotation. thanks great! can you point me in the direction of where I can change the map rotation? thank you!
Coordinator
Apr 4, 2013 at 3:15 PM
latest release has it, latest hot build has bugs, therefore it's disabled

p.s. map.Bearing = xxx
Apr 4, 2013 at 7:06 PM
Great that works. I was looking for "Rotation" properties and never happened to see "Bearing."

I am having some limited success, however. All my routes work fine. My normal map markers work fine. I do have one map marker which is an arrow representing your direction of travel: so that marker's OnRender function had code in it to do a RotationTransform and TranslateTransform already. So I just made a small modification to adjust for the rotation of the map as well - works great.

My issue is with GMapImage. Here was my original OnRender function which worked perfectly fine before I began rotating the map around:
public override void OnRender(Graphics g)
{
    if (image == null)
        return;

    Rectangle rect = new Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
    g.DrawImage(image, rect);
    g.DrawRectangle(Outline, rect);    
}
So, naturally, I just did the transforming that I was used to doing with the arrow marker I described above to have it also rotate with the map:
public double MapBearing { get; set; }

public override void OnRender(Graphics g)
{
    if (image == null)
        return;

    g.RotateTransform(Convert.ToSingle(MapBearing));
    g.TranslateTransform(LocalPosition.X, LocalPosition.Y, System.Drawing.Drawing2D.MatrixOrder.Append);

    Rectangle rect = new Rectangle(0, 0, Size.Width, Size.Height);
    g.DrawImage(image, rect);
    g.DrawRectangle(Outline, rect);    
}
But this is not working at all. The image plots in different locations based on zoom and as I pan the map, it's moves wildly around the screen. Something is not tracking correctly to keep it aligned with the rotating map. Any suggestions?

I was worried that doing a rotation on the marker and then doing a rotation on the image was the problem but they are both on separate overlays, so I assume that is not the issue.
Apr 4, 2013 at 7:30 PM
I believe my problem is here: I do this every time I update the image of the GMapImage
standaloneHeatMap.Image = value;
var tl = MainMap.FromLatLngToLocal(heatTL);
var br = MainMap.FromLatLngToLocal(heatBR);
standaloneHeatMap.Position = heatTL;
standaloneHeatMap.Size = new System.Drawing.Size(br.X - tl.X, br.Y - tl.Y);
MainMap.Invalidate();
You'll see that I know the Lat and Lon I want for the top-left (TL) and bottom-right (BR) corners. But I am getting the local coordinates and assigning that as the size of the GMapImage, which I use for drawing the image. However, when the map is rotated, the local points that correspond to those Lat's and Lon's are messing up the size of the GMapImage.

Not sure how to tackle this.
Coordinator
Jan 15, 2015 at 4:12 PM
rotation fixed

p.s. marker rotation demo [left menu, Live->FlightRadar] and GMarkerArrow.cs
Marked as answer by radioman on 1/15/2015 at 8:12 AM