Hi,
this is my javascript example, please corrent my wrong :
if (GBrowserIsCompatible()) {
var Icon = new GIcon(G_DEFAULT_ICON);
Icon.image = "coldmarker.png";
var side_bar_html = "";
var gmarkers = [];
var listeners=[];
var htmls = [];
var i = 0;
// A function to create the marker and set up the event window
function createMarker(point,name,html) {
var marker = new GMarker(point,Icon);
var EventHandler=GEvent.addListener(marker, "click", function() {
if (marker==undefined){
GEvent.removeListener(EventHandler);
}else{
marker.openInfoWindowHtml(html);
}
});
// Switch icon on marker mouseover and mouseout
GEvent.addListener(marker, "mouseover", function() {
marker.setImage("marker.png");
});
GEvent.addListener(marker, "mouseout", function() {
marker.setImage("coldmarker.png");
});
gmarkers[i] = marker;
htmls[i] = html;
*// i try to remove marker when event onmouseout, after marker clear, this
still appear when function myclick called*, please look at on myclick
function
side_bar_html += '<a href="javascript:myclick(' + i + ')"
onmouseout="removeMarker('+i+');" >' + name + '<\/a><br>';
i++;
return marker;
}
function removeMarker(index)
{
// i try to remove marker twice, but marker still apear when myclick
function called? what wrong?
map.removeOverlay(gmarkers[index]);
gmarkers[index].remove();
}
// This function picks up the click and opens the corresponding info
window
function myclick(i) {
gmarkers[i].openInfoWindowHtml(htmls[i]);
}
// create the map
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(43.907787,-79.359741),9);
// Read the data from example.xml
var request = GXmlHttp.create();
request.open("GET", "example.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
// obtain the array of markers and loop through it
var markers =
xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var html = markers[i].getAttribute("html");
var label = markers[i].getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
map.addOverlay(marker);
}
// put the assembled side_bar_html contents into the side_bar div
document.getElementById("side_bar").innerHTML = side_bar_html;
}
}
request.send(null);
}
else {
alert("Sorry, the Google Maps API is not compatible with this
browser");
}
On Mon, Jul 5, 2010 at 8:30 PM, Andrew Leach <[email protected]>wrote:
> On Jul 4, 12:44 pm, tazkiyah arrosyidah
> <[email protected]> wrote:
> >
> > how i can delete listener too when mark in array is delete?
>
> If there is no marker, there is nothing for an event to be triggered
> on, so any listener is redundant and won't actually do anything.
>
> If you want to remove an event listener explicitly, the easy way is to
> retain a reference to it:
> var myListener = GEvent.addListener(...);
> GEvent.removeListener(myListener);
> but there are other methods available too:
>
> http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GEvent.clearListeners
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.