Home arrow JavaScript arrow Page 4 - Adding Zoom Controls to Yahoo! Maps
JAVASCRIPT

Adding Zoom Controls to Yahoo! Maps


Welcome to the second part of the series “Working with Yahoo! Maps.” As the title clearly suggests, this series provides you with all the elements that you will need to start utilizing the Yahoo! Maps Ajax-based framework. It complements theoretical explanations with numerous code samples. This article will discuss how to incorporate zoom controls into an existing Yahoo! Map.

Author Info:
By: Alejandro Gervasio
Rating: 3 stars3 stars3 stars3 stars3 stars / 3
April 08, 2008
TABLE OF CONTENTS:
  1. · Adding Zoom Controls to Yahoo! Maps
  2. · A quick review: building different types of Yahoo! Maps
  3. · Adding a long zoom control to Yahoo! Maps
  4. · Using a short zoom control with Yahoo! Maps

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Adding Zoom Controls to Yahoo! Maps - Using a short zoom control with Yahoo! Maps
(Page 4 of 4 )

As I stated in the previous section, it’s also feasible to incorporate a “short” zoom control into an existing Yahoo! Map by using another method of the handy “YMap()” JavaScript class, called “addShortZoom().”

This method supports practically the same implementation as its counterpart “long” and can be seen in action in the following hands-on example:


<!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 short zoom 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 short zoom 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 short zoom control to the map

map.addZoomShort();

// 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 you can see, displaying a “short” zoom control on a selected Yahoo! Map is only a question of calling the appropriate JavaScript method of the pertinent “YMap” class. In this case, the mentioned control is added before specifying the type of map that should be constructed. Pretty simple to grasp, isn’t it?

In addition, you may want to look at the following screen shot, which shows the visual appearance of the previously mentioned zoom control:



As shown in the above image, the short zoom control is composed basically of two small arrows for zooming in and out on the targeted Yahoo! Map. Of course, it’s up to you to decide what zoom control best suits your needs, according to the specific requirements of the web application that will use these interactive maps.

Final thoughts

That’s all for now. In this second part of the series, I demonstrated how to incorporate two different zoom controls into an existing Yahoo! Map, making it much more functional and usable.

However, I’m only scratching the surface when it comes to exploring the numerous features packaged with the Yahoo! Map Ajax framework. Thus, in the next article, you’ll learn how to incorporate some useful pan controls into a given map, providing it with the capacity to scroll all over a selected geographical location.

Now that you’re aware of the topics that will be discussed in the upcoming article of this series, you won't want to miss it!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials