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

handling when map mode changes

7 Answers 127 Views
Map
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ewart
Top achievements
Rank 1
ewart asked on 04 Apr 2010, 10:37 PM
Hi tema, what is the best way of detecting if the user changes settings on the MapCommandBar.  I need to be able to save these settings and also update other on screen controls when they change from Aerial to Road, or if the LabelsVisible setting is changed.  The MapCommandBar does not seem to have an event for detecting these changes?

regards
ewart

 

7 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Apr 2010, 10:23 AM
Hello Ewart,

We will add new "MapModeChanged" event in the future releases.
As workaround you can create a custom map provider class which would inherit from BingMapProvider. You should override the OnMapModeChanged method for raising an event.
The sample code of the custom provider is below.
class CustomBingMapProvider : BingMapProvider
{
    public CustomBingMapProvider(MapMode mode, bool labelVisible, string applicationId)
        : base(mode, labelVisible, applicationId)
    {
    }
    /// <summary>
    /// Event occurs when the mode of the map provider is changed.
    /// </summary>
    public event EventHandler MapModeChanged;
    protected override void OnMapModeChanged(MapMode oldMode, MapMode newMode)
    {
        base.OnMapModeChanged(oldMode, newMode);
        if (this.MapModeChanged != null)
        {
            this.MapModeChanged(this, null);
        }
    }
}

Then having used the custom map provider class instead of BingMapProvider you should add an event handler to your application like this:
public MainPage()
{
    InitializeComponent();
    // load "mode" and "labelVisible" settings
    // ...
    CustomBingMapProvider provider = new CustomBingMapProvider(mode, labelVisible, "BING KEY");
    provider.MapModeChanged += new EventHandler(provider_MapModeChanged);
    this.radMap.Provider = provider;
}
private void provider_MapModeChanged(object sender, EventArgs e)
{
    MapProviderBase provider = (MapProviderBase)sender;
    // save settings
    // provider.Mode;
    // provider.IsLabelVisible;
}

Regards,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ewart
Top achievements
Rank 1
answered on 26 Apr 2010, 12:39 PM
awesum thanks I see you have added a new change event. 

at the moment i find the event is raised twice, and also my map_initialise is fired twice when I change the event through the UI (am using the telerik MapCommandBar defined seperately from the radmap in my situation.  weird - I may experiment with a small test project to see if it's something strange I'm doing.

cheers
ewart.

0
Andrey
Telerik team
answered on 27 Apr 2010, 03:25 PM
Hi Ewart,

Thank you for the feedback.
Unfortunately we cannot reproduce the case when the MapModeChanged event occurs twice.
The RadMap.InitializeCompleted event occurs when the BingMapProvider has retrieved necessary data for initializing from WCF service.
It occurs once when the map mode is changed to Aerial or Road mode first time. Also it occurs when the label visible flag is changed first time for any mode.
The bird's eye mode raises the InitializeCompleted event each time the scene of 3D projection is changed. There is a problem in this mode. If it has been used, then it continues to refresh scenes data also for any other mode.

Sincerely yours,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ewart
Top achievements
Rank 1
answered on 21 Mar 2011, 10:20 AM
Hi, I've just updated to Q1, 2011 and MapModeChanged seems to be missing again?  Can you confirm if this has been deprecated in some way and if so what the new API looks like? 

I was hooking it like so:
provider.MapModeChanged += new EventHandler<MapModeChangedEventArgs>(provider_MapModeChanged);

The current documentation on silverlight does not include the Q1 2011 backwards compatibility/change section so it's real hard to know whats changed (other than the new build errors of course!)

Also, on a similar note I can no longer init OpenStreetMapProvider like this (where providerMode is MapMode),
provider = new OpenStreetMapProvider( providerMode, true);

The whole code being:
// Determine which provider to use
        switch (mapProvider)
        {
            case MapProvider.OpenStreetMap: provider = new OpenStreetMapProvider(  providerMode, true); break;
            default: provider = new BingMapProvider( providerMode, true, _bingMapKey); break;
        }
 
        // Set the provider of the map
        this.radMap.Provider = provider;
         
        provider.MapModeChanged += new EventHandler<MapModeChangedEventArgs>(provider_MapModeChanged);

Any ideas?

cheers
ewart

0
Andrey
Telerik team
answered on 21 Mar 2011, 07:05 PM
Hi Ewart,

For information about changes of the Q1 2011, please, take a look to the release history:
http://www.telerik.com/products/silverlight/whats-new/release-history/q1-2011-version-2011-1-0315.aspx

Please see the following topic of RadMap: "Custom map provider architecture is not backwards compatible with previous versions".

The map providers architecture is not backwards compatible with previous versions. Unfortunately the documentation is not updated yet but should be online later this week.
Currently the map mode is supported for Bing map provider only. The OpenStreet provider has not Aerial or Road modes. The OpenStreet (like many other providers) site even have not analogs for the "mode" term. They have two renderers: Mapnik and Osmarenderer.
You can use the SetMapSource method of the map provider to set certain source like to the following:

var provider = new OpenStreetMapProvider();
provider.SetMapSource(typeof(Telerik.Windows.Controls.Map.OpenStreetOsmarenderSource).FullName);

Currently every provider has own set of the commands are shown in the command bar. They are listed in the "Commads" property of the map provider. The buttons for commands are displayed automatically when the provider is assigned to the map control.

The MapModeChanged event no longer exists. We are sorry. Currently the map control does not contain appropriate event in new architecture. We have created the PITS issue to implement the MapSourceChanged event instead of MapModeChanged. It will be available in the MapProviderBase class in nearest internal build.
You can track it using the following link:
http://www.telerik.com/support/pits.aspx#/public/silverlight/5187

Best wishes,
Andrey Murzov
the Telerik team

0
ewart
Top achievements
Rank 1
answered on 21 Mar 2011, 07:21 PM
originally the two map modes did change the two types of tiles for the opensource but I shall look into the map provider to change the source, that should be OK.

the mapmodechanged event missing really screws me, hopefully that can be a priority, as well as documenting the release.

cheers
ewart

0
Andrey
Telerik team
answered on 24 Mar 2011, 11:08 AM
Hi Ewart,

We've added the MapSourceChanged event to MapProviderBase already. The fix should be available in the nearest internal build.

Kind regards,
Andrey Murzov
the Telerik team
Tags
Map
Asked by
ewart
Top achievements
Rank 1
Answers by
Andrey
Telerik team
ewart
Top achievements
Rank 1
Share this question
or