diff options
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 3 | ||||
-rw-r--r-- | perllib/Utils/OpenStreetMap.pm | 44 | ||||
-rw-r--r-- | templates/email/default/submit.txt | 2 | ||||
-rw-r--r-- | templates/email/fixmystreet/submit-oxfordshire.txt | 2 | ||||
-rw-r--r-- | templates/email/fixmystreet/submit.txt | 2 |
5 files changed, 53 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index 55b1bb21c..d26e0fa70 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -7,6 +7,7 @@ use CronFns; use DateTime::Format::Pg; use Utils; +use Utils::OpenStreetMap; use mySociety::MaPit; use FixMyStreet; @@ -91,8 +92,10 @@ sub send(;$) { : _('The user could not locate the problem on a map, but to see the area around the location they entered'); $h{closest_address} = ''; + $h{osm_url} = Utils::OpenStreetMap::short_url($h{latitude}, $h{longitude}); if ( $row->used_map ) { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row ); + $h{osm_url} .= '?m'; } if ( $cobrand->allow_anonymous_reports && diff --git a/perllib/Utils/OpenStreetMap.pm b/perllib/Utils/OpenStreetMap.pm new file mode 100644 index 000000000..900569a77 --- /dev/null +++ b/perllib/Utils/OpenStreetMap.pm @@ -0,0 +1,44 @@ +package Utils::OpenStreetMap; + +use strict; +use warnings; +use Exporter 'import'; +use POSIX qw(ceil); + +our @EXPORT_OK = qw(short_url); + +my $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~"; + +sub short_url { + my ($lat, $lon, $zoom) = @_; + $zoom ||= 16; + my $x = ($lon + 180) * 2**32 / 360; + my $y = ($lat + 90) * 2**32 / 180; + my $code = _interleave($x, $y); + + my $str = ''; + # add eight to the zoom level, which approximates an accuracy of + # one pixel in a tile + my $n = ceil(($zoom + 8) / 3) - 1; + for my $i (0..$n) { + my $digit = ($code >> (58 - 6 * $i)) & 0x3f; + $str .= substr($chars, $digit, 1); + } + # append characters onto the end of the string to represent + # partial zoom levels (characters themselves have a granularity + # of 3 zoom levels). + $str .= "-" x (($zoom + 8) % 3); + return "http://osm.org/go/$str"; +} + +sub _interleave { + my ($x, $y) = @_; + my $c = 0; + for (my $i=31; $i>=0; $i--) { + $c = ($c << 1) | (($x >> $i) & 1); + $c = ($c << 1) | (($y >> $i) & 1); + } + return $c; +} + +1; diff --git a/templates/email/default/submit.txt b/templates/email/default/submit.txt index 0ab29e412..52d52669b 100644 --- a/templates/email/default/submit.txt +++ b/templates/email/default/submit.txt @@ -25,6 +25,8 @@ Details: <?=$values['detail']?> Longitude: <?=$values['longitude']?> +View OpenStreetMap of this location: <?=$values['osm_url']?> + <?=$values['closest_address']?>---------- Replies to this email will go to the user who submitted the problem. diff --git a/templates/email/fixmystreet/submit-oxfordshire.txt b/templates/email/fixmystreet/submit-oxfordshire.txt index 23a8504ee..9e5efb608 100644 --- a/templates/email/fixmystreet/submit-oxfordshire.txt +++ b/templates/email/fixmystreet/submit-oxfordshire.txt @@ -25,6 +25,8 @@ Details: <?=$values['detail']?> Longitude: <?=$values['longitude']?> +View OpenStreetMap of this location: <?=$values['osm_url']?> + <?=$values['closest_address']?>---------- Replies to this email will go to the user who submitted the problem. diff --git a/templates/email/fixmystreet/submit.txt b/templates/email/fixmystreet/submit.txt index 315411fb4..7abed7b50 100644 --- a/templates/email/fixmystreet/submit.txt +++ b/templates/email/fixmystreet/submit.txt @@ -25,6 +25,8 @@ Details: <?=$values['detail']?> Longitude: <?=$values['longitude']?> +View OpenStreetMap of this location: <?=$values['osm_url']?> + <?=$values['closest_address']?>---------- Replies to this email will go to the user who submitted the problem. |