Skip to content
Snippets Groups Projects
Unverified Commit e62aaa1e authored by Nick Fitzpatrick's avatar Nick Fitzpatrick Committed by GitHub
Browse files

Show error when geojson coordinates are outside lat/lng bounds (#46064)

parent e1232397
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -1111,4 +1111,25 @@ describe("scenarios > admin > settings > map settings", () => {
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Invalid custom GeoJSON: does not contain features");
});
it("should show an informative error when adding a calid URL that contains GeoJSON that does not use lat/lng coordinates", () => {
//intercept call to api/geojson and return projected.geojson. Call to load file actually happens in the BE
cy.fixture("../../e2e/support/assets/projected.geojson").then(data => {
cy.intercept("GET", "/api/geojson*", data);
});
cy.visit("/admin/settings/maps");
cy.button("Add a map").click();
modal().within(() => {
// GeoJSON with an unsupported format (not a Feature or FeatureCollection)
cy.findByPlaceholderText("Like https://my-mb-server.com/maps/my-map.json")
.clear()
.type("http://assets/projected.geojson");
cy.findByText("Load").click();
cy.findByText(
"Invalid custom GeoJSON: coordinates are outside bounds for latitude and longitude",
);
});
});
});
......@@ -15,6 +15,7 @@ import CS from "metabase/css/core/index.css";
import { uuid } from "metabase/lib/uuid";
import { SettingsApi, GeoJSONApi } from "metabase/services";
import LeafletChoropleth from "metabase/visualizations/components/LeafletChoropleth";
import { computeMinimalBounds } from "metabase/visualizations/lib/mapping";
import SettingHeader from "../SettingHeader";
......@@ -99,6 +100,21 @@ export default class CustomGeoJSONWidget extends Component {
throw t`Invalid custom GeoJSON: feature is missing properties`;
}
}
const bounds = computeMinimalBounds(geoJson.features);
const northEast = bounds.getNorthEast();
const southWest = bounds.getSouthWest();
if (
[
[northEast.lat, northEast.lng],
[southWest.lat, southWest.lng],
].every(
([lat, lng]) => lat < -90 || lat > 90 || lng < -180 || lng > 180,
)
) {
throw t`Invalid custom GeoJSON: coordinates are outside bounds for latitude and longitude`;
}
}
if (geoJson.type === "Feature") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment