diff options
Diffstat (limited to 'perllib/Page.pm')
-rw-r--r-- | perllib/Page.pm | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index cafd9ba91..70b320548 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -47,6 +47,11 @@ BEGIN { mySociety::Config::set_file("$dir/../conf/general"); } +use constant TILE_WIDTH => mySociety::Config::get('TILES_WIDTH'); +use constant TIF_SIZE_M => mySociety::Config::get('TILES_TIFF_SIZE_METRES'); +use constant TIF_SIZE_PX => mySociety::Config::get('TILES_TIFF_SIZE_PIXELS'); +use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH); + my $lastmodified; sub do_fastcgi { @@ -409,7 +414,7 @@ sub display_map { $params{pins} ||= ''; $params{pre} ||= ''; $params{post} ||= ''; - my $mid_point = 254; + my $mid_point = TILE_WIDTH; # Map is 2 TILE_WIDTHs in size, square. if ($q->{site} eq 'barnet') { # Map is c. 380px wide $mid_point = 189; } @@ -455,31 +460,42 @@ EOF } else { $img_type = '<img'; } - my $imgw = '254px'; - my $imgh = '254px'; + my $imgw = TILE_WIDTH . 'px'; + my $tile_width = TILE_WIDTH; + my $tile_type = mySociety::Config::get('TILES_TYPE'); $out .= <<EOF; <script type="text/javascript"> -var fms_x = $x - 2; var fms_y = $y - 2; -var start_x = $px; var start_y = $py; $root_path_js +var fixmystreet = { + 'x': $x - 2, + 'y': $y - 2, + 'start_x': $px, + 'start_y': $py, + 'tile_type': '$tile_type', + 'tilewidth': $tile_width, + 'tileheight': $tile_width +}; </script> <div id="map_box"> $params{pre} <div id="map"><div id="drag"> - $img_type alt="NW map tile" id="t2.2" name="tile_$tl" src="$tl_src" style="top:0px; left:0;">$img_type alt="NE map tile" id="t2.3" name="tile_$tr" src="$tr_src" style="top:0px; left:$imgw;"><br>$img_type alt="SW map tile" id="t3.2" name="tile_$bl" src="$bl_src" style="top:$imgh; left:0;">$img_type alt="SE map tile" id="t3.3" name="tile_$br" src="$br_src" style="top:$imgh; left:$imgw;"> + $img_type alt="NW map tile" id="t2.2" name="tile_$tl" src="$tl_src" style="top:0px; left:0;">$img_type alt="NE map tile" id="t2.3" name="tile_$tr" src="$tr_src" style="top:0px; left:$imgw;"><br>$img_type alt="SW map tile" id="t3.2" name="tile_$bl" src="$bl_src" style="top:$imgw; left:0;">$img_type alt="SE map tile" id="t3.3" name="tile_$br" src="$br_src" style="top:$imgw; left:$imgw;"> <div id="pins">$params{pins}</div> </div> EOF - if (Cobrand::show_watermark($cobrand)) { + if (Cobrand::show_watermark($cobrand) && mySociety::Config::get('TILES_TYPE') ne 'streetview') { $out .= '<div id="watermark"></div>'; } $out .= compass($q, $x, $y); - my $copyright = _('Crown copyright. All rights reserved. Ministry of Justice'); - my $license_info = Cobrand::license_info($cobrand); - $license_info = "100037819 2008" unless $license_info; + my $copyright; + if (mySociety::Config::get('TILES_TYPE') eq 'streetview') { + $copyright = _('Map contains Ordnance Survey data © Crown copyright and database right 2010.'); + } else { + $copyright = _('© Crown copyright. All rights reserved. Ministry of Justice 100037819 2008.'); + } $out .= <<EOF; </div> - <p id="copyright">© $copyright $license_info</p> + <p id="copyright">$copyright</p> $params{post} EOF $out .= '</div>'; @@ -613,8 +629,8 @@ sub os_to_px { # BL is bottom left tile reference of displayed map sub tile_to_px { my ($p, $bl, $invert) = @_; - $p = 254 * ($p - $bl); - $p = 508 - $p if $invert; + $p = TILE_WIDTH * ($p - $bl); + $p = 2 * TILE_WIDTH - $p if $invert; $p = int($p + .5 * ($p <=> 0)); return $p; } @@ -622,18 +638,18 @@ sub tile_to_px { # Tile co-ordinates are linear scale of OS E/N # Will need more generalising when more zooms appear sub os_to_tile { - return $_[0] / (5000/31); + return $_[0] / SCALE_FACTOR; } sub tile_to_os { - return $_[0] * (5000/31); + return $_[0] * SCALE_FACTOR; } sub click_to_tile { my ($pin_tile, $pin, $invert) = @_; - $pin -= 254 while $pin > 254; - $pin += 254 while $pin < 0; - $pin = 254 - $pin if $invert; # image submits measured from top down - return $pin_tile + $pin / 254; + $pin -= TILE_WIDTH while $pin > TILE_WIDTH; + $pin += TILE_WIDTH while $pin < 0; + $pin = TILE_WIDTH - $pin if $invert; # image submits measured from top down + return $pin_tile + $pin / TILE_WIDTH; } sub os_to_px_with_adjust { @@ -799,7 +815,7 @@ sub display_problem_meta_line($$) { if ($problem->{whensent}) { $problem->{council} =~ s/\|.*//g; my @councils = split /,/, $problem->{council}; - my $areas_info = mySociety::MaPit::get_voting_areas_info(\@councils); + my $areas_info = mySociety::MaPit::call('areas', \@councils); my $council = join(' and ', map { $areas_info->{$_}->{name} } @councils); $out .= '<small class="council_sent_info">'; $out .= $q->br() . sprintf(_('Sent to %s %s later'), $council, prettify_duration($problem->{whensent}, 'minute')); @@ -898,6 +914,19 @@ sub display_problem_updates($$) { return $out; } +sub mapit_check_error { + my $location = shift; + if ($location->{error}) { + return _('That postcode was not recognised, sorry.') if $location->{code} =~ /^4/; + return $location->{error}; + } + my $island = $location->{coordsyst}; + if ($island eq 'I') { + return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region."); + } + return 0; +} + # geocode STRING QUERY # Given a user-inputted string, try and convert it into co-ordinates using either # MaPit if it's a postcode, or Google Maps API otherwise. Returns an array of @@ -908,10 +937,8 @@ sub geocode { my ($s, $q) = @_; my ($x, $y, $easting, $northing, $error); if (mySociety::PostcodeUtil::is_valid_postcode($s)) { - try { - my $location = mySociety::MaPit::get_location($s); - my $island = $location->{coordsyst}; - throw RABX::Error(_("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.")) if $island eq 'I'; + my $location = mySociety::MaPit::call('postcode', $s); + unless ($error = mapit_check_error($location)) { $easting = $location->{easting}; $northing = $location->{northing}; my $xx = Page::os_to_tile($easting); @@ -920,14 +947,6 @@ sub geocode { $y = int($yy); $x -= 1 if ($xx - $x < 0.5); $y -= 1 if ($yy - $y < 0.5); - } catch RABX::Error with { - my $e = shift; - if ($e->value() && ($e->value() == mySociety::MaPit::BAD_POSTCODE - || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND)) { - $error = _('That postcode was not recognised, sorry.'); - } else { - $error = $e; - } } } else { ($x, $y, $easting, $northing, $error) = geocode_string($s, $q); |