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

Cannot read properties of null (reading 'toString') #1

Open
abewartech opened this issue Dec 13, 2023 · 1 comment
Open

Cannot read properties of null (reading 'toString') #1

abewartech opened this issue Dec 13, 2023 · 1 comment
Assignees

Comments

@abewartech
Copy link

abewartech commented Dec 13, 2023

aismaps.js:40 Error fetching AIS data: TypeError: Cannot read properties of null (reading 'toString')
    at Ei (aisTrackSymbol.ts:373:25)
const aisItem = {
    "id": 373001,
    "sensor_data_id": 419208,
    "vessel_id": 1222,
    "latitude": "-9.6449217",
    "longitude": "114.7692100",
    "speed": "11.50",
    "course": 54,
    "heading": 53,
    "navigation_status": "Under way using engine",
    "turning_rate": 0,
    "is_inside_geofence": null,
    "turning_direction": 1,
    "timestamp": "2023-12-13 04:20:48",
    "distance": "513.63",
    "created_at": "2023-12-13T04:20:48.000000Z",
    "updated_at": "2023-12-13T04:20:48.000000Z",
    "vessel": {
        "id": 1222,
        "vessel_name": null,
        "vessel_type": null,
        "mmsi": "636093023",
        "imo": null,
        "callsign": null,
        "draught": null,
        "dimension_to_bow": null,
        "dimension_to_stern": null,
        "dimension_to_port": null,
        "dimension_to_starboard": null,
        "reported_destination": null,
        "out_of_range": "0",
        "type_number": null,
        "reported_eta": null,
        "created_at": "2023-12-13T04:20:48.000000Z",
        "updated_at": "2023-12-13T04:20:48.000000Z"
    },
    "sensor_data": {
        "id": 419208,
        "sensor_id": 1,
        "payload": "!ABVDM,1,1,,B,19N`2Gh0Ak8=GjerNjej61cN00Ra,0*02",
        "timestamp": "2023-12-13 04:20:48",
        "created_at": "2023-12-13T04:20:48.000000Z",
        "updated_at": "2023-12-13T04:20:48.000000Z",
        "sensor": {
            "id": 1,
            "datalogger_id": 1,
            "name": "AIS",
            "status": "Active",
            "interval": 5,
            "jarak": 20,
            "jumlah_data": 200,
            "created_at": "2023-12-02T09:16:49.000000Z",
            "updated_at": "2023-12-02T09:16:49.000000Z",
            "datalogger": {
                "id": 1,
                "name": "Datalogger 1",
                "serial_number": "DL001",
                "latitude": "-6.2256992",
                "longitude": "106.8503082",
                "status": "Online",
                "installation_date": "2022-01-01",
                "last_online": "2023-05-24 12:34:56",
                "coverage": null,
                "created_at": "2023-12-02T09:16:49.000000Z",
                "updated_at": "2023-12-02T09:16:49.000000Z"
            }
        }
    }
};
const p1 = [+aisItem.latitude || 0, +aisItem.longitude || 0];
        const trueHeading1 = aisItem.heading || 0;
        const cog1 = aisItem.course || 0;
        const sog1 = +aisItem.speed || 0;

        // Creating the PositionReport
        let positionReport1 = {
            latitude: p1[0],
            longitude: p1[1],
            trueHeading: trueHeading1,
            cog: cog1,
            sog: sog1,
        };

        const aisTrackSymbol = new L.AISTrackSymbol(positionReport1, {
            shipStaticData: {
                userId: aisItem.vessel.id || 0,
                imoNumber: aisItem.vessel.imo || 0,
                callSign: aisItem.vessel.callsign || "",
                name: aisItem.vessel.vessel_name || "",
                type: aisItem.vessel.type_number || 0,
                dimension: {
                    A: aisItem.vessel.dimension_to_bow || 0,
                    B: aisItem.vessel.dimension_to_stern || 0,
                    C: aisItem.vessel.dimension_to_port || 0,
                    D: aisItem.vessel.dimension_to_starboard || 0,
                },
                fixType: aisItem.vessel.out_of_range || 0,
                eta: {
                    month: aisItem.vessel.reported_eta
                        ? new Date(aisItem.vessel.reported_eta).getMonth() + 1
                        : null,
                    day: aisItem.vessel.reported_eta
                        ? new Date(aisItem.vessel.reported_eta).getDate()
                        : null,
                    hour: aisItem.vessel.reported_eta
                        ? new Date(aisItem.vessel.reported_eta).getHours()
                        : null,
                    minute: aisItem.vessel.reported_eta
                        ? new Date(aisItem.vessel.reported_eta).getMinutes()
                        : null,
                },
                destination: aisItem.vessel.reported_destination || "",
                dte: aisItem.vessel.dte === "1",
            },
        });
        aisTrackSymbol.bindTooltip(aisItem.vessel.vessel_name || "");
        aisTrackSymbol.addTo(map);

Tasks

Preview Give feedback
No tasks being tracked yet.
@ngyewch ngyewch self-assigned this Dec 15, 2023
@ngyewch
Copy link
Member

ngyewch commented Dec 15, 2023

Candidate fix: v0.1.4

Cause:

  • ETA objects with null/undefined property values
    • In this case: { month: null, day: null, hour: null, minute: null }
    • v0.1.4 handles this case

Notes:

  • New helper method: AISTrackSymbol.etaFromDate(date: Date | null | undefined): ETA
    • Example: aisItem.vessel.reported_eta ? AISTrackSymbol.etaFromDate(new Date(aisItem.vessel.reported_eta)) : undefined
      `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants