|
Example 7
Here we've started again with the most basic map, no user controls and only a single
marker. What we've done is added an event to the marker. What events do is trigger an
http request, passing along valuable information as parameters in the request.
For this methodology to work properly you may have to set the map's scope
to "site". This places the map in the session so it can be retrieved by a servlet. If you
plan to process the event with a scriplet or a bean on the same page that displays the
map, then this is not necessary.
Here's the code we used:
<googlemaps:map id="map" width="250" height="300" version="2" type="STREET"
zoom="12">
<googlemaps:key domain="localhost" key="xxxx"/>
<googlemaps:point id="point1" address="74 Connors Lane" city="Elkton"
state="MD" zipcode="21921" country="US"/>
<googlemaps:marker id="marker1" point="point1">
<googlemaps:event action="click" url="/GoogleMaps/example_7.jsp"/>
</googlemaps:marker>
<googlemaps:message>
<img src="/GoogleMaps/images/loading.gif"/> Please wait...
</googlemaps:message>
</googlemaps:map>
To see the event in action, click on the marker. You'll notice that the page reloads with a different
url. This url contains information on the click event that was triggered. In this example you'll see the
following values are provided:
http://www.lamatek.com/GoogleMaps/example_7.jsp?event=click&map=map&component=marker1&type=marker
- map
This is the name of the map that generated the event. If this were a servlet you can lookup the
map data using this value and searching in the session.
- component
This is the name of the overlay that generated the event.
- event
This denotes what type of event was triggered.
- type
Thie denotes the type of overlay that triggered the event. Using this you'll know what to retrieve
from the GoogleMapTag.
Well that's the most basic event example. It doesn't do anything, but you get to see how the events
build urls that give you the data you need to process it and modifying the map data. Markers can only
generate click events. In Example 8 we'll see all the events
that a map can generate and what there url's look like.
|