1. Go to this page and download the library: Download arakne/php-map-parser 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/ */
arakne / php-map-parser example snippets
use Arakne\MapParser\DofusMapParser;
use Arakne\MapParser\Loader\MapCoordinates;
use Arakne\MapParser\Tile\Cache\SqliteTileCache;
use Arakne\MapParser\Sprite\Cache\SqliteSpriteCache;
use Arakne\MapParser\Loader\MapKey;
// Configure paths
const DOFUS_CLIENT_PATH = '/path/to/dofus/client';
// Maps path is not er = new DofusMapParser(
dofusPath: DOFUS_CLIENT_PATH,
mapsPath: SERVER_MAP_PATH,
// Configure map resolver from coordinates: this is used only if you want to use world map using leaflet for example
mapByCoordinates: function (MapCoordinates $coordinates, int $superAreaId) {
$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
// SQL query to get the map ID from coordinates and super area
// In this example, Araknemu database structure is used
$query = <<<'SQL'
SELECT id FROM maps
WHERE MAP_X = ? AND MAP_Y = ?
AND INDOOR = 0
AND SUBAREA_ID IN (SELECT SUBAREA_ID FROM SUBAREA WHERE AREA_ID IN (SELECT AREA_ID FROM AREA WHERE SUPERAREA_ID = ?))
SQL
;
$stmt = $pdo->prepare($query);
$stmt->bindValue(1, $coordinates->x, PDO::PARAM_INT);
$stmt->bindValue(2, $coordinates->y, PDO::PARAM_INT);
$stmt->bindValue(3, $superAreaId, PDO::PARAM_INT);
$stmt->execute();
$map = $stmt->fetch();
if (!$map) {
return null;
}
return (int) $map['id'];
},
// Configure cache. Rendering tiles is expensive, so caching them is recommended
// SQLite provides good performances without flooding the filesystem with thousands of files
tileCache: new SqliteTileCache(CACHE_DIR . '/tiles.db'),
spriteCache: new SqliteSpriteCache(CACHE_DIR . '/sprites.db'),
// Attachments will load extra data from the database (or any other sources)
// This is
/** @var \Arakne\MapParser\DofusMapParser $parser */
// Load and parse the map with ID 37
$map = $parser->parse(37);
// Now you can access to all cells properties
foreach ($map->cells as $id => $cell) {
echo "Cell {$id}\n";
echo " Ground: {$cell->ground->number}\n";
echo " Layer1: {$cell->layer1->number}\n";
echo " Layer2: {$cell->layer2->number}\n";
}
/** @var \Arakne\MapParser\DofusMapParser $parser */
// Directly render the map as an image
$img = $parser->render(37);
// Render returns a GD image object, so you must use GD functions to manipulate or save it
imagepng($img, 'map37.png');
/** @var \Arakne\MapParser\DofusMapParser $parser */
// Get the tile renderer, here for amakna world map
$tiles = $parser->amaknaWorldMap();
// Warmup the cache using a CLI command
// php index.php warmup
// This will take some time (more than 1 hour) but will speed up tile rendering
// The tile renderer can be used without warmup and even in parallel of the warmup process
if (($argv[1] ?? null) === 'warmup') {
$amaknaRenderer->warmup(
function (string $name, int $current, int $total) {
echo sprintf("Building %s (%d/%d)\n", $name, $current, $total);
},
);
exit(0);
}
$page = trim($_SERVER['PATH_INFO'] ?? '', '/');
switch ($page) {
case '':
// Show the template with leaflet
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.