JavaScript
  Home arrow JavaScript arrow Page 2 - 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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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


    Using Polylines and Smart Markers with Yahoo! Maps - Review: adding basic markers to an existing map


    (Page 2 of 4 )

    Of course, I know that you're so curious about learning how to draw some polylines on a given Yahoo! Map that you can't wait to read that particular section of the tutorial. However, as you know, small moves take us a long way, so in this case, I'm going to show you the complete process of adding a number of basic markers to a selected map, in case you didn't have the chance to read the article in which I discussed this process in detail.

    Having clarified this point, pay close attention to the following hands-on example, which demonstrates how to incorporate a few basic markers into a sample Yahoo! Map:


    <!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 and adding simple markers</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 and adding simple markers</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 slong 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,displayMarker);

    // display new marker on the map

    function displayMarker(_e,_c){

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

    map.addMarker(geoPoint);

    }

    }

    window.onload=function(){

    initializeMap();

    }

    </script>

    </body>

    </html>


    Even though the previous example is actually very easy to follow, let me briefly explain what it does. Basically, in this particular case, I used the click logger that you saw in the preceding article of the series to display different basic markers on a satellite Yahoo! map as the map in question is being clicked on.

    As you can see, markers are added dynamically via the callback "displayMarker()" JavaScript function, which is invoked by the pertinent "YEvent.Capture()" method, which comes bundled with the Yahoo UI library. The most relevant point to stress here is that those markers are actually included into the map by using the "addMarker()" method, something that should be quite easy to grasp.

    Well, at this point you've hopefully recalled the foundations of how to incorporate a few simple markers into an existing Yahoo! Map. Thus, considering this propitious scenario, it's time to learn other useful features that come packaged with the Yahoo! Map Ajax framework.

    In the section to come, I'm going to show you how to draw different polylines on a selected map by utilizing the click logger that I reviewed earlier. Click on the link below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


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

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek