You are here

function gmap_polyutil_polyline in GMap Module 6

Same name and namespace in other branches
  1. 5 gmap_polyutil.inc \gmap_polyutil_polyline()
  2. 6.2 gmap_polyutil.inc \gmap_polyutil_polyline()
  3. 7.2 gmap_polyutil.inc \gmap_polyutil_polyline()
  4. 7 gmap_polyutil.inc \gmap_polyutil_polyline()

Simplify a set of points and generate an "Encoded Polyline" for Google Maps.

Parameters

$points: An array of coordinate pairs as latitude, longitude.

Return value

An array containing the point and zoom information necessary to display encoded polylines on Google Maps: 'points', 'levels', 'numLevels', and 'zoomFactor'.

File

./gmap_polyutil.inc, line 153
Encoded polyline utilities.

Code

function gmap_polyutil_polyline($points) {
  $points_encoded = '';
  $levels_encoded = '';

  // simplify the line
  $weights = gmap_polyutil_dp_encode($points);
  $previous = array(
    0,
    0,
  );
  foreach ($points as $i => $p) {
    if (isset($weights[$i])) {

      // encode each simplified point
      // the deltas between points are encoded, rather than the point values themselves
      $points_encoded .= gmap_polyutil_encode_latlon($p[0] - $previous[0]) . gmap_polyutil_encode_latlon($p[1] - $previous[1]);
      $levels_encoded .= gmap_polyutil_encode_levels(_gmap_polyutil_get_zoom_level($weights[$i]));
      $previous = $p;
    }
  }
  return array(
    'points' => $points_encoded,
    'levels' => $levels_encoded,
    'numLevels' => GMAP_ZOOM_LEVELS,
    'zoomFactor' => GMAP_ZOOM_FACTOR,
  );
}