Porting to WPF

Topics: Feature Requests
Jan 22, 2009 at 2:36 PM
Hello again,

Another suggestion... How about porting the control to WPF. It would avoid having to wrap it in a windowsformshost with all the problems (for those using wpf like myself).

A fisrt look at the code seems to suggest that only the DrawmapGdi functions would have to be modified. using the DrawingContext and replacing the OnPaint by OnRender in a wpf UserControl.

Jan 22, 2009 at 6:05 PM
please for the love of god dont port to wpf.

not that I have anything against wpf (i love the stuff), but if you are wanting this lib to be cross platform (works on desktop, and compact framework) you must ensure that you keep to using what is only available on the Compact Framework.

a way you can port to WPF is to seperate your code like this

GMap4DotNet.Shared - this is an acual implementation, handles the tiles, does the downloading, all of the logic behind the control.
GMap4DotNet.WPF - this has a reference to .Shared and presents the control as a WPF control.
GMap4DotNet.Mobile - has a reference to .Shared and presents the control as a System.Windows.Forms.Control.


Coordinator
Jan 22, 2009 at 6:45 PM
i can easily make special version for only wpf/etc, and sinchronize threir functionality from time to time. Using modal dll system is also good idea. We shall see...
Jan 23, 2009 at 6:51 AM
Ok my suggestion was a little selfish. madG33K suggestion is the way to do it - separate the logic from the presentation part.
Coordinator
Jan 27, 2009 at 8:51 AM
Logic separated successufy! Map is loaded and rendered in WPF too. Just need some time to clean things up ;}
Coordinator
Jan 27, 2009 at 6:22 PM
on wpf map dragging isn't working correct, any idea? 
Jan 28, 2009 at 5:45 AM
In GMapWindowsPresentation:

Change

 

protected override void OnMouseMove(MouseEventArgs e)
{
    
if(Core.IsDragging)
    {
        Core.mouseDown =
new System.Drawing.Point((int) e.GetPosition(this).X, (int) e.GetPosition(this).Y);

TO:

protected override void OnMouseMove(MouseEventArgs e)
{
    if(Core.IsDragging)
    {
        Core.mouseCurrent = new System.Drawing.Point((int) e.GetPosition(this).X, (int) e.GetPosition(this).Y);

 

Coordinator
Jan 28, 2009 at 12:53 PM
;/ oh caramba, thx
Jan 28, 2009 at 2:49 PM

There's a problem with sizing of the map in wpf when displaying the map in the grid with columns and rows or when using dockpanels. The map isn't contained. If you change your MainWindow.xaml to something like this

 

 

 

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
    <src:GMap Name="MainMap" />

 

 

 

    <Grid Grid.Column="1" Width="150">
        <Button Height="23" Margin="6,6,6,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">Reload</Button>
    
</Grid>

 

</Grid>

 

 

 

 

you'll notice the map tiles overlapping the button. Could be that you use the control's width/height instead of actualwidth/actualheight. Not sure as I'm uncertain of where and how you redraw the tiles.

 

 

 

Coordinator
Jan 28, 2009 at 6:20 PM
try now ;}
Jan 29, 2009 at 6:37 AM
Thanks. all good.
Coordinator
Jan 29, 2009 at 6:57 AM
good ;} , can you look at wpf demo with loading reports now there is strange threading isue?
Jan 29, 2009 at 8:43 AM
Just uploaded a patch to fix the issue. Happens all the time when calling async processes or using timers.
Coordinator
Jan 29, 2009 at 9:12 AM
are you sure?, i still don't see the patch yet ;/
Jan 29, 2009 at 9:25 AM
??? re-done. Check now
Coordinator
Jan 29, 2009 at 9:44 AM
ok, i've got it, ..but why backgroundworker don't do this automaticaly, maybe there is something special about WPF?
Coordinator
Jan 29, 2009 at 10:45 AM
i found the bug! bakground workers was initiated to early, and they work correct only initiated when control is loaded.
Jan 30, 2009 at 3:28 PM
Regarding markers, the drawingContext in WPF doesn't handle System.drawing.bitmap, meaning that the marker property would have to be converterted on each call to OmRender resulting in a lot of overhead.

I've had a look at what you've done for rendering the tile images -great! Are you planning on something similar for the markers?

Just thought I'd ask out of interest.
Coordinator
Jan 30, 2009 at 3:54 PM
i think for marker system just use predefined custom shape drawing classes(class MarkerShapeBig: IMarkerDraw), so even user can draw custom marker class
Feb 2, 2009 at 4:01 PM
I've been playing with the code a little drawing shapes onto the map. To do so I have create my own Map class inherited from GMap in which I override OnRender and place my code calling functions such as drawingContext.DrawLine, DrawGeometry etc..

To draw a line, for example, I convert my Lat/Lng point using:

System.Drawing.

Point pll = GMaps.Instance.FromLatLngToPixel(new PointLatLng(p.Y, p.X), this.Zoom);

then create a System.Windows.Point

Point pp = new Point(pll.X, pll.Y);

 

then call the DrawLine(...)

The problem with this is that I don't have access to the Core.RenderOffset. Could the overidden GMap.OnRender not call a virtual function passing the drawingContext and the RenderOffset that I could override without altering GMap? This however won't allow me to lock the collections while drawing so the code has to stay in GMap.

So, my question, have you advanced on the Imarker and IRoute classes  so that addMarker and addRoute are again implemented in the GMap ( that is call DrawMarkers or DrawRoutes or something)

Thanks
Coordinator
Feb 2, 2009 at 4:13 PM
..look at current marker drawing in wpf version, it will be something like that for other map objects