Use selected marker for selected facility & set map view conditionally #749
Conversation
When a facility has been selected -- via URL change, which can be triggered by marker clicks -- set the facility marker in the vector tile layer to use the selected marker.
b961a40
to
221a41a
Compare
Realized there's one more map interaction to re-create which is: center the map when selecting the facility if the facility is currently not visible in the bbox. |
Looking at this now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice, clear implementation.
icon: unselectedMarkerIcon, | ||
}); | ||
|
||
tileLayer.setFeatureStyle(oarID, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFeatureStyle
is such a nice API. Thanks, Leaflet.VectorGrid
.
noop(); | ||
} else if (fetching && !isFetchingFacility) { | ||
setIsFetchingFacility(true); | ||
} else if (!fetching && isFetchingFacility && data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names are hard. If you read this method without a lot of context, it is a little confusing to be !fetching
and isFetchingFacility
at the same time. Is there a way we can rename fetching
to more descriptive? Looks like fetching
is the value coming from Redux and isFetchingFacility is our component local flag. This isn't the first time we have had a pattern like this and it seems like a thing that is going to pop up the more we use local state hooks. I don't have any good ideas right now. This may be something to ask the larger team or #react about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me. Generally I've been thinking that it might be worthwhile for us to start writing more custom hooks so that we can extract the wonky logic into something that has a more reasonable name for its interface. In this case it probably makes sense just to rename either fetching
or isFetchingFaciliity
to distinguish them, so I'll think about how to do that and make a change before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed isFetchingFacility
to appIsGettingFacilityData
, as well as the related setter.
I found an edge-case bug after approving this.
|
Interesting. I'll look into this. |
I was able to re-create the hard-refresh zoom issue in FF, so I'll see if I can mitigate it. It does not appear to affect Chrome. |
When the user has arrived at the map by visiting a URL which contains an OAR ID, set the map view to center on the facility when the facility data returns. Otherwise, selecting a facility will not re-center the viewport. If the OAR ID encoded in a URL returns an error, switch off the setView behavior to ensure that the next manually selected facility does not incite a setView call. If a facility which is off-screen is selected (as may happen when selecting a facility from the list sidebar), center the map view on the facility when its data returns.
7fe7539
to
2a87040
Compare
I fixed the Firefox/hard-refresh quirk by using a |
Overview
When a facility has been selected -- via URL change, which can be
triggered by marker clicks -- set the facility marker in the vector tile
layer to use the selected marker.
When the user has arrived at the map by visiting a URL which contains an
OAR ID, set the map view to center on the facility when the facility
data returns. Otherwise, selecting a facility will not re-center the
viewport.
If the OAR ID encoded in a URL returns an error, switch off the setView
behavior to ensure that the next manually selected facility does not
incite a setView call.
Connects #739
Testing Instructions
Checklist
fixup!
commits have been squashed