Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

244 Part III — Google Map Hacks


FIGURE12-10: Reducing the overlay visibility.

Identifying Elements from Click Locations


Adding information to a map extends and enhances the data that the map can provide.
However, the map itself can help to provide information or trigger the display of information.
For example, when clicking on a map you might want to determine what is located in that
area without necessarily highlighting that information with a marker or overlay. This can be
achieved in many ways, but the most effective way is to create a new object type. Each object
will contain the confines of different areas on the map, a simple description of the area, and a
method that checks a supplied point against the object to determine if the click was within the
defined area.

The map application in the previous section can then be updated. First, the different areas on
the map are registered using the new object. A number of events are also added to the map so
that a click on the map will trigger a check of the registered objects, and movements and
changes to the map will trigger modifications to the overlay.

Creating a Unique Map Object


The first step is to create a new object class to hold the top-left and bottom-right areas on the
map for a given location. The information will be stored in properties for the object. Objects
within JavaScript use the special thisvalue to reference and define entities of the object.
Free download pdf