Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 12: The Realtors and Archaeologists Toolkit


Basic TLabel Creation


To use TLabel, copy the TLabel javascriptfile from the web site mentioned in the pre-
ceding section. This ensures that the JavaScript for the label is always available in your applica-
tions. You can then import the JavaScript using a line like the following:



To create a new TLabel, you just create a new object based on the TLabelclass defined in
the preceding JavaScript file:


var tlabel = new TLabel();


Labels can be added and removed from the map using extensions to the Google Maps object.
For example, to add a TLabelto your Google Map, use the following:


map.addTLabel(tlabel);


And to remove a previously added label, use this:


map.removeTLabel(tlabel);


Finally, the TLabelclass exposes two methods that control the location (setPosition())
and the opacity (setOpacity()) of the label on the map. Some examples of how to use these
are shown later in this chapter.


Anchor Points and Other Properties


The properties of the TLabelobject control how it appears. The critical elements are the
anchorPointand anchorLatLngproperties, which specify the relative location on the
label that will be pinned to the specified location.


Table 12-1 lists the properties supported by the TLabelobject.


Table 12-1 TLabel Properties

Property Required Description

id Yes The ID of the label. It is exposed through the
standard DOM interface, so you can edit and
control the content style by modifying the value
of the DOM element directly, rather than
updating the property value of the TLabel
object.
anchorLatLng Yes The GPointobject that refers to the latitude/
longitude where the label will be anchored.
This works in tandem with the anchorPoint
property to determine which point of the label is
attached to the lat/long on the map.

Continued
Free download pdf