From f2cd1e6b05eaeb6f88716c3c5988ffe3ebf1296f Mon Sep 17 00:00:00 2001 From: pezholio Date: Fri, 5 May 2017 15:49:43 +0100 Subject: Allow inspectors to shortlist all reports in view If zoom level is >= 14, then inspectors can click a button that marks all reports in the map view as shortlisted --- web/js/map-OpenLayers.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index b53246279..f0f3dca44 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -2,7 +2,9 @@ var fixmystreet = fixmystreet || {}; (function() { - fixmystreet.maps = { + fixmystreet.maps = fixmystreet.maps || {} + + $.extend(fixmystreet.maps, { // This function might be passed either an OpenLayers.LonLat (so has // lon and lat), or an OpenLayers.Geometry.Point (so has x and y). update_pin: function(lonlat) { @@ -198,7 +200,7 @@ var fixmystreet = fixmystreet || {}; } fixmystreet.markers.redraw(); } - }; + }); var drag = { activate: function() { @@ -541,6 +543,9 @@ var fixmystreet = fixmystreet || {}; fixmystreet.map.addControl( fixmystreet.select_feature ); fixmystreet.select_feature.activate(); fixmystreet.map.events.register( 'zoomend', null, fixmystreet.maps.markers_resize ); + fixmystreet.map.events.register( 'zoomend', null, function() { + fixmystreet.run(fixmystreet.maps.show_shortlist_control) + }); // Set up the event handlers to populate the filters and react to them changing $("#filter_categories").on("change.filters", categories_or_status_changed); -- cgit v1.2.3 From 8f0b3ca3fd6d978aa96b9541f9d6c9544c0db8eb Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 23 May 2017 11:43:37 +0100 Subject: Fix linting errors --- web/js/map-OpenLayers.js | 99 +++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 51 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index f0f3dca44..3e3c33bba 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -2,7 +2,7 @@ var fixmystreet = fixmystreet || {}; (function() { - fixmystreet.maps = fixmystreet.maps || {} + fixmystreet.maps = fixmystreet.maps || {}; $.extend(fixmystreet.maps, { // This function might be passed either an OpenLayers.LonLat (so has @@ -70,12 +70,8 @@ var fixmystreet = fixmystreet || {}; markers_list: function(pins, transform) { var markers = []; - var size = fixmystreet.maps.marker_size_for_zoom( - fixmystreet.map.getZoom() + fixmystreet.zoomOffset - ); - var selected_size = fixmystreet.maps.selected_marker_size_for_zoom( - fixmystreet.map.getZoom() + fixmystreet.zoomOffset - ); + var size = fixmystreet.maps.marker_size(); + var selected_size = fixmystreet.maps.selected_marker_size(); for (var i=0; i= 15) { return window.selected_problem_id ? 'small' : 'normal'; } else if (zoom >= 13) { @@ -131,7 +124,8 @@ var fixmystreet = fixmystreet || {}; } }, - selected_marker_size_for_zoom: function(zoom) { + selected_marker_size: function() { + var zoom = fixmystreet.map.getZoom() + fixmystreet.zoomOffset; if (zoom >= 15) { return 'big'; } else if (zoom >= 13) { @@ -213,7 +207,9 @@ var fixmystreet = fixmystreet || {}; this._drag.activate(); }, deactivate: function() { - this._drag && this._drag.deactivate(); + if (this._drag) { + this._drag.deactivate(); + } } }; @@ -312,7 +308,7 @@ var fixmystreet = fixmystreet || {}; var filter_categories = replace_query_parameter(qs, 'filter_categories', 'filter_category'); var filter_statuses = replace_query_parameter(qs, 'statuses', 'status'); var sort_key = replace_query_parameter(qs, 'sort', 'sort'); - delete qs['p']; + delete qs.p; var new_url; if ($.isEmptyObject(qs)) { new_url = location.href.replace(location.search, ""); @@ -367,6 +363,37 @@ var fixmystreet = fixmystreet || {}; ]); var loaded = 0; var new_geometry = new OpenLayers.Geometry.Polygon(lr); + var style_area = function() { + loaded++; + var style = this.styleMap.styles['default']; + if ( fixmystreet.area_format ) { + style.defaultStyle = fixmystreet.area_format; + } else { + $.extend(style.defaultStyle, { fillColor: 'black', strokeColor: 'black' }); + } + var geometry = this.features[0].geometry; + if (geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') { + $.each(geometry.components, function(i, polygon) { + new_geometry.addComponents(polygon.components); + extent.extend(polygon.getBounds()); + }); + } else if (geometry.CLASS_NAME == 'OpenLayers.Geometry.Polygon') { + new_geometry.addComponents(geometry.components); + extent.extend(this.getDataExtent()); + } + if (loaded == fixmystreet.area.length) { + var f = this.features[0].clone(); + f.geometry = new_geometry; + this.removeAllFeatures(); + this.addFeatures([f]); + var qs = parse_query_string(); + if (!qs.bbox) { + zoomToBounds(extent); + } + } else { + fixmystreet.map.removeLayer(this); + } + }; for (var i=0; i Date: Fri, 26 May 2017 12:30:54 +0100 Subject: Allow cobrands to define pin colour for new reports Previously, a green marker would be used for reports as they were being created. Now, cobrands can override `pin_new_report_colour` to show a different pin image when users are creating a new report. --- web/js/map-OpenLayers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 3e3c33bba..cacf88dd9 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -52,7 +52,7 @@ var fixmystreet = fixmystreet || {}; /* Already have a pin */ fixmystreet.markers.features[0].move(lonlat); } else { - var markers = fixmystreet.maps.markers_list( [ [ lonlat.lat, lonlat.lon, 'green' ] ], false ); + var markers = fixmystreet.maps.markers_list( [ [ lonlat.lat, lonlat.lon, fixmystreet.pin_new_report_colour ] ], false ); fixmystreet.bbox_strategy.deactivate(); fixmystreet.markers.removeAllFeatures(); fixmystreet.markers.addFeatures( markers ); -- cgit v1.2.3 From 8e44bc941b85f3a2e453c7434434e40755931a1b Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Wed, 28 Jun 2017 23:48:42 +0200 Subject: [FixaMinGata] Consolidate with upstream. Add hook for post-title field content in report form. Update translations. --- web/js/map-OpenLayers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index cacf88dd9..549da6ebe 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -570,7 +570,8 @@ var fixmystreet = fixmystreet || {}; 'Show pins', 'Hide pins', 'Dangos pinnau', 'Cuddio pinnau', "Vis nåler", "Skjul nåler", - "Zeige Stecknadeln", "Stecknadeln ausblenden" + "Zeige Stecknadeln", "Stecknadeln ausblenden", + 'Visa kartnålar', 'Göm kartnålar' ]; for (var i=0; i Date: Mon, 17 Jul 2017 13:30:07 +0100 Subject: Use standard JS translation for show/hide pins. --- web/js/map-OpenLayers.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 549da6ebe..97507ea4a 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -566,23 +566,14 @@ var fixmystreet = fixmystreet || {}; $('#hide_pins_link').click(function(e) { e.preventDefault(); - var showhide = [ - 'Show pins', 'Hide pins', - 'Dangos pinnau', 'Cuddio pinnau', - "Vis nåler", "Skjul nåler", - "Zeige Stecknadeln", "Stecknadeln ausblenden", - 'Visa kartnålar', 'Göm kartnålar' - ]; - for (var i=0; i Date: Mon, 14 Aug 2017 12:32:34 +0100 Subject: [Zurich] Fix map on /reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A seemingly unrelated change in ef6ffbdb was causing JS errors on the /reports page which meant the map loading spinner was permanently present. This commit fixes that, and also fixes another bug which was uncovered where the ?ajax=1 param was being ignored by the Zürich /reports page, leading to HTML being returned and another JS error. The call to `new OpenLayers.Bounds` in OpenLayers.Strategy.FixMyStreet.getMapBounds was causing three of the 4 bounds params to be lost when run on OpenLayers 2.11, as this version doesn’t accept an array to the Bounds constructor. This in turn was using an invalid `bbox` parameter (only the west value was present) in the AJAX call to /reports which returned a 500 error. This then crashed the JS and caused the loading spinner to get stuck. --- web/js/map-OpenLayers.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 97507ea4a..e7702e764 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -772,7 +772,10 @@ OpenLayers.Strategy.FixMyStreet = OpenLayers.Class(OpenLayers.Strategy.BBOX, { getMapBounds: function() { var bounds = OpenLayers.Strategy.BBOX.prototype.getMapBounds.apply(this); if (bounds) { - bounds = new OpenLayers.Bounds(bounds.toArray()); + // OpenLayers 2.11 (as used by Zürich) doesn't allow Bounds to be + // created by passing an array to the constructor, so we have to use + // this convenience method instead. + bounds = OpenLayers.Bounds.fromArray(bounds.toArray()); } return bounds; }, -- cgit v1.2.3 From d034f3c1447ea91cb4333365ce123d58deb2de0d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 17 Aug 2017 15:50:07 +0100 Subject: Refactor /around list code to share with others. Both /reports and /my share an ID and a /reports/ajax function, use these also on /around (and share ajax/non-ajax code). --- web/js/map-OpenLayers.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index e7702e764..53535b146 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -861,10 +861,6 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { } else { obj = json; } - var current; - if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { - current.innerHTML = obj.current; - } var reports_list; if (typeof(obj.reports_list) != 'undefined' && (reports_list = document.getElementById('js-reports-list'))) { reports_list.innerHTML = obj.reports_list; -- cgit v1.2.3 From 1d9e10e980e480196ba1a5f1a3bc450a06b78dde Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 16 Aug 2017 18:04:41 +0100 Subject: Fix replaced sidebar losing hover behaviour. If the list was replaced by JavaScript, the event handlers were being dropped. Switch the handlers to the parent that remains present. --- web/js/map-OpenLayers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 53535b146..6a0d938fc 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -674,7 +674,7 @@ var fixmystreet = fixmystreet || {}; (function() { var timeout; - $('.item-list--reports').on('mouseenter', '.item-list--reports__item', function(){ + $('#js-reports-list').on('mouseenter', '.item-list--reports__item', function(){ var href = $('a', this).attr('href'); var id = parseInt(href.replace(/^.*[\/]([0-9]+)$/, '$1'),10); clearTimeout(timeout); -- cgit v1.2.3 From f1859bc10aaa153568ea866142c8535cbf769b87 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 17 Aug 2017 21:08:51 +0100 Subject: Make sure /around permalink/redirect have js param The change in 17e38922 would not deal with the URL construted by the map permalink code, or the redirect after inspection. --- web/js/map-OpenLayers.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 6a0d938fc..9e02c8ea9 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -746,6 +746,10 @@ OpenLayers.Control.PermalinkFMS = OpenLayers.Class(OpenLayers.Control.Permalink, } href += separator + OpenLayers.Util.getParameterString(this.createParams(center, zoom)); // Could use mlat/mlon here as well if we are on a page with a marker + if (this.base == '/around') { + href += '&js=1'; + } + if (this.anchor && !this.element) { window.location.href = href; } -- cgit v1.2.3 From 31b8337e38b1b39db1660fb877bf1419cc6128f9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 15 Aug 2017 13:31:17 +0100 Subject: [Zurich] Upgrade OpenLayers to master, matching others. --- web/js/map-OpenLayers.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 9e02c8ea9..dc65f750d 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -701,14 +701,6 @@ OpenLayers.Control.PanZoomFMS = OpenLayers.Class(OpenLayers.Control.PanZoom, { btn.action = id; btn.className = "olButton"; this.div.appendChild(btn); - if (OpenLayers.VERSION_NUMBER.indexOf('2.11') > -1) { - btn.map = this.map; - OpenLayers.Event.observe(btn, "mousedown", OpenLayers.Function.bindAsEventListener(this.buttonDown, btn)); - var slideFactorPixels = this.slideFactor; - btn.getSlideFactor = function() { - return slideFactorPixels; - }; - } this.buttons.push(btn); return btn; }, @@ -776,10 +768,7 @@ OpenLayers.Strategy.FixMyStreet = OpenLayers.Class(OpenLayers.Strategy.BBOX, { getMapBounds: function() { var bounds = OpenLayers.Strategy.BBOX.prototype.getMapBounds.apply(this); if (bounds) { - // OpenLayers 2.11 (as used by Zürich) doesn't allow Bounds to be - // created by passing an array to the constructor, so we have to use - // this convenience method instead. - bounds = OpenLayers.Bounds.fromArray(bounds.toArray()); + bounds = new OpenLayers.Bounds(bounds.toArray()); } return bounds; }, -- cgit v1.2.3 From f57adcb38568a0321f349cd823fbd2578eacb2ef Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 7 Sep 2017 08:22:35 +0100 Subject: Make sure pin ID is an integer. The JavaScript assumes it is, but due to a string comparison in DBIx::Class [1] when a has_many prefetch is in use (as it is on a /reports page when a shortlist-using staff user is logged in) all IDs bar the first were being given an internal string value and JSON encoding was outputting them as a string. [1] https://github.com/dbsrgits/dbix-class/blob/v0.08209/lib/DBIx/Class/ResultSet.pm#L1331 --- web/js/map-OpenLayers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'web/js/map-OpenLayers.js') diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index dc65f750d..8cc2e8e2c 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -82,12 +82,13 @@ var fixmystreet = fixmystreet || {}; fixmystreet.map.getProjectionObject() ); } - var marker_size = (pin[3] === window.selected_problem_id) ? selected_size : size; + var id = +pin[3]; + var marker_size = (id === window.selected_problem_id) ? selected_size : size; var marker = new OpenLayers.Feature.Vector(loc, { colour: pin[2], size: pin[5] || marker_size, faded: 0, - id: pin[3], + id: id, title: pin[4] || '', draggable: pin[6] === false ? false : true }); -- cgit v1.2.3