GoogleMaps JSP Tag Library


Standard Syntax:
     <%@ taglib prefix="googlemaps" uri="/WEB-INF/googlemaps.tld" %>

XML Syntax:
     <anyxmlelement xmlns:googlemaps="urn:jsptld:/WEB-INF/googlemaps.tld" />

A custom tag library to provide general GoogleMaps API capabilities.

Google recently released it's wonderful
GoogleMaps API to the
public. GoogleMaps API is a javascript/AJAX application that provides dynamic,
interactive mapping and satellite capabilities for webpages. The possible uses are
endless.

Before using GoogleMaps and the GoogleMaps API JSP Tag Library you should read their
Terms of Use and you will need to Register
each domain that will use the API.

While this tag library does not expose all the possibilities of the GoogleMaps API,
it provides good functionality without the need to learn the API, advanced Javascript or
AJAX, and provides a familiar JSP tag library interface.

What this tag library provides that GoogleMaps API does not provide is some
geolocation capabilities. Geolocation is the practice of converting a physical location
to a longitude/latitude pair. The GoogleMaps API JSP Tag Library allows you to specify a location
by any of the following, not just Longitude and Latitude pairs:

It also provides built-in capabilities to draw circles, boxes and polygons that the standard API does not contain.

The GoogleMaps API JSP Tag Library also provides mousewheel handling that the default
GoogleMaps API does not.

The tags fit into 2 categories: 1) Data tags that provide the data needed to create a map and 2) Display tags that generate the actual HTML, Javascript and AJAX output.

The following tags make up the data portion of the tag library:

The following tags represent the display portion of the tag library. They must be placed after the <googlemaps:map> tag and have specific places they must be put:

Future versions of this tag library will provide driving directions, course plotting and much more.
Stay tuned!

Tag Library Information
Display NameGoogleMaps JSP Tag Library
Version1.0
Short Namegooglemaps
URI/WEB-INF/googlemaps.tld
 

Tag Summary
map

This tag provides the general setup for a GoogleMap. It provides Geolocation functionality and initialization features, but generates no output. The following tags are children of the <googlemaps:map> tag:

coordinatesThis tag adds a small control to the map that displays the cursor's current longitude and latitude location. Developers can assign style and class attributes, as well as an x and y anchor point.
insertThe insert tag allows you to add an image as an overlay directly on the map. When the map is moved, the image moves. When the map is zoomed, the image zooms. It provides a simple way to provide an overlay onto a map without having to create your own tiles.
labelAllows developers to place a label (rather than a marker) on a map. This could be used to label interesting areas, etc. Labels do not accept events, and do not block events. Only works on version 2 maps.
clusterClusters multiple markers into single larger markers, based on the attributes set. This provides cleaner maps at smaller zoom levels and improves the performance of the map. As the user zooms in, the clustered markers will expand to reveal all the markers in it's cluster. You can define a single <googelmaps:icon> tag as a child to this tag to define the clustered icon (so users can differentiate them from non-clustered icons).
overviewControlDisplays a smaller overview control map of the specified width and height, at the specified x, y location. Only works with maps of version 2.41 or higher. Maps of earlier versions will be ignored.
wmsNo Description
maptypeAllows developers to define custom maps through a custom tile provider. The developer provides a url to a resource that can return map tiles based on x tile number, y tile number and zoom level.
icon

Allows you to specify a custom icon and matching shadow for markers. This tag must be the child of a <googlemaps:marker> tag to work.

Note that the images should be .png files, 24 bits. The shadow and the icon images must line up properly from the upper left hand corner.

imageoverlay

Allows the user to define a fixed image overlay. This can take the form of a button, a logo, whatever. The image can also be assigned a hyperlink that will be triggered if clicked on.

traffic

This tag displays a series of markers that relate to traffic events within a defined radius of a given point. The severity of the events can be selected, and when a traffic event marker is clicked, the details of the event are displayed in an info window.

A <googlemaps:traffic> tag can be parent to a <googlemaps:icon> tag to specify unique icons for traffic events.

event

Adds an event listener to the parent tag. This tag can only effectively be a child of a <googlemaps:map> or <googlemaps:marker> tag. If a child of any other tag, this tag will register itself with the next highest instance of <googlemaps:map> or <googlemaps:marker>. When a map or marker with a registered event is triggered, the URL is called additional parameters based upon the parent component type and the event that is triggered. The complete list is as follows:

  • <googlemaps:box>
    • click
      Triggers when the box is clicked on.
      • component
        The box's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'box'.
    • dblclick
      Triggers when the box is double-clicked on.
      • component
        The box's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'box'.
  • <googlemaps:circle>
    • click
      Triggers when the circle is clicked on.
      • component
        The circle's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'circle'.
    • dblclick
      Triggers when the circle is double-clicked on.
      • component
        The circle's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'circle'.
  • <googlemaps:marker>
    • click
      Triggers when the marker is clicked on.
      • component
        The marker's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'marker'.
    • dblclick
      Triggers when the marker is double-clicked on.
      • component
        The marker's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'marker'.
    • dragstart
      Triggers when a draggable marker is initially dragged.
      • component
        The marker's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'marker'.
      • longitude
        The longitude where the drag was initiated.
      • latitude
        The latitude where the drag was initiated.
    • dragend
      Triggers when a draggable marker is dropped.
      • component
        The marker's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'marker'.
      • longitude
        The longitude where the marker was dropped.
      • latitude
        The latitude where the marker was dropped.
  • <googlemaps:polyline>
    • click
      Triggers when the polyline is clicked on.
      • component
        The polyline's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'polyline'.
    • dblclick
      Triggers when the polyline is double-clicked on.
      • component
        The polyline's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'polyline'.
  • <googlemaps:polygon>
    • click
      Triggers when the polygon is clicked on.
      • component
        The polygon's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'polygon'.
    • dblclick
      Triggers when the polygon is double-clicked on.
      • component
        The polygon's id.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
      • type
        Returns 'polygon'.
  • <googlemaps:map>
    • click
      Triggers when the map is clicked on.
      • longitude
        The longitude where the click occurred.
      • latitude
        The latitude where the click occurred.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
    • dblclick
      Triggers when the map is double-clicked on.
      • longitude
        The longitude where the click occurred.
      • latitude
        The latitude where the click occurred.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
    • moveend
      Triggers when the user has completed moving the map.
      • longitude
        The longitude of the new centerpoint for the map.
      • latitude
        The latitude of the new centerpoint for the map.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
    • zoom
      Triggers when the user changes the zoom level.
      • zoom
        The new zoom level of the map.
      • map
        The parent map's id.
      • event
        The event type that was triggered.
    • maptypechanged
      • type
        Returns the new map type (map, satellite or hybrid).
      • map
        The parent map's id.
      • event
        The event type that was triggered.

The intended use is to have the event trigger a request to either a servlet or JSP page. This page would retrieve the map from the session using the map id (passed as map parameter) making the required changes, additions, etc. and then pass the response back to the requesting page or another page that displays that map, which would then render the map with the changes.

For this methodology to work properly, the parent map must have a scope of type site, so the receiving entity can locate the map from the session.

key

The <googlemaps:key> tag allows you to specify multiple keys for your GoogleMaps API. To use this tag library you will need to register each domain that will use the API.

If your website is registered with multiple domain names, you will need to obtain and specify a key for each one

bodyAllows you to specify body content for the GoogleMap generated <div> tag. This is reserved for future use (potentially in generating custom controls).
messageAllows you to specify a message window to appear when maps are loading or requests are being processed.
marker

Adds a marker to the google map. A <googlemaps:map> tag can have any number of marker tags.

The marker may contain child <googlemaps:infowindow> tags.

infowindow

Describes an <googlemaps:infowindow> for a <googlemaps:marker>. There can only be one <googlemaps:infowindow> tag per <googlemaps:marker> tag. If set to display, the <googlemaps:infowindow> will be initially displayed, otherwise it will be displayed when the user clicks on the corresponding marker.

If an <googlemaps:infowindow> is going to display HTML content, you must set the html attribute to true, otherwise the content will be rendered as XML and may give undesireable results.

The body content of the <googlemaps:infowindow> tag will be the displayed data. You can include complete HTML pages including nifty things like forms, images and more!

tabbedInfoWindowDisplays a tabbed info window over the parent marker. The tabs are defined using <googlemaps:tab> tags as the body of this tag.
tabAdds a tab to the parent <googlemaps:tabbedInfoWindow>. The body contents of this tab tag become the contents displayed in the tab.
blowupSets up a map blowup window for the parent marker.
box

Draws a box on a GoogleMap using polylines. The pointlist must contain two points (additional points will be ignored) that will serve as the opposing corners of the box.

Due to a problem in Internet Explorer, it is imperative that you use the following HTML tag in any page that uses the GoogleMaps API and Polylines in Internet Explorer:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

polygon

Draws a closed polygon on a GoogleMap using polylines. It will plot a line between each of the points specified in the point list, and then close it back to the first point.

Due to a problem in Internet Explorer, it is imperative that you use the following HTML tag in any page that uses the GoogleMaps API and Polylines in Internet Explorer:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

circle

Draws a circle on a GoogleMap using Polylines using the location if the specified <googlemaps:point> as it's centerpoint.

Due to a problem in Internet Explorer, it is imperative that you use the following HTML tag in any page that uses the GoogleMaps API and Polylines in Internet Explorer:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

polyline

Allows the user to draw a polygonal line onto the Google Map. The <googlemaps:polyline> tag defines the generic attributes for the line (color, size, etc.). The <googlemaps:points> ids listed in the pointlist form the endpoints of each line segment.

Due to a problem in Internet Explorer, it is imperative that you use the following HTML tag in any page that uses the GoogleMaps API and Polylines in Internet Explorer:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

pointA point represents a geographical location. User must specify either a longitude/latitude pair or address information. This tag provides geocoding through the following:
  • IP Address
    Using ip2geo web service.
  • US Address
    Using Yahoo web service.
  • International Address
    Using Maporama.
wheelControlThis tag, when present within a <googlemaps:map> tag set, will provide AJAX mousewheel support for smooth zooming in and out of your google map. This feature currently only works if the map version attribute is set to 1. Version 2 of the GoogleMaps API has significant exposure changes. Future versions should support this feature.
typeControlThis tag must be nested inside a <googlemaps:map> tag. It provides information on whether to allow the user to change map types. If added to a <googlemaps:map> tag and set to display, the user will be presented with three buttons in the upper right-hand corner of the map, allowing them to change the view to MAP, SATELLITE or HYBRID views on the fly.
zoomControlThis tag must be nested inside a <googlemaps:map> tag. It provides information on whether to allow the user to zoom in and out of the map. If added to a <googlemaps:map> tag and set to display it will provide the user with zoom in ('+') and zoom out ('-') buttons. If the size is set to large they will also get a full zoom slider control on the left hand side of the map.
panControlThis tag must be nested inside a <googlemaps:map> tag. It provides information on whether to allow the user to pan around the map. If added to a <googlemaps:map> tag and set to display, the user will be presented with up, down, left and right buttons in the uppor left-hand corner of the map.
scaleControlThis tag, when present within a <googlemaps:map> tag set, will display a map scale appropriate for the current zoom level.
scripttagGenerates the required script tag to import the GoogleMaps API. This tag must be placed after and outside the <googlemaps:map> tag and should be placed in the <head> section of your JSP for maximum portability.
javascriptGenerates the required javascript AJAX code needed to create the google map. This must be placed after and outside the <googlemaps:map> tag. For maximum browser compatibility it should also be placed in the <head> section, anywhere after the <googlemaps:scripttag>.
divGenerates the <div> tag that will be the actual visible map. This tag must be placed after and outside the <head> tag. It can be placed anywhere on the page.
initializeGenerates the required javascript code to initialize the google map and register any listeners. For maximum browser compatibility, this tag should be placed just before the closing </body> tag.
 


Java, JSP, and JavaServer Pages are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries. Copyright 2002-3 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054, U.S.A. All Rights Reserved.