diff --git a/html/static/js/map-multipoint.js b/html/static/js/map-multipoint.js index 2fea9bad..d976190f 100644 --- a/html/static/js/map-multipoint.js +++ b/html/static/js/map-multipoint.js @@ -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); } diff --git a/html/template/sync/communication-root.html b/html/template/sync/communication-root.html index 8f50e4b3..87eec006 100644 --- a/html/template/sync/communication-root.html +++ b/html/template/sync/communication-root.html @@ -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", diff --git a/platform/publicreport/report.go b/platform/publicreport/report.go index f3d50988..8bad0531 100644 --- a/platform/publicreport/report.go +++ b/platform/publicreport/report.go @@ -18,19 +18,19 @@ import ( ) type Report struct { - Log []LogEntry `db:"-" json:"log"` - Address types.Address `db:"address" json:"address"` - AddressRaw string `db:"address_raw" json:"address_raw"` - 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"` - Nuisance *Nuisance `db:"nuisance" json:"nuisance"` - PublicID string `db:"public_id" json:"public_id"` - Reporter types.Contact `db:"reporter" json:"reporter"` - Status string `db:"status" json:"status"` - Type string `db:"report_type" json:"type"` - Water *Water `db:"water" json:"water"` + Log []LogEntry `db:"-" json:"log"` + Address types.Address `db:"address" json:"address"` + AddressRaw string `db:"address_raw" json:"address_raw"` + 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"` + Nuisance *Nuisance `db:"nuisance" json:"nuisance"` + PublicID string `db:"public_id" json:"public_id"` + Reporter types.Contact `db:"reporter" json:"reporter"` + Status string `db:"status" json:"status"` + Type string `db:"report_type" json:"type"` + Water *Water `db:"water" json:"water"` } func ReportsForOrganization(ctx context.Context, org_id int32) ([]*Report, error) { @@ -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