knyazevdev/gpx2png

Gpx and track to image on OSM and other tiles

1.3.1 2020-04-17 14:43 UTC

This package is auto-updated.

Last update: 2024-03-26 23:36:21 UTC


README

Php class that helps draw track and points on OSM maps.

Install

Via Composer

$ composer require knyazevdev/gpx2png

Basic usage

require "vendor/autoload.php";
use Gpx2Png\Gpx2Png;

$gpx = new Gpx2Png();
$gpx2png->loadFile($gpxTrackFile);

$res = $gpx2png->generateImage();
$res->saveToFile($target_file);

Extend usage

require "vendor/autoload.php";
use Gpx2Png\Gpx2Png;
use Gpx2Png\Models\Overlays\DrawParamsPoint;
use Gpx2Png\Models\Point;

// prepare points set from own source 

$points = array();
foreach ($mypoints as $mypoint) {
    $points[] = new Point($mypoint['lat'], $mypoint['lon'], $point['timestamp']);
}

// load points

$gpx2png->loadPoints($points);

// set custom draw params

$gpx2png->drawParams->track->color = "black";
$gpx2png->drawParams->track->opacity = "0.3";
$gpx2png->drawParams->track->startPoint->color = "yellow";
$gpx2png->drawParams->track->distanceLabel->text_size = 20;
$gpx2png->drawParams->track->distanceLabel->text_color = 'red';

// set osm source type

$gpx2png->setMapSourceName("osm_topo");

// set custom tiles cache directory
// default: sys_get_temp_dir().'/tiles'

$gpx2png->mapSource->setTilesDirectory(__DIR__.'/tiles');

// receive result

$res = $gpx2png->generateImage();

// add extra overlays

$extraPoint = $points[mt_rand(0, count($points)-1)];
$drawParamsPoint = new DrawParamsPoint();
$drawParamsPoint->setTemplate(DrawParamsPoint::TPL_LIVE_POINT);

$res->image->drawPoint($extraPoint, $drawParamsPoint);

// save or output file

$res->saveToFile("result.png");
$res->output();

Credits

License

The MIT License (MIT). Please see License File for more information.