Deleting an overlay through button and HTML

48 views
Skip to first unread message

VolksNav

unread,
Jan 31, 2012, 6:16:09 AM1/31/12
to google-map...@googlegroups.com



Hi,

I'm passing to V3, could solve difficult tasks - see www.volksnav.de/iNY - but until now it wasn't possible to delete an overlay through a button, see

www.volksnav.de/PLZv3test/indexSimple.htm

and the following code. Can anybody help? Thank you in advance

VolksNav

----------------

<html>
<head>
<meta name="viewport" content="initial-scale=1, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var map;

  function initialize() {

      var centroMapa = new google.maps.LatLng(48.1375, 11.5757); 
      var myOptions = {    zoom: 16, center: centroMapa, mapTypeId: google.maps.MapTypeId.ROADMAP    }
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

      var Circulo = new google.maps.Circle({ center: centroMapa, radius: 300, strokeColor: "#FF0000",strokeWeight: 3, fillOpacity: 0 });

      Circulo.setMap(map);   

// just for information:

// doesn't work:          setTimeout(deleteCirculo(), 3000); 
// OK:                        setTimeout(deleteCirculo, 3000);  
// OK:            google.maps.event.addListener(map, 'click', function() {Circulo.setMap(null);});
// OK:            google.maps.event.addListener(map, 'click', function(){deleteCirculo();}); 
// OK:            deleteCirculo(); 

    function deleteCirculo() {
       Circulo.setMap(null);   
    };
} // initialize

</script>
</head>

<body onload="initialize()">
<div id="map_canvas" style="width:60%; height:60%"></div>

<input type="button" value="show grid" onclick="map.Circulo.setMap(null)"; />

<!--
on V2 this was OK:     onClick="map.clearOverlays()"

Also not working:
<input type="button" value="delete grid" onclick="deleteCirculo"; />
<input type="button" value="delete grid" onclick="deleteCirculo()"; >
<input type="button" value="delete grid" onclick="Circulo.setMap(null)"; >
<input type="button" value="delete grid" onclick="Circulo.set_map(null)"; >
<input type="button" value="delete grid" onclick="map.Circulo.set_map(null)"; >
-->


</body>
</html>

Pil

unread,
Jan 31, 2012, 6:39:11 AM1/31/12
to Google Maps JavaScript API v3
Three basic hints:

1: Try to write valid html using a valid doctype.

2. Try to declare all your global variables as global and distinguish
clearly between local and global variables.

3. Try to find out whats wrong here

var posLat = "40.8";
var posLon = "-73.9";
var radio = "92";

var CentroMapa = new google.maps.LatLng(posLat, posLon);

when the docs say that a LatLng object expects two numbers as argument
- not strings.
Reply all
Reply to author
Forward
0 new messages