You are here

function gmap_gpx_data2map in GMap Addons 7

Same name and namespace in other branches
  1. 5 gmap_gpx.inc \gmap_gpx_data2map()
  2. 6 gmap_gpx.inc \gmap_gpx_data2map()
1 call to gmap_gpx_data2map()
_gmap_cck_get_gpx in ./gmap_cck.module
process gpx-parameter to show something on the map

File

./gmap_gpx.inc, line 49

Code

function gmap_gpx_data2map(&$map) {
  global $gmap_gpx;
  $c = is_array($gmap_gpx['wpt']) ? count($gmap_gpx['wpt']) : 0;
  for ($i = 0; $i <= $c; $i++) {
    $wp =& $gmap_gpx['wpt'][$i];
    $m = array(
      'latitude' => $wp['lat'],
      'longitude' => $wp['lon'],
    );
    if ($wp['name']) {
      $m['opts']['title'] = $wp['name'];
    }
    $map['markers'][] = $m;

    // TODO: select icon from $wp['sym'] and $wp['type']
  }

  // 0..n routes with 0..x points each
  if (isset($gmap_gpx['rte']) && is_array($gmap_gpx['rte'])) {
    $c = count($gmap_gpx['rte']);

    // number of routes
    for ($i = 0; $i < $c; $i++) {
      _gmap_gpx_add_wp_poly($map, $gmap_gpx['rte'][$i]['points']);
    }
  }

  // 0..n tracks with 1..m segments
  if (isset($gmap_gpx['trk']) && is_array($gmap_gpx['trk'])) {
    $c = count($gmap_gpx['trk']);

    // number of tracks
    for ($i = 0; $i < $c; $i++) {
      $segs =& $gmap_gpx['trk'][$i]['segs'];
      $c2 = count($segs);

      // number of segments in track
      for ($j = 0; $j < $c2; $j++) {
        _gmap_gpx_add_wp_poly($map, $segs[$j]['points']);
      }
    }
  }

  // TODO: make sure we don't screw up around 180 degrees
  if ($gmap_gpx['bounds']) {
    $lat = ($gmap_gpx['bounds']['minlat'] + $gmap_gpx['bounds']['maxlat']) / 2;
    $lon = ($gmap_gpx['bounds']['minlon'] + $gmap_gpx['bounds']['maxlon']) / 2;
    $map['latlong'] = $lat . ',' . $lon;
  }
}