private Dictionary <string, object> CreateGeoJsonProperties(VehicleLocation location)
        {
            DateTime datetime = CreateLocalTimestamp(location);

            var properties = new Dictionary <string, object>();

            properties.Add("heading", location.Heading);
            properties.Add("colour", _routeColourService.Get(location.ServiceName)?.Colour);
            properties.Add("text_colour", _routeColourService.Get(location.ServiceName)?.TextColor);
            properties.Add("name", location.ServiceName);
            properties.Add("vehicleId", location.VehicleId);
            properties.Add("last_update", datetime.ToString());
            properties.Add("destination", location.Destination);
            return(properties);
        }
Exemple #2
0
        public async void OnNext(VehicleLocation[] vehicleUpdates)
        {
            if (vehicleUpdates == null)
            {
                return;
            }
            foreach (var update in vehicleUpdates)
            {
                var             vehicleId = update.VehicleId;
                VehicleLocation existingRecord;
                var             recordExists = _latest.TryGetValue(vehicleId, out existingRecord);

                if (!recordExists)
                {
                    _latest.TryAdd(vehicleId, update);
                }

                if (update.LastGpsFix > existingRecord?.LastGpsFix && (update.ServiceName != null || update.JourneyId != null))
                {
                    var timestamp  = CreateLocalTimestamp(update);
                    var properties = new Dictionary <string, object>();
                    properties.Add("heading", update.Heading);
                    properties.Add("colour", _routeColourService.Get(update.ServiceName)?.Colour);
                    properties.Add("text_colour", _routeColourService.Get(update.ServiceName)?.TextColor);
                    properties.Add("name", update.ServiceName);
                    properties.Add("vehicleId", update.VehicleId);
                    properties.Add("last_update", timestamp);
                    properties.Add("destination", update.Destination);

                    var position   = new Position(update.Longitude, update.Latitude);
                    var point      = new Point(position);
                    var feature    = new Feature(point, properties);
                    var collection = new FeatureCollection(new List <Feature> {
                        feature
                    });

                    await _hubContext.Clients.All.SendAsync("ReceiveMessage", collection.ToJson());

                    _latest[vehicleId] = update;
                }
            }
        }