6.51.  < rich:gmap >

6.51.1. Description

Component that presents the Google map in the JSF applications.

<rich:gmap> component

Figure 6.99.  <rich:gmap> component


6.51.2. Key Features

  • Presents all the Google map functionality

  • Highly customizable via attributes

  • No developers JavaScript writing needed to use on a pages

Table 6.210. rich : gmap attributes

Attribute NameDescription
bindingThe attribute takes a value-binding expression for a component property of a backing bean
enableContinuousZoomEnables continuous smooth zooming for selected browsers. The default value is "false"
enableDoubleClickZoomEnables zooming in by a double click. The default value is "false"
enableDraggingEnables a map dragging with the mouse. The default value is "true"
enableInfoWindowEnables Info Window. The default value is "true"
gmapKeyGoogle Map key. A single Maps API key is valid for a single "directory" on your web server
gmapVarThe JavaScript variable that is used to access the Google Map API. If you have more than one Google Map components on the same page, use individual key for each of them. The default variable name is "map" (without quotes)
idEvery component may have a unique id that is automatically created if omitted
latInitial latitude coordinate in degrees, as a number between -90 and +90
lngInitial longitude coordinate in degrees, as a number between -180 and +180
mapTypeInitial map type. The possible values are G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP. The default value is G_SATELLITE_MAP
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
oninitJavaScript code invoked just after the Google Map object is initiated.
onkeydownHTML: a script expression; a key is pressed down
onkeypressHTML: a script expression; a key is pressed and released
onkeyupHTML: a script expression; a key is released
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
renderedIf "false", this component is not rendered
showGLargeMapControlShows the GLarge control. The default value is "true"
showGMapTypeControlShows the Type switch control. The default value is "true"
showGScaleControlIt shows the scale control. The default value is "true"
styleCSS style(s) is/are to be applied when this component is rendered
styleClassCorresponds to the HTML class attribute
warningMessageThe warning message that appears if a browser is not compatible with Google Map. The default value is "Your browser does not support Google Maps"
zoomInitial zoom level as a number between 1 and 18. The default value is 17

Table 6.211. Component identification parameters

NameValue
component-typeorg.richfaces.Gmap
component-classorg.richfaces.component.html.HtmlGmap
component-familyorg.richfaces.Gmap
renderer-typeorg.richfaces.GmapRenderer
tag-classorg.richfaces.taglib.GmapTag

6.51.3. Creating the Component with a Page Tag

To create the simplest variant on a page use the following syntax:

Example:


...
    <rich:gmap gmapKey="..."/>
...

6.51.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.HtmlGmap;
...
HtmlGmap myMap = new HtmlGmap();
...

6.51.5. Details of Usage

To use Google Map in your application, generate a key on Google Map official resource. One key could be used for one directory on the server.

Here are the main settings of initial rendering performed with a component map that are accessible with the following attributes:

  • "zoom" defines an approximation size (boundary values 1-18)

  • "lat" specifies an initial latitude coordinate in degrees, as a number between -90 and +90

  • "lng" specifies an initial longitude coordinate in degrees, as a number between -180 and +180

  • "mapType" specifies a type of a rendered map (G_NORMAL_MAP, G_SATELLITE_MAP (DEFAULT), G_HYBRID_MAP)

For example, the city of Paris is shown after rendering with the following initial settings: "lat" = 48.44, "lng" = 2.24 and "zoom" = 5.

<rich:gmap> initial rendering

Figure 6.100.  <rich:gmap> initial rendering


It's also possible to set accessible controls on the map with the help of the attributes:

  • "showGMapTypeControl" determines whether the controls for a map type definition are switched on

  • "showGScaleControl" determines whether the controls for scaling are switched on

  • "showGLargeMapControl" determines whether the control for map scale rendering is rendered

<rich:gmap> accessible controls

Figure 6.101.  <rich:gmap> accessible controls


To set all these parameters and perform some activity (Zoom In/Out etc.) is possible with your JavaScript, i.e. declare a name of an object on a map in the "gmapVar" attribute and then call the object directly with API Google Map.

For example, to approximate a map for "gmapVar" = "map" declared inside the component, call map.zoomIn() on an event.

Moreover, to add e.g. some JavaScript effects, events defined on it are used.

  • onmouseover

  • onclick

  • onmouseout

  • etc.

Note

Google Map does not support XHTML format of the page. Thus, if you use Facelets and JSF 1.2, do not forget to put the following tags somewhere on the page:


...
<f:view contentType="text/html">...</f:view>
...

6.51.6. Look-and-Feel Customization

<rich:gmap> component isn't tied to skin parameters, as there is no additional elements on it, except the ones provided with Google Map.

6.51.7. Definition of Custom Style Classes

Table 6.212. Classes names that define a component appearance

Class nameDescription
rich-gmapDefines styles for a wrapper <div> element of a component

In order to redefine styles for all <rich:gmap> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the tables above) and define necessary properties in them.

Example:


...
.rich-gmap{
    
font-style:italic;
}
...

This is a result:

Redefinition styles with predefined classes

Figure 6.102. Redefinition styles with predefined classes


In the example the font style for buttons was changed.

Also it’s possible to change styles of particular <rich:gmap> component. In this case you should create own style classes and use them in corresponding <rich:gmap> styleClass attributes. An example is placed below:

Example:


...
.myClass{
    
font-weight:bold;
}
...

The "styleClass" attribute for <rich:gmap> is defined as it’s shown in the example below:

Example:


<rich:gmap ... styleClass="myClass"/>

This is a result:

Redefinition styles with own classes and "styleClass" attributes

Figure 6.103. Redefinition styles with own classes and "styleClass" attributes


As it could be seen on the picture above, the font weight for buttons was changed.

6.51.8. Relevant Resources Links

Here you can see the example of <rich:gmap> usage and sources for the given example.