[Silverlight] Bing Maps development application and Technique 3: offline development of Bing Maps Silverlight Control

Source: Internet
Author: User

I believe that most of the users who use Bing Maps for development have seen the following picture: when we develop Bing Maps, a prompt error occurs when the Development KEY is incorrect, resulting in user authorization verification failure.

        

 

The disadvantage of using Bing Maps Silverlight Control is that it uses the online map data provided by Microsoft by default, and Bing Maps Silverlight Control is bound with the developer account for normal use, if the development KEY is incorrect or you do not enter the development KEY, a prompt is displayed. In fact, this verification failure prompt information can be blocked. We can also use Bing Maps Silverlight Control for our offline operations (without using Microsoft map data, developed without user development KEY verification.

 

Through careful analysis, we can see that there is essentially no big difference between limited and offline operations. The difference is that the map data loaded is different, you can use custom TileSource to load different map data. In addition, we need to solve the problem by removing the error prompt layer, that is, deleting or shielding the error prompt layer, without passing the development KEY verification.

 

In actual development, the error prompt layer cannot be blocked directly, but can only be handled in other indirect ways. After carefully checking the API, we can find that the Map Control of Bing Maps Silverlight Control has a LoadError event. In this event, we can move some hands and feet to eliminate the hateful error prompt layer. Through Reflector decompilation, we can find the LoadError event processing code:

 

Private void Map_LoadingError (object sender, LoadingErrorEventArgs e)
{
If (this. loadingErrorMessage = null)
{
This. loadingErrorMessage = new LoadingErrorMessage ();
Base. RootLayer. get_Children (). Add (this. loadingErrorMessage );
}
If (e. get_LoadingException () is UriSchemeNotSupportedException)
{
This. loadingErrorMessage. SetUriSchemeError (base. Culture );
}
Else if (e. get_LoadingException () is ConfigurationNotLoadedException)
{
This. loadingErrorMessage. SetConfigurationError (base. Culture );
}
Else if (e. get_LoadingException () is CredentialsInvalidException)
{
This. loadingErrorMessage. SetCredentialsError (base. Culture );
}
}

 

Through the decompilation and debugging tracking, we can find that the root layout container of the Map control is named RootLayer, which contains multiple subnode elements. The other is the node element of the error prompt layer, to shield error message, you must use code to remove the child element from the child element node of the Map control. Here, we intentionally do not enter the development KEY and add the LoadError event processing for testing, as shown in.

      

 

It can be found that when an error occurs and LoadError is triggered, the event Delegate method decompiled above will be triggered. Tracking the child nodes of the RootLayer can be found that there are 6 subnodes under the Map control, the LoadErrorMessage is last added to the Map subnode element, that is, the index of the LoadErrorMessage node in the Children of the Map control is 5, after finding the specific child node element, you only need to hide it or remove it directly to solve the problem.

 

The simplest way is to expand a Map control by yourself. In its constructor, the error prompt layer is killed, and then the custom Map control is used in the project, which can be roughly implemented as follows.

Public class OfflineMap: Map
{
Public OfflineMap ()
: Base ()
{
Base. LoadingError + = (sender, e) =>
{
Base. RootLayer. Children. RemoveAt (5 );
};
}
}

 

<! -- Use the custom Map control->

<Controls: OfflineMap> </controls: OfflineMap>

 

 

The biggest problem has been solved. Next we can develop offline based on our own needs. For example, you can use your own map data. For details, refer to Bing Maps advanced Series 9: How to Use MapCruncher to slice Maps and integrate them into Bing Maps. Alternatively, you can use the custom TileSource to load the map data locally deployed by Google. For details, see [Silverlight] Bing Maps Learning Series (8 ): use Bing Maps Silverlight Control to load your deployed Google Maps.

        

 

PS: the indirect method of blocking the error prompt layer described in this article is only a temporary feasible solution. It does not mean that it can be implemented in the future. You may not be able to use this method in the new Bing Maps Silverlight Control release. Based on this implementation method, it can be used for offline development and offline demonstration.

 

 

Copyright description

This article is an original article. You are welcome to repost it and indicate the source of the Article. Its copyright belongs to the author and the blog Park.

Author: Beniao

Article Source: http://beniao.cnblogs.com/or http://www.cnblogs.com/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.