Solved

Toggle effect on a button

Posted on 2011-09-08
4
301 Views
Last Modified: 2012-05-12
I have just added a "zoom in" button into an info window within a Google Map (you can see it working here http://www.soundsairpark.com/sandpit/mapTest2.html).
What I would like to do is have the button change so that after it has been clicked and "zoomed in" the button value will change to "zoom out" and the onclick event will set the zoom level back to its default 8.
Cheers,
N

// code shows my info window and the zoom button
var marker = createMarker(point,'<div style="width:240px; font-family:Arial; font-size:14px"> <input type="button" id="zoom" value="Zoom" onclick="map.setZoom(15)"/><\/div>')

Open in new window

0
Comment
Question by:Neil_Bradley
  • 2
4 Comments
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 36506875
have figured out how to update the button value but not toggle between zooming in and out
http://www.soundsairpark.com/sandpit/mapTest-toggle.html
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36506972
which button?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 36506982
Check this :

<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Maps JavaScript API Example: Ground Overlays</title> 
<script src="//maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAI8kIB4hk8gD-5yrnCohd5RSkwzceBTFrUE_2xjvYDKmGarCKKBSCCpAUeziDLbQ5V2Ky46IDwydShg" type="text/javascript"></script> 
</head> 
<body onunload="GUnload()"> 
<div id="map" style="width: 800px; height: 600px"></div> 
<script type="text/javascript"> 
//<![CDATA[
	if (GBrowserIsCompatible()) { 
	
		function createMarker(point,html) {
			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function() {
				//marker.openInfoWindowHtml(html); // NOT SURE YOU STILL WANT THIS ELSE UNCOMMENT
				map.setCenter(marker.getLatLng());
				if( map.getZoom() != 8 ) {
					map.setZoom(8);
				}
				else {
					map.setZoom(15);
				}
			});
			return marker;
		}
		
		// Display the map, with some controls and set the initial location 
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(-41.34204, 173.957801),8); 
		map.setMapType(G_HYBRID_MAP);
		
		// Set up marker with info windows
		var point = new GLatLng(-41.34204, 173.957801);
		var marker = createMarker(point,'<div style="width:240px; font-family:Arial; font-size:14px"><img src="http://www.soundsairpark.com/sandpit/images/structure/logo-icon.png" width="66" height="48"  style="float:left; margin-right:10px">Marlborough Sounds <br>Air Park<br>SH1, Picton. NZ<br><\/div>');
		map.addOverlay(marker);

		// ground overlay
		var boundaries = new GLatLngBounds(new GLatLng(-41.34630,173.95099), new GLatLng(-41.33990,173.9610));
		var oldmap = new GGroundOverlay("http://www.soundsairpark.com/images/map-overlay.png", boundaries);
		map.setUIToDefault();
		map.addOverlay(oldmap);
	
	}
//]]>
</script> 
</body>
</html>

Open in new window

0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 36507048
That is brilliant. I have adapted your script so that the the 'zoom in' toggle effect is applied to the button within the  info window.
Thanks for your help.
Cheers,
N
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding Special HTML Characters using Javascript? 2 23
Why doesn't Google directions work? 6 40
Scroll 5 news at a time. 4 25
Help with removing item from Session Array 3 21
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

813 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

11 Experts available now in Live!

Get 1:1 Help Now