WIP for polyline.

This commit is contained in:
Malte Hübner 2017-05-26 14:58:47 +02:00
parent 495bbbb095
commit aaa90f6d53
1 changed files with 49 additions and 8 deletions

View File

@ -52,7 +52,7 @@ class staticMapLite
protected $useTileCache = true;
protected $tileCacheBaseDir = '../cache/tiles';
protected $useMapCache = true;
protected $useMapCache = false;
protected $mapCacheBaseDir = '../cache/maps';
protected $mapCacheID = '';
protected $mapCacheFile = '';
@ -115,12 +115,8 @@ class staticMapLite
}
if (!empty($_GET['polylines'])) {
$polylines = explode('|', $_GET['polylines']);
foreach ($polylines as $polyline) {
list($polylineString, $colorRed, $colorGreen, $colorBlue) = explode(',', $polyline);
$this->polylines[] = array('polyline' => $polylineString, 'colorRed' => $colorRed, 'colorGreen' => $colorGreen, 'colorBlue' => $colorBlue);
}
list($polylineString, $colorRed, $colorGreen, $colorBlue) = explode(',', $_GET['polylines']);
$this->polylines[] = array('polyline' => $polylineString, 'colorRed' => $colorRed, 'colorGreen' => $colorGreen, 'colorBlue' => $colorBlue);
}
if ($_GET['maptype']) {
if (array_key_exists($_GET['maptype'], $this->tileSrcUrl)) $this->maptype = $_GET['maptype'];
@ -265,8 +261,52 @@ class staticMapLite
};
}
pu
public function placePolylines()
{
// loop thru marker array
foreach ($this->polylines as $polyline) {
// set some local variables
$polylineString = $polyline['polyline'];
$colorRed = $polyline['Red'];
$colorGreen = $polyline['colorGreen'];
$colorBlue = $polyline['colorBlue'];
// clear variables from previous loops
$polylineList = \Polyline::decode($polylineString);
$sourceLatitude = null;
$sourceLongitude = null;
$destinationLatitude = null;
$destinationLongitude = null;
$color = imagecolorallocate($this->image, $colorRed, $colorGreen, $colorBlue);
while (!empty($polylineList)) {
if (!$sourceLatitude) {
$sourceLatitude = array_shift($polylineList);
}
if (!$sourceLongitude) {
$sourceLongitude = array_shift($polylineList);
}
$sourceX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($sourceLongitude, $this->zoom)));
$sourceY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($sourceLatitude, $this->zoom)));
$destinationLatitude = array_shift($polylineList);
$destinationLongitude = array_shift($polylineList);
$destinationX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($destinationLongitude, $this->zoom)));
$destinationY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($destinationLatitude, $this->zoom)));
imageline($this->image , $sourceX, $sourceY , $destinationX, $destinationY, $color);
$sourceLatitude = $destinationLatitude;
$sourceLongitude = $destinationLongitude;
}
}
}
public function tileUrlToFilename($url)
{
@ -352,6 +392,7 @@ class staticMapLite
$this->initCoords();
$this->createBaseMap();
if (count($this->markers)) $this->placeMarkers();
if (count($this->polylines)) $this->placePolylines();
if ($this->osmLogo) $this->copyrightNotice();
}