fix "flying"-boats in rare cases of auto-zooming (e.g. after deselecting a boat) by serializing setZoom and panTo which otherwise interfere with each other;

This commit is contained in:
Christopher Ronnewinkel (D036654) committed 2014-08-07 14:37:52 +02:00
1 parent a3b5b09638
commit cc42ecf91b
1 file changed
+29 -3
@@ -34,6 +34,8 @@ import com.google.gwt.maps.client.events.click.ClickMapEvent;
import com.google.gwt.maps.client.events.click.ClickMapHandler;
import com.google.gwt.maps.client.events.dragend.DragEndMapEvent;
import com.google.gwt.maps.client.events.dragend.DragEndMapHandler;
import com.google.gwt.maps.client.events.idle.IdleMapEvent;
import com.google.gwt.maps.client.events.idle.IdleMapHandler;
import com.google.gwt.maps.client.events.mouseout.MouseOutMapEvent;
import com.google.gwt.maps.client.events.mouseout.MouseOutMapHandler;
import com.google.gwt.maps.client.events.mouseover.MouseOverMapEvent;
@@ -279,6 +281,8 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
private LatLngBounds currentMapBounds;
private int currentZoomLevel;
private boolean autoZooming = false;
private LatLngBounds newLatLngBounds;
private WindStreamletsRaceboardOverlay streamletOverlay;
private final boolean showViewStreamlets;
@@ -381,6 +385,15 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
settings.getZoomSettings().setTypesToConsiderOnZoom(emptyList);
}
});
map.addIdleHandler(new IdleMapHandler() {
@Override
public void onEvent(IdleMapEvent event) {
if (autoZooming) {
map.panTo(newLatLngBounds.getCenter());
autoZooming = false;
}
}
});
map.addBoundsChangeHandler(new BoundsChangeMapHandler() {
@Override
public void onEvent(BoundsChangeMapEvent event) {
@@ -1211,9 +1224,22 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
// only change bounds if the new bounds don't fit into the current map zoom
List<ZoomTypes> oldZoomSettings = settings.getZoomSettings().getTypesToConsiderOnZoom();
setAutoZoomInProgress(true);
LatLngBounds newLatLngBounds = BoundsUtil.getAsLatLngBounds(newBounds);
map.panTo(newLatLngBounds.getCenter());
map.setZoom(getZoomLevel(newLatLngBounds));
newLatLngBounds = BoundsUtil.getAsLatLngBounds(newBounds);
int newZoomLevel = getZoomLevel(newLatLngBounds);
if (newZoomLevel != map.getZoom()) {
// remove the canvas animations for boats
for (BoatOverlay boatOverlay : RaceMap.this.getBoatOverlays().values()) {
boatOverlay.removeCanvasPositionAndRotationTransition();
}
// remove the canvas animations for the info overlays of the selected boats
for(CompetitorInfoOverlay infoOverlay: competitorInfoOverlays.values()) {
infoOverlay.removeCanvasPositionAndRotationTransition();
}
autoZooming = true;
map.setZoom(newZoomLevel);
} else {
map.panTo(newLatLngBounds.getCenter());
}
settings.getZoomSettings().setTypesToConsiderOnZoom(oldZoomSettings);
setAutoZoomInProgress(false);
}