Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 7 — Extending the Google API Examples 123


Event Listeners


Events can be used to add interesting effects to a map. There are a number of events, such
as when

The user clicks on the map.
The user moves the map (there are separate event types for when the user moves the
map, one before the redraw and one after the move has been completed).

The map zooms for any reason.
An info window is displayed or closed.

An overlay is added to or removed from the map.

Monitoring Movement


One of the simplest events you can monitor is the movement of your map. If a user moves a
map and either moves off the limits of your mapping area, or moves to a point where different
overlays and information should be displayed, you will want to know about the movement.

For a very simple demonstration of this movement in operation, look at Listing 7-10. Here you
create two maps: One is a typical map, the other the satellite view. The two maps are the same
size and dimension, and you initialize them with the same zoom level and location.

Listing 7-10: Synchronizing Two Maps

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8”/>

<title>MCslp Maps Chapter 7, Ex 10</title>
<script src=”http://maps.google.com/maps?file=api&v=1&key=XXX”
type=”text/javascript”>
</script>

<script type=”text/javascript”>
//<![CDATA[

var map;
var earth;

function onLoad() {
if (GBrowserIsCompatible()) {
Continued
Free download pdf