Back to home page.
How to Use the Map Viewer & GeoCoder Components
Mark Basler,
Roger Kitain & Craig McClanahan
Status: In Early Access
The MapViewer sample application utilizes two Java Blueprint's
1.4 Catalog components written by Roger Kitain and modified for a
Creator 2 sample by Craig McClanahan. This sample is based on
Craig's Creator sample. The GeoCoder uses the Yahoo map service
to verify the entered address and to get the exact
latitude and longitude. This information is then used by
the
MapViewer component to render and center the Google map.
Currently the early access sample application only presents the first
address returned from the Yahoo map service. The tag library for
the MapViewer &
GeoCoder components can be accessed using the
declaration:
<%@taglib prefix="ui" uri="http://java.sun.com/blueprints/ui/14"%>
The Map Viewer component uses a backing bean to provide the
necessary information to render the Google map. This information
is populated by user input, and from the return of the GeoCoder
component's Yahoo lookup. These components can be used
independently, but the exact latitude and longitude is required by the
Map Viewer component to center the returned Google map. To see
how to use the GeoCoder component look at the "findAction" method of
the com.sun.javaee.blueprints.mapviewer.MapBean backing bean. It
encapsulates the entire call and return of the GeoCoder and sets the
values that are used by the Map Viewer.
An example of the JSF Map Viewer component's use is as follows:
<ui:mapViewer id="mapViewerx" center="#{MapBean.mapPoint}" info="#{MapBean.mapMarker}"
markers="#{MapBean.locations}" style="height: 500px; width: 700px"/>
As you can see above, the component tag name is "mapViewer" and has the
following
attributes whose values are populated by the MapBean backing bean:
- id - This optional attribute holds the name of the component.
- center - This required attribute
is populated by a com.sun.j2ee.blueprints.ui.mapviewer.MapPoint which
is accessed through the MapBean backing bean. This point is used
to center the map utilizing the latitude and longitude retrieved from
the point.
- draggingEnabled- This optional attribute holds the boolean value
string that denotes whether the contexts of the map can be changed by
dragging the map's content. The default value is "true".
- info - This optional attribute holds the text that is printed in
the information balloon that is shown with the map.
- markers - This optional attribute holds an Array of
com.sun.j2ee.blueprints.ui.mapviewer.MapMarker objects that represent
points to be identified on the map. The current sample only
populates the Array with the first point returned from the GeoCoder.
- zoomLevel - This optional attribute is not implemented yet, but
it is intended to be the initial zoom level at which the map will be
shown. Currently the zoom level is defaulted to level 4.
- key - This optional attribute hold the Google map key that is
required to access the Google map service. For more information,
see the note below.
- style - This optional attribute holds a standard HTML style of
the component.
- styleClass - This optional attribute holds a standard HTML style
class of the component.
Since the GeoCode and the MapViewer accesses external services a proxy
server will be needed if you are situated behind a firewall and isn't
set to use a transparent proxy. The setting of the proxy
server's host and port has prompts on the main lookup page, but
security
permissions will need to be granted to set the System property
values. To grant write access to set the JVMs proxy settings, the
server.policy will have to be altered to include write
permission. For Glassfish the server.policy file resides under
the domain's config directory. For example if the domain is named
"domain1" the file is located at
.../glassfish/domains/domain1/config/server.policy. The
PropertyPermission should be
altered to add write permission, which would look like the following:
permission java.util.PropertyPermission "*","read,write";
NOTE: If the sample application is accessed through a URL other than
"http://localhost:8080/bp-map-viewer" then a new map KEY will have to
generated to access the Google map service. The key is currently
free and can be generated from http://www.google.com/apis/maps/.
The resultant key can be placed in the Map Viewer component's "key"
attribute or placed in the WEB-INF/web.xml deployment descriptor under
the param-name com.sun.j2ee.blueprints.ui.mapviewer.KEY. For
example:
<param-name>com.sun.j2ee.blueprints.ui.mapviewer.KEY</param-name>
<param-value>ABQIAAAAyQYKk4__l80DyIsqLPvvuxTRFLl8Tcq3arEgFHYFeOMvEMiJ8RQehhrYXPIDrf1muScWAd1MXrlVkQ</param-value>
Back to home page.
© Sun Microsystems 2006. All of the material in The
Java BluePrints Solutions Catalog is copyright-protected
and may not be published in other works without express
written permission from Sun Microsystems.