yenbao1340 / gmaps-utility-library-dev

Automatically exported from code.google.com/p/gmaps-utility-library-dev
0 stars 0 forks source link

moving markers and zoom #51

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. having markers in markermanager (normal or labeledmarkers)
2. zooming map 
3. moving the markers

What is the expected output? What do you see instead?
Expected: map bigger, with new marker in it
Instead: this happens, but the page "crashes" from future use or updating 
with error message "this_div has no problems".

Currently I've fixed this with  window.setTimeout('xxx',2000), which is 
implicating that the problem occurs while the zooming of the map hasn't 
yet completed, when I try to change my markers place 

What version of the product are you using? On what operating system?
release (and/or LabeledMarker dev/Normal GMarker, and MarkerManager 
release) Both cause the problem. 

Please provide any additional information below.
This is the code that causes the problem (this done every 15s, when 
updating the locations of markers to map and to all i markers)
i = the marker currently updated
mgr = MarkerManager

    var gb = map.getBounds();
    while(!gb.containsLatLng(point)){           
        map.zoomOut();
    gb = map.getBounds();
    }
    marker[i].setLatLng(point);
    mgr.refresh();

So what I now would need is that the updating of the marker location 
wouldn't happen before the zoom is ready. I succeeded to fix this with 
modularizing and rearranging the whole logig and then using setTimeout in 
the end of this zooming and then as function called function that sets 
Markers location and then returns to this loop for next marker (made 
things very difficult =) ). What I'd like to have is somekind of function 
to check that the map is ready (zooming done). Callback function to zoom? 

Original issue reported on code.google.com by rouv...@gmail.com on 10 Jul 2008 at 7:34

GoogleCodeExporter commented 8 years ago
There is an event to do what you want: "zoomend"
http://code.google.com/apis/maps/documentation/events.html
http://code.google.com/apis/maps/documentation/reference.html#GMap2

A possible fix for your code (map is the GMap2 object containing your markers):

var gb = map.getBounds();
var zoomStarted = 0;
var zoomEnded = 0;
GEvent.addListener(map, "zoomend", function(oldLevel, newLevel) {
  zoomEnded = 1;
});
while(!gb.containsLatLng(point)) {
  if (!zoomStarted) {
    zoomStarted = 1;
    zoomEnded = 0;
    map.zoomOut();
  }
  if (zoomEnded) {
    zoomStarted = 0;
    zoomEnded = 0;
    gb = map.getBounds();
  }
}
marker[i].setLatLng(point);
mgr.refresh();

Better yet would probably be to replace the while loop with something fancier 
within the zoomend function to keep zooming out appropriately.

Original comment by lem...@gmail.com on 31 Jul 2008 at 4:53