This project has moved. For the latest updates, please go here.

Possible Bug with MapRectangle?

Oct 9, 2013 at 8:46 PM
There seems to be a bug with MapRectange. This is how to reproduce the problem in the WPF Sample Application:

Add a new SampleItemCollection to the resources section in mainwindow.xaml
        <local:SampleItemCollection x:Key="Rectangles">
            <map:MapRectangle South="53.5" West="8.75" North="53.75" East="9" Cursor="Hand" Fill="Blue"/>
        </local:SampleItemCollection>
Add a MapItemsControl to the map using the new resource for its ItemSource
            <map:MapItemsControl ItemsSource="{StaticResource Rectangles}"/>
Expected Behavoir:
The cursor changes to "hand", only when hovering within the blue rectangle. Dragging the map is not possible whithin the blue rectanlge, because the item in the MapItemsControl will receive mouse events.

Observed Behaviour:
The "hand" shows up way out the blue rectangle. Dragging the map is not possible in this enlarged area. The enlarged area with the "hand" cursor only extends to the south and to the west of the rectangle. Behaviour at the north or east border is fine.

Additional Information:
Whe using one of the pushpins or other map items the control behaves as expected.

I would like to add a screenshot, but as far as I can see, codeplex does not allow this. Anyway, the steps to reproduce are simple enough.

Michael Ewe
Coordinator
Oct 9, 2013 at 9:42 PM
It's not even necessary to put the MapRectangle into a MapItemsControl. Putting it directly on the Map also shows the strange cursor behaviour. The cause of the problem seems to be the way in which a MapRectangle is transformed to viewport coordinates.

Changing line 11 in MapRectangle.cs from
RenderTransform = ParentMap.ViewportTransform;
to
geometry.Transform = ParentMap.ViewportTransform;
yields the desired behaviour, but also impacts how MapImages are transformed. I'll further investigate on this.
Coordinator
Oct 9, 2013 at 10:48 PM
Here we go, please check out the latest release.
Oct 10, 2013 at 7:45 AM
Thank you very much. Works like expected now.

I really appreciate the way you are dealing with my problem. You need a book, a CD, DVD or something? Have a wishlist on amazon?
Coordinator
Oct 10, 2013 at 8:20 AM
You're welcome. I'm doing this for fun, and in the end it was really a bug.

I have the feeling that there was a reason why I initially used RenderTransform here, but I can't remember. The only thing that comes into mind is that with using RenderTransform the Stroke of the Shape would also be transformed to viewport coordinates. In other words it would be measured in lat/lon degrees. I guess that isn't feasible anyway. However, the code is cleaner right now.
Coordinator
Oct 10, 2013 at 10:50 AM
And now I found out why I used RenderTransform. With the latest change, the ImageBrush in a MapImage is not transformed correctly. And I've built this into MapRectangle in order to enable not only SolidColorBrushes but also DrawingBrushes or ImageBrushes, which have to be transformed by the VieportTransform. I guess I'll have to provide another fix.
Coordinator
Oct 10, 2013 at 8:39 PM
Ok, next release. This time with proper transformation of the Fill brush of a MapRectangle or MapImage.
Coordinator
Oct 12, 2013 at 7:39 AM
Edited Oct 12, 2013 at 7:40 AM
Michael, the cause of the problem seems to be a bug (or at least some kind of too rough approximation) in the way WPF does input hit testing on scaled elements. I've created this question on StackOverflow: http://stackoverflow.com/q/19324094/1136211.