diff --git a/web/cobrands/fixmystreet-uk-councils/assets.js b/web/cobrands/fixmystreet-uk-councils/assets.js index c0ca1b777ae..a8474b90f90 100644 --- a/web/cobrands/fixmystreet-uk-councils/assets.js +++ b/web/cobrands/fixmystreet-uk-councils/assets.js @@ -1393,6 +1393,32 @@ fixmystreet.assets.shropshire.streetlight_asset_message = function(asset) { fixmystreet.assets.tfl = {}; +function tfl_check_bus_layer(layer, asset) { + var lonlat = asset.geometry.getBounds().getCenterLonLat(); + + var overlap_threshold = 1; + var overlapping_features = layer.getFeaturesWithinDistance( + new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat), + overlap_threshold + ); + if (overlapping_features.length) { + layer.setAttributeFields(overlapping_features[0], true); + } +} + +fixmystreet.assets.tfl.bus_attribute_set = function(asset) { + var other_layer; + if (this.name == 'TfL Bus Stops') { + other_layer = fixmystreet.map.getLayersByName("TfL Bus Shelters")[0]; + } else if (this.name == 'TfL Bus Shelters') { + other_layer = fixmystreet.map.getLayersByName("TfL Bus Stops")[0]; + } + if (!other_layer) { + return; + } + tfl_check_bus_layer(other_layer, asset); +}; + fixmystreet.assets.tfl.asset_found = function(asset) { fixmystreet.message_controller.asset_found.call(this, asset); fixmystreet.assets.named_select_action_found.call(this, asset); @@ -1579,18 +1605,29 @@ fixmystreet.assets.tfl.red_routes_not_found = function(layer) { $(function(){ var layer = fixmystreet.map.getLayersByName('Red Routes')[0]; - if (!layer) { - return; + if (layer) { + 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(); + } + }); } - 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(); - } + // One of the bus stop/shelter layers could have loaded before the other, + // and a feature auto-selected already, and we need the data from both + // layers, so make sure we poke it after the second layer loads + layers = fixmystreet.map.getLayersByName(/TfL Bus/); + $.each(layers, function(i, layer) { + layer.events.register( 'loadend', layer, function(){ + var feature = fixmystreet.assets.selectedFeature(); + if (feature) { + tfl_check_bus_layer(this, feature); + } + }); }); }); diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 3d81356eaa1..eb05e15b84f 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -137,10 +137,16 @@ OpenLayers.Layer.VectorBase = OpenLayers.Class(OpenLayers.Layer.Vector, { } }, - setAttributeFields: function(feature) { + setAttributeFields: function(feature, no_action) { if (!this.fixmystreet.attributes) { return; } + // If we have a select layer with multiple asset layers, it is possible + // on category change that we get called on one asset layer with a + // selected asset from another layer. We do not want to confuse this. + if (this !== feature.layer) { + return; + } // Set the extra fields to the value of the selected feature var $mobile_display = $('#change_asset_mobile').text(''); $.each(this.fixmystreet.attributes, function(field_name, attribute_name) { @@ -156,6 +162,10 @@ OpenLayers.Layer.VectorBase = OpenLayers.Class(OpenLayers.Layer.Vector, { $inspect_fields.val(value); $mobile_display.append(field_name + ': ' + value + '
'); }); + + if (!no_action && this.fixmystreet.actions && this.fixmystreet.actions.attribute_set) { + this.fixmystreet.actions.attribute_set.call(this, feature); + } }, clearAttributeFields: function() {