Source: maps/callout/content.js


/**
 * Create HTML content for a callout that shows the name/title of a marker.
 * Use this function as a contentCreator when creating an {@link lucid.maps.callout.InfoBox} object.
 * 
 * @param {google.maps.Marker} marker  The marker that is the subject of the callout.
 */
lucid.maps.callout.content.createContentTitle = function( marker )
{
	var titleDiv = jQuery( "<div class='place-name'>" + marker.getTitle() + "</div>" );
	
	var contentDiv = jQuery( "<div></div>" );
	contentDiv.append( titleDiv );
	
	return contentDiv;
};

/**
 * Create HTML content for a callout that shows the rating and opening hours a place.
 * Use this function as a contentCreator when creating an {@link lucid.maps.callout.InfoBox} object.
 * 
 * @param {google.maps.Marker} marker  The marker that marks the location of the place.
 *                                     The marker must also have a placeReference property, which holds the uid of the place.
 */
lucid.maps.callout.content.createContentPlaceInfo = function( marker )
{
	var contentDiv = lucid.maps.callout.content.createContentTitle( marker );
	
	var initialMessage;
	if (typeof marker.placeReference !== "undefined")
	{
		initialMessage = "Loading ...";
		requestPlaceDetail();
	}
	else
	{
		initialMessage = "No place ref for marker.";
	}
	
	var infoDiv = jQuery( "<div class='place-info'>" + initialMessage + "</div>" );
	contentDiv.append( infoDiv );
	
	return contentDiv;
	
	
	function requestPlaceDetail()
	{
		var searchService = new google.maps.places.PlacesService( marker.getMap() );
		var placeDetailRequest = { "reference": marker.placeReference };
		searchService.getDetails( placeDetailRequest, processPlaceDetail );
	}
	
	function processPlaceDetail( place, status )
	{
		// TODO Handle non "OK" states.
		
		var placeDetailParser = new lucid.maps.places.PlaceDetailParser( place );
		
		var html = "";
		if (placeDetailParser.hasRating())
		{
			html += "<p>Rating: " + placeDetailParser.getRating() + "</p>";
		}
		if (placeDetailParser.hasOpeningHours())
		{
			html += "<p>" + placeDetailParser.getOpeningHoursToday() + "</p>";
		}
		
		infoDiv.html( html );
	}
};