转:Virtual Earth and AJAX--Part one

来源:互联网 发布:口红推荐 知乎 编辑:程序博客网 时间:2024/04/19 18:39

其实关于AJAX的技术网上已经讨论的很多了,不过很多时候直到我们开始要用的时候才开始学习(比如我吧)所以找到很适合入门者的一系列文章,再着这个系列的另外一位主角也是大有来头--Virtual Earth

好了,下面就是系列转载了 

引用地址:http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!526.entry

Tutorial Part 1 - AJAX and Virtual Earth

AJAX isn’t so much a technology, but an umbrella covering the use of a handful of technologies that in concert can make web applications feel much more fluid and interactive. This is achieved by bringing more of the application code to the client, and making small, asynchronous fetches to the server that don’t require re-fetching and rendering of an entire web page. It’s important to understand what AJAX can do for your applications, and just as important to understand what it doesn’t do. AJAX won’t help you implement right-click context menus or drag-n-drop, but it is often incorrectly credited at doing so. But Drag and Drop and context menus are two good companions for AJAX that can make your applications behave and respond more like a native application.

 

I should note that there are a bunch of AJAX toolkits available whose aim it is to simplify coding. This tutorial intentionally doesn’t make use of any of them in an effort to help you better understand the basic pattern of AJAX applications. With this knowledge, it will make investigating and choosing (not to mention using) a toolkit much easier. And I DO encourage you to do so.  

 

Upon completing this simple tutorial you’ll have a mapping application built with the Virtual Earth map control that utilizes AJAX to asynchronously do a reverse geocode for the center point of the map. We’ll build the application in three logical parts, each building upon the previous.

 

  • Part 1 – Basic mapping application built with the Virtual Earth Control. Pan and zoom with the onscreen compass, Mouse wheel, Drag box, or keyboard. Each time the map moves, we draw a marker icon dead center of the visible map area. In part two, it is the coordinate of this marker we’ll be passing to the server.
  • Part 2 – We add a link in the page that fires off an asynchronous call to a server component. We pass the current Latitude/Longitude in this call. We’ll stub out the server piece in this part, implementing the reverse Geocode in part three. My Server component is an ASPX page written in C# – you can implement the functionality with whatever server programming or scripting language you prefer. The Server page will spit out javascript as its response, to be executed in the client. And finally to complete the round-trip, we’ll implement the callback in the client that takes the returned Javascript and executes it with the eval() menthod.
  • Part 3 – We’ll Flesh out the Server component to make a SOAP call to the MapPoint Web Service (MWS) to reverse geocode the coordinate passed in from the client. You could choose to do whatever you like here – perhaps grabbing traffic from MWS, Business listings from Windows Live Local, Photos from Flickr, whatever you want…    

You can try out part one of the tutorial here. Or better yet, view source after it loads and go ahead and include it into an html file on your own server. It begins by including the VE map control and style sheet. When the Body loads, it calls the OnPageLoad() method which loads and initializes the map as well as attaching to the event onchangeview, which allows us to draw the center marker whenever the map is adjusted. Pretty straight up. No Ajax to see here. In part 2 we’ll add that in.