perliedman / leaflet-realtime

Put realtime data on a Leaflet map
ISC License
743 stars 167 forks source link

GeoJSON object not returning markers on map #162

Closed lrpatterson closed 4 years ago

lrpatterson commented 4 years ago

I have been working to pass source object to leaflet-realtime (great library by the way). I am currently using the below code but I do not get marks on the map.

I am essitially getting a json (which has data I need) matching it with the appropriate ID in the GeoJSON to create a new GeoJSON object PlaceGEOJSON. I have included a sample of the GeoJSON below as well. I have also checked that it is a valid GeoJSON(using: http://geojson.io/ and http://geojsonlint.com/). I am currently getting no console errors. What could cause this issue?

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 1, "geometry": { "type": "Point", "coordinates": [ -80.59772519496771, 35.49965363657394 ] }, "properties": { "OBJECTID": 1, "ID": "2", "NAME": "NEW HOPE LUTHERAN CHURCH", "NAME_1": "12341", "Waittime": "12", "Help Status": "0", "GenStatus": "Ready" } },

var realtimePlace = L.realtime(

        function(success, error) {
                try {
                    function PlaceLoc() {
                        return axios.get('.../Places.geojson');
                    }

                    function PlaceData() {
                        return axios.get('../RETRIEVE_TABLE_DASHBOARD_DATA.php');
                    }

                    axios.all([PlaceLoc(), PlaceData()])
                    .then(axios.spread(function (loc, data) {
                            var PlaceDataRestruct = {}
                            var PlaceGEOJSON = loc.data
                            var PlaceLocArray = PlaceGEOJSON.features
                            var PlaceDataArray = data.data
                            var result

                            PlaceDataArray.forEach(function(e, i){
                                PlaceDataRestruct[data.data[i].FKID.trim()] = {'Wait time' : data.data[i].WAITTIME, 'Help': data.data[i].SendHelp, 'GenStatus': data.data[i].STATUS}

                            });                                

                          PlaceLocArray.forEach(function(e, i){

                                var PlaceDataForMigration = PlaceDataRestruct[e.properties.NAME_1]

                                try {
                                    e.properties['Waittime'] = PlaceDataRestruct[e.properties.NAME_1]['Wait time']
                                } catch (error) {
                                    e.properties['Waittime'] = 'No wait data available'
                                }

                                try {
                                    e.properties['Help Status'] = PlaceDataRestruct[e.properties.NAME_1]['Help']
                                } catch (error) {
                                    e.properties['Help Status'] = '0'
                                }

                                try {
                                    e.properties['GenStatus'] = PlaceDataRestruct[e.properties.NAME_1]['GenStatus']
                                } catch (error) {
                                    e.properties['GenStatus'] = 'No Status'
                                }

                            });

                }));
                console.log(PlaceGEOJSON)
                success(PlaceGEOJSON)

                    } catch (e) {
                        error(e)
                    }

    }, {
        interval: 3000,

       getFeatureId: function(f){
           return f.properties.ID
       }

    }).addTo(map);