From ccdf3e164d3493363fc5349f0404928d75c1dc38 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 17 Jan 2025 09:22:40 +0000 Subject: [PATCH] [Street Manager] Only update layer when pin placed. --- .cypress/cypress/integration/peterborough.js | 18 ++++++++++-- .../fixmystreet-uk-councils/roadworks.js | 29 ++++++++++++++----- web/js/map-OpenLayers.js | 2 +- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/.cypress/cypress/integration/peterborough.js b/.cypress/cypress/integration/peterborough.js index eb064cbb0c5..b7a2c9002d8 100644 --- a/.cypress/cypress/integration/peterborough.js +++ b/.cypress/cypress/integration/peterborough.js @@ -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(); diff --git a/web/cobrands/fixmystreet-uk-councils/roadworks.js b/web/cobrands/fixmystreet-uk-councils/roadworks.js index 7426c736293..5be443c8e60 100644 --- a/web/cobrands/fixmystreet-uk-councils/roadworks.js +++ b/web/cobrands/fixmystreet-uk-councils/roadworks.js @@ -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'; @@ -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", @@ -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(); } }); diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 4c49646d927..5f3bdc74798 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -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();