diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-07-20 15:27:45 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-07-21 13:41:20 +0100 |
commit | e97a90eb5732530cfe1fa544643a7b5e05530fd2 (patch) | |
tree | e017541ae23b646198346b4fc632d97060dda979 | |
parent | c798298d9320810b602b34e3e8c86d32dca01769 (diff) |
Remove no-longer-used tilma code.
-rw-r--r-- | conf/httpd.conf-example | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tilma.pm | 46 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original.pm | 232 | ||||
-rw-r--r-- | t/app/controller/tilma.t | 12 | ||||
-rw-r--r-- | templates/web/default/maps/tilma/openlayers.html | 29 | ||||
-rw-r--r-- | templates/web/default/maps/tilma/original.html | 89 | ||||
-rw-r--r-- | web/js/map-tilma.js | 312 |
11 files changed, 1 insertions, 743 deletions
diff --git a/conf/httpd.conf-example b/conf/httpd.conf-example index 8abb13831..378aa88a5 100644 --- a/conf/httpd.conf-example +++ b/conf/httpd.conf-example @@ -50,12 +50,9 @@ RewriteRule ^/reports/{/rss/(.*)}$ /rss/$1 [R=permanent,L] # In case of misspelling RewriteRule ^/alerts/?$ /alert [R=permanent,L] -# Proxy tilma so that our js code can make calls on the originating server. Use +# Proxy mapit so that our js code can make calls on the originating server. Use # a RewriteRule rather than ProxyPass so that Apache's processing order is more # predictable. ProxyPassReverse is not affected by this. -RewriteRule /tilma/(.*) http://tilma.mysociety.org/$1 [P,L] -ProxyPassReverse /tilma/ http://tilma.mysociety.org/ - RewriteRule /mapit/(.*) http://mapit.mysociety.org/$1 [P,L] ProxyPassReverse /mapit/ http://mapit.mysociety.org/ diff --git a/perllib/FixMyStreet/App/Controller/Tilma.pm b/perllib/FixMyStreet/App/Controller/Tilma.pm deleted file mode 100644 index 1be481949..000000000 --- a/perllib/FixMyStreet/App/Controller/Tilma.pm +++ /dev/null @@ -1,46 +0,0 @@ -package FixMyStreet::App::Controller::Tilma; -use Moose; -use namespace::autoclean; - -BEGIN { extends 'Catalyst::Controller'; } - -use LWP::UserAgent; - -=head1 NAME - -FixMyStreet::App::Controller::Tilma - Tilma proxy - -=head1 DESCRIPTION - -A tilma proxy - only intended to be used during dev. In production the webserver should do this proxying. - -=head1 METHODS - -=head2 default - -Proxy everything through to the tilma servers. - -=cut - -sub default : Path { - my ( $self, $c ) = @_; - - my $path = $c->req->uri->path_query; - $path =~ s{/tilma/}{}; - - my $tilma_uri = URI->new("http://tilma.mysociety.org/$path"); - - my $tilma_res = LWP::UserAgent->new->get($tilma_uri); - - if ( $tilma_res->is_success ) { - $c->res->content_type( $tilma_res->content_type ); - $c->res->body( $tilma_res->content ); - } - else { - die sprintf "Error getting %s: %s", $tilma_uri, $tilma_res->message; - } -} - -__PACKAGE__->meta->make_immutable; - -1; diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 9496570ea..a12fa6d06 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -76,9 +76,5 @@ sub recent_photos { return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } -sub tilma_mid_point { - return 189; -} - 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 2ac1a81b8..134111076 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -634,16 +634,6 @@ The MaPit types this site handles sub area_types { return qw(DIS LBO MTD UTA CTY COI); } sub area_min_generation { 10 } -=head2 tilma_mid_point - -If the map is smaller than the usual, return half its size. - -=cut - -sub tilma_mid_point { - return 0; -} - =head2 contact_name, contact_email Return the contact name or email for the cobranded version of the site (to be diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index abf6e3082..bd461f5e2 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -76,9 +76,5 @@ sub recent_photos { return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } -sub tilma_mid_point { - return 189; -} - 1; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 20f18a547..825e1cd19 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -13,7 +13,6 @@ use strict; use Module::Pluggable sub_name => 'maps', search_path => __PACKAGE__, - except => 'FixMyStreet::Map::Tilma::Original', require => 1; # Get the list of maps we want and load map classes at compile time diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm deleted file mode 100644 index 08260708c..000000000 --- a/perllib/FixMyStreet/Map/Tilma/Original.pm +++ /dev/null @@ -1,232 +0,0 @@ -#!/usr/bin/perl -# -# FixMyStreet:Map -# Adding the ability to have different maps on FixMyStreet. -# -# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ - -package FixMyStreet::Map::Tilma::Original; - -sub TILE_WIDTH { return 254; } -sub TIF_SIZE_M { return 5000; } -sub TIF_SIZE_PX { return 7874; } -sub SCALE_FACTOR { return TIF_SIZE_M() / (TIF_SIZE_PX() / TILE_WIDTH()); } -sub TILE_TYPE { return '10k-full'; } - -use strict; -use LWP::Simple; - -use mySociety::GeoUtil; -use mySociety::Locale; -use mySociety::Web qw(ent NewURL); -use Utils; -use RABX; - -sub _ll_to_en { - my ($lat, $lon) = @_; - return Utils::convert_latlon_to_en( $lat, $lon ); -} - -# display_map C PARAMS -# PARAMS include: -# latitude, longitude for the centre point of the map -# CLICKABLE is set if the map is clickable -# PINS is array of pins to show, location and colour -sub display_map { - my ($self, $c, %params) = @_; - my $mid_point = TILE_WIDTH; # Map is 2 TILE_WIDTHs in size, square. - if (my $mp = $c->cobrand->tilma_mid_point) { - $mid_point = $mp; - } - - # convert map center point to easting, northing - ( $params{easting}, $params{northing} ) = - _ll_to_en( $params{latitude}, $params{longitude} ); - - # X/Y tile co-ords may be overridden in the query string - my @vars = qw(x y); - 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($c, $params{easting}, $params{northing}, $input{x}, $input{y}); - - foreach my $pin (@{$params{pins}}) { - 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; - $py = defined($py) ? $mid_point - $py : 0; - $x = int($x)<=0 ? 0 : $x; - $y = int($y)<=0 ? 0 : $y; - 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); - my $tileids = RABX::unserialise($tiles); - $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 => 1, - copyright => _('© Crown copyright. All rights reserved. Ministry of Justice 100037819 2008.'), - }; -} - -sub display_pin { - my ($c, $px, $py, $col, $id, $title, $num) = @_; - $num = '' if !$num || $num > 9; - 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; - my $url = $c->uri_for( '/report/' . $id ); - $out = '<a title="' . ent($title) . '" href="' . $url . '">' . $out . '</a>'; - return $out; -} - -sub map_pins { - my ($self, $c, $interval) = @_; - - # Our current X/Y middle of visible map - my $x = ( $c->req->param('x') || 0 ) + 0; - my $y = ( $c->req->param('y') || 0 ) + 0; - - # Where we started as that's the (0,0) we have to work to - my $sx = ( $c->req->param('sx') || 0 ) + 0; - my $sy = ( $c->req->param('sy') || 0 ) + 0; - - 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( $c, $lat, $lon, $interval ); - - my $pins = ''; - foreach (@$around_map) { - 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) { - 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); -} - -# P is easting or northing -# C is centre tile reference of displayed map -sub os_to_px { - 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 -# C is centre tile reference of displayed map -sub tile_to_px { - 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; -} - -# Tile co-ordinates are linear scale of OS E/N -# Will need more generalising when more zooms appear -sub os_to_tile { - return $_[0] / SCALE_FACTOR; -} - -sub tile_to_os { - return int($_[0] * SCALE_FACTOR + 0.5); -} - -sub click_to_tile { - my ($pin_tile, $pin, $invert) = @_; - $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; -} - -# Given some click co-ords (the tile they were on, and where in the -# tile they were), convert to OSGB36 and return. -sub click_to_os { - my ($pin_tile_x, $pin_x, $pin_tile_y, $pin_y) = @_; - my $tile_x = click_to_tile($pin_tile_x, $pin_x); - my $tile_y = click_to_tile($pin_tile_y, $pin_y, 1); - my $easting = tile_to_os($tile_x); - my $northing = tile_to_os($tile_y); - return ($easting, $northing); -} - -# Given some click co-ords (the tile they were on, and where in the -# tile they were), convert to WGS84 and return. -sub click_to_wgs84 { - my $self = 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 ); -} - -# Given (E,N) and potential override (X,Y), return the X/Y tile for the centre -# 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 ($c, $easting, $northing, $in_x, $in_y) = @_; - - my $x = os_to_tile($easting); - my $y = os_to_tile($northing); - my $x_tile = $in_x || int($x); - my $y_tile = $in_y || int($y); - - # Try and have point near centre of map - if (!$in_x && $x - $x_tile > 0.5) { - $x_tile += 1; - } - if (!$in_y && $y - $y_tile > 0.5) { - $y_tile += 1; - } - - my $px = os_to_px($easting, $x_tile); - my $py = os_to_px($northing, $y_tile, 1); - 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); - } - if (!$in_y && $py > 380) { - $y_tile--; - $py = os_to_px($northing, $y_tile, 1); - } - } - - return ($x_tile, $y_tile, $px, $py); -} - -1; diff --git a/t/app/controller/tilma.t b/t/app/controller/tilma.t deleted file mode 100644 index 0eb0b251e..000000000 --- a/t/app/controller/tilma.t +++ /dev/null @@ -1,12 +0,0 @@ -use strict; -use warnings; - -use Test::More; -use FixMyStreet::TestMech; - -my $mech = FixMyStreet::TestMech->new; - -$mech->get_ok('/tilma/tileserver/10k-full/3278-3283,1110-1115/JSON'); -is $mech->res->content_type, 'text/javascript', "got JS response"; - -done_testing();
\ No newline at end of file diff --git a/templates/web/default/maps/tilma/openlayers.html b/templates/web/default/maps/tilma/openlayers.html deleted file mode 100644 index ea3219296..000000000 --- a/templates/web/default/maps/tilma/openlayers.html +++ /dev/null @@ -1,29 +0,0 @@ -[% map_js = BLOCK %] -<script type="text/javascript" src="/jslib/OpenLayers-2.10/OpenLayers.js"></script> -<script type="text/javascript" src="/js/map-OpenLayers.js"></script> -<script type="text/javascript" src="/js/map-tilma-ol.js"></script> -<script type="text/javascript" src="/js/OpenLayers.Projection.OrdnanceSurvey.js"></script> -<!--[if lte IE 6]> - <link rel="stylesheet" href="/jslib/OpenLayers-2.10/theme/default/ie6-style.css" type="text/css" /> -<![endif]--> -[% END %] - -[% map_html = BLOCK %] -<script type="text/javascript"> -var fixmystreet = { - 'tilewidth': [% map.tilewidth %], - 'tileheight': [% map.tilewidth %], - 'latitude': [% map.latitude %], - 'longitude': [% map.longitude %], - 'pins': [% INCLUDE maps/pins_js.html %], - 'tile_type': '[% map.tile_type %]', - 'maxResolution': [% map.maxResolution %] -}; -</script> -<div id="map_box"> - [% pre_map %] - <div id="map"> - [% '<div id="watermark"></div>' IF map.watermark %] - </div> - <p id="copyright">[% map.copyright %]</p> -[% END %] diff --git a/templates/web/default/maps/tilma/original.html b/templates/web/default/maps/tilma/original.html deleted file mode 100644 index 5a07683ac..000000000 --- a/templates/web/default/maps/tilma/original.html +++ /dev/null @@ -1,89 +0,0 @@ -[% map_js = BLOCK %] -<script type="text/javascript" src="/js/map-tilma.js"></script> -[% END %] - -[% map_html = BLOCK %] - -[% IF !map.tiles %] - <div id="map_box"> - <div id="map"><div id="drag"> - [% loc("Unable to fetch the map tiles from the tile server.") %] - </div></div> - [% RETURN %] -[% END %] - -[% IF map.clickable %] -<input type="hidden" name="x" id="formX" value="[% map.x %]"> -<input type="hidden" name="y" id="formY" value="[% map.y %]"> - [% map.img_type = 'input type="image"' %] -[% ELSE %] - [% map.img_type = 'img' %] -[% END %] -<script type="text/javascript"> -[% c.cobrand.root_path_js %] -var fixmystreet = { - 'all_pins': [% all_pins || "''" | html %], - 'x': [% map.x - 3 %], - 'y': [% map.y - 3 %], - 'start_x': [% map.px %], - 'start_y': [% map.py %], - 'tile_type': '[% map.tile_type %]', - 'tilewidth': [% map.tilewidth %], - 'tileheight': [% map.tilewidth %] -}; -</script> -<div id="map_box"> - [% pre_map %] - <div id="map"><div id="drag"> - <[% map.img_type %] - alt="NW map tile" id="t2.2" name="tile_[% map.x - 1 %].[% map.y %]" src="[% map.url %][% map.tileids.0.0 %]" style="top:0px; left:0;"><[% map.img_type %] - alt="NE map tile" id="t2.3" name="tile_[% map.x %].[% map.y %]" src="[% map.url %][% map.tileids.0.1 %]" style="top:0px; left:[% map.tilewidth %]px;"><br><[% map.img_type %] - alt="SW map tile" id="t3.2" name="tile_[% map.x - 1 %].[% map.y - 1 %]" src="[% map.url %][% map.tileids.1.0 %]" style="top:[% map.tilewidth %]px; left:0;"><[% map.img_type %] - alt="SE map tile" id="t3.3" name="tile_[% map.x %].[% map.y - 1 %]" src="[% map.url %][% map.tileids.1.1 %]" style="top:[% map.tilewidth %]px; left:[% map.tilewidth %]px;"> - <div id="pins">[% FOR pin IN map.pins %][% INCLUDE pin %][% END %]</div> - </div> - [% '<div id="watermark"></div>' IF map.watermark %] - [% INCLUDE compass %] - </div> - <p id="copyright">[% map.copyright %]</p> -[% END %] - - -[% BLOCK pin %] - -[% num = '' IF !num or num > 9; - cols = { - red = 'R', green = 'G', blue = 'B', purple = 'P', - } -%] -[% IF pin.id %] -<a title="[% pin.title | html %]" href="[% c.uri_for('/report/' _ pin.id) %]"> -[%- END -%] -<img class="pin" src="[% c.uri_for('/i/pin' _ cols.${pin.colour} _ num _ '.gif') %]" - alt="[% loc('Problem') %]" style="top:[% pin.py - 59 %]px; left:[% pin.px %]px; position: absolute;"> -[%- IF pin.id -%] -</a> -[% END %] - -[% END %] - - -[% BLOCK compass %] - <table cellpadding="0" cellspacing="0" border="0" id="compass"> - <tr valign="bottom"> - <td align="right"><a href="[% c.req.uri_with( { x => map.x - 1, y => map.y + 1 } ) %]"><img src="[% c.uri_for('/i/arrow-northwest.gif') %]" alt="NW" width=11 height=11></a></td> - <td align="center"><a href="[% c.req.uri_with( { x => map.x, y => map.y + 1 } ) %]"><img src="[% c.uri_for('/i/arrow-north.gif') %]" vspace="3" alt="N" width=13 height=11></a></td> - <td><a href="[% c.req.uri_with( { x => map.x + 1, y => map.y + 1 } ) %]"><img src="[% c.uri_for('/i/arrow-northeast.gif') %]" alt="NE" width=11 height=11></a></td> - </tr> - <tr> - <td><a href="[% c.req.uri_with( { x => map.x - 1, y => map.y } ) %]"><img src="[% c.uri_for('/i/arrow-west.gif') %]" hspace="3" alt="W" width=11 height=13></a></td> - <td align="center"><a href="$recentre"><img src="[% c.uri_for('/i/rose.gif') %]" alt="Recentre" width=35 height=34></a></td> - <td><a href="[% c.req.uri_with( { x => map.x + 1, y => map.y } ) %]"><img src="[% c.uri_for('/i/arrow-east.gif') %]" hspace="3" alt="E" width=11 height=13></a></td> - </tr> - <tr valign="top"> - <td align="right"><a href="[% c.req.uri_with( { x => map.x - 1, y => map.y - 1 } ) %]"><img src="[% c.uri_for('/i/arrow-southwest.gif') %]" alt="SW" width=11 height=11></a></td> - <td align="center"><a href="[% c.req.uri_with( { x => map.x, y => map.y - 1 } ) %]"><img src="[% c.uri_for('/i/arrow-south.gif') %]" vspace="3" alt="S" width=13 height=11></a></td> - <td><a href="[% c.req.uri_with( { x => map.x + 1, y => map.y - 1 } ) %]"><img src="[% c.uri_for('/i/arrow-southeast.gif') %]" alt="SE" width=11 height=11></a></td> - </tr> - </table> -[% END %] diff --git a/web/js/map-tilma.js b/web/js/map-tilma.js deleted file mode 100644 index a6e4fa082..000000000 --- a/web/js/map-tilma.js +++ /dev/null @@ -1,312 +0,0 @@ -/* - * map-tilma.js - * JavaScript specifically for the tilma based maps - */ - -function compass_pan(e, a) { - YAHOO.util.Event.preventDefault(e); - if (a.home) { - a.x = a.orig_x-drag_x; - a.y = a.orig_y-drag_y; - } - pan(a.x, a.y); -} - -YAHOO.util.Event.onContentReady('compass', function() { - var ua=navigator.userAgent.toLowerCase(); - // if (document.getElementById('mapForm') && (/safari/.test(ua) || /Konqueror/.test(ua))) return; - if (document.getElementById('map').offsetWidth > 510) return; - - var points = this.getElementsByTagName('a'); - YAHOO.util.Event.addListener(points[1], 'click', compass_pan, { x:0, y:fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[3], 'click', compass_pan, { x:fixmystreet.tilewidth, y:0 }); - YAHOO.util.Event.addListener(points[5], 'click', compass_pan, { x:-fixmystreet.tilewidth, y:0 }); - YAHOO.util.Event.addListener(points[7], 'click', compass_pan, { x:0, y:-fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[0], 'click', compass_pan, { x:fixmystreet.tilewidth, y:fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[2], 'click', compass_pan, { x:-fixmystreet.tilewidth, y:fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[6], 'click', compass_pan, { x:fixmystreet.tilewidth, y:-fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[8], 'click', compass_pan, { x:-fixmystreet.tilewidth, y:-fixmystreet.tileheight }); - YAHOO.util.Event.addListener(points[4], 'click', compass_pan, { home:1, orig_x:drag_x, orig_y:drag_y }); -}); - -YAHOO.util.Event.onContentReady('map', function() { - var ua=navigator.userAgent.toLowerCase(); - // if (document.getElementById('mapForm') && (/safari/.test(ua) || /Konqueror/.test(ua))) return; - if (document.getElementById('map').offsetWidth > 510) return; - new YAHOO.util.DDMap('map'); - update_tiles(fixmystreet.start_x, fixmystreet.start_y, true); -}); - - -YAHOO.util.Event.addListener('hide_pins_link', 'click', function(e) { - YAHOO.util.Event.preventDefault(e); - if (this.innerHTML == 'Show pins') { - YAHOO.util.Dom.setStyle('pins', 'display', 'block'); - this.innerHTML = 'Hide pins'; - } else if (this.innerHTML == 'Dangos pinnau') { - YAHOO.util.Dom.setStyle('pins', 'display', 'block'); - this.innerHTML = 'Cuddio pinnau'; - } else if (this.innerHTML == 'Cuddio pinnau') { - YAHOO.util.Dom.setStyle('pins', 'display', 'none'); - this.innerHTML = 'Dangos pinnau'; - } else if (this.innerHTML == 'Hide pins') { - YAHOO.util.Dom.setStyle('pins', 'display', 'none'); - this.innerHTML = 'Show pins'; - } -}); -YAHOO.util.Event.addListener('all_pins_link', 'click', function(e) { - YAHOO.util.Event.preventDefault(e); - YAHOO.util.Dom.setStyle('pins', 'display', 'block'); - var welsh = 0; - if (this.innerHTML == 'Include stale reports') { - this.innerHTML = 'Hide stale reports'; - fixmystreet.all_pins = 1; - load_pins(fixmystreet.x, fixmystreet.y); - } else if (this.innerHTML == 'Cynnwys hen adroddiadau') { - this.innerHTML = 'Cuddio hen adroddiadau'; - fixmystreet.all_pins = 1; - welsh = 1; - load_pins(fixmystreet.x, fixmystreet.y); - } else if (this.innerHTML == 'Cuddio hen adroddiadau') { - this.innerHTML = 'Cynnwys hen adroddiadau'; - welsh = 1; - fixmystreet.all_pins = ''; - load_pins(fixmystreet.x, fixmystreet.y); - } else if (this.innerHTML == 'Hide stale reports') { - this.innerHTML = 'Include stale reports'; - fixmystreet.all_pins = ''; - load_pins(fixmystreet.x, fixmystreet.y); - } - if (welsh) { - document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; - } else { - document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; - } -}); - -// I love the global -var tile_x = 0; -var tile_y = 0; - -var myAnim; -function pan(x, y) { - if (!myAnim || !myAnim.isAnimated()) { - myAnim = new YAHOO.util.Motion('drag', { points:{by:[x,y]} }, 10, YAHOO.util.Easing.easeOut); - myAnim.useSeconds = false; - //myAnim.onTween.subscribe(function(){ update_tiles(x/10, y/10, false); }); - myAnim.onComplete.subscribe(function(){ - update_tiles(x, y, false); - cleanCache(); - }); - myAnim.animate(); - } -} - -var drag_x = 0; -var drag_y = 0; -function update_tiles(dx, dy, force) { - dx = getInt(dx); dy = getInt(dy); - if (!dx && !dy && !force) return; - var old_drag_x = drag_x; - var old_drag_y = drag_y; - drag_x += dx; - drag_y += dy; - - var drag = document.getElementById('drag'); - drag.style.left = drag_x + 'px'; - drag.style.top = drag_y + 'px'; - - var horizontal = Math.floor(old_drag_x/fixmystreet.tilewidth) - Math.floor(drag_x/fixmystreet.tilewidth); - var vertical = Math.floor(old_drag_y/fixmystreet.tileheight) - Math.floor(drag_y/fixmystreet.tileheight); - if (!horizontal && !vertical && !force) return; - fixmystreet.x += horizontal; - - tile_x += horizontal; - fixmystreet.y -= vertical; - tile_y += vertical; - var url = [ root_path + '/tilma/tileserver/' + fixmystreet.tile_type + '/', fixmystreet.x, '-', (fixmystreet.x+5), ',', fixmystreet.y, '-', (fixmystreet.y+5), '/JSON' ].join(''); - YAHOO.util.Connect.asyncRequest('GET', url, { - success: urls_loaded, failure: urls_not_loaded, - argument: [tile_x, tile_y] - }); - - if (force) return; - load_pins(fixmystreet.x, fixmystreet.y); -} - -function load_pins(x, y) { - if (document.getElementById('formX') && !document.getElementById('problem_submit')) { - var ajax_params = [ 'sx=' + document.getElementById('formX').value, - 'sy=' + document.getElementById('formY').value, - 'x=' + (x+3), - 'y=' + (y+3), - 'all_pins=' + fixmystreet.all_pins ]; - - var url = [ root_path , '/ajax?', ajax_params.join(';')].join(''); - YAHOO.util.Connect.asyncRequest('GET', url, { - success: pins_loaded - }); - } -} - -function pins_loaded(o) { - var data = eval(o.responseText); - document.getElementById('pins').innerHTML = data.pins; - if (typeof(data.current) != 'undefined') - document.getElementById('current').innerHTML = data.current; - if (typeof(data.current_near) != 'undefined') - document.getElementById('current_near').innerHTML = data.current_near; - if (typeof(data.fixed_near) != 'undefined') - document.getElementById('fixed_near').innerHTML = data.fixed_near; -} - -function urls_not_loaded(o) { /* Nothing yet */ } - -// Load 6x6 grid of tiles around current 2x2 -function urls_loaded(o) { - var tiles = eval(o.responseText); - var drag = document.getElementById('drag'); - for (var i=0; i<6; i++) { - var ii = (i + o.argument[1]); - for (var j=0; j<6; j++) { - if (tiles[i][j] == null) continue; - var jj = (j + o.argument[0]); - var id = [ 't', ii, '.', jj ].join(''); - var xx = fixmystreet.x+j; - var yy = fixmystreet.y+5-i; - var img = document.getElementById(id); - if (img) { - if (!img.galleryimg) { img.galleryimg = false; } - img.onclick = drag_check; - tileCache[id] = { x: xx, y: yy, t: img }; - continue; - } - img = cloneNode(); - img.style.top = ((ii-2)*fixmystreet.tileheight) + 'px'; - img.style.left = ((jj-2)*fixmystreet.tilewidth) + 'px'; - img.name = [ 'tile_', xx, '.', yy ].join('') - img.id = id; - if (browser) { - img.style.visibility = 'hidden'; - img.onload=function() { this.style.visibility = 'visible'; } - } - img.src = 'http://tilma.mysociety.org/tileserver/' + fixmystreet.tile_type + '/' + tiles[i][j]; - tileCache[id] = { x: xx, y: yy, t: img }; - drag.appendChild(img); - } - } -} - -var imgElCache; -function cloneNode() { - var img = null; - if (!imgElCache) { - var form = document.getElementById('mapForm'); - if (form) { - img = imgElCache = document.createElement('input'); - img.type = 'image'; - } else { - img = imgElCache = document.createElement('img'); - } - img.onclick = drag_check; - img.style.position = 'absolute'; - img.style.width = fixmystreet.tilewidth + 'px'; - img.style.height = fixmystreet.tileheight + 'px'; - img.galleryimg = false; - img.alt = 'Loading...'; - } else { - img = imgElCache.cloneNode(true); - } - return img; -} - -var tileCache=[]; -function cleanCache() { - for (var i in tileCache) { - if (tileCache[i].x < fixmystreet.x || tileCache[i].x > fixmystreet.x+5 || tileCache[i].y < fixmystreet.y || tileCache[i].y > fixmystreet.y+5) { - var t = tileCache[i].t; - t.parentNode.removeChild(t); // de-leak? - delete tileCache[i]; - } - } -} - -/* Called every mousemove, so on first call, overwrite itself with quicker version */ -function get_posn(ev) { - var posx, posy; - if (ev.pageX || ev.pageY) { - get_posn = function(e) { - return { x: e.pageX, y: e.pageY }; - }; - } else if (ev.clientX || ev.clientY) { - get_posn = function(e) { - return { - x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, - y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop - }; - }; - } else { - get_posn = function(e) { - return { x: undef, y: undef }; - }; - } - return get_posn(ev); -} - -function setCursor(s) { - var drag = document.getElementById('drag'); - var inputs = drag.getElementsByTagName('input'); - for (var i=0; i<inputs.length; i++) { - inputs[i].style.cursor = s; - } -} - -var in_drag = false; -function drag_check(e) { - if (in_drag) { - in_drag = false; - return false; - } - return true; -} - -/* Simpler version of DDProxy */ -var mouse_pos = {}; -YAHOO.util.DDMap = function(id, sGroup, config) { - this.init(id, sGroup, config); -}; -YAHOO.extend(YAHOO.util.DDMap, YAHOO.util.DD, { - scroll: false, - b4MouseDown: function(e) { }, - startDrag: function(x, y) { - mouse_pos = { x: x, y: y }; - setCursor('move'); - in_drag = true; - }, - b4Drag: function(e) { }, - onDrag: function(e) { - var point = get_posn(e); - if (point == mouse_pos) return false; - var dx = point.x-mouse_pos.x; - var dy = point.y-mouse_pos.y; - mouse_pos = point; - update_tiles(dx, dy, false); - }, - endDrag: function(e) { - setCursor('crosshair'); - cleanCache(); - }, - toString: function() { - return ("DDMap " + this.id); - } -}); - -var browser = 1; -var ua=navigator.userAgent.toLowerCase(); -if (!/opera|safari|gecko/.test(ua) && typeof document.all!='undefined') - browser=0; - -function getInt(n) { - n = parseInt(n); return (isNaN(n) ? 0 : n); -} - |