Skip to content

Instantly share code, notes, and snippets.

@codemasher
Last active December 25, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemasher/75d8e1a24b2363cabebf to your computer and use it in GitHub Desktop.
Save codemasher/75d8e1a24b2363cabebf to your computer and use it in GitHub Desktop.
<?php
/**
* gw2staticmaps.php
* created: 26.09.13
*/
function max_zoom($continent_id){
return $continent_id === 1 ? 7 : 6;
}
function project($point, $continent, $zoom, $max_zoom){
$div = 1 << ($max_zoom-$zoom);
return [$point[0]/$div, $point[1]/$div];
}
function get_tiles($rect, $continent, $zoom){
$tiles = [];
$max_zoom = max_zoom($continent);
if($zoom > $max_zoom){
$zoom = $max_zoom;
}
$nw = project($rect[0], $continent, $zoom, $max_zoom);
$se = project($rect[1], $continent, $zoom, $max_zoom);
for($y = 0; $y < (1 << $zoom); $y++){
for($x = 0; $x < (1 << $zoom); $x++){
if($x >= floor($nw[0]/256) && $x < ceil($se[0]/256) && $y >= floor($nw[1]/256) && $y < ceil($se[1]/256)){
$tiles[$y][$x] = 'https://tiles.guildwars2.com/'.$continent.'/1/'.$zoom.'/'.$x.'/'.$y.'.jpg';
}
}
}
return $tiles;
}
##########
#$ = [[0, 0], [(1 << $max_zoom)*256, (1 << $max_zoom)*256]]; // get all tiles for the given continent
$m = [[9856, 11648], [13440, 14080]]; // example: queensdale (continent_rect)
$c = 1; //desired continent_id, 1 for tyria, 2 for the mists
$z = 7; // desired zoomlevel
$t = get_tiles($m, $c, $z);
foreach($t as $y){
echo '<div style="white-space: nowrap; width: '.((1 << $z)*256).'px;">'."\n";
foreach($y as $x){
echo '<img src="'.$x.'" />';
}
echo '</div>'."\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment