This is a migrated thread and some comments may be shown as answers.

Map pinpoint on mouse click

7 Answers 232 Views
Map
This is a migrated thread and some comments may be shown as answers.
Finbarr
Top achievements
Rank 1
Finbarr asked on 11 Jun 2013, 08:34 AM
Hi,

Is it possible to add a map pin point on a mouse click event,using the mvvm pattern?

Thanks

7 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 12 Jun 2013, 08:37 AM
Hi Finbarr,

Yes, it is possible. You can use the RadMap.MapMouseClick event.
I would recommend to take a look at the following online example:
http://demos.telerik.com/silverlight/#Map/DataBinding

Regards,
Andrey Murzov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Finbarr
Top achievements
Rank 1
answered on 12 Jun 2013, 08:55 AM
Sorry,I want to fire a command in my viewmodel when the mouse is clicked?
0
Andrey
Telerik team
answered on 13 Jun 2013, 08:21 AM
Hi Finbarr,

You can create a method in your viewmodel. And you can invoke it in the handler of the RadMap.MapMouseClick event.

Regards,
Andrey Murzov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gauthier
Top achievements
Rank 1
answered on 11 Sep 2013, 03:22 PM
Unfortunately, I don't see this as a real solution.

You have to write code in the codebehind of your view (or usercontrol), which should be avoided in a clean MVvM approach.
(Testability ? , 'Blendability ?', ....)


For a map control, it appears so common that we need to now the coordinates clicked by the user, I would expect that it is feasible to really bind a command on the viewmodel, and not having to handle an event in the codebehind. 

0
Andrey
Telerik team
answered on 16 Sep 2013, 12:07 PM
Hello Gauthier,

I am afraid RadMap doesn't expose any commands which can be handled in your model. Only events are available.

Best regards,
Andrey Murzov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stuart
Top achievements
Rank 1
answered on 16 Sep 2013, 01:56 PM
Hi Gauthier,

The interactivity library can solve this problem: 

1. Download "System.Windows.Interactivity.WPF" from NuGet.
2. Add a command to your ViewModel
3. Add an interaction trigger to your RadMap to fire your command on click:

  <i:Interaction.Triggers>
                <i:EventTrigger EventName="MapMouseClick">
                    <i:InvokeCommandAction Command="{Binding ClickedCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

Regards,
Stuart
0
Andrey
Telerik team
answered on 19 Sep 2013, 06:46 AM
Hello Stuart,

Unfortunately your approach will not work in this case. The InvokeCommandAction can't pass event arguments as command parameters. But arguments of the RadMap.MapMouseClick event contains geographical location of the place where mouse button has been clicked. It is very important to pass it to the command. The alternative is creation of own behavior. You can find samples in the Internet. For example, here:

http://stackoverflow.com/a/16317999/677857

Regards,
Andrey Murzov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Map
Asked by
Finbarr
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Finbarr
Top achievements
Rank 1
Gauthier
Top achievements
Rank 1
Stuart
Top achievements
Rank 1
Share this question
or