Map pinpoint on mouse click

8 posts, 0 answers
  1. Finbarr
    Finbarr avatar
    4 posts
    Member since:
    Apr 2013

    Posted 11 Jun 2013 Link to this post

    Hi,

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

    Thanks
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 12 Jun 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Finbarr
    Finbarr avatar
    4 posts
    Member since:
    Apr 2013

    Posted 12 Jun 2013 Link to this post

    Sorry,I want to fire a command in my viewmodel when the mouse is clicked?
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 13 Jun 2013 Link to this post

    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.

  6. Gauthier
    Gauthier avatar
    3 posts
    Member since:
    Sep 2013

    Posted 11 Sep 2013 Link to this post

    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. 

  7. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 16 Sep 2013 Link to this post

    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 >>
  8. Stuart
    Stuart avatar
    1 posts
    Member since:
    Nov 2012

    Posted 16 Sep 2013 Link to this post

    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
  9. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 19 Sep 2013 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready