JavaScript
  Home arrow JavaScript arrow Page 2 - A Closer Look at Smart Markers with Yahoo!...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

A Closer Look at Smart Markers with Yahoo! Maps
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-06

    Table of Contents:
  • A Closer Look at Smart Markers with Yahoo! Maps
  • Inserting smart markers into a satellite map
  • Dropping smart markers in a regional Yahoo! Map
  • Displaying smart markers on a hybrid Yahoo! Map

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    A Closer Look at Smart Markers with Yahoo! Maps - Inserting smart markers into a satellite map


    (Page 2 of 4 )

    As I expressed in the introduction, the goal of this particular tutorial is to demonstrate how to incorporate diverse smart markers into different Yahoo! Maps. So bearing this in mind, I’m going to start by showing you a concrete example where these markers are displayed on a satellite-based map.

    This being said, please have a close look at the following code sample:


    <!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 using smart markers with satellite YAHOO! Map</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 using smart markers with satellite YAHOO! Map</h1>

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

    <script type="text/javascript">

    function initializeMap(){

    // 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();

    // Add long zoom control to the map

    map.addZoomLong();

    // 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);

    // Add an event to report to our Logger

    YEvent.Capture(map,EventsList.MouseClick,displaySmartMarker);

    // display smartMarker

    function displaySmartMarker(_e,_c){

    var geoPoint=new YGeoPoint(_c.Lat,_c.Lon);

    var newMarker= new YMarker(geoPoint);

    // call 'autoexpand()' method

    newMarker.addAutoExpand('This is a smart marker');

    // add HTML to the smart marker

    var markerHTML= '<p>This is the markup<br />';

    markerHTML+='of the smart marker</p>';

    YEvent.Capture(newMarker,EventsList.MouseClick,function()
    {newMarker.openSmartWindow(markerHTML)});

    map.addOverlay(newMarker);

    }

    }

    window.onload=function(){

    initializeMap();

    }

    </script>

    </body>

    </html>


    Despite the fact that the previous practical example may look rather complex at first, it’s quite simple to grasp. First, a satellite map is built using the “YMap” JavaScript class, and then, the pertinent smart markers are constructed via another handy JavaScript class, called “YMarker.”

    Also, it’s worthwhile to note here that each of the smart markers are created and dropped into the map by using a custom callback function, named “displaySmartMarker().” This is invoked each time a mouse click occurs within the map in question. As you learned in the previous article of the series, this event is properly handled by the “YEvent.Capture” JavaScript class, which is part of the Yahoo! UI library.

    And finally, you should pay careful attention first to the way that smart markers are turned into “auto expandable” elements via the use of the corresponding “addAutoExpand()” method, and second to the manner in which they’re displayed on the selected map, which in this case was by using a dynamic box, called “smartWindow.” This can be hidden and shown alternatively in response to specific events, like mouse clicks, for instance.

    Of course, the characteristic that turns a basic marker into a smart one is its capacity to include additional markup on its own. In the previous example, I decided to include an extra paragraph in each marker, but you can use other tags that probably will better suit your personal needs.

    In either case, the functionality of smart markers will be best understood if you have a look at the following image, which demonstrates how they work. Here it is:



    So far, so good. At this point, you hopefully learned the key concepts surrounding the incorporation of a few smart markers into a satellite Yahoo! Map. So, what’s next? Well, in the upcoming section of this tutorial, I’m going to teach you how to utilize the same smart markers that you learned earlier, but this time in conjunction with a regional map.

    To see how this process will be achieved, please click on the link that appears below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this last article of the series, you’ll learn how to include smart markers in...
       · Hi,I am some trouble to use the openSmartWindow in Yahoo maps. My markers should...
     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway