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

Latitude or longitude out of range results in display of blank map #38

Closed
simonw opened this issue Dec 7, 2021 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Dec 7, 2021

https://git-history-demos.datasette.io/ca-fires/incidents

ca-fires__incident__250_rows

This SQL query also fails to load markers: https://git-history-demos.datasette.io/ca-fires?sql=select+Latitude%2C+Longitude+from+incident+order+by+_id+limit+101

But... if I add some filters, e.g. this one https://git-history-demos.datasette.io/ca-fires/incident?_sort=_id&_facet=ArchiveYear&ArchiveYear__exact=2020 - the map works.

@simonw simonw added the bug Something isn't working label Dec 7, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

I can replicate locally by downloading this DB: https://git-history-demos.datasette.io/ca-fires.db

@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

After messing around with console.log() a bit I'm suspicious that this line isn't working correctly in this case:

map.fitBounds(markerClusterGroup.getBounds());

Bounds in question for that first page load are:

{
    "_southWest": {
        "lat": 32.578481,
        "lng": -1191414610
    },
    "_northEast": {
        "lat": 41.927772,
        "lng": -115.917099
    }
}

@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

It's definitely a bounds issue. Here are bounds that DO work, copied from a page that displays correctly:

theMap.fitBounds([
  [41.86889,-116.9075],
  [32.75277778,-123.88658]
])

Running that on the empty map page that is meant to be showing 250 items zooms into California and makes the items visible.

@simonw simonw changed the title No markers shown on first load of map No markers shown on first load of map if bounds are invalid Dec 7, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

Looking closer at the bad bounds example shows what's happening:

    "_southWest": {
        "lat": 32.578481,
        "lng": -1191414610
    },

That Longitude is missing its decimal point! So there's a corrupt record in this database which causes the map to fail to load.

@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

One easy fix would be to not attempt to include a marker for any locations where the latitude or longitude are outside of normal -90 < latitude < 90 and -180 < longitude < 180 limits

@simonw simonw changed the title No markers shown on first load of map if bounds are invalid Latitude or longitude out of range results in display of blank map Dec 7, 2021
@simonw simonw closed this as completed in 83132e4 Dec 7, 2021
simonw added a commit that referenced this issue Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant