public void AddShipData(StaticAndVoyageRelatedDataMessage item) { if (ShipDatas.ContainsKey(item.Mmsi)) { ShipDatas[item.Mmsi].Add(item); } else { ShipDatas.Add(item.Mmsi, new List <AisMessage>() { item }); } }
public List <VesselInfo> GetAllShipInArea(List <LatLngLiteral> Area) { var list = new List <VesselInfo>(); try { foreach (var item in ShipPositions.Values) { PointXY loc; VesselInfo data = null; if (item[item.Count - 1] is PositionReportClassAMessage) { var obj = item[item.Count - 1] as PositionReportClassAMessage; if (!ShipDatas.ContainsKey(obj.Mmsi)) { continue; } var shipInfo = ShipDatas[obj.Mmsi].Last() as StaticAndVoyageRelatedDataMessage; loc = new PointXY(obj.Latitude, obj.Longitude); data = new VesselInfo() { Mmsi = obj.Mmsi, Lat = obj.Latitude, Course = obj.CourseOverGround, Dest = shipInfo.Destination, ETA = $"{shipInfo.EtaDay}/{shipInfo.EtaMonth} {shipInfo.EtaHour}:{shipInfo.EtaMinute}", Lng = obj.Longitude, ShipName = shipInfo.ShipName, Speed = obj.SpeedOverGround, Status = obj.NavigationStatus.ToString(), Direction = obj.TrueHeading }; } else if (item[item.Count - 1] is ExtendedClassBCsPositionReportMessage) { var obj = item[item.Count - 1] as ExtendedClassBCsPositionReportMessage; if (!ShipDatas.ContainsKey(obj.Mmsi)) { continue; } var shipInfo = ShipDatas[obj.Mmsi].Last() as StaticAndVoyageRelatedDataMessage; loc = new PointXY(obj.Latitude, obj.Longitude); data = new VesselInfo() { Mmsi = obj.Mmsi, Lat = obj.Latitude, Course = obj.CourseOverGround, Dest = shipInfo.Destination, ETA = $"{shipInfo.EtaDay}/{shipInfo.EtaMonth} {shipInfo.EtaHour}:{shipInfo.EtaMinute}", Lng = obj.Longitude, ShipName = shipInfo.ShipName, Speed = obj.SpeedOverGround, Status = "", Direction = obj.TrueHeading }; } if (data != null) { if (Area == null) { list.Add(data); } else if (GeoFence.PointInPolygon(new LatLngLiteral() { Lat = data.Lat, Lng = data.Lng }, Area)) { list.Add(data); } } } } catch (Exception ex) { Console.WriteLine("get ships error : " + ex.Message); } return(list); }