Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no enterprises have been geocoded yet make sure Open Street Map displays correctly #5680

Merged

Conversation

cillian
Copy link
Contributor

@cillian cillian commented Jun 26, 2020

What? Why?

Before if Open Street Map was enabled and no geocoded enterprises were present the map wouldn't display correctly, it would display a gray/blank element. These changes make sure the map displays correctly even if no geocoded enterprises present. It also includes a setting to change the default map coordinates.

This is a start for the last item in #5542

What should we test?

  1. Enabling Open Street Map in Admin > Configuration > Content.
  2. View the /map page or group map where there are no geocoded enterprises yet.
  3. Check the map displays correctly and a gray/blank element is not there.

Extra testing note from Matt: turn Open Street Map off again in the staging server after you've finished testing this please! 😅

Release notes

Prevent blank Open Street Map when no geocoded enterprises present.

Changelog Category: Fixed

…ill displays correctly.

Before it would display a gray/blank div instead of map because the map latitude, longitude couldn't be calculated without geocoded enterprises. This adds a setting so the default coordinates can be set even if no geocoded enterprises present.
Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

wonderful, thanks a lot for one more @cillian

I think we need to move some of this code to a service with tests

… given a set of coordinates.

Also removing the hardcoded default latitude/longitude from open_street_map directive because it's probably not very likely that it will be needed.
@Matt-Yorkley Matt-Yorkley mentioned this pull request Jun 27, 2020
2 tasks
averagePositiveAngle - averageNegativeAngle
else
averageNegativeAngle - averagePositiveAngle

buildMarker = (enterprise, latlng, title) ->
icon = L.icon
Copy link
Contributor

Choose a reason for hiding this comment

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

Where's this L variable coming from? I can't see where it's set...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

zoomLevel = 6
map = L.map('open-street-map')
L.tileLayer.provider(openStreetMapProviderName, openStreetMapProviderOptions).addTo(map)
map.setView([averageLatitude, averageLongitude], zoomLevel)
map.setView([initialLatitude(), initialLongitude()], zoomLevel)
Copy link
Contributor

Choose a reason for hiding this comment

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

These two methods are only called in this one place, right? I think I would extract #initialLatitude and #initialLongitude to the service as well, and just have something like this:

map.setView([MapCentreCalculator.initialLatitude(), MapCentreCalculator.initialLongitude()], zoomLevel)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Matt-Yorkley yes that works well. I have moved those method into the MapCentreCalculator service now.

@luisramos0
Copy link
Contributor

Moving to In Dev until @cillian 's feedback.

Copy link
Contributor

@luisramos0 luisramos0 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, thanks @cillian


_calculate: (angleName, coordinates) =>
positiveAngles = []
negativeAngles = []
Copy link
Contributor

@sauloperez sauloperez Aug 3, 2020

Choose a reason for hiding this comment

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

these two arrays can be removed right? We append values to them but I don't see them used. I'm moving this to test ready anyway, but it'd be good the clarify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sauloperez ah yes, I should have spotted that, it's fixed now in
e6ab2ae

@sauloperez
Copy link
Contributor

Pretty neat @cillian !

…e calculator service.

I forgot to remove these when I was refactoring this earlier.
@luisramos0
Copy link
Contributor

Verifying the issue before staging this.
I deleted all longitude and latitude data from staging katuma DB with this SQL.
image

Google maps centers around melbourne by default with no enterprise.
Checking the OSM option in the content settings, I see a grey OSM map:
image

After deployment, google maps still works and OSM now shows the default location in AUS (it's not so zoomed in as in google maps).
I set the address of an enterprise to Barcelona and the map moves there and shows the enterprise.
I deactivated OSM after this, google maps showing the enterprise in Barcelona 👍

This is ready to go ✔️

@luisramos0 luisramos0 merged commit f14bb28 into openfoodfoundation:master Aug 5, 2020
@cillian cillian deleted the prevent-blank-open-street-map branch September 17, 2021 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants