<slide title="Map Tiles API">
<blurb>
You can also ask for a single map tile of any location at any size.
</blurb>

<example title="REST Query to get a tile" result="0" fontsize="1.4em" marginright="0em"><![CDATA[http://local.yahooapis.com/MapsService/V1/mapImage?appid=rlerdorf&location=94539]]></example>

<example title="Returned XML" result="0" fontsize="1.4em" marginright="0em"><![CDATA[<Result>
http://img.maps.yahoo.com/mapimage?MAPDATA=NE6uked6wXUvMKeeO65.zg9FRNGF36TLiC8QU14ROsDkbVumowh8Jm3JSJUKwebcVHHXcvWDLt8WExnWh59FAevHEV5ynmh6WyJ3zNdmrLJYh3S95w--
</Result>
]]></example>

<example fontsize="1.2em" title="Example" result="1" marginright="0em"><![CDATA[<html><head><title>Map Tile Demo</title>
<script type="text/javascript">
<?php
function request_cache($url, $dest_file, $timeout=43200) {
  if(!file_exists($dest_file) || filemtime($dest_file) < (time()-$timeout)) {
    $stream = fopen($url,'r');
    $tmpf = tempnam('/tmp','YWS');
    file_put_contents($tmpf, $stream);
    fclose($stream);
    rename($tmpf, $dest_file);
  }
}

$cities = array("San Francisco", "Los Angeles", "Seattle", "Atlanta", "Chicago", "Dallas",
                "Vancouver, Canada", "New York City", "Toronto", "Miami, FL", "Boston");

$width = 600; $height = 300; $zoom = 7;
 
$url  = "http://local.yahooapis.com/MapsService/V1/mapImage?appid=rlerdorf"; 
$url .= "&image_height=$height&image_width=$width&zoom=$zoom";
$url .= "&location=";
$i=0;
foreach($cities as $city) {
  $q = $url.rawurlencode($city); 
  $tmp = '/tmp/yws_tile_'.md5($q); 
  request_cache($q, $tmp);
  $xml = simplexml_load_file($tmp); 
  if($i==0) $first = (string)$xml;
  echo <<<EOB
image$i = new Image();
image$i.src = "$xml";
EOB;
  $i++;
}
?>
</script>
</head><body>
<?php
echo <<<EOB
<div id="img_container" 
  style="float:left; height:{$height}px; width:{$width}px; padding: 0px 10px 0px 10px;">
<img id="the_img" src="$first" height="$height" width="$width"/></div>
EOB;
$i=0;
foreach($cities as $city) {
  $q = rawurlencode($city);
  echo <<<EOB
<a href="http://maps.yahoo.com/beta/index.php?#trf=0&q1=$q"
   onmouseover="document.getElementById('the_img').src=image$i.src;
                this.style.backgroundColor='white';"
   onmouseout="this.style.backgroundColor='#eeee33';">$city</a><br />
EOB;
  $i++;
}
?>
</body></html>]]></example>

</slide>
