views:

1269

answers:

3

hey

i have a google map in my site and attach to it event handler of moveend

   GEvent.addListener(map, "moveend", function() 
    {
            map.clearovrelays();
            GetLayerDataFromServer(); //it set the markers again on the map  acording the map position


    });

and also i have event handler for click on marker

GEvent.addListener(marker, 'click', function()
    { 
        marker.openInfoWindowHtml('this is the data');
    });

my problem is this

when user press on one of the marker on the map it open the openInfoWindowHtml of the related marker.

and it also move the map to that marker position and then it triggers the event map.moveend

and in the event map.moveend i am clear all the marker on the map and reload them according to the map new position

the result is that when user is click on marker it open for second his indoWindowHtml and the clear the map and load again the markers without showing the indoWindowHtml of the clicked marker.

my q is what shell i do in order to show the infoWindowHtml

?

than for all the replaying i hope u understand

+1  A: 

You can set a flag that indicates if the user clicked a marker and not clear the map if that's the case.

var marker_clicked = false;

GEvent.addListener(map, "moveend", function() 
{
    if(!marker_clicked)
    {
     map.clearovrelays();
     GetLayerDataFromServer(); //it set the markers again on the map  acording the map position
    }
    marker_clicked = false;
});

GEvent.addListener(marker, 'click', function()
{
    marker_clicked = true;
    marker.openInfoWindowHtml('this is the data');
});
Daff
okbut i want that GetLayerDataFromServerwill occur because i want to get the markers for the map new coordinates
avi
@avi: then move the GetLayerDataFromServer() outside the if clause.
NickFitz
A: 

One possible alternative strategy is to open your info window with {suppressMapPan:true} which tells the map not to pan when the infowindow opens. That way, you know that any map movements are real map movements by the user.

Caution: {suppressMapPan:true} is undocumented, so it might possibly disappear in some future release.

Mike Williams
A: 

Another strategy would be to write

GEvent.addListener(marker, 'click', function()
    { 
        var iwAnchor = marker.getIcon().infoWindowAnchor;
        var iconAnchor = marker.getIcon().iconAnchor;
        var offset = new GSize(iwAnchor.x-iconAnchor.x,iwAnchor.y-iconAnchor.y);
        map.openInfoWindowHtml(marker.getLatLng(),'this is the data',{pixelOffset:offset});
    });

and then instead of calling clearOverlays(), loop through your markers one by one removing them.

By opening the infowindow on the map instead of the marker, it doesn't get automatically closed when the marker is removed.

The infowindow is now an overlay, so clearOverlays removes it, so you can't use clearOverlays. It might sound inefficient to loop through your markers, removing them one by one, but the clearOverlays does a very similar loop internally.

The iconAnchor calculations above simply position the infowindow in the same place that it would be if you had used marker.openInfowindowHtml, rather than at the foot of the marker.

Mike Williams