- 浏览: 1539017 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (525)
- SEO (16)
- JAVA-EE-Hibernate (6)
- JAVA-EE-Struts (29)
- JAVA-EE-Spring (15)
- Linux (37)
- JAVA-SE (29)
- NetWork (1)
- CMS (14)
- Semantic Research (3)
- RIA-Flex (0)
- Ajax-Extjs (4)
- Ajax-Jquery (1)
- www.godaddy.com (0)
- SSH (34)
- JavaScript (6)
- SoftwareEngineer (9)
- CMMI (0)
- IDE-Myeclipse (3)
- PHP (1)
- Algorithm (3)
- C/C++ (18)
- Concept&Items (2)
- Useful WebSite (1)
- ApacheServer (2)
- CodeReading (1)
- Socket (2)
- UML (10)
- PowerDesigner (1)
- Repository (19)
- MySQL (3)
- SqlServer (0)
- Society (1)
- Tomcat (7)
- WebService (5)
- JBoss (1)
- FCKeditor (1)
- PS/DW/CD/FW (0)
- DesignPattern (11)
- WebSite_Security (1)
- WordPress (5)
- WebConstruction (3)
- XML|XSD (7)
- Android (0)
- Project-In-Action (9)
- DatabaseDesign (3)
- taglib (7)
- DIV+CSS (10)
- Silverlight (52)
- JSON (7)
- VC++ (8)
- C# (8)
- LINQ (1)
- WCF&SOA (5)
- .NET (20)
- SOA (1)
- Mashup (2)
- RegEx (6)
- Psychology (5)
- Stock (1)
- Google (2)
- Interview (4)
- HTML5 (1)
- Marketing (4)
- Vaadin (2)
- Agile (2)
- Apache-common (6)
- ANTLR (0)
- REST (1)
- HtmlAnalysis (18)
- csv-export (3)
- Nucth (3)
- Xpath (1)
- Velocity (6)
- ASP.NET (9)
- Product (2)
- CSS (1)
最新评论
-
lt26w:
理解成门面模式应该比较容易明白吧
FacadePattern-Java代码实例讲解 -
lt26w:
看下面的例子比较明白.
FacadePattern-Java代码实例讲解 -
javaloverkehui:
这也叫文档,别逗我行吗,也就自己看看。
HtmlCleaner API -
SE_XiaoFeng:
至少也应该写个注释吧。
HtmlCleaner API -
jfzshandong:
...
org.springframework.web.filter.CharacterEncodingFilter 配置
I don’t generally fi nd the fall or winter an appropriate time to track weather conditions, but this is an exception. Microsoft recently released the Bing Maps Silverlight Control SDK, which ties Silverlight and Bing Maps closely together, allowing developers to create some very powerful mapping applications. In this article, I’ll walk the reader through the process of creating an Europe weather map application in Silverlight by using the Bing Maps Silverlight Control.
Getting started
To use the control in Silverlight projects, you have to download the Bing Maps Silverlight Control SDK and install it. If not already done so, you’ll have to create a Bing Maps Developer Account at https://www.bingmapsportal.com (you’ll need a Windows Live ID). After your account has been created, you’ll have to create at least one Bing Maps key for accessing the Bing Maps services (max 5 keys are allowed). With the key created, you’re ready to create your first Bing Maps Application. One last thing. After creating a Silverlight project in Visual Studio or Blend, make sure you include (Add Reference…) the following libraries in the project:
Microsoft.Maps.MapControl.dll
and
Microsoft.Maps.MapControl.Common.dll.
Getting the data
In order to create a weather map, we need information about the current weather condition. I used XML feeds that our National Environmental Agency provides as a service . There are currently four feeds to choose from – I used the feeds for Europe’s capital and other larger cities.
Each feed provides a bunch of metadata about the feed itself (such as credits, suggested pickup time and period, etc.), as well as a collection of items, describing the weather conditions for included locations. This is an example of an item definition in one of the feeds (short excerpt):
<nn_icon>modCloudy</nn_icon> <nn_shortText>moderately cloudy</nn_shortText> <nn_decodeText>5/8 .. 6/8</nn_decodeText> <wwsyn_icon /> <wwsyn_shortText>Rain</wwsyn_shortText> <wwsyn_longText>Rain (not freezing)</wwsyn_longText> <nn_icon-wwsyn_icon>modCloudy</nn_icon-wwsyn_icon> <t_var_desc>Temperature</t_var_desc> <t_var_unit>°C</t_var_unit> <t>8</t> <t_degreesC>8</t_degreesC> <windchill /> <vis_value>45</vis_value> <vis_unit>km</vis_unit>
This XML elements have to be parsed into a valid structure and stored in the database. LINQ2XML query will be used to parse the XML…
var data = from item in document.Root.Elements("metData") select new WeatherCondition { MeteoId = item.Element("domain_meteosiId").Value, UpdatedTime = item.Element("tsUpdated_UTC").Value, City = item.Element("domain_longTitle").Value, CountryCode = item.Element("domain_countryIsoCode2").Value, Latitude = decimal.Parse(item.Element("domain_lat").Value, System.Globalization.CultureInfo.GetCultureInfo("en-us")), Longitude = decimal.Parse(item.Element("domain_lon").Value, System.Globalization.CultureInfo.GetCultureInfo("en-us")), Condition = item.Element("nn_shortText").Value, ConditionIcon = item.Element("nn_icon").Value, Weather = item.Element("wwsyn_shortText").Value, Temperature = int.Parse(item.Element("t").Value), TemperatureUnit = item.Element("t_var_unit").Value, Humidity = item.Element("rh").Value.Length == 0 ? default(int?) : int.Parse(item.Element("rh").Value), HumidityUnit = item.Element("rh_var_unit").Value, ... };
… and LINQ2SQL will help us store it into the database…
List<WeatherCondition> items = Collect(); WeatherDataContext context = new WeatherDataContext(); context.ExecuteCommand("delete dbo.WeatherCondition"); context.WeatherConditions.InsertAllOnSubmit(items); context.SubmitChanges();
Of course, this part was done on the server side. We need to expose this data as a service:
[ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class WeatherService { [OperationContract] public IEnumerable<WeatherCondition> GetWeatherConditions() { return from wc in new WeatherDataContext().WeatherConditions select wc; } }
With weather data captured and exposed as a WeatherService , we’re ready to move on to the client part .
Setting up the Map control
The first thing to do after putting a Bing Maps control on a Silverlight page is setting the Bing Maps key you created previously. All the control’s properties can be found under the Miscellaneous section. You set the key by pasting it into the CredentialsProvider field. Don’t worry if the text changes to something else when focusing out of the field; it’s just the name of the ApplicationIdCredentialsProvider object, holding a reference to your key.
<map:Map.CredentialsProvider> <map:ApplicationIdCredentialsProvider ApplicationId="Your-Key"/> </map:Map.CredentialsProvider>
There are additional options for controlling what is displayed on the map and how: you can set the Mode
property to either Road
or Aerial
, hide logo, copyright, navigation and scale overlays, set zoom level and initial center point, etc.
Putting data into the context
The map control gets the weather data from the ViewModel, which is responsible for calling the WeatherService to collect the data, whenever required. The MainPageViewModel exposes weather conditions as a collection property to be easily consumed by the control (a common MVVM pattern scenario). The MapItemsControl object adds ItemsControl-like features to the map control, making it bindable to a collection of items, while enabling visual appearance changes to either control itself, and/or bound items.
Each weather condition should be represented by its own icon. There’s another class in the SDK called Pushpin – this one is used to put custom objects on the map. Using it in the MapItemsControl’s ItemTemplate will get all the bound items pinned to the bound location.
Pushpin’s location property can be bound to the underlying object’s location of type Location. Because the Location type is proprietary to the Map control it’s not very likely to be defined and exposed on the server side object. We can, however, extend the client proxy item class to expose the Location property:
namespace WeatherMap.WeatherServiceProxy { public partial class WeatherCondition { public Location Location { get { return new Location((double)Latitude, (double)Longitude) ;} } } }
Displaying weather icons
Each Pushpin should have a look that would correspond to the current weather condition for that place. This could easily be achieved by putting an Image control into the Pushpin template and setting its source to point to an appropriate icon file, possibly through a kind of value converter. Finding this approach being somehow limiting, I went with a bit more flexible way – using a custom template selector, I was able to define how weather would be represented for each condition. The template selector is bound to the CurrentCondtion property, which is a derivate of two parts: the sky cloud coverage (cloudiness) and precipitation (rain, snow, fog, …). Because a lot of different combinations are possible, I simplified the logic by reducing them to the following mapping table:
<local:TemplateSelector x:Name="templateSelector" DataType="{Binding CurrentCondition}"> <local:TemplateSelector.DataTemplates> <local:TemplateSelectorDataTemplate DataType="clear"> <local:Clear /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="Clear"> <local:Overcast /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="overcast"> <local:Overcast /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="Cloudy"> <local:Cloudy /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="FG"> <local:Fog /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="RA"> <local:Rain /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="SN"> <local:Snow /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate DataType="TH"> <local:Thunder /> </local:TemplateSelectorDataTemplate> <local:TemplateSelectorDataTemplate> <TextBlock Text="{Binding CurrentCondition}" /> </local:TemplateSelectorDataTemplate> </local:TemplateSelector.DataTemplates> </local:TemplateSelector>
Each template contains a single user control, graphically representing a weather condition. And by graphically, I don’t mean just a static icon (we could have used a simple bitmap icon for that); by using XAML, we can put the icon in motion through various animations.
Lastly, we can create ‘layers’ of presenting different conditions. Using a very simple animation for switching the opacity of two controls, we can transition from an graphics conditions view to the temperature view. The ControlStoryboardAction behavior was used for starting this continuous transition when the page first loaded.
Showing full weather details
Users, wanting to know more information about current conditions, will be able to click on any weather symbol on the map to get the details. A customized ChildWindow control will be used to display the data, and a special ShowWindowAction behavior will be used to show it:
[DefaultTrigger(typeof(UIElement), typeof(System.Windows.Interactivity.EventTrigger), new object[] { "MouseLeftButtonDown" })] public class ShowChildWindowAction : TriggerAction<FrameworkElement> { public string ChildWindowType { get; set; } protected override void Invoke(object parameter) { ChildWindow window = Activator.CreateInstance( Type.GetType(ChildWindowType, false, true)) as ChildWindow; if (window == null) { return; } if (AssociatedObject != null) { window.DataContext = AssociatedObject.DataContext; } window.Show(); } }
This behavior simply takes the name of the ChildWindow , and in case of successfully creating a new instance, sets its DataContext to whatever context the associated object had. The ChildWindowType property should be set to a fully qualified object name. This is because Silverlight doesn’t support binding to types.
Summary
Bing Maps Silverlight control is a very powerful, yet simple to use Silverlight control for creating virtually any kind of online location-based visualization application. Its data binding abilities make it “blendable” plus you can use Bing Maps Web Services to (reverse) geocode locations and even calculate a travel route.
This tutorial covered the very basics of creating a Silverlight weather map. Many improvements to the application is in the works, including better graphics (current icons were taken from the Weather Sniffer and animated), more accurate information, ability to play back recorded history, etc.
Many additional mapping samples are provided to explore through Bing Maps Silverlight Control Interactive SDK .
Run the Europe weather map application online .
发表评论
-
SilverLight异步调用WebService出错!
2010-01-19 12:58 5399SilverLight异步调用WebService出错! ... -
Silverlight播放器 C#语言
2010-01-13 13:30 3302这段时间研究Silverlight中的MediaElement ... -
使用Silverlight,制作简单播放器的一点点心得。
2010-01-13 13:28 3658首先介绍什么是Silverligh ... -
初探silverlight--简易播放器
2010-01-13 13:28 1518<UserControl xmlns=" ... -
新开发的silverlight视频播放器,
2010-01-13 13:21 4481http://www.chenjiliang.com/Arti ... -
Silverlight教程第四部分:使用 Style 元素更好地封装观感
2010-01-12 22:11 1265Silverlight教程第四部分 ... -
Silverlight Carousel: Creating a Silverlight Control Displays Picture in an Inte
2010-01-12 18:18 1896http://www.codeproject.com/KB/s ... -
Using projection to build a 3D carousel in Silverlight 3
2010-01-12 18:14 2330http://ww ... -
CoverFlow – built using Silverlight 3's 'Projection' feature
2010-01-12 18:11 1888CoverFlow – built using Silver ... -
silverlight动画播放停止重播等控制
2010-01-06 12:38 1382ani.begin() ani.stop(); ani. ... -
silverlight速学范例100
2010-01-06 12:37 1275silverlight速学范例100 ... -
Silverlight 中的 HTTP 通信和安全
2010-01-04 23:43 2007Silverlight 中的 HTTP 通信和安全 < ... -
Visual Studio的 诡异bug(mscorlib无法引用)引发的对话 and Silverlight XAML 构造出错
2010-01-04 09:25 4125... -
Silverlight常见问题及解决方法
2009-12-22 14:06 1277Silverlight常见问题及解决方法 ... -
网上常用免费webservice 查询
2009-12-22 12:47 4598网上常用免费webservice 查询 2008-11 ... -
必应 Bing 新特性之最新文章, Wolfram|Alpha 整合, 天气搜索等已推出
2009-12-21 23:33 1530必应 Bing 增加了一项“最新文章”的搜索结果特性,例如下图 ... -
下载silverlight官网的全部视频教程
2009-12-21 23:30 14856Silverlight官网提供了许 ... -
Silverlight客户端和WCF服务器端共享类库
2009-12-21 23:21 1832在Silverlight企业级项目开发中,访问数据库是很常见的 ... -
必应地图图片系统(Tile System)之二
2009-12-21 22:53 2322【坐标系和地图图片编 ... -
必应地图SilverLight控件入门讲座之六:显示街景(Streetside)
2009-12-21 22:51 4877必应地图SilverLight控件入门讲座之六:显示街景(St ...
相关推荐
create__a_map_by_R_REmap
标题"map create_MAPmatlab_"表明我们将讨论如何利用MATLAB来构建这样的地图。描述中的"random height map create code"进一步确认了我们关注的是生成随机高度数据的程序。 首先,我们需要了解基本的MATLAB编程概念...
At the end, you’ll put everything you have learned together to create a sample Silverlight 4 website. Whether you’re an experienced .NET or web developer, or you’re just starting out, this book ...
带详细解决方案说明文档,提供三种解决方式,另外包含stax2-api.jar,stax2-api-source.jar,woodstox-core-asl-4.4.1.jar,stax-ex.jar,wstx-asl-3.2.9.jar等jar文件,亲测有效。
欧姆包 owm 实现了 Open Weather Map API 的包装器。 在此处阅读有关原始 API 的更多信息: : 。... NewClient ( "YOUR_OPEN_WEATHER_MAP_API_KEY" )// Decode the current weather of a location given the cit
create a Rich Internet Application. In general, I will not be covering in great detail how to develop in Silverlight or the related ASP.NET technology that is required for all Silverlight-based ...
cordova-icreate-amap-location 描述 本插件来源于:https://github.com/ergoli/cordova-amap-location,作者为ergoli。 由于原插件不适配cordova-android7.0以上,本人作了部分代码的修改。 高德(amap)定位cordova...
Enviro includes a very powerfull weather system. You can create your own weather types and drive light, sky, fog and clouds. Enviro supports all kind of unity shuriken particle effects to give you the...
Lining Up Data in ArcGIS: A Guide to Map Projections is an easy-to-navigate troubleshooting reference for any GIS user with the common problem of data misalignment. Complete with full-color maps and ...
How to Create a Database in Python using SQL Lite 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
The second is at a discrete level, in which graph theory is used to create a data model with the goal of implementation in computer systems. Finally, maps are examined at an implementation level, in ...
Create a fully functional application using Silverlight 4 Silverlight 4 boasts long-awaited features that conquer writing a Rich Internet Application. Using new line-of-business features in this book...
* 2257:AG_E_PARSER_CREATE_OBJECT_FAILED * 2258:AG_E_PARSER_PROPERTY_NOT_FOUND * 2259:AG_E_PARSER_BAD_PRO 这些错误代码是 Silverlight 开发中常见的错误,理解和解决这些错误对于 Silverlight 应用程序的...
create_map(1).m
Enviro includes a very powerfull weather system. You can create your own weather types and drive light, sky, fog and clouds. Enviro supports all kind of unity shuriken particle effects to give you the...
CREATE PROCEDURE [dbo].[Login] (@UserName Varchar(30)) AS BEGIN SELECT cUserName, cPassword FROM Users WHERE cUserName = @UserName; RETURN; END; ``` ##### 2. Silverlight项目搭建 在Visual Studio中...
MVVM (Model View View Model) is a Microsoft best practices pattern for working in WPF and Silverlight that is highly recommended by both Microsoft and industry experts alike. This book will look at ...