GMap neu initialisieren

schlumsch

Mitglied
Ja Hallo

habe da wieder einmal ein Problem mit der GoogleMap und hoffe es kann mir jemand helfen. Ich verwende jsf mit Richfaces und lasse mir in einem xhtml-file eine GMap anzeigen. Funktioniert alles wunderbar, und es werden auch mein initialisieren alle Punkte adequat dargestellt. Nun möchte ich beim klicken auf einen Link die Map komplett neu initialisieren, sprich alle Punkte löschen und andere auf der Map darstellen. Konkret geht es hier um die Function showschlumsch ... *g* ... Was passiert ist, das der dort definierte Punkt zusätzlich auf der Map dargestellt wird, aber eben die alten auch noch.

Mal meine xhtml:

Code:
.....
<f:view>
<h:form>

    <rich:panel style="border:15px solid #DDFFCC; border-bottom-width:0px;">
        <h:panelGrid  style="padding:0px;" columns="2"       columnClasses="gridContent">
       <h:panelGroup  style="padding:0px;" >

	<rich:gmap id="gm2" lat="#{Bean.MAP_LATTIDUDE_INITIAL}" lng="#{Bean.MAP_LONGTIDUDE_INITIAL}" zoom="#{Bean.MAP_ZOOM_INITIAL}" gmapVar="map2"
	 gmapKey="...."
	  style="#{Bean.MAP_STYLE}" oninit="initializePoints()" />  
		 		<script type="text/javascript"> 
				   //<![CDATA[
	
	 var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.schlumsch.eu/e2e/gmapicons/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
	   
				  
			      function createMarker(point,html) {
			        var marker = new GMarker(point);
			        GEvent.addListener(marker, "click", function() {
			          marker.openInfoWindowHtml(html);
			        });
			        return marker;
			      }
			      
				   function showSchlumsch() {
				    var point = new  GLatLng(50.604977,10.710382);
				    map2.setCenter(point);
			      	var marker = createMarker(point,'turn2stone: <a target="_blank" href="http://www.schlumsch.eu">schlumsch</a>');
			
					map2.setZoom(15);
					map2.addOverlay(marker);
				   
				   }
				   
				    function setCenter(lag, lat, zoom) {
			
				       map2.setCenter(new GLatLng(lag, lat), zoom);
				       var ulp = new GPoint(lag,lat);
			     	   var ul = G_NORMAL_MAP.getProjection().fromPixelToLatLng(ulp,zoom); 
			        }

				  	function createPoints(data) {
						for (var i = 0; data.length; i++) {
							var point = new GLatLng(data[i].latitude, data[i].longitude);
							map2.setCenter(point);	
							map2.setZoom(16);			
							map2.addOverlay(createMarkerWithIdentifier(point, data[i].id, data[i].beschreibung));
						}			
				   	} 
				   	
				   	function createMarkerWithIdentifier(point, id, beschreibung) {
                      var nummer = id;
                      var idIcon = new GIcon(baseIcon);
                      idIcon.image = "http://www.schlumsch.eu/e2e/gmapicons/marker" + id + ".png";
                      markerOptions = { icon:idIcon };
					  var marker = new GMarker(point, markerOptions);
					  GEvent.addListener(marker, "click", function() {
					    marker.openInfoWindowHtml(beschreibung);
					  });
					  return marker;
					}  	

		
				    //]]>
					</script>
	     
			<a4j:jsFunction name="initializePoints" data="#{Bean.hotels}"
			oncomplete="createPoints(data)">
			</a4j:jsFunction>
 

   <a href="javascript:void(0);" onclick="showSchlumsch();return false;"><font size="-2">der Author</font></a> 
   

... 
       
   

</h:form>
</f:view>
</ui:composition>
 
Zurück