Hello Miguel,
I would like for you to review the attached patch that converts
MarkerOptions to a JavaScript overlay. Following the convention in
Josh Bloch's Effective Java, I've named the factory method
'getInstance()'. I had to modify several demos to get rid of using hte
constructor.
M maps/maps/src/com/google/gwt/maps/client/overlay/Icon.java
M maps/maps/src/com/google/gwt/maps/client/overlay/MarkerOptions.java
M
maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DragMarkerDemo.java
M
maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/MapEventDemo.java
M
maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconClassDemo.java
M
maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconDemo.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/overlay/Icon.java
M maps/maps/src/com/google/gwt/maps/client/overlay/MarkerOptions.java
M maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DragMarkerDemo.java
M maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/MapEventDemo.java
M maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconClassDemo.java
M maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconDemo.java
Index: maps/maps/src/com/google/gwt/maps/client/overlay/Icon.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/Icon.java (revision 751)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/Icon.java (working copy)
@@ -101,7 +101,7 @@
public String getDragCrossImageUrl() {
return IconImpl.impl.getDragCrossImage(jsoPeer);
}
-
+
/**
* Returns the pixel size of the cross image when an icon is dragged.
*
@@ -385,4 +385,9 @@
public void setTransparentImageURL(String url) {
IconImpl.impl.setTransparent(jsoPeer, url);
}
+
+ // Temporary method until this class is converted to a JS overlay
+ JavaScriptObject getJavaScriptObject() {
+ return jsoPeer;
+ }
}
Index: maps/maps/src/com/google/gwt/maps/client/overlay/MarkerOptions.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/MarkerOptions.java (revision 751)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/MarkerOptions.java (working copy)
@@ -16,26 +16,40 @@
package com.google.gwt.maps.client.overlay;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.maps.client.impl.MarkerOptionsImpl;
/**
* Instances of this class are used in the [EMAIL PROTECTED] Marker} constructor
* <code>options</code> argument.
*/
-public final class MarkerOptions {
+public final class MarkerOptions extends JavaScriptObject {
- private final JavaScriptObject jsoPeer;
+ public static MarkerOptions getInstance() {
+ return (MarkerOptions) createObject();
+ }
- public MarkerOptions() {
- jsoPeer = MarkerOptionsImpl.impl.construct();
+ public static MarkerOptions getInstance(Icon icon) {
+ MarkerOptions options = getInstance();
+ options.setIcon(icon);
+ return options;
}
- public MarkerOptions(Icon icon) {
- this();
- setIcon(icon);
+ /**
+ * JavaScript overlays require a protected constructor.
+ */
+ protected MarkerOptions() {
}
/**
+ * Auto-pan the map as you drag the marker near the edge. If the marker is
+ * draggable the default value for this option is <true>true</true>.
+ *
+ * @param autoPan <code>true</code> to turn on auto pan.
+ */
+ public native void setAutoPan(boolean autoPan) /*-{
+ this.autoPan = autoPan;
+ }-*/;
+
+ /**
* When finishing dragging, this number is used to define the acceleration
* rate of the marker during the bounce down to earth. The default value for
* this option is 1.
@@ -43,9 +57,9 @@
* @param bounceGravity number used to define the acceleration rate of the
* marker during the bounce.
*/
- public void setBounceGravity(double bounceGravity) {
- MarkerOptionsImpl.impl.setBounceGravity(jsoPeer, bounceGravity);
- }
+ public native void setBounceGravity(double bounceGravity) /*-{
+ this.bounceGravity = bounceGravity;
+ }-*/;
/**
* Toggles whether or not the marker should bounce up and down after it
@@ -53,21 +67,21 @@
*
* @param bouncy <code>true</code> to set the marker to be bouncy.
*/
- public void setBouncy(boolean bouncy) {
- MarkerOptionsImpl.impl.setBouncy(jsoPeer, bouncy);
- }
+ public native void setBouncy(boolean bouncy) /*-{
+ this.bouncy = bouncy;
+ }-*/;
/**
* Toggles whether or not the marker is clickable. Markers that are not
* clickable or draggable are inert, consume less resources and do not respond
- * to any events. The default value for this option is <code>true</code>,
- * i.e. if the option is not specified, the marker will be clickable.
+ * to any events. The default value for this option is <code>true</code>, i.e.
+ * if the option is not specified, the marker will be clickable.
*
* @param clickable whether or not the marker is clickable.
*/
- public void setClickable(boolean clickable) {
- MarkerOptionsImpl.impl.setClickable(jsoPeer, clickable);
- }
+ public native void setClickable(boolean clickable) /*-{
+ this.clickable = clickable;
+ }-*/;
/**
* When dragging markers normally, the marker floats up and away from the
@@ -75,12 +89,12 @@
* and moves the cross downwards instead. The default value for this option is
* false.
*
- * @param dragCrossMove set to <code>true</code> to keep the marker
- * underneath the cursor when dragged.
+ * @param dragCrossMove set to <code>true</code> to keep the marker underneath
+ * the cursor when dragged.
*/
- public void setDragCrossMove(boolean dragCrossMove) {
- MarkerOptionsImpl.impl.setDragCrossMove(jsoPeer, dragCrossMove);
- }
+ public native void setDragCrossMove(boolean dragCrossMove) /*-{
+ this.dragCrossMove = dragCrossMove;
+ }-*/;
/**
* Toggles whether or not the marker will be draggable by users. Markers set
@@ -91,9 +105,9 @@
*
* @param draggable whether or not the marker will be draggable by users.
*/
- public void setDraggable(boolean draggable) {
- MarkerOptionsImpl.impl.setDraggable(jsoPeer, draggable);
- }
+ public native void setDraggable(boolean draggable) /*-{
+ this.draggable = draggable;
+ }-*/;
/**
* Chooses the Icon for this class. If not specified,
@@ -102,7 +116,8 @@
* @param icon sets the icon for this class.
*/
public void setIcon(Icon icon) {
- MarkerOptionsImpl.impl.setIcon(jsoPeer, icon);
+ // Once Icon becomes a JSO subclass, we can make this a native method.
+ nativeSetIcon(icon.getJavaScriptObject());
}
/**
@@ -111,7 +126,11 @@
*
* @param title a string to set as the tooltip on the marker.
*/
- public void setTitle(String title) {
- MarkerOptionsImpl.impl.setTitle(jsoPeer, title);
- }
+ public native void setTitle(String title) /*-{
+ this.title = title;
+ }-*/;
+
+ private native void nativeSetIcon(JavaScriptObject icon) /*-{
+ this.icon = icon;
+ }-*/;
}
Index: maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DragMarkerDemo.java
===================================================================
--- maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DragMarkerDemo.java (revision 751)
+++ maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DragMarkerDemo.java (working copy)
@@ -78,7 +78,7 @@
public void onShow() {
map.clearOverlays();
- MarkerOptions options = new MarkerOptions();
+ MarkerOptions options = MarkerOptions.getInstance();
options.setDraggable(true);
final Marker marker = new Marker(map.getCenter(), options);
final InfoWindow info = map.getInfoWindow();
Index: maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/MapEventDemo.java
===================================================================
--- maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/MapEventDemo.java (revision 751)
+++ maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/MapEventDemo.java (working copy)
@@ -240,7 +240,7 @@
map.addControl(new SmallMapControl());
map.addControl(new MapTypeControl());
- MarkerOptions opt = new MarkerOptions();
+ MarkerOptions opt = MarkerOptions.getInstance();
opt.setDraggable(true);
marker = new Marker(ATLANTA, opt);
Index: maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconClassDemo.java
===================================================================
--- maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconClassDemo.java (revision 751)
+++ maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconClassDemo.java (working copy)
@@ -120,7 +120,7 @@
final char letter = (char) ('A' + index);
Icon icon = new Icon(baseIcon);
icon.setImageURL("http://www.google.com/mapfiles/marker" + letter + ".png");
- MarkerOptions options = new MarkerOptions();
+ MarkerOptions options = MarkerOptions.getInstance();
options.setIcon(icon);
final Marker marker = new Marker(point, options);
Index: maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconDemo.java
===================================================================
--- maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconDemo.java (revision 751)
+++ maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/IconDemo.java (working copy)
@@ -96,7 +96,7 @@
LatLng northEast = bounds.getNorthEast();
double lngSpan = northEast.getLongitude() - southWest.getLongitude();
double latSpan = northEast.getLatitude() - southWest.getLatitude();
- MarkerOptions options = new MarkerOptions();
+ MarkerOptions options = MarkerOptions.getInstance();
options.setIcon(icon);
for (int i = 0; i < 10; i++) {
LatLng point = new LatLng(southWest.getLatitude() + latSpan