Solved

Toggle effect on a button

Posted on 2011-09-08
4
298 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
Comment Utility
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
Comment Utility
which button?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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…

744 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

9 Experts available now in Live!

Get 1:1 Help Now