Handle nuisance reports without location data

This commit is contained in:
Eli Ribble 2026-03-19 19:16:39 +00:00
parent 7a111ab9b3
commit 2c4e7c4f96
No known key found for this signature in database
3 changed files with 40 additions and 20 deletions

View file

@ -28,11 +28,7 @@ class MapMultipoint extends HTMLElement {
this._map.remove();
}
}
_initializeMap() {
const centroid = JSON.parse(this.getAttribute("centroid"));
const organization_id = Number(this.getAttribute("organization-id") || 0);
const tegola = this.getAttribute("tegola");
_bounds() {
const xmin = parseFloat(this.getAttribute("xmin"));
const ymin = parseFloat(this.getAttribute("ymin"));
const xmax = parseFloat(this.getAttribute("xmax"));
@ -47,6 +43,12 @@ class MapMultipoint extends HTMLElement {
[-70, 50],
];
}
return bounds;
}
_initializeMap() {
const bounds = this._bounds();
const organization_id = Number(this.getAttribute("organization-id") || 0);
const tegola = this.getAttribute("tegola");
const mapElement = this.shadowRoot.querySelector("#map");
this._map = new maplibregl.Map({
@ -129,9 +131,19 @@ class MapMultipoint extends HTMLElement {
return this._map.queryRenderedFeatures(a);
}
ClearMarkers() {
this._markers.forEach((marker) => marker.remove());
}
FitBounds(bounds, options) {
return this._map.fitBounds(bounds, options);
}
// Reset the view back to whatever the html properties define
ResetCamera() {
const bounds = this._bounds();
this.FitBounds(bounds, {
linear: false,
});
}
SetLayoutProperty(layout, property, value) {
return this._map.setLayoutProperty(layout, property, value);
}

View file

@ -276,6 +276,11 @@
updateMap() {
const map = document.querySelector("map-multipoint");
const loc = this.selectedCommunication.public_report.location;
if (loc == null) {
map.ClearMarkers();
map.ResetCamera();
return;
}
let markers = [
new maplibregl.Marker({
color: "#FF0000",

View file

@ -24,7 +24,7 @@ type Report struct {
Created time.Time `db:"created" json:"created"`
ID int32 `db:"id" json:"-"`
Images []types.Image `db:"images" json:"images"`
Location types.Location `db:"location" json:"location"`
Location *types.Location `db:"location" json:"location"`
Nuisance *Nuisance `db:"nuisance" json:"nuisance"`
PublicID string `db:"public_id" json:"public_id"`
Reporter types.Contact `db:"reporter" json:"reporter"`
@ -45,8 +45,8 @@ func ReportsForOrganization(ctx context.Context, org_id int32) ([]*Report, error
"address_street AS \"address.street\"",
"created",
"id",
"ST_Y(location::geometry::geometry(point, 4326)) AS \"location.latitude\"",
"ST_X(location::geometry::geometry(point, 4326)) AS \"location.longitude\"",
"COALESCE(ST_Y(location::geometry::geometry(point, 4326)), 0.0) AS \"location.latitude\"",
"COALESCE(ST_X(location::geometry::geometry(point, 4326)), 0.0) AS \"location.longitude\"",
"public_id",
"report_type",
"reporter_email AS \"reporter.email\"",
@ -94,6 +94,9 @@ func ReportsForOrganization(ctx context.Context, org_id int32) ([]*Report, error
row.Log = logs_by_report_id[row.ID]
row.Nuisance = nuisances_by_report_id[row.ID]
row.Water = waters_by_report_id[row.ID]
if row.Location.Latitude == 0.0 || row.Location.Longitude == 0.0 {
row.Location = nil
}
results[i] = &row
}
return results, nil