php动态生成图像地图坐标

发布于 2024-11-14 07:30:27 字数 8892 浏览 3 评论 0原文

我有一张带有网格的地图。网格的每个单元格将是通过图像地图坐标在地图上可点击的区域。我想动态地执行此操作,以节省为图像映射编写所有这些代码,但我无法完全弄清楚我需要使用的语句或方程。 这是迄今为止我所拥有的图像映射的示例。

<div style="text-align:center;" id="location_title">The Hearth Lands</div>
                        <img id="map1" src="./images/maps/regions/1.png" usemap="#map1" border="0" width="800" height="800" alt="" />
                        <map name="map1" id="_map1">
                            <area shape="rect" coords="0,0,50,50" href=""  alt="" title="" />
                            <area shape="rect" coords="50,0,100,50" href=""  alt="" title="" />
                            <area shape="rect" coords="100,0,150,50" href=""  alt="" title="" />
                            <area shape="rect" coords="150,0,200,50" href=""  alt="" title="" />
                            <area shape="rect" coords="200,0,250,50" href=""  alt="" title="" />
                            <area shape="rect" coords="250,0,300,50" href=""  alt="" title="" />
                            <area shape="rect" coords="300,0,350,50" href=""  alt="" title="" />
                            <area shape="rect" coords="350,0,400,50" href=""  alt="" title="" />
                            <area shape="rect" coords="400,0,450,50" href=""  alt="" title="" />
                            <area shape="rect" coords="450,0,500,50" href=""  alt="" title="" />
                            <area shape="rect" coords="500,0,550,50" href=""  alt="" title="" />
                            <area shape="rect" coords="550,0,600,50" href=""  alt="" title="" />
                            <area shape="rect" coords="600,0,650,50" href=""  alt="" title="" />
                            <area shape="rect" coords="650,0,700,50" href=""  alt="" title="" />
                            <area shape="rect" coords="700,0,750,50" href=""  alt="" title="" />
                            <area shape="rect" coords="750,0,800,50" href=""  alt="" title="" />

                            <area shape="rect" coords="0,50,50,100" href=""  alt="" title="" />
                            <area shape="rect" coords="50,50,100,100" href=""  alt="" title="" />
                            <area shape="rect" coords="100,50,150,100" href=""  alt="" title="" />
                            <area shape="rect" coords="150,50,200,100" href=""  alt="" title="" />
                            <area shape="rect" coords="200,50,250,100" href=""  alt="" title="" />
                            <area shape="rect" coords="250,50,300,100" href=""  alt="" title="" />
                            <area shape="rect" coords="300,50,350,100" href=""  alt="" title="" />
                            <area shape="rect" coords="350,50,400,100" href=""  alt="" title="" />
                            <area shape="rect" coords="400,50,450,100" href=""  alt="" title="" />
                            <area shape="rect" coords="450,50,500,100" href=""  alt="" title="" />
                            <area shape="rect" coords="500,50,550,100" href=""  alt="" title="" />
                            <area shape="rect" coords="550,50,600,100" href=""  alt="" title="" />
                            <area shape="rect" coords="600,50,650,100" href=""  alt="" title="" />
                            <area shape="rect" coords="650,50,700,100" href=""  alt="" title="" />
                            <area shape="rect" coords="700,50,750,100" href=""  alt="" title="" />
                            <area shape="rect" coords="750,50,800,100" href=""  alt="" title="" />

                            <area shape="rect" coords="0,100,50,150" href=""  alt="" title="" />
                            <area shape="rect" coords="50,100,100,150" href=""  alt="" title="" />
                            <area shape="rect" coords="100,100,150,150" href=""  alt="" title="" />
                            <area shape="rect" coords="150,100,200,150" href=""  alt="" title="" />
                            <area shape="rect" coords="200,100,250,150" href=""  alt="" title="" />
                            <area shape="rect" coords="250,100,300,150" href=""  alt="" title="" />
                            <area shape="rect" coords="300,100,350,150" href=""  alt="" title="" />
                            <area shape="rect" coords="350,100,400,150" href=""  alt="" title="" />
                            <area shape="rect" coords="400,100,450,150" href=""  alt="" title="" />
                            <area shape="rect" coords="450,100,500,150" href=""  alt="" title="" />
                            <area shape="rect" coords="500,100,550,150" href=""  alt="" title="" />
                            <area shape="rect" coords="550,100,600,150" href=""  alt="" title="" />
                            <area shape="rect" coords="600,100,650,150" href=""  alt="" title="" />
                            <area shape="rect" coords="650,100,700,150" href=""  alt="" title="" />
                            <area shape="rect" coords="700,100,750,150" href=""  alt="" title="" />
                            <area shape="rect" coords="750,100,800,150" href=""  alt="" title="" />

                            <area shape="rect" coords="0,150,50,200" href=""  alt="" title="" />
                            <area shape="rect" coords="50,150,100,200" href=""  alt="" title="" />
                            <area shape="rect" coords="100,150,150,200" href=""  alt="" title="" />
                            <area shape="rect" coords="150,150,200,200" href=""  alt="" title="" />
                            <area shape="rect" coords="200,150,250,200" href=""  alt="" title="" />
                            <area shape="rect" coords="250,150,300,200" href=""  alt="" title="" />
                            <area shape="rect" coords="300,150,350,200" href=""  alt="" title="" />
                            <area shape="rect" coords="350,150,400,200" href=""  alt="" title="" />
                            <area shape="rect" coords="400,150,450,200" href=""  alt="" title="" />
                            <area shape="rect" coords="450,150,500,200" href=""  alt="" title="" />
                            <area shape="rect" coords="500,150,550,200" href=""  alt="" title="" />
                            <area shape="rect" coords="550,150,600,200" href=""  alt="" title="" />
                            <area shape="rect" coords="600,150,650,200" href=""  alt="" title="" />
                            <area shape="rect" coords="650,150,700,200" href=""  alt="" title="" />
                            <area shape="rect" coords="700,150,750,200" href=""  alt="" title="" />
                            <area shape="rect" coords="750,150,800,200" href=""  alt="" title="" />

                            <area shape="rect" coords="0,200,50,250" href=""  alt="" title="" />
                            <area shape="rect" coords="50,200,100,250" href=""  alt="" title="" />
                            <area shape="rect" coords="100,200,150,250" href=""  alt="" title="" />
                            <area shape="rect" coords="150,200,200,250" href=""  alt="" title="" />
                            <area shape="rect" coords="200,200,250,250" href=""  alt="" title="" />
                            <area shape="rect" coords="250,200,300,250" href=""  alt="" title="" />
                            <area shape="rect" coords="300,200,350,250" href=""  alt="" title="" />
                            <area shape="rect" coords="350,200,400,250" href=""  alt="" title="" />
                            <area shape="rect" coords="400,200,450,250" href=""  alt="" title="" />
                            <area shape="rect" coords="450,200,500,250" href=""  alt="" title="" />
                            <area shape="rect" coords="500,200,550,250" href=""  alt="" title="" />
                            <area shape="rect" coords="550,200,600,250" href=""  alt="" title="" />
                            <area shape="rect" coords="600,200,650,250" href=""  alt="" title="" />
                            <area shape="rect" coords="650,200,700,250" href=""  alt="" title="" />
                            <area shape="rect" coords="700,200,750,250" href=""  alt="" title="" />
                            <area shape="rect" coords="750,200,800,250" href=""  alt="" title="" />
                        </map>

如何用更少的代码创建所有这些区域?

I have a map with a grid on it. each cell of the grid will be a clickable area on the map via image map coords. I would like to do this dynamically to save writing all this code for the image maps, but I can't quite figure out the statement or equation i need to use.
Here is an example of what I have of the image map so far.

<div style="text-align:center;" id="location_title">The Hearth Lands</div>
                        <img id="map1" src="./images/maps/regions/1.png" usemap="#map1" border="0" width="800" height="800" alt="" />
                        <map name="map1" id="_map1">
                            <area shape="rect" coords="0,0,50,50" href=""  alt="" title="" />
                            <area shape="rect" coords="50,0,100,50" href=""  alt="" title="" />
                            <area shape="rect" coords="100,0,150,50" href=""  alt="" title="" />
                            <area shape="rect" coords="150,0,200,50" href=""  alt="" title="" />
                            <area shape="rect" coords="200,0,250,50" href=""  alt="" title="" />
                            <area shape="rect" coords="250,0,300,50" href=""  alt="" title="" />
                            <area shape="rect" coords="300,0,350,50" href=""  alt="" title="" />
                            <area shape="rect" coords="350,0,400,50" href=""  alt="" title="" />
                            <area shape="rect" coords="400,0,450,50" href=""  alt="" title="" />
                            <area shape="rect" coords="450,0,500,50" href=""  alt="" title="" />
                            <area shape="rect" coords="500,0,550,50" href=""  alt="" title="" />
                            <area shape="rect" coords="550,0,600,50" href=""  alt="" title="" />
                            <area shape="rect" coords="600,0,650,50" href=""  alt="" title="" />
                            <area shape="rect" coords="650,0,700,50" href=""  alt="" title="" />
                            <area shape="rect" coords="700,0,750,50" href=""  alt="" title="" />
                            <area shape="rect" coords="750,0,800,50" href=""  alt="" title="" />

                            <area shape="rect" coords="0,50,50,100" href=""  alt="" title="" />
                            <area shape="rect" coords="50,50,100,100" href=""  alt="" title="" />
                            <area shape="rect" coords="100,50,150,100" href=""  alt="" title="" />
                            <area shape="rect" coords="150,50,200,100" href=""  alt="" title="" />
                            <area shape="rect" coords="200,50,250,100" href=""  alt="" title="" />
                            <area shape="rect" coords="250,50,300,100" href=""  alt="" title="" />
                            <area shape="rect" coords="300,50,350,100" href=""  alt="" title="" />
                            <area shape="rect" coords="350,50,400,100" href=""  alt="" title="" />
                            <area shape="rect" coords="400,50,450,100" href=""  alt="" title="" />
                            <area shape="rect" coords="450,50,500,100" href=""  alt="" title="" />
                            <area shape="rect" coords="500,50,550,100" href=""  alt="" title="" />
                            <area shape="rect" coords="550,50,600,100" href=""  alt="" title="" />
                            <area shape="rect" coords="600,50,650,100" href=""  alt="" title="" />
                            <area shape="rect" coords="650,50,700,100" href=""  alt="" title="" />
                            <area shape="rect" coords="700,50,750,100" href=""  alt="" title="" />
                            <area shape="rect" coords="750,50,800,100" href=""  alt="" title="" />

                            <area shape="rect" coords="0,100,50,150" href=""  alt="" title="" />
                            <area shape="rect" coords="50,100,100,150" href=""  alt="" title="" />
                            <area shape="rect" coords="100,100,150,150" href=""  alt="" title="" />
                            <area shape="rect" coords="150,100,200,150" href=""  alt="" title="" />
                            <area shape="rect" coords="200,100,250,150" href=""  alt="" title="" />
                            <area shape="rect" coords="250,100,300,150" href=""  alt="" title="" />
                            <area shape="rect" coords="300,100,350,150" href=""  alt="" title="" />
                            <area shape="rect" coords="350,100,400,150" href=""  alt="" title="" />
                            <area shape="rect" coords="400,100,450,150" href=""  alt="" title="" />
                            <area shape="rect" coords="450,100,500,150" href=""  alt="" title="" />
                            <area shape="rect" coords="500,100,550,150" href=""  alt="" title="" />
                            <area shape="rect" coords="550,100,600,150" href=""  alt="" title="" />
                            <area shape="rect" coords="600,100,650,150" href=""  alt="" title="" />
                            <area shape="rect" coords="650,100,700,150" href=""  alt="" title="" />
                            <area shape="rect" coords="700,100,750,150" href=""  alt="" title="" />
                            <area shape="rect" coords="750,100,800,150" href=""  alt="" title="" />

                            <area shape="rect" coords="0,150,50,200" href=""  alt="" title="" />
                            <area shape="rect" coords="50,150,100,200" href=""  alt="" title="" />
                            <area shape="rect" coords="100,150,150,200" href=""  alt="" title="" />
                            <area shape="rect" coords="150,150,200,200" href=""  alt="" title="" />
                            <area shape="rect" coords="200,150,250,200" href=""  alt="" title="" />
                            <area shape="rect" coords="250,150,300,200" href=""  alt="" title="" />
                            <area shape="rect" coords="300,150,350,200" href=""  alt="" title="" />
                            <area shape="rect" coords="350,150,400,200" href=""  alt="" title="" />
                            <area shape="rect" coords="400,150,450,200" href=""  alt="" title="" />
                            <area shape="rect" coords="450,150,500,200" href=""  alt="" title="" />
                            <area shape="rect" coords="500,150,550,200" href=""  alt="" title="" />
                            <area shape="rect" coords="550,150,600,200" href=""  alt="" title="" />
                            <area shape="rect" coords="600,150,650,200" href=""  alt="" title="" />
                            <area shape="rect" coords="650,150,700,200" href=""  alt="" title="" />
                            <area shape="rect" coords="700,150,750,200" href=""  alt="" title="" />
                            <area shape="rect" coords="750,150,800,200" href=""  alt="" title="" />

                            <area shape="rect" coords="0,200,50,250" href=""  alt="" title="" />
                            <area shape="rect" coords="50,200,100,250" href=""  alt="" title="" />
                            <area shape="rect" coords="100,200,150,250" href=""  alt="" title="" />
                            <area shape="rect" coords="150,200,200,250" href=""  alt="" title="" />
                            <area shape="rect" coords="200,200,250,250" href=""  alt="" title="" />
                            <area shape="rect" coords="250,200,300,250" href=""  alt="" title="" />
                            <area shape="rect" coords="300,200,350,250" href=""  alt="" title="" />
                            <area shape="rect" coords="350,200,400,250" href=""  alt="" title="" />
                            <area shape="rect" coords="400,200,450,250" href=""  alt="" title="" />
                            <area shape="rect" coords="450,200,500,250" href=""  alt="" title="" />
                            <area shape="rect" coords="500,200,550,250" href=""  alt="" title="" />
                            <area shape="rect" coords="550,200,600,250" href=""  alt="" title="" />
                            <area shape="rect" coords="600,200,650,250" href=""  alt="" title="" />
                            <area shape="rect" coords="650,200,700,250" href=""  alt="" title="" />
                            <area shape="rect" coords="700,200,750,250" href=""  alt="" title="" />
                            <area shape="rect" coords="750,200,800,250" href=""  alt="" title="" />
                        </map>

How can i create all of these areas with less code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

舞袖。长 2024-11-21 07:30:27
$columns = 5;
$rows = 5;
$width = 50;
$height = 50;

for( $x = 0; $x < $columns; $x++ )
{
   for( $y = 0; $y < $rows; $y++ )
   {
      $a = ($x * $width);
      $b = ($y * $height);

      $coords = array( $a, $b, ($a + $width), ($b + $height) );
      echo '<area shape="rect" coords="'.implode( ',', $coords ).'" href="'.$href.'" alt="'.$alt.'" title="'.$title.'" />';
   }
}

您可以在此处查看其实际效果:http://codepad.org/MMKfY1zc

$columns = 5;
$rows = 5;
$width = 50;
$height = 50;

for( $x = 0; $x < $columns; $x++ )
{
   for( $y = 0; $y < $rows; $y++ )
   {
      $a = ($x * $width);
      $b = ($y * $height);

      $coords = array( $a, $b, ($a + $width), ($b + $height) );
      echo '<area shape="rect" coords="'.implode( ',', $coords ).'" href="'.$href.'" alt="'.$alt.'" title="'.$title.'" />';
   }
}

You can see it in action here: http://codepad.org/MMKfY1zc

韬韬不绝 2024-11-21 07:30:27
<map name="map1" id="_map1">
<?php
$rows = 5;
$cols = 16;
$w = $h = 50;
for ($i = 0; $i < $rows; $i++) {
    for ($j = 0; $j < $cols; $j++)
        echo "\t", '<area shape="rect" coords=', $j * $w , ',', $i * $h, ',', ($j + 1) * $w, ',', ($i + 1) * $h, '" href=""  alt="" title="" />', "\n";
    echo "\n";
}
?>
</map>

简单的数学。 :P

<map name="map1" id="_map1">
<?php
$rows = 5;
$cols = 16;
$w = $h = 50;
for ($i = 0; $i < $rows; $i++) {
    for ($j = 0; $j < $cols; $j++)
        echo "\t", '<area shape="rect" coords=', $j * $w , ',', $i * $h, ',', ($j + 1) * $w, ',', ($i + 1) * $h, '" href=""  alt="" title="" />', "\n";
    echo "\n";
}
?>
</map>

Simple math. :P

万人眼中万个我 2024-11-21 07:30:27

像这样:

<?php 

$i=0;
foreach(range(0,750,50) as $b){
    foreach(range(0,750,50) as $a){
        echo '<area shape="rect" coords="'.$a.','.$b.','.($a+50).','.($b+50).'" href=""  alt="" title="" />'."\n";
    }
    $i++;
    if($i==5){break;}
}

?>

like this:

<?php 

$i=0;
foreach(range(0,750,50) as $b){
    foreach(range(0,750,50) as $a){
        echo '<area shape="rect" coords="'.$a.','.$b.','.($a+50).','.($b+50).'" href=""  alt="" title="" />'."\n";
    }
    $i++;
    if($i==5){break;}
}

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文