A fast way (or alternate way) to dynamically load 40000 links in an image map?

只谈情不闲聊 提交于 2020-01-25 09:54:48

问题


I'm bringing back a GD Image which is generated from user information in a database, now on the page where this image is viewed. I have the following area map for the image generated by the same sort of query to create a link to that users profile. However, there are a possible 40000 users in the database... anyway, what I have IS working, but as you can imagine it takes a long while for it to load.

<map id="pixel" name="pixel">

<?
    $map_x_1 = 0;
    $map_y_1 = 0;

    $map_x_2 = 5;
    $map_y_2 = 5;

    $block_num = 1;

    while ($map_y_2 <= 1000) {

        while ($map_x_2 <= 1000) {

            $actual_x_cood = $map_x_1+1;
            $actual_y_cood = $map_y_1+1;

            $grid_search = mysql_query("SELECT *
                            FROM project
                            WHERE project_x_cood = '$actual_x_cood' AND project_y_cood = '$actual_y_cood'") or die(mysql_error());

            $block_exists = mysql_num_rows($grid_search);

            if ($block_exists == 1) {

                echo("<area shape=\"rect\" coords=\"$map_x_1, $map_y_1, $map_x_2, $map_y_2\" href=\"/block/$block_num/\" alt=\"\" title=\"$block_num\" />\n");

            } else {

                echo("<area shape=\"rect\" coords=\"$map_x_1, $map_y_1, $map_x_2, $map_y_2\" href=\"/block/$block_num/\" alt=\"\" title=\"$block_num\" />\n");

            }

            $map_x_1 = $map_x_1 + 5;
            $map_x_2 = $map_x_2 + 5;

            $block_num = $block_num+1;  

        }

        $map_y_1 = $map_y_1 + 5;
        $map_y_2 = $map_y_2 + 5;

        $map_x_1 = 0;
        $map_x_2 = 5;

    }
?>

</map>

I was thinking about just throwing in a quick jquery load screen over the top in a div and then hiding it once the page has fully loaded so it looks nicer. But I'm not really too happy with the idea of it since I would just like to load it faster.

So is there a quicker way to do it, maybe PHP? JS? Thanks!


回答1:


you should capture the coordinates in the image map (easy with jquery) and pass it to the server which then calculates the user clicked.

i did something similar with a rate bar that hat hat 100 values (1-100%). but it was done in prototype so the code wont help you much.

small hint: i had to substract the left position of the container from the absolute click position.

in php and forms its not so flexible but far easier. you can just specify an input type image. the coordinates will be passed as post variables.

something like

will suffice




回答2:


You should consider using an input:image element. It will retreive the x-y coords as built-in functionality, and can be used in JavaScript or as part of the submission of a form.

After receiving the x-y coords, you can use a quad-tree or other algorithm for quick spacial-searching in your dataset.



来源:https://stackoverflow.com/questions/4820303/a-fast-way-or-alternate-way-to-dynamically-load-40000-links-in-an-image-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!