PHP code example of heymoon / vector-tile-data-provider
1. Go to this page and download the library: Download heymoon/vector-tile-data-provider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
heymoon / vector-tile-data-provider example snippets
use Brick\Geo\IO\GeoJSONReader;
use Brick\Geo\Exception\GeometryException;
use HeyMoon\VectorTileDataProvider\Entity\TilePosition;
use HeyMoon\VectorTileDataProvider\Factory\SourceFactory;
use HeyMoon\VectorTileDataProvider\Service\GridService;
use HeyMoon\VectorTileDataProvider\Service\TileService;
use HeyMoon\VectorTileDataProvider\Service\ExportService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:export')]
class ExportCommand extends Command
{
public function __construct(
private readonly GeoJSONReader $geoJSONReader,
private readonly SourceFactory $sourceFactory,
private readonly GridService $gridService,
private readonly TileService $tileService,
private readonly ExportService $exportService
)
{
parent::__construct();
}
public function configure()
{
$this->addArgument('in', InputArgument::REQUIRED);
$this->addArgument('out', InputArgument::REQUIRED);
$this->addOption('zoom', 'z', InputOption::VALUE_OPTIONAL);
$this->addOption('type', 't', InputOption::VALUE_OPTIONAL,
'mvt for .mvt or svg for .svg');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$source = $this->sourceFactory->create();
try {
$source->addCollection('export', $this->geoJSONReader->read(file_get_contents($input->getArgument('in'))));
$grid = $this->gridService->getGrid($source, $input->getOption('zoom') ?? 0);
$path = $input->getArgument('out');
$type = $input->getOption('type') ?? 'mvt';
$grid->iterate(fn (TilePosition $position, array $data) =>
$this->exportService->dump(
$this->tileService->getTileMVT($data, $position), "$path/$position.$type")
);
} catch (GeometryException $e) {
$output->writeln("Data error: {$e->getMessage()}");
return 1;
}
return 0;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.