Using Polylines and Smart Markers with Yahoo! Maps
Welcome to the fifth part of the series “Working with Yahoo! Maps.” This series teaches you how to implement the most useful features that come packaged with the Yahoo! Maps Ajax framework. It will permit you to include powerful, highly interactive maps into your own website by using a combination of basic structural markup and a few lines of JavaScript code.
Using Polylines and Smart Markers with Yahoo! Maps - Drawing polygonal lines (polylines) (Page 3 of 4 )
In the section that you just read, I told you that the Yahoo! Maps framework permits you to draw polylines by using another handy JavaScript class, which, not surprisingly, is called "YPolyline()." As you will see for yourself in a moment, the class is quite flexible and allows you to display these lines using different customization parameters, including line colors, opacity, etc.
Let me show you a concrete example of how to draw a few simple polygonal lines on an existing Yahoo! Map. 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 polylines</title>
As you can see, the above hands-on example first constructs a simple satellite map, and then uses the same click logger that you learned in the previous section to dynamically include different markers as the map is being clicked on. So far, this process should be pretty familiar to you. Please notice that I also defined a "polylinePoints" array with the purpose of storing the different latitude/longitude values corresponding to each mouse click.
These array elements are then used to create several black polygonal lines, which are inserted into the map by way of another JavaScript method, called "addOverlay()." As you may guess, this method is utilized to "overlap" different elements on a given map, and certainly polylines are no exception.
If you're anything like me, then you may want to see the final result of this process. Below I included a screen shot that shows the polylines in action. Here it is:
As you can see, the pertinent polygonal lines come in handy for interconnecting different markers as they are displayed on the map. Quite simple to grasp, right?
So far, so good. At this point, you should have an exact idea of how to draw a few basic polylines in an existing Yahoo! Map. So the next step will consist of demonstrating how to build special markers, which in the context of the Yahoo! Map framework are called "smart markers."
As you'll see in the section to come, these special markers can include additional markup in their structures. Therefore, jump forward and keep reading, since I'll be there waiting for you.