aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-07-04 21:12:12 +0100
committerMatthew Somerville <matthew@mysociety.org>2019-07-10 15:53:27 +0100
commitc30ae857af7f2e2bccf974da34cf2f3868e7b7f2 (patch)
treed5237c547791a17786ac6e40735bea7a7ea75a2e
parent12d234639171b0965c2ce5cf0fea5a6af180cc9b (diff)
Improve map JavaScript defensiveness.
Add more checking for map things so e.g. on a skipped map page we stop getting JavaScript errors given there is no map present.
-rw-r--r--CHANGELOG.md1
-rw-r--r--web/cobrands/fixmystreet/assets.js8
-rw-r--r--web/js/duplicates.js6
-rw-r--r--web/js/map-OpenLayers.js7
4 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 525c350b5..89f215660 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
- Improve keyboard accessibility.
- Report form now indicates that details are kept private if report is
made in a private category. #2528
+ - Improve map JavaScript defensiveness.
- Admin improvements:
- Add new roles system, to group permissions and apply to users.
- New features:
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js
index 15ac3a9a3..c86f09ed9 100644
--- a/web/cobrands/fixmystreet/assets.js
+++ b/web/cobrands/fixmystreet/assets.js
@@ -526,6 +526,10 @@ fixmystreet.assets = {
},
add: function(default_options, options) {
+ if (!document.getElementById('map')) {
+ return;
+ }
+
options = $.extend(true, {}, default_options, options);
var asset_fault_layer = null;
@@ -734,6 +738,10 @@ fixmystreet.assets = {
return;
}
+ if (!fixmystreet.map) {
+ return;
+ }
+
// Make sure the assets get hidden if the back button is pressed
fixmystreet.maps.display_around = (function(original) {
function hide_assets() {
diff --git a/web/js/duplicates.js b/web/js/duplicates.js
index 0844cb5f3..3ed7e6079 100644
--- a/web/js/duplicates.js
+++ b/web/js/duplicates.js
@@ -121,6 +121,9 @@
}
function render_duplicate_pins(api_response) {
+ if (!fixmystreet.markers) {
+ return;
+ }
var markers = fixmystreet.maps.markers_list( api_response.pins, true );
fixmystreet.markers.removeFeatures( current_duplicate_markers );
fixmystreet.markers.addFeatures( markers );
@@ -138,6 +141,9 @@
}
function remove_duplicate_pins() {
+ if (!fixmystreet.markers) {
+ return;
+ }
fixmystreet.markers.removeFeatures( current_duplicate_markers );
}
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index ae86269c9..cd2283491 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -304,6 +304,9 @@ $.extend(fixmystreet.utils, {
// fixmystreet.select_feature).
markers_highlight: function(problem_id) {
+ if (!fixmystreet.markers) {
+ return;
+ }
for (var i = 0; i < fixmystreet.markers.features.length; i++) {
if (typeof problem_id == 'undefined') {
// There is no highlighted marker, so unfade this marker
@@ -791,6 +794,10 @@ $.extend(fixmystreet.utils, {
$(function(){
+ if (!document.getElementById('map')) {
+ return;
+ }
+
// Set specific map config - some other JS included in the
// template should define this
fixmystreet.maps.config();