aboutsummaryrefslogtreecommitdiffstats
path: root/web/index.cgi
blob: 90d01e93fa38b8f9f10fd107f2191b49a12a0417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl -w

# index.pl:
# Main code for BCI - not really.
#
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
# $Id: index.cgi,v 1.2 2006-09-19 16:24:22 francis Exp $

use strict;
use CGI::Fast qw(-no_xhtml);
use Error qw(:try);

my $q;
try {
    while ($q = new CGI::Fast()) {
        print $q->header();
        my $x = $q->param('x') || 62;
        my $y = $q->param('y') || 171;
        my $zoom = $q->param('z') || 250;

        my $dir;
        if ($zoom == 25) {
            $dir = 'tl/';
        } else {
            $dir = 't/';
        }

        my $tl = $dir.$x.'.'.$y.'.png';
        my $tr = $dir.($x+1).'.'.$y.'.png';
        my $bl = $dir.$x.'.'.($y+1).'.png';
        my $br = $dir.($x+1).'.'.($y+1).'.png';

        my $url = sub {
            my ($x, $y, $z) = @_;
            $z = $zoom unless $z;
            return '?x=' . $x . '&y=' . $y . '&z=' . $z;
        };

        my $nw = &$url($x-1, $y-1);
        my $n = &$url($x, $y-1);
        my $ne = &$url($x+1, $y-1);
        my $w = &$url($x-1,$y);
        my $e = &$url($x+1,$y);
        my $sw = &$url($x-1, $y+1);
        my $s = &$url($x, $y+1);
        my $se = &$url($x+1, $y+1);
        print <<EOF;
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html lang="en-gb">
            <head>
                <title>MapOS testing</title>
                <script type="text/javascript" src="build/YAHOO.js"></script>
                <script type="text/javascript" src="build/dom.js"></script>
                <script type="text/javascript" src="build/event.js"></script>
                <script type="text/javascript" src="build/animation.js"></script>
                <script type="text/javascript">
                var x = $x;
                var y = $y;
                </script>
                <script type="text/javascript" src="js.js"></script>
                <style type="text/css">\@import url("css.css");</style>
            </head>
            <body>
                <h1>MapOS</h1>
                <p>Drag to move, double-click to centre, or use the arrows. Zoom's a bit of a jump (250,000:1 to 25,000:1 and back) but should be okay - if you double-click just before a zoom in, that's probably best.
                <strong>Bugs:</strong> None at this immediate moment</p>
                <div id="wrap">
                <div id="column">

        <table cellpadding="0" cellspacing="0" border="0" id="compass">
        <tr valign="bottom">
        <td align="right"><a href="$nw"><img src="i/arrow-northwest.gif" alt="NW"></a></td>
        <td align="center"><a href="$n"><img src="i/arrow-north.gif" vspace="3" alt="N"></a></td>
        <td><a href="$ne"><img src="i/arrow-northeast.gif" alt="NE"></a></td>
        </tr>
        <tr>
        <td><a href="$w"><img src="i/arrow-west.gif" hspace="3" alt="W"></a></td>
        <td align="center"><img src="i/rose.gif" alt=""></a></td>
        <td><a href="$e"><img src="i/arrow-east.gif" hspace="3" alt="E"></a></td>
        </tr>
        <tr valign="top">
        <td align="right"><a href="$sw"><img src="i/arrow-southwest.gif" alt="SW"></a></td>
        <td align="center"><a href="$s"><img src="i/arrow-south.gif" vspace="3" alt="S"></a></td>
        <td><a href="$se"><img src="i/arrow-southeast.gif" alt="SE"></a></td>
        </tr>
        </table>

        <p id="zoom" align="center">
EOF
        if ($zoom != 250) {
            printf('<a href="%s"><img src="i/zoomout.gif" alt="Zoom out" border="0"></a>', &$url(round($x/10)-1,round($y/10)-1,250) );
        }
        if ($zoom != 25) {
            print '<a href="' . &$url(($x+1)*10,($y+1)*10,25) . '"><img src="i/zoomin.gif" alt="Zoom in" border="0"></a>';
        }

        print <<EOF;
        </p>

                <div id="log"></div>
                </div>
                <div id="map">
                    <div id="drag">
                        <img id="2.2" nm="$tl" src="$tl" style="top:0px; left:0px;"><img id="3.2" nm="$tr" src="$tr" style="top:0px; left:250px;"><br><img id="2.3" nm="$bl" src="$bl" style="top:250px; left:0px;"><img id="3.3" nm="$br" src="$br" style="top:250px; left:250px;">
                    </div>
                </div>
                </div>
            </body>
        </html>
EOF
    }
} catch Error::Simple with {
    my $E = shift;
    my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text());
    warn "caught fatal exception: $msg";
    warn "aborting";
    encode_entities($msg);
    print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
            q(<p>Unfortunately, something went wrong. The text of the error
                    was:</p>),
            qq(<blockquote class="errortext">$msg</blockquote>),
            q(<p>Please try again later.);
};