aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Map/Tilma/Original.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Map/Tilma/Original.pm')
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm190
1 files changed, 47 insertions, 143 deletions
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index 0af6ed277..6fa854cb2 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -11,7 +11,6 @@ package FixMyStreet::Map::Tilma::Original;
use strict;
use LWP::Simple;
-use Cobrand;
use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::Web qw(ent NewURL);
@@ -27,25 +26,15 @@ sub _ll_to_en {
return Utils::convert_latlon_to_en( $lat, $lon );
}
-sub header_js {
- return '
-<script type="text/javascript" src="/js/map-tilma.js"></script>
-';
-}
-
-# display_map Q PARAMS
+# display_map C PARAMS
# PARAMS include:
# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 2 if clickable and has a form upload,
-# 0 if not clickable
+# CLICKABLE is set if the map is clickable
# PINS is array of pins to show, location and colour
-# PRE/POST are HTML to show above/below map
sub display_map {
- my ($self, $q, %params) = @_;
- $params{pre} ||= '';
- $params{post} ||= '';
+ my ($self, $c, %params) = @_;
my $mid_point = TILE_WIDTH; # Map is 2 TILE_WIDTHs in size, square.
- if (my $mp = Cobrand::tilma_mid_point(Page::get_cobrand($q))) {
+ if (my $mp = $c->cobrand->tilma_mid_point) {
$mid_point = $mp;
}
@@ -53,27 +42,18 @@ sub display_map {
( $params{easting}, $params{northing} ) =
_ll_to_en( $params{latitude}, $params{longitude} );
- # FIXME - convert all pins to lat, lng
- # all the pins are currently [lat, lng, colour] - convert them
- foreach my $pin ( @{ $params{pins} ||= [] } ) {
- my ( $lat, $lon ) = ( $pin->[0], $pin->[1] );
- my ( $e, $n ) = _ll_to_en( $lat, $lon );
- ( $pin->[0], $pin->[1] ) = ( $e, $n );
- }
-
# X/Y tile co-ords may be overridden in the query string
my @vars = qw(x y);
- my %input = map { $_ => $q->param($_) || '' } @vars;
+ my %input = map { $_ => $c->req->params->{$_} || '' } @vars;
($input{x}) = $input{x} =~ /^(\d+)/; $input{x} ||= 0;
($input{y}) = $input{y} =~ /^(\d+)/; $input{y} ||= 0;
- my ($x, $y, $px, $py) = os_to_px_with_adjust($q, $params{easting}, $params{northing}, $input{x}, $input{y});
+ my ($x, $y, $px, $py) = os_to_px_with_adjust($c, $params{easting}, $params{northing}, $input{x}, $input{y});
- my $pins = '';
foreach my $pin (@{$params{pins}}) {
- my $pin_x = os_to_px($pin->[0], $x);
- my $pin_y = os_to_px($pin->[1], $y, 1);
- $pins .= display_pin($q, $pin_x, $pin_y, $pin->[2]);
+ my ( $e, $n ) = _ll_to_en( $pin->{latitude}, $pin->{longitude} );
+ $pin->{px} = os_to_px($e, $x);
+ $pin->{py} = os_to_px($n, $y, 1);
}
$px = defined($px) ? $mid_point - $px : 0;
@@ -83,111 +63,66 @@ sub display_map {
my $url = 'http://tilma.mysociety.org/tileserver/' . TILE_TYPE . '/';
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-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];
- my $bl_src = $url . $tileids->[1][0];
- my $br_src = $url . $tileids->[1][1];
-
- my $cobrand = Page::get_cobrand($q);
- my $root_path_js = Cobrand::root_path_js($cobrand, $q);
- my $out = FixMyStreet::Map::header($q, $params{type});
- my $img_type;
- if ($params{type}) {
- $out .= <<EOF;
-<input type="hidden" name="x" id="formX" value="$x">
-<input type="hidden" name="y" id="formY" value="$y">
-<input type="hidden" name="latitude" value="$params{latitude}">
-<input type="hidden" name="longitude" value="$params{longitude}">
-EOF
- $img_type = '<input type="image"';
- } else {
- $img_type = '<img';
- }
- my $imgw = TILE_WIDTH . 'px';
- my $tile_width = TILE_WIDTH;
- my $tile_type = TILE_TYPE;
- $out .= <<EOF;
-<script type="text/javascript">
-$root_path_js
-var fixmystreet = {
- 'x': $x - 3,
- 'y': $y - 3,
- '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:$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">$pins</div>
- </div>
-EOF
- $out .= '<div id="watermark"></div>' if $self->watermark();
- $out .= compass($q, $x, $y);
- my $copyright = $self->copyright();
- $out .= <<EOF;
- </div>
- <p id="copyright">$copyright</p>
-$params{post}
-</div>
-<div id="side">
-EOF
- return $out;
+ $c->stash->{map} = {
+ %params,
+ type => 'tilma/original',
+ tiles => $tiles,
+ url => $url,
+ tileids => $tileids,
+ x => $x,
+ y => $y,
+ px => $px,
+ py => $py,
+ tile_type => TILE_TYPE,
+ tilewidth => TILE_WIDTH,
+ watermark => $self->watermark(),
+ copyright => $self->copyright(),
+ };
}
sub display_pin {
- my ($q, $px, $py, $col, $num) = @_;
+ my ($c, $px, $py, $col, $id, $title, $num) = @_;
$num = '' if !$num || $num > 9;
- my $host = Page::base_url_with_lang($q, undef);
+ my $host = $c->cobrand->base_url_with_lang;
my %cols = (red=>'R', green=>'G', blue=>'B', purple=>'P');
my $out = '<img class="pin" src="' . $host . '/i/pin' . $cols{$col}
. $num . '.gif" alt="' . _('Problem') . '" style="top:' . ($py-59)
. 'px; left:' . ($px) . 'px; position: absolute;">';
- return $out unless $_ && $_->{id} && $col ne 'blue';
- my $cobrand = Page::get_cobrand($q);
- my $url = Cobrand::url($cobrand, NewURL($q, -url => '/report/' . $_->{id}), $q);
- $out = '<a title="' . ent($_->{title}) . '" href="' . $url . '">' . $out . '</a>';
+ return $out unless $id;
+ my $url = $c->uri_for( '/report/' . $id );
+ $out = '<a title="' . ent($title) . '" href="' . $url . '">' . $out . '</a>';
return $out;
}
sub map_pins {
- my ($self, $q, $x, $y, $sx, $sy, $interval) = @_;
+ my ($self, $c, $x, $y, $sx, $sy, $interval) = @_;
my $e = tile_to_os($x);
my $n = tile_to_os($y);
my ( $lat, $lon ) = Utils::convert_en_to_latlon( $e, $n );
my ( $around_map, $around_map_list, $nearby, $dist ) =
- FixMyStreet::Map::map_features( $q, $lat, $lon, $interval );
+ FixMyStreet::Map::map_features( $c, $lat, $lon, $interval );
my $pins = '';
foreach (@$around_map) {
- ( $_->{easting}, $_->{northing} ) =
- _ll_to_en( $_->{latitude}, $_->{longitude} );
- my $px = os_to_px($_->{easting}, $sx);
- my $py = os_to_px($_->{northing}, $sy, 1);
- my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= display_pin($q, $px, $py, $col);
+ my ( $easting, $northing ) =
+ _ll_to_en( $_->latitude, $_->longitude );
+ my $px = os_to_px($easting, $sx);
+ my $py = os_to_px($northing, $sy, 1);
+ my $col = $_->state eq 'fixed' ? 'green' : 'red';
+ $pins .= display_pin($c, $px, $py, $col, $_->id, $_->title);
}
foreach (@$nearby) {
- ( $_->{easting}, $_->{northing} ) =
- _ll_to_en( $_->{latitude}, $_->{longitude} );
- my $px = os_to_px($_->{easting}, $sx);
- my $py = os_to_px($_->{northing}, $sy, 1);
- my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= display_pin($q, $px, $py, $col);
+ my $p = $_->problem;
+ my ( $easting, $northing ) =
+ _ll_to_en( $p->latitude, $p->longitude );
+ my $px = os_to_px($easting, $sx);
+ my $py = os_to_px($northing, $sy, 1);
+ my $col = $p->state eq 'fixed' ? 'green' : 'red';
+ $pins .= display_pin($c, $px, $py, $col, $p->id, $p->title);
}
return ($pins, $around_map_list, $nearby, $dist);
@@ -262,7 +197,7 @@ sub click_to_os {
# tile they were), convert to WGS84 and return.
sub click_to_wgs84 {
my $self = shift;
- my $q = shift;
+ my $c = shift;
my ( $easting, $northing ) = click_to_os(@_);
my ( $lat, $lon ) = mySociety::GeoUtil::national_grid_to_wgs84( $easting, $northing, 'G' );
return ( $lat, $lon );
@@ -272,7 +207,7 @@ sub click_to_wgs84 {
# of the map (either to get the point near the middle, or the override X,Y),
# and the pixel co-ords of the point, relative to that map.
sub os_to_px_with_adjust {
- my ($q, $easting, $northing, $in_x, $in_y) = @_;
+ my ($c, $easting, $northing, $in_x, $in_y) = @_;
my $x = os_to_tile($easting);
my $y = os_to_tile($northing);
@@ -289,7 +224,7 @@ sub os_to_px_with_adjust {
my $px = os_to_px($easting, $x_tile);
my $py = os_to_px($northing, $y_tile, 1);
- if ($q->{site} eq 'barnet') { # Map is 380px, so might need to adjust
+ if ($c->cobrand->tilma_mid_point == 189) { # Map is 380px, so might need to adjust
if (!$in_x && $px > 380) {
$x_tile++;
$px = os_to_px($easting, $x_tile);
@@ -303,35 +238,4 @@ sub os_to_px_with_adjust {
return ($x_tile, $y_tile, $px, $py);
}
-sub compass ($$$) {
- my ( $q, $x, $y ) = @_;
- my @compass;
- for ( my $i = $x - 1 ; $i <= $x + 1 ; $i++ ) {
- for ( my $j = $y - 1 ; $j <= $y + 1 ; $j++ ) {
- $compass[$i][$j] = NewURL( $q, x => $i, y => $j );
- }
- }
- my $recentre = NewURL($q);
- my $host = Page::base_url_with_lang( $q, undef );
- return <<EOF;
-<table cellpadding="0" cellspacing="0" border="0" id="compass">
-<tr valign="bottom">
-<td align="right"><a rel="nofollow" href="${compass[$x-1][$y+1]}"><img src="$host/i/arrow-northwest.gif" alt="NW" width=11 height=11></a></td>
-<td align="center"><a rel="nofollow" href="${compass[$x][$y+1]}"><img src="$host/i/arrow-north.gif" vspace="3" alt="N" width=13 height=11></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y+1]}"><img src="$host/i/arrow-northeast.gif" alt="NE" width=11 height=11></a></td>
-</tr>
-<tr>
-<td><a rel="nofollow" href="${compass[$x-1][$y]}"><img src="$host/i/arrow-west.gif" hspace="3" alt="W" width=11 height=13></a></td>
-<td align="center"><a rel="nofollow" href="$recentre"><img src="$host/i/rose.gif" alt="Recentre" width=35 height=34></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y]}"><img src="$host/i/arrow-east.gif" hspace="3" alt="E" width=11 height=13></a></td>
-</tr>
-<tr valign="top">
-<td align="right"><a rel="nofollow" href="${compass[$x-1][$y-1]}"><img src="$host/i/arrow-southwest.gif" alt="SW" width=11 height=11></a></td>
-<td align="center"><a rel="nofollow" href="${compass[$x][$y-1]}"><img src="$host/i/arrow-south.gif" vspace="3" alt="S" width=13 height=11></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y-1]}"><img src="$host/i/arrow-southeast.gif" alt="SE" width=11 height=11></a></td>
-</tr>
-</table>
-EOF
-}
-
1;