From 7cb0dc726f2dc04bf2b1d52881f2bdebc7574566 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Fri, 8 Nov 2024 16:23:50 -0800 Subject: [PATCH 1/5] There are use cases where 0,0 coordinate is treated as null so treat it as such and do not plot it on the map --- .../cloudcare/static/cloudcare/js/formplayer/menus/views.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js index ab9eca9710ee..8ed7675a3fcc 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js @@ -933,13 +933,14 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ L.mapbox.accessToken = token; const allCoordinates = []; + const nullCoordinate = ['0', '0']; const markers = []; this.options.collection.models .forEach(model => { const addressCoordinates = model.attributes.data[addressIndex]; if (addressCoordinates) { let markerCoordinates = addressCoordinates.split(" ").slice(0,2); - if (markerCoordinates.length > 1) { + if (markerCoordinates.length > 1 && JSON.stringify(markerCoordinates) !== JSON.stringify(nullCoordinate)) { const rowId = `row-${model.id}`; const popupText = markdown.render(model.attributes.data[popupIndex]); let marker = L.marker(markerCoordinates, {icon: locationIcon}); From 9d101af946d33d5783fc758d71bcb09d9b38cbc0 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Fri, 8 Nov 2024 16:39:32 -0800 Subject: [PATCH 2/5] avoid errors when there's no coorindates --- .../cloudcare/static/cloudcare/js/formplayer/menus/views.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js index 8ed7675a3fcc..0f4fc9c64420 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js @@ -999,7 +999,9 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ .addTo(addressMap); allCoordinates.push(homeCoordinates); } - addressMap.fitBounds(allCoordinates, {maxZoom: 14}); + if (allCoordinates.length > 0) { + addressMap.fitBounds(allCoordinates, {maxZoom: 14}); + } } catch (error) { console.error(error); } From eacab00cf6fd3e0a03a99949ff8b38ed79249b97 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Fri, 8 Nov 2024 18:10:52 -0800 Subject: [PATCH 3/5] if there are valid coordinates to map, default map to center on project default location --- .../cloudcare/js/formplayer/menus/views.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js index 0f4fc9c64420..3716e2a61e53 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js @@ -887,19 +887,24 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ loadMap: function () { const token = initialPageData.get("mapbox_access_token"); + const defaultGeocoderLocation = initialPageData.get('default_geocoder_location') || {}; try { const locationIcon = this.fontAwesomeIcon("fa-solid fa-location-dot"); const selectedLocationIcon = this.fontAwesomeIcon("fa fa-star"); const homeLocationIcon = this.fontAwesomeIcon("fa fa-street-view"); - const lat = 30; - const lon = 15; + let initialLat = 30; + let initialLon = 15; + if (defaultGeocoderLocation && defaultGeocoderLocation.coordinates) { + initialLat = defaultGeocoderLocation.coordinates.latitude; + initialLon = defaultGeocoderLocation.coordinates.longitude; + } const zoom = 3; const addressMap = L.map( 'module-case-list-map', { zoomControl: false, - }).setView([lat, lon], zoom); + }).setView([initialLat, initialLon], zoom); L.control.zoom({ position: 'bottomright', @@ -1001,6 +1006,12 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ } if (allCoordinates.length > 0) { addressMap.fitBounds(allCoordinates, {maxZoom: 14}); + } else if (defaultGeocoderLocation.bbox) { + const bbox = defaultGeocoderLocation.bbox; + const southWestCorner = L.latLng(bbox[1], bbox[0]); + const northEastCorner = L.latLng(bbox[3], bbox[2]); + const bounds = L.latLngBounds(southWestCorner, northEastCorner); + addressMap.fitBounds(bounds); } } catch (error) { console.error(error); From b737d7c812d5e1304a1b36f8be1e8ca89bf148e0 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Mon, 11 Nov 2024 11:06:22 -0800 Subject: [PATCH 4/5] lint --- .../cloudcare/static/cloudcare/js/formplayer/menus/views.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js index 3716e2a61e53..8b4cac66026a 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js @@ -1,4 +1,3 @@ -'use strict'; hqDefine("cloudcare/js/formplayer/menus/views", [ 'jquery', 'underscore', @@ -450,7 +449,7 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ const scrollContainer = $(constants.SCROLLABLE_CONTENT_CONTAINER); const offset = getScrollTopOffset(this.smallScreenEnabled); $(scrollContainer).animate({ - scrollTop: scrollContainer.scrollTop() + $(e.currentTarget).parent().offset().top - offset + scrollTop: scrollContainer.scrollTop() + $(e.currentTarget).parent().offset().top - offset, }); } @@ -1599,7 +1598,7 @@ hqDefine("cloudcare/js/formplayer/menus/views", [ $('#persistent-menu-arrow-toggle').attr('data-bs-toggle', collapse); } }, - initialize: function (options) { + initialize: function () { self.smallScreenListener = cloudcareUtils.smallScreenListener(smallScreenEnabled => { this.handleSmallScreenChange(smallScreenEnabled); }); From 462cd63cc2ed55d149e7108ed1195e62f91f0c70 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 12 Nov 2024 13:22:50 -0800 Subject: [PATCH 5/5] add back use strict --- .../apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js | 1 + 1 file changed, 1 insertion(+) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js index f977bcc65050..645f5a79358b 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views.js @@ -1,3 +1,4 @@ +'use strict'; hqDefine("cloudcare/js/formplayer/menus/views", [ 'jquery', 'underscore',