diff options
author | Matthew Somerville <matthew@balti.ukcod.org.uk> | 2010-08-02 11:36:02 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@balti.ukcod.org.uk> | 2010-08-02 11:36:02 +0100 |
commit | 7bbd05ddfffd81cbc183988194a86d6275b48cff (patch) | |
tree | 910d9c2ba98946da8520238d512c693e4f4bff2c | |
parent | c2239ce7c633aec362b90ae6fc2cd33e5783358a (diff) |
Switch X/Y to be middle of map, clearer when going to RSS feed/alerts.
-rw-r--r-- | perllib/Page.pm | 52 | ||||
-rwxr-xr-x | web/ajax.cgi | 2 | ||||
-rwxr-xr-x | web/index.cgi | 12 | ||||
-rw-r--r-- | web/js.js | 8 | ||||
-rwxr-xr-x | web/rss.cgi | 10 |
5 files changed, 40 insertions, 44 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index 70b320548..470625749 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -423,14 +423,14 @@ sub display_map { my $x = int($params{x})<=0 ? 0 : $params{x}; my $y = int($params{y})<=0 ? 0 : $params{y}; my $url = mySociety::Config::get('TILES_URL'); - my $tiles_url = $url . $x . '-' . ($x+1) . ',' . $y . '-' . ($y+1) . '/RABX'; + my $tiles_url = $url . ($x-1) . '-' . $x . ',' . ($y-1) . '-' . $y . '/RABX'; my $tiles = LWP::Simple::get($tiles_url); return '<div id="map_box"> <div id="map"><div id="drag">' . _("Unable to fetch the map tiles from the tile server.") . '</div></div></div><div id="side">' if !$tiles; my $tileids = RABX::unserialise($tiles); - my $tl = $x . '.' . ($y+1); - my $tr = ($x+1) . '.' . ($y+1); - my $bl = $x . '.' . $y; - my $br = ($x+1) . '.' . $y; + my $tl = ($x-1) . '.' . $y; + my $tr = $x . '.' . $y; + my $bl = ($x-1) . '.' . ($y-1); + my $br = $x . '.' . ($y-1); return '<div id="side">' if (!$tileids->[0][0] || !$tileids->[0][1] || !$tileids->[1][0] || !$tileids->[1][1]); my $tl_src = $url . $tileids->[0][0]; my $tr_src = $url . $tileids->[0][1]; @@ -467,8 +467,8 @@ EOF <script type="text/javascript"> $root_path_js var fixmystreet = { - 'x': $x - 2, - 'y': $y - 2, + 'x': $x - 3, + 'y': $y - 3, 'start_x': $px, 'start_y': $py, 'tile_type': '$tile_type', @@ -537,16 +537,12 @@ sub map_pins { my ($q, $x, $y, $sx, $sy, $interval) = @_; my $pins = ''; - my $min_e = Page::tile_to_os($x-2); # Extra space to left/below due to rounding, I think - my $min_n = Page::tile_to_os($y-2); - #my $map_le = Page::tile_to_os($x); - #my $map_ln = Page::tile_to_os($y); - my $mid_e = Page::tile_to_os($x+1); - my $mid_n = Page::tile_to_os($y+1); - #my $map_re = Page::tile_to_os($x+2); - #my $map_rn = Page::tile_to_os($y+2); - my $max_e = Page::tile_to_os($x+3); - my $max_n = Page::tile_to_os($y+3); + my $min_e = Page::tile_to_os($x-3); # Extra space to left/below due to rounding, I think + my $min_n = Page::tile_to_os($y-3); + my $mid_e = Page::tile_to_os($x); + my $mid_n = Page::tile_to_os($y); + my $max_e = Page::tile_to_os($x+2); + my $max_n = Page::tile_to_os($y+2); my $cobrand = Page::get_cobrand($q); # list of problems aoround map can be limited, but should show all pins my $around_limit = Cobrand::on_map_list_limit($cobrand); @@ -619,17 +615,17 @@ EOF } # P is easting or northing -# BL is bottom left tile reference of displayed map +# C is centre tile reference of displayed map sub os_to_px { - my ($p, $bl, $invert) = @_; - return tile_to_px(os_to_tile($p), $bl, $invert); + my ($p, $c, $invert) = @_; + return tile_to_px(os_to_tile($p), $c, $invert); } # Convert tile co-ordinates to pixel co-ordinates from top left of map -# BL is bottom left tile reference of displayed map +# C is centre tile reference of displayed map sub tile_to_px { - my ($p, $bl, $invert) = @_; - $p = TILE_WIDTH * ($p - $bl); + my ($p, $c, $invert) = @_; + $p = TILE_WIDTH * ($p - $c + 1); $p = 2 * TILE_WIDTH - $p if $invert; $p = int($p + .5 * ($p <=> 0)); return $p; @@ -667,7 +663,7 @@ sub os_to_px_with_adjust { $py = Page::os_to_px($northing, $y_tile, 1); } if ($px > 380) { - $x_tile--; + $x_tile++; $px = Page::os_to_px($easting, $x_tile); } } @@ -945,8 +941,8 @@ sub geocode { my $yy = Page::os_to_tile($northing); $x = int($xx); $y = int($yy); - $x -= 1 if ($xx - $x < 0.5); - $y -= 1 if ($yy - $y < 0.5); + $x += 1 if ($xx - $x > 0.5); + $y += 1 if ($yy - $y > 0.5); } } else { ($x, $y, $easting, $northing, $error) = geocode_string($s, $q); @@ -971,8 +967,8 @@ sub geocoded_string_coordinates { my $yy = Page::os_to_tile($northing); $x = int($xx); $y = int($yy); - $x -= 1 if ($xx - $x < 0.5); - $y -= 1 if ($yy - $y < 0.5); + $x += 1 if ($xx - $x > 0.5); + $y += 1 if ($yy - $y > 0.5); } catch Error::Simple with { $error = shift; $error = _('That location does not appear to be in Britain; please try again.') diff --git a/web/ajax.cgi b/web/ajax.cgi index 1b3ff5cf8..fff437846 100755 --- a/web/ajax.cgi +++ b/web/ajax.cgi @@ -19,7 +19,7 @@ sub main { my %input = map { $_ => $q->param($_) || '' } @vars; my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; - # Our current X/Y bottom left of visible map + # Our current X/Y middle of visible map my $x = $input{x}; my $y = $input{y}; $x ||= 0; $x += 0; diff --git a/web/index.cgi b/web/index.cgi index f9428efa3..9df86adc2 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -478,8 +478,8 @@ sub display_form { # Map was clicked on $pin_x = Page::click_to_tile($pin_tile_x, $pin_x); $pin_y = Page::click_to_tile($pin_tile_y, $pin_y, 1); - $input{x} ||= int($pin_x) - 1; - $input{y} ||= int($pin_y) - 1; + $input{x} ||= int($pin_x); + $input{y} ||= int($pin_y); $px = Page::tile_to_px($pin_x, $input{x}); $py = Page::tile_to_px($pin_y, $input{y}, 1); $easting = Page::tile_to_os($pin_x); @@ -927,12 +927,12 @@ sub display_problem { my ($x, $y, $x_tile, $y_tile, $px, $py) = Page::os_to_px_with_adjust($q, $problem->{easting}, $problem->{northing}, $input{x}, $input{y}); # Try and have pin near centre of map - if (!$input{x} && $x - $x_tile < 0.5) { - $x_tile -= 1; + if (!$input{x} && $x - $x_tile > 0.5) { + $x_tile += 1; $px = Page::os_to_px($problem->{easting}, $x_tile); } - if (!$input{y} && $y - $y_tile < 0.5) { - $y_tile -= 1; + if (!$input{y} && $y - $y_tile > 0.5) { + $y_tile += 1; $py = Page::os_to_px($problem->{northing}, $y_tile, 1); } @@ -57,8 +57,8 @@ YAHOO.util.Event.onContentReady('mapForm', function() { this.onsubmit = function() { return false; }; } - this.x.value = fixmystreet.x + 2; - this.y.value = fixmystreet.y + 2; + this.x.value = fixmystreet.x + 3; + this.y.value = fixmystreet.y + 3; /* if (swfu && swfu.getStats().files_queued > 0) { swfu.startUpload(); @@ -309,8 +309,8 @@ function load_pins(x, y) { } var ajax_params = [ 'sx=' + document.getElementById('formX').value, 'sy=' + document.getElementById('formY').value, - 'x=' + (x+2), - 'y=' + (y+2), + 'x=' + (x+3), + 'y=' + (y+3), 'all_pins=' + all_pins ]; if (document.getElementById('extra_param')) { diff --git a/web/rss.cgi b/web/rss.cgi index 7060d1709..44bb24be7 100755 --- a/web/rss.cgi +++ b/web/rss.cgi @@ -25,13 +25,13 @@ sub main { my $out; if ($type eq 'local_problems') { $out = rss_local_problems($q); - return unless $out; + return unless $out; } elsif ($type eq 'new_updates') { my $id = $q->param('id'); my $problem = Problems::fetch_problem($id); if (!$problem) { - print $q->header(-status=>'404 Not Found',-type=>'text/html'); - return; + print $q->header(-status=>'404 Not Found',-type=>'text/html'); + return; } my $qs = 'report/' . $id; $out = mySociety::Alert::generate_rss($type, $xsl, $qs, [$id], undef, $cobrand, $q); @@ -72,8 +72,8 @@ sub rss_local_problems { ($e, $n) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G'); $x = int(Page::os_to_tile($e)); $y = int(Page::os_to_tile($n)); - print $q->redirect(-location => "$base/rss/$x/$y"); - return ''; + print $q->redirect(-location => "$base/rss/$x/$y"); + return ''; } elsif ($x && $y) { $e = Page::tile_to_os($x); $n = Page::tile_to_os($y); |