Hello Miguel,

This change addresses issue 46 (add the closeInfoWindow() method to the
MapWidget class), and also addresses a long standing issue, which is to make
a 1:1 relationship between the InfoWindow object and the MapWidget object.
Now there is an instance variable in MapWidget so that we only construct a
new InfoWindow object once.

M      maps/maps/src/com/google/gwt/maps/client/impl/MapImpl.java
M      maps/maps/src/com/google/gwt/maps/client/MapWidget.java
M      maps/maps/test/com/google/gwt/maps/client/MapWidgetTest.java

-- 
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

M      maps/maps/src/com/google/gwt/maps/client/impl/MapImpl.java
M      maps/maps/src/com/google/gwt/maps/client/MapWidget.java
M      maps/maps/test/com/google/gwt/maps/client/MapWidgetTest.java

Index: maps/maps/src/com/google/gwt/maps/client/impl/MapImpl.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/impl/MapImpl.java	(revision 785)
+++ maps/maps/src/com/google/gwt/maps/client/impl/MapImpl.java	(working copy)
@@ -59,14 +59,15 @@
 
   void clearOverlays(JavaScriptObject jsoPeer);
 
+  void closeInfoWindow(JavaScriptObject jsoPeer);
+  
   void closeInfoWindow(MapWidget map);
 
   @Constructor("$wnd.GMap2")
   JavaScriptObject construct(Element container);
 
   @Constructor("$wnd.GMap2")
-  JavaScriptObject construct(Element container,
-      JavaScriptObject mapOptions);
+  JavaScriptObject construct(Element container, JavaScriptObject mapOptions);
 
   boolean continuousZoomEnabled(JavaScriptObject jsoPeer);
 
@@ -134,7 +135,7 @@
 
   void openInfoWindow(MapWidget map, LatLng point, JavaScriptObject content,
       JavaScriptObject options);
-  
+
   void openInfoWindow(MapWidget map, LatLng point, String content,
       JavaScriptObject options);
 
@@ -163,8 +164,7 @@
 
   void setCenter(JavaScriptObject jsoPeer, LatLng center, int zoom);
 
-  void setCenter(JavaScriptObject jsoPeer, LatLng center, int zoom,
-      MapType type);
+  void setCenter(JavaScriptObject jsoPeer, LatLng center, int zoom, MapType type);
 
   void setMapType(JavaScriptObject jsoPeerPeer, MapType type);
 
Index: maps/maps/src/com/google/gwt/maps/client/MapWidget.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/MapWidget.java	(revision 785)
+++ maps/maps/src/com/google/gwt/maps/client/MapWidget.java	(working copy)
@@ -124,8 +124,8 @@
   }
 
   private static native void nativeUnload() /*-{
-      $wnd.GUnload && $wnd.GUnload();
-    }-*/;
+    $wnd.GUnload && $wnd.GUnload();
+  }-*/;
 
   private HandlerCollection<MapInfoWindowBeforeCloseHandler> infoWindowBeforeCloseHandlers;
   private HandlerCollection<MapInfoWindowCloseHandler> infoWindowCloseHandlers;
@@ -152,6 +152,7 @@
   private HandlerCollection<MapRightClickHandler> mapRightClickHandlers;
   private HandlerCollection<MapTypeChangedHandler> mapTypeChangedHandlers;
   private HandlerCollection<MapZoomEndHandler> mapZoomEndHandlers;
+  private InfoWindow infoWindow;
 
   /**
    * Cache of the map panes returned for this widget.
@@ -688,6 +689,13 @@
   }
 
   /**
+   * Close the currently open [EMAIL PROTECTED] InfoWindow}.
+   */
+  public void closeInfoWindow() {
+    MapImpl.impl.closeInfoWindow(jsoPeer);
+  }
+
+  /**
    * Computes the geographical coordinates from pixel coordinates in the div
    * that holds the draggable map. You need this when you implement interaction
    * with custom overlays.
@@ -767,13 +775,13 @@
    * 
    * There is only one info window per map.
    * 
-   * TODO(samgross): assign the info window to an instance field so that there
-   * is only one instance per map.
-   * 
    * @return the info window associated with the map.
    */
   public InfoWindow getInfoWindow() {
-    return new InfoWindow(this);
+    if (infoWindow == null) {
+      infoWindow = new InfoWindow(this);
+    }
+    return infoWindow;
   }
 
   /**
@@ -942,7 +950,8 @@
 
   /**
    * Removes a single handler of this map previously added with
-   * [EMAIL PROTECTED] MapWidget#addInfoWindowBeforeCloseHandler(MapInfoWindowBeforeCloseHandler)}.
+   * [EMAIL PROTECTED] MapWidget#addInfoWindowBeforeCloseHandler(MapInfoWindowBeforeCloseHandler)}
+   * .
    * 
    * @param handler the handler to remove
    */
Index: maps/maps/test/com/google/gwt/maps/client/MapWidgetTest.java
===================================================================
--- maps/maps/test/com/google/gwt/maps/client/MapWidgetTest.java	(revision 785)
+++ maps/maps/test/com/google/gwt/maps/client/MapWidgetTest.java	(working copy)
@@ -17,12 +17,17 @@
 
 import com.google.gwt.junit.client.GWTTestCase;
 import com.google.gwt.maps.client.geom.LatLng;
+import com.google.gwt.maps.client.overlay.Marker;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.ui.RootPanel;
 
 /**
  * Tests for the MapWidget and related classes.
  */
 public class MapWidgetTest extends GWTTestCase {
+  // length of time to wait for asynchronous test to complete.
+  static final int ASYNC_DELAY_MSEC = 5000;
 
   @Override
   public String getModuleName() {
@@ -51,6 +56,7 @@
     assertTrue("Center didn't match.", m.getCenter().isEquals(
         LatLng.newInstance(0, 80)));
     assertEquals("Zoom level didn't match.", m.getZoomLevel(), 4);
+    RootPanel.get().add(m);
   }
 
   public void testMapWidgetDefault() {
@@ -68,4 +74,23 @@
         LatLng.newInstance(45, 45)));
     assertEquals("Zoom level didn't match.", m.getZoomLevel(), 8);
   }
+
+  public void testMapWidgetCloseInfoWindow() {
+    LatLng center = LatLng.newInstance(0, 0);
+    final MapWidget map = new MapWidget(center, 1);
+    map.setSize("300px", "300px");
+    RootPanel.get().add(map);
+    InfoWindowContent content = new InfoWindowContent("<i>Hello World!</i>");
+    InfoWindow info = map.getInfoWindow();
+    info.open(center, content); 
+    DeferredCommand.addCommand(new Command() {
+
+      public void execute() {
+        map.closeInfoWindow();
+        finishTest();
+      }
+
+    });
+    delayTestFinish(ASYNC_DELAY_MSEC);
+  }
 }

Reply via email to