jp.sf.mapswidgets
Class GoogleMaps

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by jp.sf.mapswidgets.GoogleMaps
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class GoogleMaps
extends org.eclipse.swt.widgets.Composite

Instances of this class implement the Google Maps browser.

Note that although this class is a subclass of Composite, it does not make sense to set a layout on it.

IMPORTANT: This class is not intended to be subclassed.


Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
GoogleMaps(org.eclipse.swt.widgets.Composite parent, int style)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
GoogleMaps(org.eclipse.swt.widgets.Composite parent, int style, java.lang.String url)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 
Method Summary
 void addGoogleMapsListener(GoogleMapsListener listener)
          Adds the listener to the collection of listeners who will be notified when the Google Maps status is changed, by sending it one of the messages defined in the GoogleMapsListener interface.
 void addOverlay(Overlay added)
          Adds the given overlay object (Marker or Polyline) to the map.
 boolean execute(java.lang.String script)
          Executes a java script code
 java.lang.String executeWithResult(java.lang.String script)
          Executes a java script code and get a result.
 Point getCenter()
          Returns the center point of the map viewport in latitude/longitude coordinates.
 Bounds getMapBounds()
          Returns the latitude/longitude bounds of the map viewport.
 Size getMapSpan()
          Returns the width and height of the map viewport in latitude/longitude ticks.
 MapType getMapType()
          Returns the map type currently in use.
 MapType[] getSupportedMapTypes()
          Returns an array of map types supported by this map.
 int getZoomLevel()
          Returns the integer zoom level of the map.
 void hideWindow()
          Closes the window if it is open.
 boolean isDraggingEnabled()
          Returns true if dynamic dragging is enabled.
 boolean isInfoWindowEnabled()
          Returns true if the info window is enabled on this map.
 boolean isLargeMapControlVisible()
          Returns true if the large pan/zoom map control is showed.
 boolean isMapTypeControlVisible()
          Returns true if the map type control is showed.
 boolean isSmallMapControlVisible()
          Returns true if the small pan/zoom map control is showed.
 boolean isSmallZoomControlVisible()
          Returns true if the small zoom map control (no panning control) is showed.
 void moveTo(Point targetPoint)
          Centers the map at the given point, doing a fluid pan to the point if it is within the current map viewport.
 void removeAllOverlays()
          Removes all of the overlays from the map.
 void removeGoogleMapsListener(GoogleMapsListener listener)
          Removes the listener from the collection of listeners who will be notified when the Google Maps status is changed.
 void removeOverlay(Overlay removed)
          Removes the given overlay object from the map.
 void runAfterLoading(java.lang.Runnable runAfterLoading)
          Set the code running after this component is initialized (Google Maps page loading finished).
 void setCenter(Point newPoint)
          Centers the map at the given point.
 void setDebug(boolean on)
          Turns on/off the debug mode.
 void setDraggingEnabled(boolean on)
          Enables/Disables dynamic dragging (enabled by default).
 void setInfoWindowEnabled(boolean on)
          Enables/Disables the info window on this map (enabled by default).
 void setLargeMapControlVisible(boolean on)
          Shows/Hieds the large pan/zoom map control.
 void setMapType(MapType newMapType)
          Switches this map to the given map type.
 void setMapTypeControlVisible(boolean on)
          Shows/Hieds the map type control.
 void setSmallMapControlVisible(boolean on)
          Shows/Hieds the small pan/zoom map control.
 void setSmallZoomControlVisible(boolean on)
          Shows/Hieds the small zoom map control (no panning control).
 void setZoomLevel(int newLevel)
          Zooms to the given integer zoom level, ignoring the request if the given zoom level is outside the bounds of the current map type.
 void showInfoWindow(Point point, java.lang.String html)
          Displays the info window with the given HTML content at the given point.
 void showInfoWindow(Point point, java.lang.String html, Size offset)
          Displays the info window with the given HTML content at the given point.
 void showMapWindow(Point point)
          Shows a blowup of the map at the given point.
 void showMapWindow(Point point, int zoomLevel)
          Shows a blowup of the map at the given point.
 void showMapWindow(Point point, int zoomLevel, MapType type)
          Shows a blowup of the map at the given point.
 void showMapWindow(Point point, int zoomLevel, MapType type, Size offset)
          Shows a blowup of the map at the given point.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setCursor, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GoogleMaps

public GoogleMaps(org.eclipse.swt.widgets.Composite parent,
                  int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
parent - a widget which will be the parent of the new instance (cannot be null)
style - the style of widget to construct
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
org.eclipse.swt.SWTError -
  • ERROR_NO_HANDLES if a handle could not be obtained for browser creation
See Also:
Widget.getStyle()

GoogleMaps

public GoogleMaps(org.eclipse.swt.widgets.Composite parent,
                  int style,
                  java.lang.String url)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
parent - a widget which will be the parent of the new instance (cannot be null)
style - the style of widget to construct
url - the url of a Google Maps included page
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
org.eclipse.swt.SWTError -
  • ERROR_NO_HANDLES if a handle could not be obtained for browser creation
See Also:
Widget.getStyle()
Method Detail

addGoogleMapsListener

public void addGoogleMapsListener(GoogleMapsListener listener)
Adds the listener to the collection of listeners who will be notified when the Google Maps status is changed, by sending it one of the messages defined in the GoogleMapsListener interface.

See Google Maps API documentation [Class Reference > GMap > Events].

clicked(Overlay clicked) is called when the user clicks the overlay on the map. clicked(Point point) is called when the user clicks the map. moved() is called when the map is moving. This event is triggered continuously as the map is dragged. moveStarted() is called at the beginning of a continuous pan/drag movement. This event is not triggered when the map moves discretely. moveEnded() is called at the end of a discrete or continuous map movement. This event is triggered once at the end of a continuous pan. zoomed(int oldZoomLevel, int newZoomLevel) is called after the map zoom level changes. mapTypeChanged() is called after the map type (Map, Hybrid, or Satellite) changes. windowOpend() is called after the info window is displayed. windowClosed() is called after the info window is closed. overlayAdded(Overlay added) is called after an overlay is added to the map. overlayRemoved(Overlay removed) is called after an overlay is removed from the map. allOverlaysRemoved() is called after all overlays are cleared from the map.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
See Also:
GoogleMapsListener, GoogleMapsAdapter, removeGoogleMapsListener(jp.sf.mapswidgets.GoogleMapsListener)

addOverlay

public void addOverlay(Overlay added)
Adds the given overlay object (Marker or Polyline) to the map.

See Google Maps API documentation [Class Reference > GMap > addOverlay(overlay)].

Parameters:
added - an added overlay

execute

public boolean execute(java.lang.String script)
Executes a java script code

Parameters:
script - a java script code
Returns:
the execution result
  • true - success
  • false - failure

executeWithResult

public java.lang.String executeWithResult(java.lang.String script)
Executes a java script code and get a result.

If you want to get a result value from a java script code, you must set the status bar by code.

Parameters:
script - a java script code
Returns:
the current status bar text

getCenter

public Point getCenter()
Returns the center point of the map viewport in latitude/longitude coordinates.

See Google Maps API documentation [Class Reference > GMap > getCenterLatLng()].

Returns:
the center point of the map viewport

getMapBounds

public Bounds getMapBounds()
Returns the latitude/longitude bounds of the map viewport.

See Google Maps API documentation [Class Reference > GMap > getBoundsLatLng()].

Returns:
the bounds of the map viewport

getMapSpan

public Size getMapSpan()
Returns the width and height of the map viewport in latitude/longitude ticks.

See Google Maps API documentation [Class Reference > GMap > getSpanLatLng()].

Returns:
the width and height of the map viewport

getMapType

public MapType getMapType()
Returns the map type currently in use.

See Google Maps API documentation [Class Reference > GMap > getCurrentMapType()].

Returns:
the current map type

getSupportedMapTypes

public MapType[] getSupportedMapTypes()
Returns an array of map types supported by this map.

See Google Maps API documentation [Class Reference > GMap > getMapTypes()].

Returns:
the supported map types

getZoomLevel

public int getZoomLevel()
Returns the integer zoom level of the map.

See Google Maps API documentation [Class Reference > GMap > getZoomLevel()].

Returns:
the zoom level of the map

hideWindow

public void hideWindow()
Closes the window if it is open.

See Google Maps API documentation [Class Reference > GMap > closeInfoWindow()].


isDraggingEnabled

public boolean isDraggingEnabled()
Returns true if dynamic dragging is enabled.

See Google Maps API documentation [Class Reference > GMap > draggingEnabled()].

Returns:
  • true - enabled
  • false - disabled

isInfoWindowEnabled

public boolean isInfoWindowEnabled()
Returns true if the info window is enabled on this map.

See Google Maps API documentation [Class Reference > GMap > infoWindowEnabled()].

Returns:
  • true - enabled
  • false - disabled

isLargeMapControlVisible

public boolean isLargeMapControlVisible()
Returns true if the large pan/zoom map control is showed.

See Google Maps API documentation [API Overview > Controls > GLargeMapControl].

Returns:
  • true - showed
  • false - hidden

isMapTypeControlVisible

public boolean isMapTypeControlVisible()
Returns true if the map type control is showed.

See Google Maps API documentation [API Overview > Controls > GMapTypeControl].

Returns:
  • true - showed
  • false - hidden

isSmallMapControlVisible

public boolean isSmallMapControlVisible()
Returns true if the small pan/zoom map control is showed.

See Google Maps API documentation [API Overview > Controls > GSmallMapControl].

Returns:
  • true - showed
  • false - hidden

isSmallZoomControlVisible

public boolean isSmallZoomControlVisible()
Returns true if the small zoom map control (no panning control) is showed.

See Google Maps API documentation [API Overview > Controls > GSmallZoomControl].

Returns:
  • true - showed
  • false - hidden

moveTo

public void moveTo(Point targetPoint)
Centers the map at the given point, doing a fluid pan to the point if it is within the current map viewport.

See Google Maps API documentation [Class Reference > GMap > recenterOrPanToLatLng(latLng)].

Parameters:
targetPoint - a new target point

removeAllOverlays

public void removeAllOverlays()
Removes all of the overlays from the map.

See Google Maps API documentation [Class Reference > GMap > clearOverlays()].


removeGoogleMapsListener

public void removeGoogleMapsListener(GoogleMapsListener listener)
Removes the listener from the collection of listeners who will be notified when the Google Maps status is changed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
See Also:
GoogleMapsListener, GoogleMapsAdapter, addGoogleMapsListener(jp.sf.mapswidgets.GoogleMapsListener)

removeOverlay

public void removeOverlay(Overlay removed)
Removes the given overlay object from the map.

See Google Maps API documentation [Class Reference > GMap > removeOverlay(overlay)].

Parameters:
removed - the removed overlay

runAfterLoading

public void runAfterLoading(java.lang.Runnable runAfterLoading)
Set the code running after this component is initialized (Google Maps page loading finished).

Parameters:
runAfterLoading - the code after initialized
Throws:
org.eclipse.swt.SWTException - if the code is already setted

setCenter

public void setCenter(Point newPoint)
Centers the map at the given point.

See Google Maps API documentation [Class Reference > GMap > centerAtLatLng(latLng)].

Parameters:
newPoint - a new center point

setDebug

public void setDebug(boolean on)
Turns on/off the debug mode.

Parameters:
on -
  • true - turns on
  • false - turns off

setDraggingEnabled

public void setDraggingEnabled(boolean on)
Enables/Disables dynamic dragging (enabled by default).

See Google Maps API documentation [Class Reference > GMap > enableDragging()/disableDragging()].

Parameters:
on -
  • true - enabled
  • false - disabled

setInfoWindowEnabled

public void setInfoWindowEnabled(boolean on)
Enables/Disables the info window on this map (enabled by default).

See Google Maps API documentation [Class Reference > GMap > enableInfoWindow()/disableInfoWindow()].

Parameters:
on -
  • true - enabled
  • false - disabled

setLargeMapControlVisible

public void setLargeMapControlVisible(boolean on)
Shows/Hieds the large pan/zoom map control.

See Google Maps API documentation [API Overview > Controls > GLargeMapControl].

Parameters:
on -
  • true - showed
  • false - hidden

setMapType

public void setMapType(MapType newMapType)
Switches this map to the given map type.

See Google Maps API documentation [Class Reference > GMap > setMapType(mapType)].

Parameters:
newMapType - a new map type

setMapTypeControlVisible

public void setMapTypeControlVisible(boolean on)
Shows/Hieds the map type control.

See Google Maps API documentation [API Overview > Controls > GMapTypeControl].

Parameters:
on -
  • true - showed
  • false - hidden

setSmallMapControlVisible

public void setSmallMapControlVisible(boolean on)
Shows/Hieds the small pan/zoom map control.

See Google Maps API documentation [API Overview > Controls > GSmallMapControl].

Parameters:
on -
  • true - showed
  • false - hidden

setSmallZoomControlVisible

public void setSmallZoomControlVisible(boolean on)
Shows/Hieds the small zoom map control (no panning control).

See Google Maps API documentation [API Overview > Controls > GSmallZoomControl].

Parameters:
on -
  • true - showed
  • false - hidden

setZoomLevel

public void setZoomLevel(int newLevel)
Zooms to the given integer zoom level, ignoring the request if the given zoom level is outside the bounds of the current map type.

See Google Maps API documentation [Class Reference > GMap > zoomTo(zoomLevel)].

Parameters:
newLevel - a new zoom level

showInfoWindow

public void showInfoWindow(Point point,
                           java.lang.String html)
Displays the info window with the given HTML content at the given point.

See Google Maps API documentation [Class Reference > GMap > openInfoWindowHtml(latLng, htmlStr)].

Parameters:
point - the point of the info window
html - the content of the info window

showInfoWindow

public void showInfoWindow(Point point,
                           java.lang.String html,
                           Size offset)
Displays the info window with the given HTML content at the given point.

See Google Maps API documentation [Class Reference > GMap > openInfoWindowHtml(latLng, htmlStr, pixelOffset)].

Parameters:
point - the point of the info window
html - the content of the info window
offset - the offset of the info window

showMapWindow

public void showMapWindow(Point point)
Shows a blowup of the map at the given point.

See Google Maps API documentation [Class Reference > GMap > showMapBlowup(point)].

Parameters:
point - the point of the map window

showMapWindow

public void showMapWindow(Point point,
                          int zoomLevel)
Shows a blowup of the map at the given point.

See Google Maps API documentation [Class Reference > GMap > showMapBlowup(point, zoomLevel)].

Parameters:
point - the point of the map window
zoomLevel - the zoom level in the map window

showMapWindow

public void showMapWindow(Point point,
                          int zoomLevel,
                          MapType type)
Shows a blowup of the map at the given point.

See Google Maps API documentation [Class Reference > GMap > showMapBlowup(point, zoomLevel, mapType)].

Parameters:
point - the point of the map window
zoomLevel - the zoom level in the map window
type - the map type in the map window

showMapWindow

public void showMapWindow(Point point,
                          int zoomLevel,
                          MapType type,
                          Size offset)
Shows a blowup of the map at the given point.

See Google Maps API documentation [Class Reference > GMap > showMapBlowup(point, zoomLevel, mapType, pixelOffset)].

Parameters:
point - the point of the map window
zoomLevel - the zoom level in the map window
type - the map type in the map window
offset - the offset of the map window