JavaScript
  Home arrow JavaScript arrow Page 4 - Using Polylines and Smart Markers with Yah...
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 
 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

Using Polylines and Smart Markers with Yahoo! Maps
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-29

    Table of Contents:
  • Using Polylines and Smart Markers with Yahoo! Maps
  • Review: adding basic markers to an existing map
  • Drawing polygonal lines (polylines)
  • Using smart markers with a selected 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

    Using Polylines and Smart Markers with Yahoo! Maps - Using smart markers with a selected Yahoo! Map


    (Page 4 of 4 )

    As I said in the prior section, Yahoo! Maps support the inclusion of "smart markers," which are markers whose visual appearance can be enriched with additional markup, such as paragraphs and bolded text. However, this concept will be better understood if you take a look at the following example, which shows how to use the markers in question:


    <!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>


    Undoubtedly, there are some interesting things to note with reference to the above example. First, notice how the smart markers are created with the brand new "YMarker" JavaScript class, and also how a basic label is added to each of them via the "addAutoExpand()" method, which comes in handy for inserting descriptive tool tips into a selected marker.

    Finally, some additional markup is added to each marker, which will be properly displayed on the map by using another helpful method, called "openSmartWindow()." In case you're wondering what a smart window is within the context of Yahoo! Maps, basically they contain DIVs that can be shown or hidden in response to a determined event, including mouse clicks, of course.

    To help you understand the functionality of smart markers, I included an image that shows them in action. Here it is:



    All right, with the inclusion of this final hands-on example you should have at least a basic background in using smart markers with an existing Yahoo! Map. Nonetheless, I suggest you practice using the code samples shown in this tutorial. It's the best learning method!

    Final thoughts

    That's all for the moment. In this fifth chapter of the series, you learned a couple of additional features of Yahoo! Maps, namely working with simple polygonal lines and using "smart" markers, which are markers that can include their own markup.

    Nonetheless, smart markers require a more detailed analysis. Thus, I'll be putting my focus on them in the final installment of this article series. You don't have any excuses 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.

       · This fifth chapter of this series demonstrates with several code samples, how to...
     

    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 5 hosted by Hostway