google maps api 3 - creating a Placemarks that can be hidden -
i have been trying create placemark can hide , show (like turning visibility on , off) on demand (on click)... using make placemark:
function placemark(lat, long, name, url, iconsrc){ var placemark = ge.createplacemark(name); ge.getfeatures().appendchild(placemark); placemark.setname(name); // create style map placemark var icon = ge.createicon(''); if(iconsrc == "0") icon.sethref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png'); else{ icon.sethref(iconsrc); } var style = ge.createstyle(''); style.geticonstyle().seticon(icon); if(iconsrc != "0") style.geticonstyle().setscale(2.5); placemark.setstyleselector(style); // create point var point = ge.createpoint(''); point.setlatitude(lat); point.setlongitude(long); //point.setaltitudemode(1500); placemark.setgeometry(point); google.earth.addeventlistener(placemark, 'click', function(event) { // prevent default balloon popping up. event.preventdefault(); var balloon = ge.createhtmlstringballoon(''); balloon.setfeature(placemark); // optional balloon.setcontentstring( '<iframe src="'+ url +'" frameborder="0"></iframe>'); ge.setballoon(balloon); }); } i have tried everything... this:
function hideplacemark(name){ var children = ge.getfeatures().getchildnodes(); for(var = 0; < children.getlength(); i++) { var child = children.item(i); if(child.gettype() == 'kmlplacemark') { if(child.getid()== name) child.setvisibility(false); } } } to using ge.getfeatures().removechild(child);
can point me right direction on creating function allow me turn visibility on/off on demand please.
your hideplacemark function missing {} in final if statement
if(child.getid()== name) you have
function hideplacemark(name){ var children = ge.getfeatures().getchildnodes(); for(var = 0; < children.getlength(); i++) { var child = children.item(i); if(child.gettype() == 'kmlplacemark') { if(child.getid()== name) child.setvisibility(false); } } } make it
function hideplacemark(name){ var children = ge.getfeatures().getchildnodes(); for(var = 0; < children.getlength(); i++) { var child = children.item(i); if(child.gettype() == 'kmlplacemark') { if(child.getid()== name) { child.setvisibility(false); } } } } however ------- better off doing faster don't need loop through placemarks
function hideplacemark(name) { var placemark = ge.getelementbyid(name); placemark.setvisibility(false); }
Comments
Post a Comment