Skip to content

Commit

Permalink
Improve use of OL ArgParser/missing zoom in URL.
Browse files Browse the repository at this point in the history
Remove the server-side zoom-in-url fix, instead use an ArgParser
subclass to default to the provided data if nothing in URL. Then
we can switch to using short lat/lon in geocoder URLs.
  • Loading branch information
dracos committed Feb 1, 2019
1 parent 7725eaf commit 6411963
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 66 deletions.
21 changes: 0 additions & 21 deletions perllib/FixMyStreet/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -420,27 +420,6 @@ sub uri_with {
return $uri;
}

=head2 uri_for
$uri = $c->uri_for( ... );
Like C<uri_for> except that it passes the uri to the cobrand to be altered if
needed.
=cut

sub uri_for {
my $c = shift;
my @args = @_;

my $uri = $c->next::method(@args);

my $cobranded_uri = $c->cobrand->uri($uri);

# note that the returned uri may be a string not an object (eg cities)
return $cobranded_uri;
}

=head2 uri_for_email
$uri = $c->uri_for_email( ... );
Expand Down
2 changes: 0 additions & 2 deletions perllib/FixMyStreet/Cobrand/Bristol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ sub map_type {
'Bristol';
}

sub default_link_zoom { 6 }

sub disambiguate_location {
my $self = shift;
my $string = shift;
Expand Down
25 changes: 1 addition & 24 deletions perllib/FixMyStreet/Cobrand/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -397,25 +397,6 @@ Return cobrand extra data for the problem

sub cobrand_data_for_generic_problem { '' }

=item uri
Given a URL ($_[1]), QUERY, EXTRA_DATA, return a URL with any extra params
needed appended to it.
In the default case, we need to make sure zoom is always present if lat/lon
are, to stop OpenLayers defaulting to null/0.
=cut

sub uri {
my ( $self, $uri ) = @_;
$uri->query_param( zoom => $self->default_link_zoom )
if $uri->query_param('lat') && !$uri->query_param('zoom');

return $uri;
}


=item header_params
Return any params to be added to responses
Expand Down Expand Up @@ -1002,18 +983,14 @@ sub tweak_all_reports_map {}

sub can_support_problems { return 0; }

=item default_map_zoom / default_link_zoom
=item default_map_zoom
default_map_zoom is used when displaying a map overriding the
default of max-4 or max-3 depending on population density.
default_link_zoom is used in links that contain a 'lat' and no
zoom, to stop e.g. OpenLayers defaulting to null/0.
=cut

sub default_map_zoom { undef };
sub default_link_zoom { 3 }

sub users_can_hide { return 0; }

Expand Down
2 changes: 0 additions & 2 deletions perllib/FixMyStreet/Cobrand/Zurich.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ sub example_places {
sub languages { [ 'de-ch,Deutsch,de_CH' ] }
sub language_override { 'de-ch' }

sub default_link_zoom { 6 }

sub prettify_dt {
my $self = shift;
my $dt = shift;
Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/around/_error_multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[% IF match.icon %]
<img src="[% match.icon %]" alt="">
[% END %]
<a href="/around?latitude=[% match.latitude | uri %];longitude=[% match.longitude | uri %][% IF c.req.params.category %];category=[% c.req.params.category | uri %][% END %]">[% match.address | html %]</a>
<a href="/around?lat=[% match.latitude | uri %]&amp;lon=[% match.longitude | uri %][% IF c.req.params.category %]&amp;category=[% c.req.params.category | uri %][% END %]">[% match.address | html %]</a>
</li>
[% END %]
</ul>
Expand Down
26 changes: 17 additions & 9 deletions web/js/map-OpenLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,6 @@ $.extend(fixmystreet.utils, {
fixmystreet.map.addLayer(layer);
}

if (!fixmystreet.map.getCenter()) {
var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude );
centre.transform(
new OpenLayers.Projection("EPSG:4326"),
fixmystreet.map.getProjectionObject()
);
fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3);
}

// map.getCenter() returns a position in "map units", but sometimes you
// want the center in GPS-style latitude/longitude coordinates (WGS84)
// for example, to pass as GET params to fixmystreet.com/report/new.
Expand Down Expand Up @@ -921,6 +912,23 @@ OpenLayers.Control.PanZoomFMS = OpenLayers.Class(OpenLayers.Control.PanZoom, {
}
});

OpenLayers.Control.ArgParserFMS = OpenLayers.Class(OpenLayers.Control.ArgParser, {
getParameters: function(url) {
var args = OpenLayers.Control.ArgParser.prototype.getParameters.apply(this, arguments);
// Get defaults from provided data if not in URL
if (!args.lat && !args.lon) {
args.lon = fixmystreet.longitude;
args.lat = fixmystreet.latitude;
}
if (args.lat && !args.zoom) {
args.zoom = fixmystreet.zoom || 3;
}
return args;
},

CLASS_NAME: "OpenLayers.Control.ArgParserFMS"
});

/* Overriding Permalink so that it can pass the correct zoom to OSM */
OpenLayers.Control.PermalinkFMS = OpenLayers.Class(OpenLayers.Control.Permalink, {
_updateLink: function(alter_zoom) {
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-OpenStreetMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fixmystreet.maps.config = function() {
permalink_id = 'map_permalink';
}
fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Attribution(),
//new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Navigation(),
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-bing-ol.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fixmystreet.maps.config = function() {

fixmystreet.controls = [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PermalinkFMS(permalink_id),
new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-google-ol.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fixmystreet.maps.config = function() {
}

fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PermalinkFMS(permalink_id),
new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-streetview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fixmystreet.maps.config = function() {
fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.PanZoomFMS()
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-toner-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fixmystreet.maps.config = function() {
permalink_id = 'map_permalink';
}
fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PermalinkFMS(permalink_id),
new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-wmts-bristol.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fixmystreet.maps.config = function() {
}

fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PermalinkFMS(permalink_id)
];
Expand Down
2 changes: 1 addition & 1 deletion web/js/map-wmts-zurich.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fixmystreet.maps.config = function() {
// This stuff is copied from js/map-bing-ol.js

fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.ArgParserFMS(),
new OpenLayers.Control.Navigation()
];
if ( fixmystreet.page != 'report' || !$('html').hasClass('mobile') ) {
Expand Down

0 comments on commit 6411963

Please sign in to comment.