From 4e8e8d3b4912ec6552ae5290dbf47cf1d5968107 Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Fri, 27 Jul 2018 15:20:02 +0100 Subject: "Report a problem here" button in nav when viewing a location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2016. When you load a page that includes either a problem report, or is centered on a location, the "Report a problem" button in the nav bar (that normally takes you to the homepage) becomes a "Report a(nother) problem here" button, that leads directly to the new report form for the location in question. On full map pages (/around and any /report/ pages loaded via it) the reporting form will be rendered client-side, avoiding a full page reload. On pages lacking the full map (eg: missing fixmystreet.bbox_strategy), namely /reports/ and any /report/ page that hasn’t been client-side loaded via /around, we fall back to a server-side page load. Finally, as you’d expect, the text and URL for the button dynamically update as you move around the map, or switch between the different client-side states of the reporting flow. We also hide the button entirely when you’re reporting a problem, which was something suggested a long time ago. --- web/js/map-OpenLayers.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index b2b74648c..6f42d13d1 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -791,6 +791,16 @@ $.extend(fixmystreet.utils, { fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); } + // map.getCenter() returns a position in "map units", but sometimes you + // want the center in GPS-style latitude/longitude coordinates (WGS84) + // for example, to pass as GET params to fixmystreet.com/report/new. + fixmystreet.map.getCenterWGS84 = function() { + return fixmystreet.map.getCenter().transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") + ); + }; + if (document.getElementById('mapForm')) { var click = fixmystreet.maps.click_control = new OpenLayers.Control.Click(); fixmystreet.map.addControl(click); @@ -804,6 +814,12 @@ $.extend(fixmystreet.utils, { onload(); } + // Allow external scripts to react to pans/zooms on the map, + // by subscribing to $(fixmystreet).on('maps:update_view') + fixmystreet.map.events.register('moveend', null, function(){ + $(fixmystreet).trigger('maps:update_view'); + }); + (function() { var timeout; $('#js-reports-list').on('mouseenter', '.item-list--reports__item', function(){ -- cgit v1.2.3