hotix for undefined data loads on map pages

This commit is contained in:
csawatzky 2025-10-21 10:44:46 -06:00
parent 7b78d7ba91
commit 46881f6656
5 changed files with 106 additions and 79 deletions

View file

@ -241,7 +241,7 @@ export default function MapBase(props: Props) {
homeMarkerAPI
.listHomeMarkers(1, 0, undefined, undefined, undefined, undefined, as)
.then(resp => {
if (resp.data.homeMarker.length < 1) {
if (!resp.data.homeMarker || resp.data.homeMarker.length < 1) {
setHomePin(undefined);
setHaveHome(false);
setStartingView(props.currentView);
@ -271,6 +271,7 @@ export default function MapBase(props: Props) {
}
})
.catch(err => {
console.log(err)
openSnack("Could not load Home Pin");
});
}, [as, homeMarkerAPI, openSnack, props.ignoreHomeLoad, user]); // eslint-disable-line react-hooks/exhaustive-deps

View file

@ -221,24 +221,26 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
.then(resp => {
let fields: Map<string, Field> = new Map();
let fieldEntries: Result[] = [];
resp.data.fields.forEach(f => {
let field = Field.any(f);
fields.set(field.key(), field);
fieldEntries.push({
id: field.key(),
place_name: field.name(),
place_type: ["field"],
center: [field.center().longitude, field.center().latitude],
address: "",
type: "Feature",
text: field.name(),
bbox: [0,0,0,0],
geometry: {type: "Point", coordinates: [field.center().longitude, field.center().latitude]},
context: [],
properties: {},
relevance: 0
if(resp.data.fields){
resp.data.fields.forEach(f => {
let field = Field.any(f);
fields.set(field.key(), field);
fieldEntries.push({
id: field.key(),
place_name: field.name(),
place_type: ["field"],
center: [field.center().longitude, field.center().latitude],
address: "",
type: "Feature",
text: field.name(),
bbox: [0,0,0,0],
geometry: {type: "Point", coordinates: [field.center().longitude, field.center().latitude]},
context: [],
properties: {},
relevance: 0
});
});
});
}
setFields(fields);
setFieldSearchEntries(fieldEntries);
})
@ -314,53 +316,56 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
let bagOp: BagModel[] = [];
let bagMarkerData: Map<string, MarkerData> = new Map();
let bagEntries: Result[] = [];
resp.data.grainBags.forEach(bag => {
let b = BagModel.create(bag);
bags.set(b.key(), b);
if (bag.settings) {
if (!b.settings.startLocation?.longitude && !b.settings.endLocation?.longitude) {
bagOp.push(b);
} else {
//build the data for the marker
//TODO-CS: think about making the creation of marker data a function in the object model
let mData: MarkerData = {
title: b.name(),
longitude: b.centerLocation().longitude,
latitude: b.centerLocation().latitude,
visibleLevels: { max: 13 },
colour: b.settings.theme?.color ?? "white",
clickFunc: (e, i, isMobile) => {
clickDelay();
closeDrawers();
setBagDrawer(true);
setIgnoreFeatures(true);
setObjectKey(b.key());
moveMap(
b.centerLocation().latitude,
b.centerLocation().longitude,
zoomLevels.far,
isMobile
);
}
};
bagMarkerData.set(b.key(), mData);
bagEntries.push({
center: [b.centerLocation().longitude, b.centerLocation().latitude],
id: b.key(),
place_name: b.name(),
place_type: ["grainBag"],
address: "",
bbox: [0,0,0,0],
context: [],
geometry: {type: "Point", coordinates: [b.centerLocation().longitude, b.centerLocation().latitude]},
properties: {},
relevance: 0,
text: "",
type: "Feature"
});
if(resp.data.grainBags){
resp.data.grainBags.forEach(bag => {
let b = BagModel.create(bag);
bags.set(b.key(), b);
if (bag.settings) {
if (!b.settings.startLocation?.longitude && !b.settings.endLocation?.longitude) {
bagOp.push(b);
} else {
//build the data for the marker
//TODO-CS: think about making the creation of marker data a function in the object model
let mData: MarkerData = {
title: b.name(),
longitude: b.centerLocation().longitude,
latitude: b.centerLocation().latitude,
visibleLevels: { max: 13 },
colour: b.settings.theme?.color ?? "white",
clickFunc: (e, i, isMobile) => {
clickDelay();
closeDrawers();
setBagDrawer(true);
setIgnoreFeatures(true);
setObjectKey(b.key());
moveMap(
b.centerLocation().latitude,
b.centerLocation().longitude,
zoomLevels.far,
isMobile
);
}
};
bagMarkerData.set(b.key(), mData);
bagEntries.push({
center: [b.centerLocation().longitude, b.centerLocation().latitude],
id: b.key(),
place_name: b.name(),
place_type: ["grainBag"],
address: "",
bbox: [0,0,0,0],
context: [],
geometry: {type: "Point", coordinates: [b.centerLocation().longitude, b.centerLocation().latitude]},
properties: {},
relevance: 0,
text: "",
type: "Feature"
});
}
}
}
});
});
}
setBagOptions(bagOp);
setGrainBags(bags);
grainBagsRef.current = bags;
@ -382,19 +387,21 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
binYardAPI
.listBinYards(400, 0, "asc", undefined, undefined, undefined, as)
.then(resp => {
resp.data.yard.forEach(yard => {
if (yard.settings) {
yardMap.set(yard.settings.key, yard.settings);
if (
(!yard.settings.latitude && !yard.settings.longitude) ||
(yard.settings.latitude === 0 && yard.settings.longitude === 0)
) {
yardOps.push(yard.settings);
} else {
let mData: MarkerData = {
title: yard.settings.name,
longitude: yard.settings.longitude,
latitude: yard.settings.latitude,
if(resp.data.yard){
resp.data.yard.forEach(yard => {
if (yard.settings) {
yardMap.set(yard.settings.key, yard.settings);
if (
(!yard.settings.latitude && !yard.settings.longitude) ||
(yard.settings.latitude === 0 && yard.settings.longitude === 0)
) {
yardOps.push(yard.settings);
} else {
let mData: MarkerData = {
title: yard.settings.name,
longitude: yard.settings.longitude,
latitude: yard.settings.latitude,
colour: yard.settings.theme?.color ?? "green",
markerIcon: <BinsIcon width={50 * 0.6} height={50 * 0.6} type="light" />,
visibleLevels: { max: 17 },
@ -429,6 +436,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
}
}
});
}
setYardMarkerData(newYardMarkers);
setYardSearchEntries(yardEntries);
setBinYards(yardMap);
@ -447,6 +455,9 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
let markerData: Map<string, MarkerData> = new Map();
let searchEntries: Result[] = [];
let binOp: IBin[] = [];
if(resp.data.bins){
resp.data.bins.forEach(bin => {
let b = IBin.create(bin);
binMap.set(b.key(), b);
@ -495,6 +506,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
}
}
});
}
setBinMarkerData(markerData);
setBinSearchEntries(searchEntries);
setBins(binMap);
@ -514,6 +526,9 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
let searchEntries: Result[] = [];
let options: DeviceModel[] = [];
if(resp.data.devices){
resp.data.devices.forEach((device, i) => {
//add device to the main map
let d = DeviceModel.any(device);
@ -553,6 +568,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
}
}
});
}
setDevices(map);
setDeviceOptions(options);
setDeviceMarkerData(newDevMarkers);
@ -725,6 +741,9 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
let fmMap: Map<string, FieldMarker> = new Map();
let markerData: Map<string, MarkerData> = new Map();
let searchEntries: Result[] = [];
if(resp.data.fieldMarker){
resp.data.fieldMarker.forEach(fieldMarker => {
let fm = FieldMarker.create(fieldMarker);
fmMap.set(fm.key(), fm);
@ -750,7 +769,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
});
setAnchorFieldMarker(event.currentTarget);
setFMIndexKey(index);
setObjectKey(fm.key());
setObjectKey(fm.key());
}
});
searchEntries.push({
@ -760,6 +779,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
place_type: ["fieldMarker"]
} as Result);
});
}
setFieldMarkers(fmMap);
setFieldMarkerData(markerData);
setFieldMarkerSearchEntries(searchEntries);

View file

@ -175,6 +175,7 @@ export default function AviationMapController(props: Props) {
let terminalMarkers: Map<string, MarkerData> = new Map();
let terminalOps: Terminal[] = [];
let searchEntries: Result[] = [];
if(resp.data.terminals){
resp.data.terminals.forEach(term => {
let terminal = Terminal.create(term);
terminalMap.set(terminal.key, terminal);
@ -207,6 +208,7 @@ export default function AviationMapController(props: Props) {
terminalOps.push(terminal);
}
});
}
setTerminals(terminalMap);
setTerminalMarkers(terminalMarkers);
setTerminalSearchEntries(searchEntries);

View file

@ -142,6 +142,7 @@ export default function ConstructionMapController(props: Props) {
siteAPI
.listSitesPageData(50, 0, "asc", "key", undefined, as)
.then(resp => {
if(resp.data.sites){
resp.data.sites.forEach(site => {
if (!site) return;
let newSite: Site = Site.any(site.site);
@ -179,6 +180,7 @@ export default function ConstructionMapController(props: Props) {
place_type: ["site"]
} as Result);
});
}
setSiteMarkerData(sm);
setSites(s);
setLoadingSites(false);

View file

@ -182,7 +182,9 @@ export default function Terminals(props: Props) {
if(loading) return
setLoading(true)
terminalAPI.listTerminals(200, 0, "asc", "name", as).then(resp => {
setTerminals(resp.data.terminals.map(a => Terminal.any(a)));
if(resp.data.terminals){
setTerminals(resp.data.terminals.map(a => Terminal.any(a)));
}
}).catch(err => {
console.log("There was a problem loading Terminals")
}).finally(() => {