From 6f707eec2110f4a2f9333908ae88025bfbc6e11d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 6 Mar 2024 12:12:26 +0000 Subject: [PATCH] [TfL] Move asset layers to configuration. --- data/test-asset-layers.yml | 88 +++++ perllib/FixMyStreet/Template/JS.pm | 21 +- templates/web/bexley/footer_extra_js.html | 2 +- templates/web/brent/footer_extra_js.html | 2 +- templates/web/bromley/footer_extra_js.html | 2 +- templates/web/camden/footer_extra_js.html | 2 +- .../footer_extra_js_base.html | 5 - .../web/fixmystreet.com/footer_extra_js.html | 1 - templates/web/greenwich/footer_extra_js.html | 2 +- templates/web/hackney/footer_extra_js.html | 2 +- templates/web/hounslow/footer_extra_js.html | 2 +- templates/web/merton/footer_extra_js.html | 2 +- templates/web/southwark/footer_extra_js.html | 2 +- templates/web/tfl/footer_extra_js.html | 2 +- .../web/westminster/footer_extra_js.html | 2 +- .../fixmystreet-uk-councils/assets.js | 222 +++++++++++ web/cobrands/tfl/assets.js | 352 ------------------ 17 files changed, 339 insertions(+), 372 deletions(-) delete mode 100644 web/cobrands/tfl/assets.js diff --git a/data/test-asset-layers.yml b/data/test-asset-layers.yml index a98758c3ed2..5cb6a3debed 100755 --- a/data/test-asset-layers.yml +++ b/data/test-asset-layers.yml @@ -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 diff --git a/perllib/FixMyStreet/Template/JS.pm b/perllib/FixMyStreet/Template/JS.pm index 72fea531ee2..d829c58c234 100644 --- a/perllib/FixMyStreet/Template/JS.pm +++ b/perllib/FixMyStreet/Template/JS.pm @@ -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); @@ -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 ]; @@ -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), diff --git a/templates/web/bexley/footer_extra_js.html b/templates/web/bexley/footer_extra_js.html index 16f445c4244..1384e2f9485 100644 --- a/templates/web/bexley/footer_extra_js.html +++ b/templates/web/bexley/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 roadworks=1 %] +[% PROCESS 'footer_extra_js_base.html' highways=1 roadworks=1 %] diff --git a/templates/web/brent/footer_extra_js.html b/templates/web/brent/footer_extra_js.html index 6b7f6e59279..eaf4b84fc2c 100644 --- a/templates/web/brent/footer_extra_js.html +++ b/templates/web/brent/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' tfl=1 roadworks=1 ~%] +[% PROCESS 'footer_extra_js_base.html' roadworks=1 ~%] diff --git a/templates/web/bromley/footer_extra_js.html b/templates/web/bromley/footer_extra_js.html index 2176f40859f..58ad180153e 100644 --- a/templates/web/bromley/footer_extra_js.html +++ b/templates/web/bromley/footer_extra_js.html @@ -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 %] diff --git a/templates/web/camden/footer_extra_js.html b/templates/web/camden/footer_extra_js.html index 16f445c4244..1384e2f9485 100644 --- a/templates/web/camden/footer_extra_js.html +++ b/templates/web/camden/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 roadworks=1 %] +[% PROCESS 'footer_extra_js_base.html' highways=1 roadworks=1 %] diff --git a/templates/web/fixmystreet-uk-councils/footer_extra_js_base.html b/templates/web/fixmystreet-uk-councils/footer_extra_js_base.html index 87146001b4e..87dfc31acca 100644 --- a/templates/web/fixmystreet-uk-councils/footer_extra_js_base.html +++ b/templates/web/fixmystreet-uk-councils/footer_extra_js_base.html @@ -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') diff --git a/templates/web/fixmystreet.com/footer_extra_js.html b/templates/web/fixmystreet.com/footer_extra_js.html index 4ee27232e06..456586ed311 100644 --- a/templates/web/fixmystreet.com/footer_extra_js.html +++ b/templates/web/fixmystreet.com/footer_extra_js.html @@ -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') ); diff --git a/templates/web/greenwich/footer_extra_js.html b/templates/web/greenwich/footer_extra_js.html index 8cbe4c48ff8..f8a3e52e479 100644 --- a/templates/web/greenwich/footer_extra_js.html +++ b/templates/web/greenwich/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 %] +[% PROCESS 'footer_extra_js_base.html' highways=1 %] diff --git a/templates/web/hackney/footer_extra_js.html b/templates/web/hackney/footer_extra_js.html index ceffa33e4bd..88fc006e768 100644 --- a/templates/web/hackney/footer_extra_js.html +++ b/templates/web/hackney/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 validation=1 %] +[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 %] diff --git a/templates/web/hounslow/footer_extra_js.html b/templates/web/hounslow/footer_extra_js.html index b21ec273d0e..9fb39b99038 100644 --- a/templates/web/hounslow/footer_extra_js.html +++ b/templates/web/hounslow/footer_extra_js.html @@ -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( diff --git a/templates/web/merton/footer_extra_js.html b/templates/web/merton/footer_extra_js.html index 3f24e389639..878ea928c9b 100644 --- a/templates/web/merton/footer_extra_js.html +++ b/templates/web/merton/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' validation=1 tfl=1 roadworks=1 %] +[% PROCESS 'footer_extra_js_base.html' validation=1 roadworks=1 %] diff --git a/templates/web/southwark/footer_extra_js.html b/templates/web/southwark/footer_extra_js.html index ceffa33e4bd..88fc006e768 100644 --- a/templates/web/southwark/footer_extra_js.html +++ b/templates/web/southwark/footer_extra_js.html @@ -1 +1 @@ -[% PROCESS 'footer_extra_js_base.html' highways=1 tfl=1 validation=1 %] +[% PROCESS 'footer_extra_js_base.html' highways=1 validation=1 %] diff --git a/templates/web/tfl/footer_extra_js.html b/templates/web/tfl/footer_extra_js.html index b0123bf549b..951c0be9a55 100644 --- a/templates/web/tfl/footer_extra_js.html +++ b/templates/web/tfl/footer_extra_js.html @@ -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( diff --git a/templates/web/westminster/footer_extra_js.html b/templates/web/westminster/footer_extra_js.html index abdb7a7a4d6..3c1419b68c9 100644 --- a/templates/web/westminster/footer_extra_js.html +++ b/templates/web/westminster/footer_extra_js.html @@ -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( diff --git a/web/cobrands/fixmystreet-uk-councils/assets.js b/web/cobrands/fixmystreet-uk-councils/assets.js index 606b5c47d69..c0ca1b777ae 100644 --- a/web/cobrands/fixmystreet-uk-councils/assets.js +++ b/web/cobrands/fixmystreet-uk-councils/assets.js @@ -1389,6 +1389,228 @@ fixmystreet.assets.shropshire.streetlight_asset_message = function(asset) { return out; }; +/* TfL */ + +fixmystreet.assets.tfl = {}; + +fixmystreet.assets.tfl.asset_found = function(asset) { + fixmystreet.message_controller.asset_found.call(this, asset); + fixmystreet.assets.named_select_action_found.call(this, asset); +}; +fixmystreet.assets.tfl.asset_not_found = function() { + fixmystreet.message_controller.asset_not_found.call(this); + fixmystreet.assets.named_select_action_not_found.call(this); +}; + +// Roadworks asset layer + +fixmystreet.assets.tfl.roadworks_stylemap = new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fillOpacity: 1, + fillColor: "#FFFF00", + strokeColor: "#000000", + strokeOpacity: 0.8, + strokeWidth: 2, + pointRadius: 6, + graphicWidth: 39, + graphicHeight: 25, + graphicOpacity: 1, + externalGraphic: '/cobrands/tfl/warning@2x.png' + }), + 'hover': new OpenLayers.Style({ + fillColor: "#55BB00", + externalGraphic: '/cobrands/tfl/warning-green@2x.png' + }), + 'select': new OpenLayers.Style({ + fillColor: "#55BB00", + externalGraphic: '/cobrands/tfl/warning-green@2x.png' + }) +}); + +function tfl_to_ddmmyyyy(date) { + date = date.toISOString(); + date = date.slice(8, 10) + '/' + date.slice(5, 7) + '/' + date.slice(0, 4); + return date; +} + +fixmystreet.assets.tfl.roadworks_attribute_start = function() { + return tfl_to_ddmmyyyy(new Date(this.attributes.start_date)); +}; +fixmystreet.assets.tfl.roadworks_attribute_end = function() { + return tfl_to_ddmmyyyy(new Date(this.attributes.end_date)); +}; + +fixmystreet.assets.tfl.roadworks_filter_value = function(feature) { + var red_routes = fixmystreet.map.getLayersByName("Red Routes"); + if (!red_routes.length) { + return false; + } + red_routes = red_routes[0]; + + var point = feature.geometry; + var relevant = !!red_routes.getFeatureAtPoint(point); + if (!relevant) { + var nearest = red_routes.getFeaturesWithinDistance(point, 10); + relevant = nearest.length > 0; + } + return relevant; +}; + +fixmystreet.assets.tfl.roadworks_asset_found = function(feature) { + this.fixmystreet.actions.asset_not_found.call(this); + feature.layer = this; + var attr = feature.attributes, + start = tfl_to_ddmmyyyy(new Date(attr.start_date)), + end = tfl_to_ddmmyyyy(new Date(attr.end_date)), + summary = attr.summary, + desc = attr.description; + + var $msg = $('
'); + var $dl = $("
").appendTo($msg); + if (attr.promoter) { + $dl.append("
Responsibility
"); + $dl.append($("
").text(attr.promoter)); + } + $dl.append("
Summary
"); + $dl.append($("
").text(summary)); + if (desc) { + $dl.append("
Description
"); + $dl.append($("
").text(desc)); + } + $dl.append("
Dates
"); + var $dates = $("
").appendTo($dl); + $dates.text(start + " until " + end); + $msg.prependTo('#js-post-category-messages'); +}; + +fixmystreet.assets.tfl.roadworks_asset_not_found = function() { + $(".js-roadworks-message-" + this.id).remove(); +}; + +/* Red routes (TLRN) asset layer & handling for disabling form when red route + is not selected for specific categories. + This comes after the point assets so that any asset is deselected by the + time the check for the red-route only categories is run. + */ + +fixmystreet.assets.tfl.tlrn_stylemap = new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fillColor: "#ff0000", + fillOpacity: 0.3, + strokeColor: "#ff0000", + strokeOpacity: 1, + strokeWidth: 2 + }) +}); + +/* + Reports in these categories can only be made on a red route. + NOTE: This must be kept in sync with the list in the TfL cobrand module. +*/ +var tlrn_categories = [ + "All out - three or more street lights in a row", + "Blocked drain", + "Damage - general (Trees)", + "Dead animal in the carriageway or footway", + "Debris in the carriageway", + "Drain Cover - Missing or Damaged", + "Fallen Tree", + "Flooding", + "Graffiti / Flyposting (non-offensive)", + "Graffiti / Flyposting (offensive)", + "Graffiti / Flyposting on street light (non-offensive)", + "Graffiti / Flyposting on street light (offensive)", + "Graffiti / Flyposting – Political or Anti-Vaccination", + "Grass Cutting and Hedges", + "Hoarding complaint", + "Light on during daylight hours", + "Lights out in Pedestrian Subway", + "Low hanging branches", + "Manhole Cover - Damaged (rocking or noisy)", + "Manhole Cover - Missing", + "Mobile Crane Operation", + "Other (TfL)", + "Overgrown vegetation", + "Pavement Defect (uneven surface / cracked paving slab)", + "Pavement Overcrowding", + "Pothole (major)", + "Pothole (minor)", + "Roadworks", + "Scaffold complaint", + "Single Light out (street light)", + "Standing water", + "Street Light - Equipment damaged, pole leaning", + "Streetspace Feedback", + "Unstable hoardings", + "Unstable scaffolding", + "Worn out road markings" +]; + +function is_tlrn_category_only(category, bodies) { + return OpenLayers.Util.indexOf(tlrn_categories, category) > -1 && + OpenLayers.Util.indexOf(bodies, 'TfL') > -1 && + bodies.length <= 1; +} + +var a13dbfo_categories = tlrn_categories.concat([ + "Flytipping (TfL)", + "Graffiti / Flyposting on traffic light (non-offensive)", + "Graffiti / Flyposting on traffic light (offensive)" +]); + +function is_a13dbfo_category(category, bodies) { + return OpenLayers.Util.indexOf(a13dbfo_categories, category) > -1 && + OpenLayers.Util.indexOf(bodies, 'TfL') > -1 && + bodies.length <= 1; +} + +fixmystreet.assets.tfl.red_routes_not_found = function(layer) { + // Only care about this on TfL cobrand + if (fixmystreet.cobrand !== 'tfl') { + return; + } + var category = fixmystreet.reporting.selectedCategory().category; + if (is_tlrn_category_only(category, fixmystreet.bodies)) { + fixmystreet.message_controller.road_not_found(layer); + } else { + fixmystreet.message_controller.road_found(layer); + } +}; + +$(function(){ + var layer = fixmystreet.map.getLayersByName('Red Routes')[0]; + if (!layer) { + return; + } + layer.events.register( 'loadend', layer, function(){ + // The roadworks layer may have finished loading before this layer, so + // ensure the filters to only show markers that intersect with a red route + // are re-applied. + var roadworks = fixmystreet.map.getLayersByName("Roadworks"); + if (roadworks.length) { + // .redraw() reapplies filters without issuing any new requests + roadworks[0].redraw(); + } + }); +}); + +fixmystreet.assets.tfl.a13_found = function(layer) { + // Only care about this on TfL cobrand + if (fixmystreet.cobrand !== 'tfl') { + return; + } + // "Other (TfL)" has a stopper message set in the admin" + $('#js-category-stopper').remove(); + var category = fixmystreet.reporting.selectedCategory().category; + if (is_a13dbfo_category(category, fixmystreet.bodies)) { + fixmystreet.message_controller.road_not_found(layer); + var body = new RegExp('&body=.*'); + ($('#a13dbfolink').attr('href', $('#a13dbfolink').attr('href').replace(body, '&body=' + encodeURIComponent(window.location.href)))); + } else { + fixmystreet.message_controller.road_found(layer); + } +}; + /* Thamesmead */ fixmystreet.assets.thamesmead = {}; diff --git a/web/cobrands/tfl/assets.js b/web/cobrands/tfl/assets.js deleted file mode 100644 index 7372dc777d9..00000000000 --- a/web/cobrands/tfl/assets.js +++ /dev/null @@ -1,352 +0,0 @@ -(function(){ - -if (!fixmystreet.maps) { - return; -} - -fixmystreet.assets.tfl = {}; - -fixmystreet.assets.tfl.asset_found = function(asset) { - fixmystreet.message_controller.asset_found.call(this, asset); - fixmystreet.assets.named_select_action_found.call(this, asset); -}; - -fixmystreet.assets.tfl.asset_not_found = function() { - fixmystreet.message_controller.asset_not_found.call(this); - fixmystreet.assets.named_select_action_not_found.call(this); -}; - -// Roadworks asset layer - -fixmystreet.assets.tfl.roadworks_stylemap = new OpenLayers.StyleMap({ - 'default': new OpenLayers.Style({ - fillOpacity: 1, - fillColor: "#FFFF00", - strokeColor: "#000000", - strokeOpacity: 0.8, - strokeWidth: 2, - pointRadius: 6, - graphicWidth: 39, - graphicHeight: 25, - graphicOpacity: 1, - externalGraphic: '/cobrands/tfl/warning@2x.png' - }), - 'hover': new OpenLayers.Style({ - fillColor: "#55BB00", - externalGraphic: '/cobrands/tfl/warning-green@2x.png' - }), - 'select': new OpenLayers.Style({ - fillColor: "#55BB00", - externalGraphic: '/cobrands/tfl/warning-green@2x.png' - }) -}); - -function tfl_to_ddmmyyyy(date) { - date = date.toISOString(); - date = date.slice(8, 10) + '/' + date.slice(5, 7) + '/' + date.slice(0, 4); - return date; -} - -fixmystreet.assets.tfl.roadworks_attribute_start = function() { - return tfl_to_ddmmyyyy(new Date(this.attributes.start_date)); -}; -fixmystreet.assets.tfl.roadworks_attribute_end = function() { - return tfl_to_ddmmyyyy(new Date(this.attributes.end_date)); -}; - -fixmystreet.assets.tfl.roadworks_filter_value = function(feature) { - var red_routes = fixmystreet.map.getLayersByName("Red Routes"); - if (!red_routes.length) { - return false; - } - red_routes = red_routes[0]; - - var point = feature.geometry; - var relevant = !!red_routes.getFeatureAtPoint(point); - if (!relevant) { - var nearest = red_routes.getFeaturesWithinDistance(point, 10); - relevant = nearest.length > 0; - } - return relevant; -}; - -fixmystreet.assets.tfl.roadworks_asset_found = function(feature) { - this.fixmystreet.actions.asset_not_found.call(this); - feature.layer = this; - var attr = feature.attributes, - start = tfl_to_ddmmyyyy(new Date(attr.start_date)), - end = tfl_to_ddmmyyyy(new Date(attr.end_date)), - summary = attr.summary, - desc = attr.description; - - var $msg = $('
'); - var $dl = $("
").appendTo($msg); - if (attr.promoter) { - $dl.append("
Responsibility
"); - $dl.append($("
").text(attr.promoter)); - } - $dl.append("
Summary
"); - $dl.append($("
").text(summary)); - if (desc) { - $dl.append("
Description
"); - $dl.append($("
").text(desc)); - } - $dl.append("
Dates
"); - var $dates = $("
").appendTo($dl); - $dates.text(start + " until " + end); - $msg.prependTo('#js-post-category-messages'); -}; - -fixmystreet.assets.tfl.roadworks_asset_not_found = function() { - $(".js-roadworks-message-" + this.id).remove(); -}; - -/* Red routes (TLRN) asset layer & handling for disabling form when red route - is not selected for specific categories. - This comes after the point assets so that any asset is deselected by the - time the check for the red-route only categories is run. - */ - -fixmystreet.assets.tfl.tlrn_stylemap = new OpenLayers.StyleMap({ - 'default': new OpenLayers.Style({ - fillColor: "#ff0000", - fillOpacity: 0.3, - strokeColor: "#ff0000", - strokeOpacity: 1, - strokeWidth: 2 - }) -}); - -/* - Reports in these categories can only be made on a red route. - NOTE: This must be kept in sync with the list in the TfL cobrand module. -*/ -var tlrn_categories = [ - "All out - three or more street lights in a row", - "Blocked drain", - "Damage - general (Trees)", - "Dead animal in the carriageway or footway", - "Debris in the carriageway", - "Drain Cover - Missing or Damaged", - "Fallen Tree", - "Flooding", - "Graffiti / Flyposting (non-offensive)", - "Graffiti / Flyposting (offensive)", - "Graffiti / Flyposting on street light (non-offensive)", - "Graffiti / Flyposting on street light (offensive)", - "Graffiti / Flyposting – Political or Anti-Vaccination", - "Grass Cutting and Hedges", - "Hoarding complaint", - "Light on during daylight hours", - "Lights out in Pedestrian Subway", - "Low hanging branches", - "Manhole Cover - Damaged (rocking or noisy)", - "Manhole Cover - Missing", - "Mobile Crane Operation", - "Other (TfL)", - "Overgrown vegetation", - "Pavement Defect (uneven surface / cracked paving slab)", - "Pavement Overcrowding", - "Pothole (major)", - "Pothole (minor)", - "Roadworks", - "Scaffold complaint", - "Single Light out (street light)", - "Standing water", - "Street Light - Equipment damaged, pole leaning", - "Streetspace Feedback", - "Unstable hoardings", - "Unstable scaffolding", - "Worn out road markings" -]; - -function is_tlrn_category_only(category, bodies) { - return OpenLayers.Util.indexOf(tlrn_categories, category) > -1 && - OpenLayers.Util.indexOf(bodies, 'TfL') > -1 && - bodies.length <= 1; -} - -var a13dbfo_categories = tlrn_categories.concat([ - "Flytipping (TfL)", - "Graffiti / Flyposting on traffic light (non-offensive)", - "Graffiti / Flyposting on traffic light (offensive)" -]); - -function is_a13dbfo_category(category, bodies) { - return OpenLayers.Util.indexOf(a13dbfo_categories, category) > -1 && - OpenLayers.Util.indexOf(bodies, 'TfL') > -1 && - bodies.length <= 1; -} - -fixmystreet.assets.tfl.red_routes_not_found = function(layer) { - // Only care about this on TfL cobrand - if (fixmystreet.cobrand !== 'tfl') { - return; - } - var category = fixmystreet.reporting.selectedCategory().category; - if (is_tlrn_category_only(category, fixmystreet.bodies)) { - fixmystreet.message_controller.road_not_found(layer); - } else { - fixmystreet.message_controller.road_found(layer); - } -}; - -fixmystreet.assets.tfl.a13_found = function(layer) { - // Only care about this on TfL cobrand - if (fixmystreet.cobrand !== 'tfl') { - return; - } - // "Other (TfL)" has a stopper message set in the admin" - $('#js-category-stopper').remove(); - var category = fixmystreet.reporting.selectedCategory().category; - if (is_a13dbfo_category(category, fixmystreet.bodies)) { - fixmystreet.message_controller.road_not_found(layer); - var body = new RegExp('&body=.*'); - ($('#a13dbfolink').attr('href', $('#a13dbfolink').attr('href').replace(body, '&body=' + encodeURIComponent(window.location.href)))); - } else { - fixmystreet.message_controller.road_found(layer); - } -}; - -var wfs_host = fixmystreet.staging ? 'tilma.staging.mysociety.org' : 'tilma.mysociety.org'; -var tilma_url = "https://" + wfs_host + "/mapserver/tfl"; -var streetmanager_url = "https://" + wfs_host + "/streetmanager.php"; - -var defaults = { - http_wfs_url: tilma_url, - asset_type: 'spot', - max_resolution: 2.388657133579254, - geometryName: 'msGeometry', - srsName: "EPSG:3857" -}; -if (fixmystreet.cobrand === '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. - defaults.body = 'TfL'; -} - -/* Point asset layers, bus stops and traffic lights. */ - -var asset_defaults = $.extend(true, {}, defaults, { - class: OpenLayers.Layer.VectorAssetMove, - body: 'TfL', - actions: { - asset_found: fixmystreet.assets.tfl.asset_found, - asset_not_found: fixmystreet.assets.tfl.asset_not_found - } -}); - -fixmystreet.assets.add(asset_defaults, { - wfs_feature: "trafficsignals", - asset_id_field: 'Site', - attributes: { - site: 'Site', - }, - asset_group: "Traffic Lights", - asset_item: 'traffic signal' -}); - -fixmystreet.assets.add(asset_defaults, { - 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' -}); - -fixmystreet.assets.add(asset_defaults, { - wfs_feature: "busstations", - asset_id_field: 'Name', - feature_code: 'Name', - attributes: { station_name: 'Name' }, - asset_group: "Bus Stations", - asset_item: 'bus station' -}); - -/* Roadworks asset layer */ - -fixmystreet.assets.add(asset_defaults, { - http_wfs_url: '', - http_options: { - url: streetmanager_url, - params: { - points: 1, - end_today: 1 - } - }, - srsName: "EPSG:27700", - format_class: OpenLayers.Format.GeoJSON, - name: "Roadworks", - non_interactive: false, - always_visible: false, - road: false, - 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 - } - -}); - -var red_routes_layer = fixmystreet.assets.add(defaults, { - 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 - } -}); -if (red_routes_layer) { - red_routes_layer.events.register( 'loadend', red_routes_layer, function(){ - // The roadworks layer may have finished loading before this layer, so - // ensure the filters to only show markers that intersect with a red route - // are re-applied. - var roadworks = fixmystreet.map.getLayersByName("Roadworks"); - if (roadworks.length) { - // .redraw() reapplies filters without issuing any new requests - roadworks[0].redraw(); - } - }); -} - -fixmystreet.assets.add(defaults, { - 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 - } -}); - -})();