You are here

function gmap_map_cleanup in GMap Module 6

Same name and namespace in other branches
  1. 5 gmap.module \gmap_map_cleanup()
  2. 6.2 gmap.module \gmap_map_cleanup()
  3. 7.2 gmap.module \gmap_map_cleanup()
  4. 7 gmap.module \gmap_map_cleanup()

Perform some normalization on the map object to prevent errors.

1 call to gmap_map_cleanup()
theme_gmap in ./gmap.module
Gmap element theme hook

File

./gmap.module, line 822
GMap -- Routines to use the Google Maps API in Drupal.

Code

function gmap_map_cleanup(&$map) {

  // Google is picky about this one.
  $map['zoom'] = (int) $map['zoom'];

  // Normalize latitude / longitude
  if ($map['latlong']) {
    $map['latlon'] = $map['latlong'];
    unset($map['latlong']);
  }

  // Normalize extent.
  if (isset($map['extent']) && is_string($map['extent'])) {
    $tmp = explode(',', $map['extent']);
    if (count($tmp) == 4) {

      // String form of extent has x,y, but native array form is lat,lon, so need to flip them a bit.
      $map['extent'] = array(
        array(
          $tmp[1],
          $tmp[0],
        ),
        array(
          $tmp[3],
          $tmp[2],
        ),
      );
    }
    else {

      // Extent was unparseable, don't pass it.
      unset($map['extent']);
    }
  }
  if (isset($map['latlon']) && (!isset($map['latitude']) || !isset($map['longitude']))) {
    list($map['latitude'], $map['longitude']) = explode(',', $map['latlon']);
  }
  unset($map['latlon']);
  foreach ($map['baselayers'] as $k => $v) {
    if (!$v) {
      unset($map['baselayers'][$k]);
    }
  }
}