You are here

public function GmapPolylineToolbox::getPolyline in GMap Module 7.2

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

former gmap_polyutil_polyline($points)

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

lib/Drupal/gmap/GmapPolylineToolbox.php, line 306
Contains GmapPolylineToolbox.php Encoded polyline utilities.

Class

GmapPolylineToolbox

Namespace

Drupal\gmap

Code

public function getPolyline() {
  $points_encoded = '';
  $levels_encoded = '';

  // Simplify the line.
  $weights = $this
    ->getDPEncode();
  $previous = array(
    0,
    0,
  );
  foreach ($this->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 .= $this
        ->setLatLonNumber($p[0] - $previous[0])
        ->getEncodedLatLon() . $this
        ->setLatLonNumber($p[1] - $previous[1])
        ->getEncodedLatLon();
      $levels_encoded .= $this
        ->setLatLonNumber($this
        ->setWeight($weights[$i])
        ->getZoomLevel())
        ->getEncodedLevels();
      $previous = $p;
    }
  }
  return array(
    'points' => $points_encoded,
    'levels' => $levels_encoded,
    'numLevels' => self::GMAP_ZOOM_LEVELS,
    'zoomFactor' => self::GMAP_ZOOM_FACTOR,
  );
}