Home arrow JavaScript arrow Page 3 - Adding Pan Controls to Yahoo! Maps
JAVASCRIPT

Adding Pan Controls to Yahoo! Maps


Welcome to the third chapter of the series “Working with Yahoo! Maps.” If you’re an enthusiastic web developer who wants to incorporate these powerful interactive maps into your own web site, then in this article series, you’ll find a step-by-step guide on how to implement their features, including numerous hands-on examples.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 15, 2008
TABLE OF CONTENTS:
  1. · Adding Pan Controls to Yahoo! Maps
  2. · Review: including short and long zoom control into an existing Yahoo! Map
  3. · Incorporating a useful pan control into a Yahoo! Map
  4. · Displaying a Yahoo! Map with zoom and pan controls

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Adding Pan Controls to Yahoo! Maps - Incorporating a useful pan control into a Yahoo! Map
(Page 3 of 4 )

True to form, any Yahoo! Map that doesn't include a panoramic control mechanism will be rather limited in terms of its functionality, since it won’t allow you to scroll over different geographical locations beyond the one selected. Nevertheless, you shouldn’t feel disappointed at this point, since this AJAX framework does support the inclusion of a powerful pan system.

A pan control can be incorporated by invoking a brand new method called “addPanControl()”, which belongs to the “YMap” JavaScript class. Not rocket science, right? Please pay attention to the following example, which shows how to include the pan control into a satellite Yahoo! Map.

The respective code sample looks like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Example on building a YAHOO! Map with pan control</title>

<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?
v=3.7&appid=Your-AP-ID"></script>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: bold 16pt Arial, Helvetica, sans-serif;

color: #000;

text-align: center;

}

#mapcontainer{

height: 400px;

width: 500px;

margin-left: auto;

margin-right: auto;

}

</style>

</head>

<body>

<h1>Example on building a YAHOO! Map with pan control</h1>

<div id="mapcontainer"></div>

<script type="text/javascript">

// Create a new map object

var map=new YMap(document.getElementById('mapcontainer'));

// Add type controls to the map

map.addTypeControl();

// Add the Pan Control to the map

map.addPanControl();

// Set map type to YAHOO_MAP_SAT

map.setMapType(YAHOO_MAP_SAT);

// Display the map centered on the selected location

map.drawZoomAndCenter("Los Angeles",3);

</script>

</body>

</html>


As was demonstrated above, including a pan control into an existing Yahoo! Map is only a matter of calling the “addPanControl()” JavaScript method before displaying the map in question on the browser. In this case, the type of map I decided to work with is based on satellite images, but this condition can be easily modified to use both regional and hybrid ones.

To complement the previous example, I included a screen shot that depicts the look and feel of this handy pan control just added. Here it is:



As you can see by looking at the upper left corner of this image, the pan control is comprised of the four typical “up,” ”down,” ”left,” and “right” arrows, which, when clicked on, will scroll the whole map toward the corresponding direction.

At this point, you've learned how to incorporate a powerful panoramic control to a given Yahoo! Map, which expands its functionality and usability. Therefore, the last thing that I’m going to teach you in this tutorial will be how to combine both the zoom and pan controls that you learned earlier in the same map, completing the discussion on principal visualization mechanisms supported by a typical Yahoo! Map. Sounds really exciting, right?

To see how these handy controls will be displayed on one single interactive map, please click on the link shown below and keep reading. We’re almost done!


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials