Skip to content

Commit

Permalink
[TfL] Look up data in other bus stop/shelter layer
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 8, 2024
1 parent 6f707ee commit 3a73c45
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
59 changes: 48 additions & 11 deletions web/cobrands/fixmystreet-uk-councils/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check warning on line 1397 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1397

Added line #L1397 was not covered by tests

var overlap_threshold = 1;
var overlapping_features = layer.getFeaturesWithinDistance(

Check warning on line 1400 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1399-L1400

Added lines #L1399 - L1400 were not covered by tests
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat),
overlap_threshold
);
if (overlapping_features.length) {
layer.setAttributeFields(overlapping_features[0], true);

Check warning on line 1405 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1404-L1405

Added lines #L1404 - L1405 were not covered by tests
}
}

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];

Check warning on line 1414 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1411-L1414

Added lines #L1411 - L1414 were not covered by tests
}
if (!other_layer) {
return;

Check warning on line 1417 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1416-L1417

Added lines #L1416 - L1417 were not covered by tests
}
tfl_check_bus_layer(other_layer, asset);

Check warning on line 1419 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1419

Added line #L1419 was not covered by tests
};

fixmystreet.assets.tfl.asset_found = function(asset) {
fixmystreet.message_controller.asset_found.call(this, asset);
fixmystreet.assets.named_select_action_found.call(this, asset);
Expand Down Expand Up @@ -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);

Check warning on line 1628 in web/cobrands/fixmystreet-uk-councils/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet-uk-councils/assets.js#L1625-L1628

Added lines #L1625 - L1628 were not covered by tests
}
});
});
});

Expand Down
12 changes: 11 additions & 1 deletion web/cobrands/fixmystreet/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 148 in web/cobrands/fixmystreet/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet/assets.js#L148

Added line #L148 was not covered by tests
}
// 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) {
Expand All @@ -156,6 +162,10 @@ OpenLayers.Layer.VectorBase = OpenLayers.Class(OpenLayers.Layer.Vector, {
$inspect_fields.val(value);
$mobile_display.append(field_name + ': ' + value + '<br>');
});

if (!no_action && this.fixmystreet.actions && this.fixmystreet.actions.attribute_set) {
this.fixmystreet.actions.attribute_set.call(this, feature);

Check warning on line 167 in web/cobrands/fixmystreet/assets.js

View check run for this annotation

Codecov / codecov/patch

web/cobrands/fixmystreet/assets.js#L167

Added line #L167 was not covered by tests
}
},

clearAttributeFields: function() {
Expand Down

0 comments on commit 3a73c45

Please sign in to comment.