A Closer Look at Smart Markers with Yahoo! Maps - Displaying smart markers on a hybrid Yahoo! Map
(Page 4 of 4 )
In accordance with the concepts that I deployed in the section you just read, I’m going to end this final article of the series by showing you how to incorporate a few smart markers into an existing hybrid Yahoo! Map. This process looks very similar to the one described when working with a regional map, so I won’t bore you with irrelevant explanations about how it works.
Instead, you can save your valuable time and have a close look at the following code sample, which demonstrates how to use the aforementioned smart markers with a selected hybrid 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 using smart markers with an hybrid YAHOO! Map</title>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?
v=3.7&appid=YahooDemo"></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 an hybrid 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 slong zoom control to the map
map.addZoomLong();
// Set map type to YAHOO_MAP_HYB
map.setMapType(YAHOO_MAP_HYB);
// 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>
As you can see, once again I used a click logger to display different smart markers as the pertinent map is being clicked. Logically, the only difference to spot here is that a hybrid map is used, instead of a regional or a satellite-based one. The rest of the source code remains the same, so you shouldn’t have major trouble understanding how this specific example functions.
Besides, below I included a complementary image that shows how these smart markers are properly displayed on this regional map:

As is usual with many of my articles on web development, feel free to modify the source code of all of the examples developed in this series. This way you can improve your skills in using the Yahoo! Map framework.
Final thoughts
We’ve come to the end of this article series. I hope that all of the code samples that I provided in this group of tutorials will be useful enough to get you started utilizing the most relevant features offered by Yahoo! Maps.
See you in the next web development tutorial!
| 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. |