Solved

Google maps v3 customize the directions panel

Posted on 2011-02-24
3
2,388 Views
Last Modified: 2012-05-11
how can i customize the directions panel with css , this is the demo i am trying to customize

http://code.google.com/apis/maps/documentation/javascript/examples/directions-panel.html
0
Comment
Question by:mugsinc
3 Comments
 
LVL 20

Expert Comment

by:thehagman
ID: 34974553
Maybe this helps you, that's how I once solved the problem:
http://www.redeker.de/CSS/googlemaps.css
Note that id="Fahrhinweise" is the div I let Google place the driving dirctions and the main trick is to use the #Fahrhinweise selector to make rules specifically for driving directions, i.e. I have
new GDirections(map,document.getElementById("Fahrhinweise"))
somewehre in my js code.

Use DOM inspector to find out about the structure and see what you wnat to restyle.

Note that you MUST NOT use css to visibly remove warning hints Google adds (e.g. for pedestrians that might cross a motorway)
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34975793
Following the information here : http://code.google.com/intl/en-US/apis/maps/documentation/javascript/controls.html#CustomControls

Your previous page and some updates on the CustomControls example  :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Google Maps JavaScript API v3 Example: Directions Complex</title> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" /> 
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript">

	var directionDisplay;
	var directionsService = new google.maps.DirectionsService();
	var map;
	var chicago = new google.maps.LatLng(41.850033, -87.6500523);
	
	$(document).ready(function() {
		initialize();
 	});
	
	function initialize() {
		directionsDisplay = new google.maps.DirectionsRenderer();
		var chicago = new google.maps.LatLng(41.850033, -87.6500523);
		var myOptions = {
			zoom:7,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			disableDefaultUI: true,
			center: chicago
		}
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		directionsDisplay.setMap(map);
		directionsDisplay.setPanel(document.getElementById("directionsPanel"));
		
		// Create the DIV to hold the control and call the HomeControl() constructor
		// passing in this DIV.
		var homeControlDiv = document.createElement('DIV');
		var homeControl = new HomeControl(homeControlDiv, map);
		
		homeControlDiv.index = 1;
		map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);	
	}
  
	function calcRoute() {
		var start = document.getElementById("start").value;
		var end = document.getElementById("end").value;
		var request = {
			origin:start, 
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			}
		});
	}

	/**
	* The HomeControl adds a control to the map that simply
	* returns the user to Chicago. This constructor takes
	* the control DIV as an argument.
	*/

	function HomeControl(controlDiv, map) {

		// Set CSS styles for the DIV containing the control
		// Setting padding to 5 px will offset the control
		// from the edge of the map
		controlDiv.style.padding = '5px';

		// Set CSS for the control border
		var controlUI = document.createElement('DIV');
		controlUI.style.backgroundColor = 'white';
		controlUI.style.borderStyle = 'solid';
		controlUI.style.borderWidth = '2px';
		controlUI.style.cursor = 'pointer';
		controlUI.style.textAlign = 'center';
		controlUI.title = 'Click to set the map to Home';
		controlDiv.appendChild(controlUI);

		var compass = document.createElement("img");
		compass.setAttribute("src", "http://a07015.uscgaux.info/Compass.jpg");
		compass.setAttribute("width", 129);

		// Set CSS for the control interior
		var controlText = document.createElement('DIV');
		controlText.style.fontFamily = 'Arial,sans-serif';
		controlText.style.fontSize = '12px';
		controlText.style.paddingLeft = '4px';
		controlText.style.paddingRight = '4px';
//		controlText.innerHTML = 'Home';
		controlText.appendChild(compass);
		controlUI.appendChild(controlText);

		// Setup the click event listeners: simply set the map to Chicago
		google.maps.event.addDomListener(controlUI, 'click', function(e) {
			if(window.event) { 
				var x = e.offsetX; 
				var y = e.offsetY; 
			} else { 
				var x = e.layerX; 
				var y = e.layerY; 
			}
//			var offset = (window.event)?({"X":e.offsetX,"Y":e.offsetY}):({"X":e.layerX,"Y":e.layerY}); 
//			alert("X: "+ offset["X"]+ "\nY :" + offset["Y"]);
			var w = 129/3;
			var h = 117/3;			
			var dx = 0;
			var dy = 0;
			if(x<w) dx--;else if(x>2*w) dx++;
			if(y<h) dy++;else if(y>2*h) dy--;
			var LatLng = map.getCenter();
			var newPos = new google.maps.LatLng(LatLng.lat() + dy, LatLng.lng() + dx);
			map.setCenter(newPos);
  		});
	}

</script> 
</head> 
<body> 
<div> 
<b>Start: </b> 
<select id="start" onchange="calcRoute();"> 
  <option value="chicago, il">Chicago</option> 
  <option value="st louis, mo">St Louis</option> 
  <option value="joplin, mo">Joplin, MO</option> 
  <option value="oklahoma city, ok">Oklahoma City</option> 
  <option value="amarillo, tx">Amarillo</option> 
  <option value="gallup, nm">Gallup, NM</option> 
  <option value="flagstaff, az">Flagstaff, AZ</option> 
  <option value="winona, az">Winona</option> 
  <option value="kingman, az">Kingman</option> 
  <option value="barstow, ca">Barstow</option> 
  <option value="san bernardino, ca">San Bernardino</option> 
  <option value="los angeles, ca">Los Angeles</option> 
</select> 
<b>End: </b> 
<select id="end" onchange="calcRoute();"> 
  <option value="chicago, il">Chicago</option> 
  <option value="st louis, mo">St Louis</option> 
  <option value="joplin, mo">Joplin, MO</option> 
  <option value="oklahoma city, ok">Oklahoma City</option> 
  <option value="amarillo, tx">Amarillo</option> 
  <option value="gallup, nm">Gallup, NM</option> 
  <option value="flagstaff, az">Flagstaff, AZ</option> 
  <option value="winona, az">Winona</option> 
  <option value="kingman, az">Kingman</option> 
  <option value="barstow, ca">Barstow</option> 
  <option value="san bernardino, ca">San Bernardino</option> 
  <option value="los angeles, ca">Los Angeles</option> 
</select> 
</div> 
<div id="map_canvas" style="float:left;width:70%; height:100%"></div> 
<div id="directionsPanel" style="float:right;width:30%;height 100%"></div> 
</body> 
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:mugsinc
ID: 35003724
it works
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question