Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Replace map component #710

Merged
merged 1 commit into from Aug 2, 2019
Merged

Replace map component #710

merged 1 commit into from Aug 2, 2019

Conversation

kellyi
Copy link
Contributor

@kellyi kellyi commented Jul 29, 2019

Overview

This PR replaces the existing Google Map component with a React Leaflet map using a Google Basemap (via GoogleMutant, via some React wrappers). I believe it has feature parity with the Google Map component version on staging, although the cluster marker sizes may be slightly different.

Connects #706

Notes

Leaflet.markercluster wants a peer dependency of Leaflet 1.3.something. There's an open PR to fix this by adjusting how it declares its peer dependencies, but the yarn install output here will currently report an incorrect peer dependency. Here's the PR:

Leaflet/Leaflet.markercluster#946

The library seems to work regardless of the peer dependency mismatch, however.

Testing Instructions

  • get this branch, then ./scripts/update and ./scripts/resetdb and ./scripts/server
  • use the map and verify that searching for facilities works as before and the clusters work as before
  • using shell_plus, set two facilities to live at Point(0, 0). I did this just to make them easily searchable:
>>> from django.contrib.gis.geos import Point
>>> f = Facility.objects.first()
>>> f.location = Point(0, 0)
>>> f.name = "Hello"
>>> f.save()
>>> f = Facility.objects.last()
>>> f.location = Point(0, 0)
>>> f.name = "Hello world"
>>> f.save()
  • search for Hello in the app and verify that you see two facilities at the same point and that the disambiguation thing works the same as it does on staging

Checklist

  • fixup! commits have been squashed
  • CI passes after rebase
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines

@jwalgran jwalgran marked this pull request as ready for review July 30, 2019 16:30
@jwalgran
Copy link
Contributor

Sorry. I was trying to click on the details of the failed PR build and the content moved. I accidentally clicked "ready for review"

@kellyi
Copy link
Contributor Author

kellyi commented Jul 30, 2019

No worries!

@kellyi kellyi force-pushed the ki/replace-map-component branch 2 times, most recently from 2e1c2be to 47ff877 Compare July 30, 2019 20:03
@kellyi kellyi changed the title WIP Replace map component Replace map component Jul 30, 2019
@kellyi kellyi requested a review from jwalgran July 30, 2019 20:12
@@ -1,519 +1,276 @@
import React, { Component, Fragment } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { bool, func, number, shape, string } from 'prop-types';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff here isn't really meaningful -- this is an entirely new file, but I deleted the prior one and replaced it with the React-Leaflet implementation.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work switching over to Leaflet. All the interactions are in tact and seem to perform a bit better. I just have a few minor suggestions related to style and zoom behavior.

),
]}
onClose={() => setFacilitiesToDisambiguate(null)}
>
<FacilitiesMapPopup
Copy link
Contributor

@jwalgran jwalgran Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our popup styling has regressed a bit. Consider adjusting the styles to

  • Have the name be left-aligned rather than centered
  • Restore the small drop shadow

Before

screen_shot_2019-07-29_at_1 46 04_pm

After

Screen Shot 2019-07-30 at 3 16 49 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this in 6ebbd43

Screen Shot 2019-08-01 at 4 20 00 PM

html: `<span>${clusterCount}</span>`,
});
}}
onClusterClick={({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some non-intuitive behavior when selecting a cluster representing overlapping markers. Clicking on the cluster zooms in really far, then clicking a popup item zooms back out.

2019-07-30 15 23 52

Consider harmonizing the max zoom level to which we zoom when clicking on a cluster and clicking on a marker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is taken care of by b9d1915 as well: we no longer adjust the zoom level on moving toward the details page, so it'll just keep the existing zoom level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up solving this in a different way: viz., we only set the map view for a details page if it is an initial page load, navigating directly to the details page.

? selectedMarkerIcon
: unselectedMarkerIcon
}
onClick={() => navigateToFacilityDetails(f.id)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current zoom behavior makes it a little difficult to click around several nearby points

2019-07-30 15 26 50

Consider panning only instead of zoom+pan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled this (and also continued adjusting the minZoom setup) in b9d1915

return L.divIcon({
className: iconClassName,
iconSize,
html: `<span>${clusterCount}</span>`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the application font and tweaking the span style so that the numbers appear more centered.

diff --git a/src/app/src/components/FacilitiesMap.jsx b/src/app/src/components/FacilitiesMap.jsx
index 8669cc1..ca794f1 100644
--- a/src/app/src/components/FacilitiesMap.jsx
+++ b/src/app/src/components/FacilitiesMap.jsx
@@ -214,9 +214,9 @@ function FacilitiesMap({
                     })();
 
                     return L.divIcon({
-                        className: iconClassName,
+                        className: `cluster-icon ${iconClassName}`,
                         iconSize,
-                        html: `<span>${clusterCount}</span>`,
+                        html: `<span style="margin: -0.1rem; display: block;">${clusterCount}</span>`,
                     });
                 }}
                 onClusterClick={({
diff --git a/src/app/src/styles/css/leafletMap.css b/src/app/src/styles/css/leafletMap.css
index 71c6d98..aea2022 100644
--- a/src/app/src/styles/css/leafletMap.css
+++ b/src/app/src/styles/css/leafletMap.css
@@ -1,3 +1,7 @@
+.cluster-icon {
+    font-family: ff-tisa-sans-web-pro, sans-serif;
+}
+
 .cluster-icon-one {
     width: 53px;
     height: 53px;

Before

Screen Shot 2019-07-30 at 16 13 52

After

Screen Shot 2019-07-30 at 16 13 30

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool -- I added this in b615822

Screen Shot 2019-08-01 at 12 52 18 PM

@@ -7,29 +7,6 @@ export const initialCenter = Object.freeze({
lng: 5,
});

export const initialZoom = 1;
export const initialZoom = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider 2 as an initial zoom rather than 3. It shows more of the world.

Zoom 3

Screen Shot 2019-07-30 at 15 58 59

Zoom 2

Screen Shot 2019-07-30 at 15 59 14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this in fcf2a55

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider setting a minimum zoom of 1

Screen Shot 2019-07-31 at 8 00 24 AM

@kellyi
Copy link
Contributor Author

kellyi commented Aug 1, 2019

I set the minZoom to 1 in dd37625

@kellyi
Copy link
Contributor Author

kellyi commented Aug 1, 2019

fd63ec1 adjusts the map panning behavior:

Previously we were setting the view anew each time a new facility details page got pushed onto the stack. Now I've adjusted things so that we only set the view around the facility if user has navigated directly to the details screen without traversing the main facilities search.

We discussed this behavior in Slack and determined that it was the preferred behavior.

@kellyi
Copy link
Contributor Author

kellyi commented Aug 1, 2019

@jwalgran I think this is ready for another look! Apologies for the fixup! fixup! fixup! etc stuff.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really excellent. A big upgrade in map interactions. I think there is only one thing we need to fix up. Now that we are not zooming on every select, the selection can get out of sync with the map if you select an item from the list that is not in the viewport. I think Google Maps shows the best way of handling this situation, where you don't move the map if you click a result on the map, but do move the map if you click an item in the sidebar.

2019-08-02 09 49 55

@jwalgran jwalgran removed their assignment Aug 2, 2019
@kellyi
Copy link
Contributor Author

kellyi commented Aug 2, 2019

where you don't move the map if you click a result on the map, but do move the map if you click an item in the sidebar

That makes sense to me -- I'll add this interaction before merging.

@kellyi
Copy link
Contributor Author

kellyi commented Aug 2, 2019

Going to squash this momentarily but 5e69460 has the changes to make the map panning work like:

  • if the selected facility is in the viewport's map bounds when it is selected (technically: when its data returns from the API), do not pan the map
  • if the selected facility is not in the viewport's map bounds when it is selected (technically: when its data returns from the API), do pan the map to center it on the facility

I also commented the useEffects so that we'll have an easier time understanding them if we ever, for instance, switch to another mapping library.

Replace the FacilitiesMap's Google Maps implementation with one which
uses Leaflet but otherwise has feature parity.
@kellyi kellyi merged commit 4d57dca into develop Aug 2, 2019
@kellyi kellyi deleted the ki/replace-map-component branch August 2, 2019 18:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants