Solved

Google maps v3 customize the directions panel

Posted on 2011-02-24
3
2,258 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now