yugalatea / gwt-google-apis

Automatically exported from code.google.com/p/gwt-google-apis
0 stars 0 forks source link

Map doesn't pan far enough for large info window--close box is invisible #236

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Found in Release:
GWT-maps version 1.0.2 (using GWT version 1.5.3)

Detailed description:
I have a map (width 700px, height 325px) with markers.  Each marker has an
associated info window, with height fairly large relative to the map.  (In
my real application, I need to put a chart into the info window, with some
other information.)  I've tried a range of sizes; use 100px for now.  

If I click on a marker that is closer to the top of the displayed area than
the height of the info window, the map pans slightly, but not enough to
make the close box (or any information at the top of the info window)
visible.  At most, the map pans for a few (~10?) pixels (at zoom 8), but
not enough that the entire info window is visible.

I have replicated this in a very simple app based off the sample
application in the tutorial, and can at least post the code if that would help.

Workaround if you have one:

Links to the relevant GWT Developer Forum posts:

Original issue reported on code.google.com by lucy.had...@gmail.com on 28 Jan 2009 at 8:36

GoogleCodeExporter commented 9 years ago
Yes, posting code would help (you could attach your modified entry point and 
other
necessary files to this issue if you like).  We will need to re-write it in JS 
to
reproduce it for the Maps API team.

Original comment by galgwt.reviews@gmail.com on 28 Jan 2009 at 8:40

GoogleCodeExporter commented 9 years ago
Here's the code; the related .gwt.xml is trivial.  No css or anything.  Let me 
know
if I left something out, or if I can say or do more.  Thanks!

Original comment by lucy.had...@gmail.com on 28 Jan 2009 at 9:09

Attachments:

GoogleCodeExporter commented 9 years ago
Two things:
1) If it's not obvious, the marker near Lawrence, MA (018) is the best one for
getting this behavior.
2) Do *you* have any suggestions for a workaround?  I'm not seeing an obvious 
way to
figure out how much more to pan the map and then do so.

I really appreciate the prompt response you've given this issue; thanks.

Original comment by lucy.had...@gmail.com on 29 Jan 2009 at 2:03

GoogleCodeExporter commented 9 years ago
I am sorry, I don't have any great ideas for workarounds.  The only thing I can 
think
of is that there is a MapWidget.convertLatLngToContainerPixel() and
MapWidget.convertLatLngToDivPixel() that might tell you if the position of the 
info
window is close to the right edge, then you could manually reset the center.  
You
might need to do this inside an InfoWindowOpenHandler callback.

Original comment by ericzun...@gmail.com on 29 Jan 2009 at 2:29

GoogleCodeExporter commented 9 years ago
I still see this behavior in version 1.1, using GWT 2.0.3.

Original comment by moor...@gmail.com on 25 Jun 2010 at 7:02

GoogleCodeExporter commented 9 years ago
In fact, for me, the infowindow opening behaves really bizarrely:

I am adding a MarkerClickHandler like so

public void onClick(MarkerClickEvent event) {
Marker marker = (MyMarker)event.getSender();
mapWidget.getInfoWindow().open(marker,infoWindowContent();
}

It opens the infowindow every time, but pans the map in seemingly random 
directions.

Original comment by moor...@gmail.com on 25 Jun 2010 at 7:19

GoogleCodeExporter commented 9 years ago
For anyone else, here was my workaround.

I added this code to a MarkerClickHandler that opens the infowindow (where 
getMap() returns the mapWidget).  I have tested this in FF3.6 so far.  This 
also only works for North America, because of assumptions about the sign of 
latitude and longitude, but should be extendable to different hemispheres.

-------------
LatLng markerLatLng = marker.getLatLng();
LatLng center = getMap().getCenter();

LatLng nePt = getMap().getBounds().getNorthEast();
LatLng swPt = getMap().getBounds().getSouthWest();

double latInView = Math.abs(nePt.getLatitude() - swPt.getLatitude());

double lngInView = Math.abs(nePt.getLongitude() - swPt.getLongitude());

double newLat = center.getLatitude(),newLng = center.getLongitude();

boolean panning = false;

if (markerLatLng.getLatitude() > center.getLatitude() + latInView/6d) {
  newLat = center.getLatitude() + latInView/6;
  panning = true;
}

// weird because of - longitudes
double boundEast = center.getLongitude() + lngInView*(3d/10);
double boundWest = center.getLongitude() - lngInView*(3d/10);

if (markerLatLng.getLongitude() > boundEast) {
  newLng = boundEast;
  panning = true;
} else if (markerLatLng.getLongitude() < boundWest) {
  newLng = boundWest;
  panning = true;
}

if (panning) {
  LatLng newCenter = LatLng.newInstance(newLat, newLng);
  getMap().panTo(newCenter);
}

-------------

The 1/6 (for latitude) and 3/10 (for longitude) ratios will differ based on the 
size of your infowindow.

Hope this helps.

Original comment by moor...@gmail.com on 25 Jun 2010 at 8:52

GoogleCodeExporter commented 9 years ago
Err, actually, I found after a bit more time that this line in the 
MarkerClickHandler works well:

----------
getMap().panTo(marker.getLatLng());
----------

That is, just pan to where the marker is.

Original comment by moor...@gmail.com on 25 Jun 2010 at 9:22

GoogleCodeExporter commented 9 years ago
Actually, neither solution I outlined above works 100% of the time.  I ended up 
just not using the info window and finding another way to display the data.

Original comment by moor...@gmail.com on 29 Jun 2010 at 12:23

GoogleCodeExporter commented 9 years ago
The Maps v2 API is now deprecated

Original comment by zundel@google.com on 28 Oct 2011 at 3:44