Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A mix of updates: LatLngBounds, MVCObject, Overlays #188

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ public class LatLngBounds extends JavaScriptObject {
protected LatLngBounds() {
}

/**
* Create a new, "empty" LatLngBounds object. The bounds can then be
* made valid by subsequent calls to {@link #extend(LatLng)} or
* {@link #union(LatLngBounds)}.
*
* @return A new empty LatLngBounds object.
*/
public final static LatLngBounds newInstance() {
return createJso().cast();
}

private final static native LatLngBounds createJso() /*-{
return new $wnd.google.maps.LatLngBounds();
}-*/;

/**
* Create a new LatLngBounds object which has as its extents just a
* single point. Strictly speaking the bounds will not be empty, but
* the area covered by the bounds will be 0.
*
* @param point The point that the bounds should cover.
* @return A new LatLngBounds object with zero area.
*/
public final static LatLngBounds newInstance(LatLng point) {
return createJso(point).cast();
}

private final static native LatLngBounds createJso(LatLng point) /*-{
return new $wnd.google.maps.LatLngBounds(point);
}-*/;

/**
* creates A LatLngBounds instance represents a rectangle in geographical coordinates, including one that crosses the
* 180 degrees longitudinal meridian.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.gwt.ajaxloader.client.Properties;
import com.google.gwt.ajaxloader.client.Properties.TypeException;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.maps.client.base.LatLng;

/**
Expand All @@ -36,6 +37,11 @@ public class MouseEvent {
* {@link LatLng}
*/
private LatLng latLng;

/**
* The original event jso as provided by the Google Maps API
*/
private JavaScriptObject event;

/**
* Create a new MouseEvent from properties of the map event call back
Expand All @@ -54,6 +60,7 @@ public MouseEvent(Properties properties) {
private void parseProperties(Properties properties) {
try {
latLng = (LatLng) properties.getObject("latLng");
event = properties;
} catch (TypeException e) {
e.printStackTrace();
}
Expand All @@ -71,8 +78,12 @@ public final LatLng getLatLng() {
/**
* Prevents this event from propagating further.
*/
public final native void stop() /*-{
this.stop();
public final void stop() {
stop(event);
}

private final native void stop(JavaScriptObject jso) /*-{
jso.stop();
}-*/;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.google.gwt.maps.client.maptypes;

/*
* #%L
* GWT Maps API V3 - Core API
* %%
* Copyright (C) 2011 - 2013 GWT Maps API V3
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.base.Size;
import com.google.gwt.maps.client.maptypes.MapType;

/**
* A bare-minimum version of the {@link MapType} interface,
* suitable to be used as an overlay over a base map type.
* Generates tile elements based on tile coordinates and zoom
* level, and optionally performs cleanup on these elements
* once they have been removed from the map.
*
* <p>To convert an implementation of this interface into a
* {@link JavaScriptObject} which can be added to the map,
* use {@link OverlayMapType.JsoWrapper#create(OverlayMapType, Size)}.
*
* @see MapWidget#getOverlayMapTypes()
* @see OverlayMapType.JsoWrapper#create(OverlayMapType, Size)
*
*/
public interface OverlayMapType {

/**
* Returns a tile for the given tile
* coordinate (x, y) and zoom level.
* This tile will be appended to the
* given owner {@link Document}.
*
* @param x the tile x coordinate at which the element will be positioned
* @param y the tile y coordinate at which the element will be positioned
* @param zoom the zoom level at which the element will be displayed
* @param owner the document to which the element will be attached
* @return a DOM element to be displayed as a tile on the map
*/
Element getTile(int x, int y, int zoom, Document owner);

/**
* Releases the given tile, performing any necessary cleanup. The provided
* tile will have already been removed from the document.
*
* <p>The above is taken from the official API documentation; in fact as of
* v3.13 the element is still attached at the time this method is called.
* If an exception should be raised at this point the element will be 'leaked',
* and remain attached to the map indefinitely.
*
* @param tile the tile that is being removed from the map
*/
void releaseTile(Node tile);

/**
* Use {@link #create(OverlayMapType, Size)} to wrap an
* {@link OverlayMapType} implementation so that it can be
* added to a map.
*
*/
public class JsoWrapper {

/**
* Wraps an implementation of {@link OverlayMapType} with
* a native {@link JavaScriptObject}, so that it can be added
* to a map via {@link MapWidget#getOverlayMapTypes()}.
*
* <p>A {@link Size} object must be provided along with the
* <code>OverlayMapType</code> implementation, which the map
* will use for requesting and laying out tiles. Therefore
* tiles created by the overlay should conform to this size.
*
* @param overlay an overlay map type
* @param tileSize the size of the tiles that the overlay will generate
* @return a JSO wrapper for the overlay
*/
public static native JavaScriptObject create(OverlayMapType overlay, Size tileSize) /*-{
if (!$wnd.GwtOverlayMapType) {
$wnd.GwtOverlayMapType = function (gwtOverlay, tileSize) {
this.gwtOverlay = gwtOverlay;
this.tileSize = tileSize;
}

$wnd.GwtOverlayMapType.prototype.getTile = function (coord, zoom, ownerDocument) {
return this.gwtOverlay.@com.google.gwt.maps.client.maptypes.OverlayMapType::getTile(IIILcom/google/gwt/dom/client/Document;)(coord.x, coord.y, zoom, ownerDocument);
}

$wnd.GwtOverlayMapType.prototype.releaseTile = function (tile) {
this.gwtOverlay.@com.google.gwt.maps.client.maptypes.OverlayMapType::releaseTile(Lcom/google/gwt/dom/client/Node;)(tile);
}
}

return new $wnd.GwtOverlayMapType(overlay, tileSize);
}-*/;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,25 @@ protected Projection() {
* translation from given LatLng values to world coordinates on the map projection. The Maps API calls this method
* when it needs to plot locations on screen. Projection objects must implement this method.
*
* @param latlng {@link LatLng}
* @param point {@link Point}
* @param latlng {@link LatLng} the coordinates to be translated
* @param point {@link Point} a point object that will be populated with the translated coordinates
* @return a point object of the translated coordinates
*/
public final native Point fromLatLngToPoint(LatLng latlng, Point point) /*-{
return this.fromLatLngToPoint(latlng, point);
}-*/;

/**
* Translates from the LatLng cylinder to the Point plane. This interface specifies a function which implements
* translation from given LatLng values to world coordinates on the map projection. The Maps API calls this method
* when it needs to plot locations on screen. Projection objects must implement this method.
*
* @param latlng {@link LatLng} the coordinates to be translated
* @return a new point object of the translated coordinates
*/
public final native Point fromLatLngToPoint(LatLng latlng) /*-{
return this.fromLatLngToPoint(latlng);
}-*/;

/**
* This interface specifies a function which implements translation from world coordinates on a map projection to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private final static native JavaScriptObject createJsoMvcObject() /*-{
* @param key
* @param target
*/
public final native void bindTo(String key, MVCObject<T> target) /*-{
public final native void bindTo(String key, MVCObject<?> target) /*-{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why I used ? at the time. :)

this.bindTo(key, target);
}-*/;

Expand All @@ -69,7 +69,7 @@ public final native void bindTo(String key, MVCObject<T> target) /*-{
* @param target
* @param targetKey
*/
public final native void bindTo(String key, MVCObject<T> target, String targetKey) /*-{
public final native void bindTo(String key, MVCObject<?> target, String targetKey) /*-{
this.bindTo(key, target, targetKey);
}-*/;

Expand All @@ -81,7 +81,7 @@ public final native void bindTo(String key, MVCObject<T> target, String targetKe
* @param targetKey
* @param noNotify
*/
public final native void bindTo(String key, MVCObject<T> target, String targetKey, boolean noNotify) /*-{
public final native void bindTo(String key, MVCObject<?> target, String targetKey, boolean noNotify) /*-{
this.bindTo(key, target, targetKey, noNotify);
}-*/;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.maps.client.MapImpl;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.base.LatLng;
import com.google.gwt.maps.client.base.LatLngBounds;
import com.google.gwt.maps.client.events.MapEventType;
Expand All @@ -48,14 +46,13 @@
import com.google.gwt.maps.client.events.radius.RadiusChangeMapHandler;
import com.google.gwt.maps.client.events.rightclick.RightClickEventFormatter;
import com.google.gwt.maps.client.events.rightclick.RightClickMapHandler;
import com.google.gwt.maps.client.mvc.MVCObject;

/**
* A circle overlay. This class extends MVCObject. <br>
* <br>
* See <a href= "https://developers.google.com/maps/documentation/javascript/reference#Circle" >Circle API Doc</a>
*/
public class Circle extends MVCObject<Circle> {
public class Circle extends Overlay<Circle> {

/**
* use newInstance();
Expand Down Expand Up @@ -106,34 +103,6 @@ public final native boolean getEditable() /*-{
return this.getEditable();
}-*/;

/**
* Renders the circle on the specified map. If map is set to null, the circle will be removed.
*
* @param mapWidget
*/
public final void setMap(MapWidget mapWidget) {
if (mapWidget == null) {
setMapImpl(null);
} else {
setMapImpl(mapWidget.getJso());
}
}

private final native void setMapImpl(MapImpl map) /*-{
this.setMap(map);
}-*/;

/**
* Returns the map on which this circle is displayed.
*/
public final MapWidget getMap() {
return MapWidget.newInstance(getMapImpl());
}

private final native MapImpl getMapImpl() /*-{
return this.getMap();
}-*/;

/**
* If set to true, the user can edit this circle by dragging the control points shown at the corners and on each edge.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,48 @@ public final native void setClickable(boolean clickable) /*-{
public final native boolean getClickable() /*-{
return this.clickable;
}-*/;

/**
* If set to <code>true</code>, the user can drag this circle
* over the map. Defaults to <code>false</code>.
*
* @param draggable whether or not the user can drag this circle
*/
public final native void setDraggable(boolean draggable) /*-{
this.draggable = draggable;
}-*/;

/**
* If set to <code>true</code>, the user can drag this circle
* over the map. Defaults to <code>false</code>.
*
* @return whether or not the user can drag this circle
*/
public final native boolean getDraggable() /*-{
return this.draggable;
}-*/;

/**
* If set to <code>true</code>, the user can edit this circle by
* dragging the control points shown at the center and around the
* circumference of the circle. Defaults to <code>false</code>.
*
* @param editable whether or not the user can edit this circle
*/
public final native void setEditable(boolean editable) /*-{
this.editable = editable;
}-*/;

/**
* If set to <code>true</code>, the user can edit this circle by
* dragging the control points shown at the center and around the
* circumference of the circle. Defaults to <code>false</code>.
*
* @return whether or not the user can edit this circle
*/
public final native boolean getEditable() /*-{
return this.editable;
}-*/;

/**
* The fill color. All CSS3 colors are supported except for extended named colors.
Expand Down Expand Up @@ -214,6 +256,24 @@ public final native void setStrokeWeight(int strokeWeight) /*-{
public final native int getStrokeWeight() /*-{
return this.strokeWeight;
}-*/;

/**
* Whether this circle is visible on the map. Defaults to <code>true</code>.
*
* @param visible visibility of this circle
*/
public final native void setVisible(boolean visible) /*-{
this.visible = visible;
}-*/;

/**
* Whether this circle is visible on the map. Defaults to <code>true</code>.
*
* @return visibility of this circle
*/
public final native boolean getVisible() /*-{
return this.visible;
}-*/;

/**
* Sets The zIndex compared to other rectangles.
Expand Down
Loading