JavaScript
  Home arrow JavaScript arrow Page 4 - Creating Click Loggers and Basic Markers w...
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

Creating Click Loggers and Basic Markers with Yahoo! Maps
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-22

    Table of Contents:
  • Creating Click Loggers and Basic Markers with Yahoo! Maps
  • Review: adding zoom and pan control to a single Yahoo! Map
  • Building a click logger within a map’s area
  • Adding basic markers on the fly

  • 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


    Creating Click Loggers and Basic Markers with Yahoo! Maps - Adding basic markers on the fly


    (Page 4 of 4 )

    As you might have guessed, Yahoo! Maps supports the inclusion of different types of markers into a selected geographical location. It's a feature that can be really useful when highlighting certain relevant points that belong to the targeted location or to other places.

    In this case, the click logger that I built in the previous section can be used in conjunction with an existing map to add some basic markers to it as the map in question is being clicked. Thus, having said that, pay close attention to the following hands-on example, which shows how to incorporate different markers to a satellite Yahoo! Map on the fly.

    The corresponding code sample is as follows:


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


    As you can see from the above example, I introduced a brand new JavaScript method, “addMarker(),” that is tasked with displaying a basic marker on the selected map. You should notice that this method takes a “Yahoo!” geo point object as an input argument. This is an object that contains a pair of latitude/longitude values that are properly calculated based on the X,Y coordinates generated each time a mouse click occurs inside the map in question.

    This process may sound a bit messy to you, but hopefully the following screen shot will help to dissipate any possible doubts about how these basic markers are added to this sample Yahoo! Map:



    See how simple it is to include a few basic markers into a given map? Sure you do! However, as with every web development topic, it requires some time and practice. So I recommend you use all the code samples shown in this tutorial to improve your skills in working with Yahoo! Maps. It’ll be a productive experience, trust me!

    Final thoughts

    In this fourth chapter of the series, you hopefully learned the foundations of adding basic markers to an existing Yahoo! Map by using an effective click detection mechanism built around the functionality provided by the Yahoo! “Event.Capture” event handling class.

    In the next part, things will get even more interesting, since you’ll see how to use the same mouse click handler, but this time to work with what, in Yahoo! jargon, is called a “smart” marker.

    Want to find out how this story continues? Don’t miss the next article!


    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.

       · In this fourth article of the series, you’ll learn in detail how to include some...
     

    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 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek