JavaScript
  Home arrow JavaScript arrow Page 3 - 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 - Building a click logger within a map’s area


    (Page 3 of 4 )

    Over the course of the section that you just read, I mentioned that it was possible to build a click detection mechanism that could log certain information, such as the respective X,Y coordinates or latitude and longitude values, regarding mouse clicks.

    Before I show you how to do this, I must say that the implementation of this click logger requires using some JavaScript classes that are bundled with the Yahoo! UI framework. This can be a bit hard to grasp if you’re not familiar with it. However, fear not, because other than those UI classes, the rest of the source code that you’ll see next is practically the same as compared to previous examples.

    Having clarified that point, pay close attention to the following example, which implements the aforementioned click logger into a regional 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 a click logger</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 a click logger</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 the logger

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

    function displayLocation(_e,_c){

    var centerCoords=map.convertLatLonXY(map.getCenterLatLon());

    // set starting location

    YLog.initPos(centerCoords);

    // display latitude and longitude values when clicking on the map

    YLog.print('You Clicked at the following values:');

    YLog.print('Latitude:'+_c.Lat);

    YLog.print('Longitude:'+_c.Lon);

    }

    }

    window.onload=function(){

    initializeMap();

    }

    </script>

    </body>

    </html>


    As you can see, the prior example uses the event handler JavaScript class that comes bundled with the Yahoo! UI library to build an effective click detection mechanism, which is capable of logging the respective latitude and longitude values of a specific mouse click.

    I defined a callback JavaScript function, called “displayLocation()”, that is responsible for displaying these values in a separate box. This box was created via the “YLog” class that comes packaged with the Yahoo! UI library. Once you grasp the logic of this part of the previous example, the rest of the source code should be pretty easy to follow, since a regional map is integrated into the click logger.

    Finally, below you can see an illustrative image that shows how this click detection system works in a real situation:



    After you've analyzed how this click logger works, you might be wondering why we built it. Well, it could be utilized to display other useful stuff. For instance, it could add basic markers on the fly. That is a procedure that deserves a closer look!

    Therefore, in the upcoming section, I’m going to teach you how to include some basic markers into a selected Yahoo! Map by using the functionality of the click logger that you just learned.

    This topic will be covered in detail in the next few lines. Thus, jump forward and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


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

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT