Skip to content

Commit

Permalink
[Street Manager] Only update layer when pin placed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 17, 2025
1 parent 816de34 commit ccdf3e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
18 changes: 16 additions & 2 deletions .cypress/cypress/integration/peterborough.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,24 @@ describe('new report form', function() {
cy.pickCategory('Trees');
cy.get('.category_meta_message').should('contain', 'You can pick a tree from the map');
});
});

it('displays nearby roadworks', function() {
cy.fixture('peterborough_roadworks.json');
describe('Roadworks', function() {
beforeEach(function() {
cy.server();
cy.route('/report/new/ajax*').as('report-ajax');
cy.route("**/peterborough.assets/4/*", 'fixture:peterborough_pcc.json').as('pcc');
cy.route("**/peterborough.assets/3/*", 'fixture:peterborough_non_pcc.json').as('non_pcc');
cy.route('/streetmanager.php**', 'fixture:peterborough_roadworks.json').as('roadworks');
cy.visit('http://peterborough.localhost:3001/');
cy.contains('Peterborough');
cy.get('[name=pc]').type('PE1 1HF');
cy.get('[name=pc]').parents('form').submit();
cy.get('#map_box').click();
cy.wait('@report-ajax');
});

it('displays nearby roadworks', function() {
cy.wait('@roadworks');
cy.pickCategory('Pothole');
cy.nextPageReporting();
Expand Down
29 changes: 22 additions & 7 deletions web/cobrands/fixmystreet-uk-councils/roadworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
* OpenLayers.Format.GeoJSON.
*/

OpenLayers.Strategy.FixMyStreetRoadworks = OpenLayers.Class(OpenLayers.Strategy.BBOX, {
// Only when we manually ask it to be updated
activate: function() {
var activated = OpenLayers.Strategy.prototype.activate.call(this);
if(activated) {
this.layer.events.on({
"refresh": this.update,
scope: this
});
}
return activated;
},

CLASS_NAME: "OpenLayers.Strategy.FixMyStreetRoadworks"
});

(function(){

var tilma_host = fixmystreet.staging ? 'tilma.staging.mysociety.org' : 'tilma.mysociety.org';
Expand All @@ -13,10 +29,10 @@ var roadworks_defaults = {
},
srsName: "EPSG:27700",
format_class: OpenLayers.Format.GeoJSON,
strategy_class: OpenLayers.Strategy.FixMyStreetRoadworks,
stylemap: fixmystreet.assets.stylemap_invisible,
non_interactive: true,
asset_category: [],
always_visible: false,
always_visible: true,
nearest_radius: 100,
road: true,
name: "Street Manager",
Expand Down Expand Up @@ -96,15 +112,14 @@ fixmystreet.roadworks.filter = function(feature) {

var roadworks_layer = fixmystreet.assets.add(roadworks_defaults);

// Don't want to activate it until they start to make a report
fixmystreet.roadworks.activate = function(){
roadworks_layer.fixmystreet.always_visible = true;
roadworks_layer.setVisibility(true);
// Don't want to update it until they place a pin
fixmystreet.roadworks.update = function(){
roadworks_layer.refresh({ force: true });
};

$(function(){
if (fixmystreet.page === 'new') {
fixmystreet.roadworks.activate();
fixmystreet.roadworks.update();
}
});

Expand Down
2 changes: 1 addition & 1 deletion web/js/map-OpenLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ $.extend(fixmystreet.utils, {
// Only now do we want to activate the Street Manager layer, if it's
// present, as we haven't needed it until now.
if (fixmystreet.roadworks) {
fixmystreet.roadworks.activate();
fixmystreet.roadworks.update();
}

fixmystreet.maps.hide_keyboard_instructions();
Expand Down

0 comments on commit ccdf3e1

Please sign in to comment.