aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/Map/Bing.pm34
-rw-r--r--perllib/FixMyStreet/Map/BingOL.pm37
-rw-r--r--perllib/FixMyStreet/Map/Google.pm31
-rw-r--r--perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm63
-rw-r--r--perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm61
-rw-r--r--perllib/FixMyStreet/Map/Tilma/OpenLayers.pm44
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm1
7 files changed, 87 insertions, 184 deletions
diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm
index 0db1a51c3..32420a0ec 100644
--- a/perllib/FixMyStreet/Map/Bing.pm
+++ b/perllib/FixMyStreet/Map/Bing.pm
@@ -21,37 +21,15 @@ sub header_js {
# display_map C PARAMS
# PARAMS include:
# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 0 otherwise.
+# 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) = @_;
- $params{pre} ||= '';
-
- my @pins;
- foreach my $pin (@{$params{pins}}) {
- $pin->[3] ||= '';
- push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
- }
- my $pins_js = join(",\n", @pins);
-
- my $out = '';
- my $copyright = _('Map contains Ordnance Survey data © Crown copyright and database right 2010.');
- my $key = mySociety::Config::get('BING_MAPS_API_KEY');
- $out .= <<EOF;
-<script type="text/javascript">
-var fixmystreet = {
- 'key': '$key',
- 'latitude': $params{latitude},
- 'longitude': $params{longitude},
- 'pins': [ $pins_js ]
-}
-</script>
-<div id="map_box">
- $params{pre}
- <div id="map"></div>
- <p id="copyright">$copyright</p>
-EOF
- return $out;
+ $c->stash->{map} = {
+ %params,
+ type => 'bing',
+ key => mySociety::Config::get('BING_MAPS_API_KEY'),
+ };
}
1;
diff --git a/perllib/FixMyStreet/Map/BingOL.pm b/perllib/FixMyStreet/Map/BingOL.pm
index 2f3ae92d2..70f9dbda1 100644
--- a/perllib/FixMyStreet/Map/BingOL.pm
+++ b/perllib/FixMyStreet/Map/BingOL.pm
@@ -9,7 +9,7 @@
package FixMyStreet::Map::BingOL;
use strict;
-use mySociety::Web qw(ent);
+use mySociety::Gaze;
sub header_js {
return '
@@ -23,35 +23,22 @@ sub header_js {
# display_map C PARAMS
# PARAMS include:
# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 0 otherwise.
+# 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) = @_;
- $params{pre} ||= '';
- my @pins;
- foreach my $pin (@{$params{pins}}) {
- $pin->[3] ||= '';
- push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
- }
- my $pins_js = join(",\n", @pins);
+ my $dist = mySociety::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude}, 200_000 );
+ my $zoom = 2;
+ $zoom = 3 if $dist < 10;
- my $out = '';
- my $copyright = _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010. Microsoft');
- $out .= <<EOF;
-<script type="text/javascript">
-var fixmystreet = {
- 'latitude': $params{latitude},
- 'longitude': $params{longitude},
- 'pins': [ $pins_js ]
-}
-</script>
-<div id="map_box">
- $params{pre}
- <div id="map"></div>
- <p id="copyright">$copyright</p>
-EOF
- return $out;
+ $c->stash->{map} = {
+ %params,
+ type => 'osm',
+ zoom => $zoom,
+ map_type => '""', # Is set by the JavaScript
+ copyright => _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010. Microsoft'),
+ };
}
1;
diff --git a/perllib/FixMyStreet/Map/Google.pm b/perllib/FixMyStreet/Map/Google.pm
index c50019099..20c3ad2b6 100644
--- a/perllib/FixMyStreet/Map/Google.pm
+++ b/perllib/FixMyStreet/Map/Google.pm
@@ -21,35 +21,14 @@ sub header_js {
# display_map C PARAMS
# PARAMS include:
# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 0 otherwise.
+# 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) = @_;
- $params{pre} ||= '';
-
- my @pins;
- foreach my $pin (@{$params{pins}}) {
- $pin->[3] ||= '';
- push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
- }
- my $pins_js = join(",\n", @pins);
-
- my $out = '';
- my $copyright = _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010.');
- $out .= <<EOF;
-<script type="text/javascript">
-var fixmystreet = {
- 'latitude': $params{latitude},
- 'longitude': $params{longitude},
- 'pins': [ $pins_js ]
-}
-</script>
-<div id="map_box">
- $params{pre}
- <div id="map"></div>
- <p id="copyright">$copyright</p>
-EOF
- return $out;
+ $c->stash->{map} = {
+ %params,
+ type => 'google',
+ };
}
1;
diff --git a/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm b/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm
index df334597b..34df8dc8b 100644
--- a/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm
+++ b/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm
@@ -7,65 +7,22 @@
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
package FixMyStreet::Map::Tilma::OL::1_10k;
+use base 'FixMyStreet::Map::Tilma::OpenLayers';
use strict;
-use constant TILE_WIDTH => 254;
-use constant TIF_SIZE_M => 5000;
-use constant TIF_SIZE_PX => 7874;
-use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH);
-use constant TILE_TYPE => '10k-full';
+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'; }
-sub header_js {
- return '
-<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>
-';
+sub copyright {
+ return _('&copy; Crown copyright. All rights reserved. Ministry of Justice 100037819&nbsp;2008.');
}
-# display_map C PARAMS
-# PARAMS include:
-# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 0 otherwise.
-# PINS is array of pins to show, location and colour
-sub display_map {
- my ($self, $c, %params) = @_;
- $params{pre} ||= '';
-
- my @pins;
- foreach my $pin (@{$params{pins}}) {
- $pin->[3] ||= '';
- push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
- }
- my $pins_js = join(",\n", @pins);
-
- my $out = '';
- my $tile_width = TILE_WIDTH;
- my $tile_type = TILE_TYPE;
- my $sf = SCALE_FACTOR / TILE_WIDTH;
- my $copyright = _('&copy; Crown copyright. All rights reserved. Ministry of Justice 100037819&nbsp;2008.');
- $out .= <<EOF;
-<script type="text/javascript">
-var fixmystreet = {
- 'tilewidth': $tile_width,
- 'tileheight': $tile_width,
- 'latitude': $params{latitude},
- 'longitude': $params{longitude},
- 'pins': [ $pins_js ],
- 'tile_type': '$tile_type',
- 'maxResolution': $sf
-};
-</script>
-<div id="map_box">
- $params{pre}
- <div id="map">
- <div id="watermark"></div>
- </div>
- <p id="copyright">$copyright</p>
-EOF
- return $out;
+sub watermark {
+ return 1;
}
1;
diff --git a/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm b/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm
index 610e50ae6..2a531766c 100644
--- a/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm
+++ b/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm
@@ -7,63 +7,22 @@
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
package FixMyStreet::Map::Tilma::OL::StreetView;
+use base 'FixMyStreet::Map::Tilma::OpenLayers';
use strict;
-use constant TILE_WIDTH => 250;
-use constant TIF_SIZE_M => 5000;
-use constant TIF_SIZE_PX => 5000;
-use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH);
-use constant TILE_TYPE => 'streetview';
+sub tile_width { return 250; }
+sub tif_size_m { return 5000; }
+sub tif_size_px { return 5000; }
+sub scale_factor { return tif_size_m() / (tif_size_px() / tile_width()); }
+sub tile_type { return 'streetview'; }
-sub header_js {
- return '
-<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>
-';
+sub copyright {
+ return _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010.');
}
-# display_map C PARAMS
-# PARAMS include:
-# latitude, longitude for the centre point of the map
-# TYPE is 1 if the map is clickable, 0 otherwise.
-# PINS is array of pins to show, location and colour
-sub display_map {
- my ($self, $c, %params) = @_;
- $params{pre} ||= '';
-
- my @pins;
- foreach my $pin (@{$params{pins}}) {
- $pin->[3] ||= '';
- push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
- }
- my $pins_js = join(",\n", @pins);
-
- my $out = '';
- my $tile_width = TILE_WIDTH;
- my $tile_type = TILE_TYPE;
- my $sf = SCALE_FACTOR / TILE_WIDTH;
- my $copyright = _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010.');
- $out .= <<EOF;
-<script type="text/javascript">
-var fixmystreet = {
- 'tilewidth': $tile_width,
- 'tileheight': $tile_width,
- 'latitude': $params{latitude},
- 'longitude': $params{longitude},
- 'pins': [ $pins_js ],
- 'tile_type': '$tile_type',
- 'maxResolution': $sf
-};
-</script>
-<div id="map_box">
- $params{pre}
- <div id="map"></div>
- <p id="copyright">$copyright</p>
-EOF
- return $out;
+sub watermark {
+ return 0;
}
1;
diff --git a/perllib/FixMyStreet/Map/Tilma/OpenLayers.pm b/perllib/FixMyStreet/Map/Tilma/OpenLayers.pm
new file mode 100644
index 000000000..96d0975f2
--- /dev/null
+++ b/perllib/FixMyStreet/Map/Tilma/OpenLayers.pm
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map::Tilma::1_10k_OL
+# Using tilma.mysociety.org with OpenLayers
+#
+# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map::Tilma::OpenLayers;
+
+use strict;
+
+sub TILE_WIDTH() { return $FixMyStreet::Map::map_class->tile_width; }
+sub SCALE_FACTOR() { return $FixMyStreet::Map::map_class->scale_factor; }
+sub TILE_TYPE() { return $FixMyStreet::Map::map_class->tile_type; }
+
+sub header_js {
+ return '
+<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>
+';
+}
+
+# display_map C PARAMS
+# PARAMS include:
+# latitude, longitude for the centre point of the map
+# TYPE is 1 if the map is clickable, 0 otherwise.
+# PINS is array of pins to show, location and colour
+sub display_map {
+ my ($self, $c, %params) = @_;
+ $c->stash->{map} = {
+ %params,
+ type => 'tilma/openlayers',
+ tile_type => TILE_TYPE,
+ tilewidth => TILE_WIDTH,
+ watermark => $self->watermark(),
+ copyright => $self->copyright(),
+ maxResolution => SCALE_FACTOR / TILE_WIDTH,
+ };
+}
+
+1;
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index f834c2d2a..ddabf2ed5 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -83,7 +83,6 @@ sub display_map {
py => $py,
tile_type => TILE_TYPE,
tilewidth => TILE_WIDTH,
- tileheight => TILE_WIDTH,
watermark => $self->watermark(),
copyright => $self->copyright(),
};