Merge branch 'master' into enhancement

This commit is contained in:
Malte Hübner 2017-05-26 16:04:51 +02:00
commit 2b460636fe
4 changed files with 126 additions and 3 deletions

View File

@ -18,5 +18,7 @@
}
},
"minimum-stability": "stable",
"require": {}
"require": {
"emcconville/google-map-polyline-encoding-tool": "^1.3"
}
}

63
composer.lock generated Normal file
View File

@ -0,0 +1,63 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "d182917c77cf8a8483700b6913cd7277",
"packages": [
{
"name": "emcconville/google-map-polyline-encoding-tool",
"version": "v1.3",
"source": {
"type": "git",
"url": "https://github.com/emcconville/google-map-polyline-encoding-tool.git",
"reference": "dbf3816936620b88f0fc4000fddd94b5ce13eadb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/emcconville/google-map-polyline-encoding-tool/zipball/dbf3816936620b88f0fc4000fddd94b5ce13eadb",
"reference": "dbf3816936620b88f0fc4000fddd94b5ce13eadb",
"shasum": ""
},
"require": {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "4.1.*",
"satooshi/php-coveralls": "dev-master",
"squizlabs/php_codesniffer": "2.0.0a2"
},
"type": "library",
"autoload": {
"files": [
"src/Polyline.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GNU"
],
"authors": [
{
"name": "Eric McConville",
"email": "emcconville@emcconville.com"
}
],
"description": "A simple class to handle polyline-encoding for Google Maps",
"keywords": [
"google",
"maps"
],
"time": "2016-04-05T01:18:39+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

View File

@ -53,13 +53,13 @@ class StaticMapLite
protected $useTileCache = true;
protected $tileCacheBaseDir = '../cache/tiles';
protected $useMapCache = true;
protected $useMapCache = false;
protected $mapCacheBaseDir = '../cache/maps';
protected $mapCacheID = '';
protected $mapCacheFile = '';
protected $mapCacheExtension = 'png';
protected $zoom, $lat, $lon, $width, $height, $markers, $image, $maptype;
protected $zoom, $lat, $lon, $width, $height, $markers, $polylines, $image, $maptype;
protected $centerX, $centerY, $offsetX, $offsetY;
public function __construct()
@ -115,6 +115,10 @@ class StaticMapLite
}
}
if (!empty($_GET['polylines'])) {
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'];
}
@ -258,6 +262,52 @@ class StaticMapLite
};
}
public function placePolylines()
{
// loop thru marker array
foreach ($this->polylines as $polyline) {
// set some local variables
$polylineString = $polyline['polyline'];
$colorRed = $polyline['colorRed'];
$colorGreen = $polyline['colorGreen'];
$colorBlue = $polyline['colorBlue'];
$polylineList = \Polyline::decode($polylineString);
$sourceLatitude = null;
$sourceLongitude = null;
$destinationLatitude = null;
$destinationLongitude = null;
$color = imagecolorallocate($this->image, $colorRed, $colorGreen, $colorBlue);
imagesetthickness($this->image, 3);
//imageantialias($this->image, true);
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)
{
@ -343,6 +393,7 @@ class StaticMapLite
$this->initCoords();
$this->createBaseMap();
if (count($this->markers)) $this->placeMarkers();
if (count($this->polylines)) $this->placePolylines();
if ($this->osmLogo) $this->copyrightNotice();
}

7
web/info.php Normal file
View File

@ -0,0 +1,7 @@
<?php
/**
* Created by PhpStorm.
* User: maltehuebner
* Date: 26.05.17
* Time: 15:09
*/