Class WGoogleMap


public class WGoogleMap extends WCompositeWidget
A widget that displays a google map.

This widget uses the online Google Maps server to display a map. It exposes a part of the google maps API.

This widget supports both version 2 and version 3 of the Google Maps API. The version 2 API is used by default, to enable the version 3 API, use the constructor's version argument.

To use the map on a public server you will need to obtain a key. The widget will look for this key as the configuration property "google_api_key". If this configuration property has not been set, it will use a key that is suitable for localhost.

CSS

Styling through CSS is not applicable.

Contributed by: Richard Ulrich.

  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Destructor.
      Overrides:
      remove in class WCompositeWidget
      See Also:
    • addMarker

      public void addMarker(WGoogleMap.Coordinate pos)
      Adds a marker overlay to the map.
    • addPolyline

      public void addPolyline(List<WGoogleMap.Coordinate> points, WColor color, int width, double opacity)
      Adds a polyline overlay to the map.

      Specify a value between 0.0 and 1.0 for the opacity or set the alpha value in the color.

    • addPolyline

      public final void addPolyline(List<WGoogleMap.Coordinate> points)
      Adds a polyline overlay to the map.

      Calls addPolyline(points, new WColor(StandardColor.Red), 2, 1.0)

    • addPolyline

      public final void addPolyline(List<WGoogleMap.Coordinate> points, WColor color)
      Adds a polyline overlay to the map.

      Calls addPolyline(points, color, 2, 1.0)

    • addPolyline

      public final void addPolyline(List<WGoogleMap.Coordinate> points, WColor color, int width)
      Adds a polyline overlay to the map.

      Calls addPolyline(points, color, width, 1.0)

    • addCircle

      public void addCircle(WGoogleMap.Coordinate center, double radius, WColor strokeColor, int strokeWidth, WColor fillColor)
      Adds a circle to the map.

      The stroke and fill opacity can be configured respectively in the strokeColor and fillColor. This feature is only supported by the Google Maps API version 3.

    • addCircle

      public final void addCircle(WGoogleMap.Coordinate center, double radius, WColor strokeColor, int strokeWidth)
    • addIconMarker

      public void addIconMarker(WGoogleMap.Coordinate pos, String iconURL)
      Adds a icon marker overlay to the map.
    • clearOverlays

      public void clearOverlays()
      Removes all overlays from the map.
    • openInfoWindow

      public void openInfoWindow(WGoogleMap.Coordinate pos, CharSequence myHtml)
      Opens a text bubble with html text at a specific location.
    • setCenter

      public void setCenter(WGoogleMap.Coordinate center)
      Sets the map view to the given center.
    • setCenter

      public void setCenter(WGoogleMap.Coordinate center, int zoom)
      Sets the map view to the given center and zoom level.
    • panTo

      public void panTo(WGoogleMap.Coordinate center)
      Changes the center point of the map to the given point.

      If the point is already visible in the current map view, change the center in a smooth animation.

    • zoomWindow

      public void zoomWindow(WGoogleMap.Coordinate topLeft, WGoogleMap.Coordinate rightBottom)
      Zooms the map to a region defined by a bounding box.
    • setZoom

      public void setZoom(int level)
      Sets the zoom level to the given new value.
    • zoomIn

      public void zoomIn()
      Increments zoom level by one.
    • zoomOut

      public void zoomOut()
      Decrements zoom level by one.
    • savePosition

      public void savePosition()
      Stores the current map position and zoom level.

      You can later restore this position using returnToSavedPosition().

    • returnToSavedPosition

      public void returnToSavedPosition()
      Restores the map view that was saved by savePosition().
    • enableDragging

      public void enableDragging()
      Enables the dragging of the map (enabled by default).
    • disableDragging

      public void disableDragging()
      Disables the dragging of the map.
    • enableDoubleClickZoom

      public void enableDoubleClickZoom()
      Enables double click to zoom in and out (enabled by default).
    • disableDoubleClickZoom

      public void disableDoubleClickZoom()
      Disables double click to zoom in and out.
    • enableGoogleBar

      public void enableGoogleBar()
      Enables the GoogleBar, an integrated search control, on the map.

      When enabled, this control takes the place of the default Powered By Google logo.

      This control is initially disabled.

      Note: This functionality is no longer available in the Google Maps API v3.

    • disableGoogleBar

      public void disableGoogleBar()
      Disables the GoogleBar integrated search control.

      When disabled, the default Powered by Google logo occupies the position formerly containing this control. Note that this control is already disabled by default.

      Note: This functionality is no longer available in the Google Maps API v3.

    • enableScrollWheelZoom

      public void enableScrollWheelZoom()
      Enables zooming using a mouse's scroll wheel.

      Scroll wheel zoom is disabled by default.

    • disableScrollWheelZoom

      public void disableScrollWheelZoom()
      Disables zooming using a mouse's scroll wheel.

      Scroll wheel zoom is disabled by default.

    • setMapTypeControl

      public void setMapTypeControl(MapTypeControl type)
      Sets the map type control.

      The control allows selecting and switching between supported map types via buttons.

    • clicked

      public JSignal1<WGoogleMap.Coordinate> clicked()
      The click event.

      This event is fired when the user clicks on the map with the mouse.

    • doubleClicked

      public JSignal1<WGoogleMap.Coordinate> doubleClicked()
      The double click event.

      This event is fired when a double click is done on the map.

    • mouseMoved

      public JSignal1<WGoogleMap.Coordinate> mouseMoved()
      This event is fired when the user moves the mouse inside the map.
    • getApiVersion

      public GoogleMapsVersion getApiVersion()
      Return the used Google Maps API version.
    • render

      protected void render(EnumSet<RenderFlag> flags)
      Description copied from class: WWidget
      Renders the widget.

      This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

      The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

      Overrides:
      render in class WCompositeWidget
    • doGmJavaScript

      protected void doGmJavaScript(String jscode)
      Execute a piece of JavaScript that manipulates the map.

      This is like WCompositeWidget#doJavaScript() but delays the javascript until the map has been loaded.