aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--templates/web/default/maps/bing.html12
-rw-r--r--templates/web/default/maps/google.html11
-rw-r--r--templates/web/default/maps/osm.html9
-rw-r--r--templates/web/default/maps/pins_js.html4
-rw-r--r--templates/web/default/maps/tilma/openlayers.html17
-rw-r--r--web/js/map-OpenLayers.js2
13 files changed, 136 insertions, 190 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(),
};
diff --git a/templates/web/default/maps/bing.html b/templates/web/default/maps/bing.html
new file mode 100644
index 000000000..fccd3311e
--- /dev/null
+++ b/templates/web/default/maps/bing.html
@@ -0,0 +1,12 @@
+<script type="text/javascript">
+var fixmystreet = {
+ 'key': '[% map.key %]',
+ 'latitude': [% map.latitude %],
+ 'longitude': [% map.longitude %],
+ 'pins': [% INCLUDE maps/pins_js.html %]
+}
+</script>
+<div id="map_box">
+ [% pre_map %]
+ <div id="map"></div>
+
diff --git a/templates/web/default/maps/google.html b/templates/web/default/maps/google.html
new file mode 100644
index 000000000..51e6cb587
--- /dev/null
+++ b/templates/web/default/maps/google.html
@@ -0,0 +1,11 @@
+<script type="text/javascript">
+var fixmystreet = {
+ 'latitude': [% map.latitude %],
+ 'longitude': [% map.longitude %],
+ 'pins': [% INCLUDE maps/pins_js.html %]
+}
+</script>
+<div id="map_box">
+ [% pre_map %]
+ <div id="map"></div>
+
diff --git a/templates/web/default/maps/osm.html b/templates/web/default/maps/osm.html
index 5f8336c52..a3e6ea27d 100644
--- a/templates/web/default/maps/osm.html
+++ b/templates/web/default/maps/osm.html
@@ -9,11 +9,10 @@
var fixmystreet = {
'latitude': [% map.latitude %],
'longitude': [% map.longitude %],
- 'pins': [
-[% FOR pin IN map.pins -%]
- [ [% pin.latitude %], [% pin.longitude %], '[% pin.colour %]', '[% pin.id %]', '[% pin.title %]' ]
- [%- IF !loop.last %],[% END %]
-[% END %] ],
+[% IF map.zoom -%]
+ 'zoom': [% map.zoom %],
+[%- END %]
+ 'pins': [% INCLUDE maps/pins_js.html %],
'map_type': [% map.map_type %]
}
</script>
diff --git a/templates/web/default/maps/pins_js.html b/templates/web/default/maps/pins_js.html
new file mode 100644
index 000000000..4a5814b15
--- /dev/null
+++ b/templates/web/default/maps/pins_js.html
@@ -0,0 +1,4 @@
+[ [% FOR pin IN map.pins -%]
+ [ [% pin.latitude %], [% pin.longitude %], '[% pin.colour %]', '[% pin.id %]', '[% pin.title %]' ]
+ [%- IF !loop.last %],[% END %]
+[% END %] ]
diff --git a/templates/web/default/maps/tilma/openlayers.html b/templates/web/default/maps/tilma/openlayers.html
new file mode 100644
index 000000000..5ee7b207e
--- /dev/null
+++ b/templates/web/default/maps/tilma/openlayers.html
@@ -0,0 +1,17 @@
+<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>
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 1134bafb7..ed3ca4653 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -24,7 +24,7 @@ YAHOO.util.Event.onContentReady('map', function() {
new OpenLayers.Projection("EPSG:4326"),
fixmystreet.map.getProjectionObject()
);
- fixmystreet.map.setCenter(centre, 2);
+ fixmystreet.map.setCenter(centre, fixmystreet.zoom || 2);
}
if (document.getElementById('mapForm')) {