Google Maps API Tutorial

© 2007, 2009 Mike Williams

Translate this page:


Alternative Map Type Controls

New formats for the map type controls were introduced in v2.93 and v2.94. These new formats can be useful in situations where you have a large number of custom map types, causing the normal GMapTypeControl to become cumbersome.

The GMenuMapTypeControl() displays all the map types in a drop-down menu.
If the optional first parameter is true, then shortnames are used.
If the optional second parameter is true, then a border is drawn round the control.

The GHeirarchicalMapTypeControl() lists "child" map types below their "parent" map type if that parent is active.
If the optional parameter is true, then shortnames are used.

GHeirarchicalMapTypeControl() has three Methods for managing parent and child map type relationships:

GHierarchicalMapTypeControl.addRelationship(parent, child, name, isDefault) adds a parent/child map type relationship. The parameters are

        1.  parent GMapType
        2.  child GMapType
        3.  (optional) Name for child
        4.  (optional) isDefault boolean
GHierarchicalMapTypeControl.removeRelationship(child) removes a parent/child map type relationship. The parameter is the child GMapType.

GHierarchicalMapTypeControl.clearRelationships() removes all relationships.

Here's an example of a map with seven map types showing all possible map type controls. Click the buttons to display the different controls.

Here's an example that sets the map type controls to look exactly like the v2.94 controls. The Terrain map type is added. Hybrid is underneath Satellite and is selected by default when the Sattelite button is clicked.

Back to Mike's Homepage
Up to the start of this tutorial