You are here

function legacy_gmap_polyutil_polyline in GMap Module 7.2

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

Parameters

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

Return value

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

File

tests/inc/gmap_polyutil.inc, line 185
Encoded polyline utilities.

Namespace

tests\inc

Code

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

  // Simplify the line.
  $weights = legacy_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 .= legacy_gmap_polyutil_encode_latlon($p[0] - $previous[0]) . legacy_gmap_polyutil_encode_latlon($p[1] - $previous[1]);
      $levels_encoded .= legacy_gmap_polyutil_encode_levels(legacy__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,
  );
}