Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Google maps v3 customize the directions panel

Posted on 2011-02-24
3
Medium Priority
?
2,683 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

647 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