Skip to content

Commit

Permalink
[TfL] Move asset layers to configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 8, 2024
1 parent fbcc00f commit 6f707ee
Show file tree
Hide file tree
Showing 17 changed files with 339 additions and 372 deletions.
88 changes: 88 additions & 0 deletions data/test-asset-layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,94 @@ shropshire:
actions:
found: 'fixmystreet.assets.shropshire.street_found'
not_found: 'fixmystreet.assets.shropshire.street_not_found'
tfl:
- - http_wfs_url: "https://tilma.staging.mysociety.org/mapserver/tfl"
asset_type: 'spot'
max_resolution: 2.388657133579254
geometryName: 'msGeometry'
srsName: "EPSG:3857"
- name: 'assets'
template: 'default'
class: OpenLayers.Layer.VectorAssetMove
body: 'TfL'
actions:
asset_found: fixmystreet.assets.tfl.asset_found
asset_not_found: fixmystreet.assets.tfl.asset_not_found
- template: 'assets'
wfs_feature: "trafficsignals"
asset_id_field: 'Site'
attributes:
site: 'Site'
asset_group: "Traffic Lights"
asset_item: 'traffic signal'
- template: 'assets'
wfs_feature: "busstops"
asset_id_field: 'STOP_CODE'
attributes:
stop_code: 'STOP_CODE'
shelter_id: 'SHELTER_ID'
asset_group: "Bus Stops and Shelters"
asset_item: 'bus stop'
- template: 'assets'
wfs_feature: "busstations"
asset_id_field: 'Name'
feature_code: 'Name'
attributes:
station_name: 'Name'
asset_group: "Bus Stations"
asset_item: 'bus station'
- template: 'assets'
http_wfs_url: ''
http_options:
url: "https://tilma.staging.mysociety.org/streetmanager.php"
params:
points: 1
end_today: 1
srsName: "EPSG:27700"
format_class: OpenLayers.Format.GeoJSON
name: "Roadworks"
asset_category: "Roadworks"
stylemap: fixmystreet.assets.tfl.roadworks_stylemap
asset_id_field: 'work_ref'
asset_item: 'roadworks'
attributes:
promoter_works_ref: 'work_ref'
start: fixmystreet.assets.tfl.roadworks_attribute_start
end: fixmystreet.assets.tfl.roadworks_attribute_end
promoter: 'promoter'
works_desc: 'description'
works_state: 'status'
tooltip: 'summary'
filter_key: true
filter_value: fixmystreet.assets.tfl.roadworks_filter_value
actions:
asset_found: fixmystreet.assets.tfl.roadworks_asset_found
asset_not_found: fixmystreet.assets.tfl.roadworks_asset_not_found
- template: 'default'
wfs_feature: "RedRoutes"
name: "Red Routes"
max_resolution: 9.554628534317017
road: true
non_interactive: true
always_visible: true
nearest_radius: 0.1
stylemap: fixmystreet.assets.tfl.tlrn_stylemap
no_asset_msg_id: '#js-not-tfl-road'
actions:
found: fixmystreet.message_controller.road_found
not_found: fixmystreet.assets.tfl.red_routes_not_found
- template: 'default'
wfs_feature: "A13TLRN_DBFO"
max_resolution: 9.554628534317017
road: true
non_interactive: true
always_visible: true
nearest_radius: 0.1
stylemap: fixmystreet.assets.tfl.tlrn_stylemap
no_asset_msg_id: '#js-tlrn-dbfo-road'
actions:
found: fixmystreet.assets.tfl.a13_found
not_found: fixmystreet.message_controller.road_found
westminster:
- - asset_type: 'spot'
max_resolution: 4.777314267158508
Expand Down
21 changes: 18 additions & 3 deletions perllib/FixMyStreet/Template/JS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ sub pick_asset_layers {
%cobrands = %$cobrands;
} elsif ($cobrand eq 'greenwich' || $cobrand eq 'bexley') {
# Special case for Thamesmead crossing the border
%cobrands = map { $_ => $cobrands->{$_} } ($cobrand, 'thamesmead');
%cobrands = map { $_ => $cobrands->{$_} } ($cobrand, 'tfl', 'thamesmead');
} elsif ($cobrand eq 'brent' || $cobrand eq 'bromley' || $cobrand eq 'camden' || $cobrand eq 'hackney' || $cobrand eq 'hounslow' || $cobrand eq 'merton' || $cobrand eq 'southwark' || $cobrand eq 'westminster') {
# All London cobrands also need the TfL assets
%cobrands = map { $_ => $cobrands->{$_} } ($cobrand, 'tfl');
} else {
# Only the cobrand's assets itself
%cobrands = map { $_ => $cobrands->{$_} } ($cobrand);
Expand All @@ -33,13 +36,17 @@ sub pick_asset_layers {
my $layers = [];
for my $moniker (sort keys %cobrands) {
my @layers = @{ $cobrands{$moniker} || [] };
push @$layers, _add_layer($moniker, @layers) if @layers;
push @$layers, _add_layer($cobrand, $moniker, @layers) if @layers;
}
return $layers;
}

# cobrand is the one the layer is being generated for,
# moniker is the cobrand whose assets are being generated
# (so normally the same, but not for .com or thamesmead
# layers are the layers to be generated
sub _add_layer {
my ($moniker, @layers) = @_;
my ($cobrand, $moniker, @layers) = @_;
my $default = shift @layers;
unless (ref $default eq 'ARRAY') {
$default = [ $default ];
Expand All @@ -54,6 +61,14 @@ sub _add_layer {
$default_lookup->{$d{name}} = { %{$default_lookup->{$template}}, %d };
}
}

if ($cobrand eq 'tfl') {
# On .com we change the categories depending on where is clicked; on
# the cobrand we use the standard 'Please click on a road' message
# which needs the body to be set so is_only_body passes.
$default_lookup->{default} = { %{$default_lookup->{default}}, body => 'TfL' };
}

return {
moniker => $moniker,
default => _encode_json_with_js_classes($default_lookup),
Expand Down
2 changes: 1 addition & 1 deletion templates/web/bexley/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 roadworks=1 %]
2 changes: 1 addition & 1 deletion templates/web/brent/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' tfl=1 roadworks=1 ~%]
[% PROCESS 'footer_extra_js_base.html' roadworks=1 ~%]
2 changes: 1 addition & 1 deletion templates/web/bromley/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[% scripts.push(
version('/vendor/jquery-3.6.0.min.js'),
) %]
[% PROCESS 'footer_extra_js_base.html' validation=1 tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' validation=1 roadworks=1 %]
2 changes: 1 addition & 1 deletion templates/web/camden/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 roadworks=1 %]
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
version('/cobrands/fixmystreet-uk-councils/roadworks.js'),
);
END;
IF tfl;
scripts.push(
version('/cobrands/tfl/assets.js'),
);
END;
scripts.push(
version('/cobrands/fixmystreet-uk-councils/assets.js'),
version('/js/asset_layers.js')
Expand Down
1 change: 0 additions & 1 deletion templates/web/fixmystreet.com/footer_extra_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
scripts.push( version('/cobrands/fixmystreet/assets.js') );
scripts.push( version('/cobrands/buckinghamshire/grass_cutting.js') );
scripts.push( version('/cobrands/oxfordshire/assets.js') );
scripts.push( version('/cobrands/tfl/assets.js') );
scripts.push( version('/cobrands/highways/assets.js') );
scripts.push( version('/cobrands/fixmystreet-uk-councils/assets.js') );
scripts.push( version('/js/asset_layers.js') );
Expand Down
2 changes: 1 addition & 1 deletion templates/web/greenwich/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 %]
2 changes: 1 addition & 1 deletion templates/web/hackney/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 validation=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 %]
2 changes: 1 addition & 1 deletion templates/web/hounslow/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 roadworks=1 %]
[%
IF bodyclass.match('mappage');
scripts.push(
Expand Down
2 changes: 1 addition & 1 deletion templates/web/merton/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' validation=1 tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' validation=1 roadworks=1 %]
2 changes: 1 addition & 1 deletion templates/web/southwark/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 validation=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 %]
2 changes: 1 addition & 1 deletion templates/web/tfl/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[% scripts.push(
version('/vendor/jquery-3.6.0.min.js'),
) %]
[% PROCESS 'footer_extra_js_base.html' highways=1 cobrand_js=1 %]
[% PROCESS 'footer_extra_js_base.html' highways=1 %]
[%~
IF bodyclass.match('mappage');
scripts.push(
Expand Down
2 changes: 1 addition & 1 deletion templates/web/westminster/footer_extra_js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[% PROCESS 'footer_extra_js_base.html' tfl=1 roadworks=1 %]
[% PROCESS 'footer_extra_js_base.html' roadworks=1 %]
[%
IF bodyclass.match('mappage');
scripts.push(
Expand Down
Loading

0 comments on commit 6f707ee

Please sign in to comment.