public IActionResult Test() { var cord = new GeoJsonClasses.LocalGeometry(); cord.coordinates.Add(46.94797); cord.coordinates.Add(7.44745); cord.type = "Point"; var geoJson = new GeoJsonClasses.GeoJson { type = "FeatureCollection", features = new List <GeoJsonClasses.LocalFeature>(new[] { new GeoJsonClasses.LocalFeature() { type = "Feature", geometry = cord } }), }; return(new JsonResult(geoJson)); }
public async Task <GeoJsonClasses.GeoJson> GetVehicles() { string url = "https://tdi.bernmobil.ch:12180/tdinterface/PatternTDI"; PatternTdiArray patterns = null; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Accept", "application/x-protobuf"); //Setting up the response... using (HttpResponseMessage res = await client.GetAsync(url)) using (HttpContent content = res.Content) { var stream = await content.ReadAsStreamAsync(); if (stream != null) { try { patterns = Serializer.Deserialize <PatternTdiArray>(stream); } catch (Exception e) { Console.Write(e.Message); } } } } string baseUrl = "https://tdi.bernmobil.ch:12180/tdinterface/VehicleTDI"; //The 'using' will help to prevent memory leaks. //Create a new instance of HttpClient using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Accept", "application/x-protobuf"); //Setting up the response... using (HttpResponseMessage res = await client.GetAsync(baseUrl)) using (HttpContent content = res.Content) { var stream = await content.ReadAsStreamAsync(); if (stream != null) { VehicleTdiArray veh; try { veh = Serializer.Deserialize <VehicleTdiArray>(stream); var geoJson = new GeoJsonClasses.GeoJson { type = "FeatureCollection", features = new List <GeoJsonClasses.LocalFeature>(), }; veh.vehicleTdiArrays.ForEach(x => { var cord = new GeoJsonClasses.LocalGeometry(); cord.coordinates.Add(Convert.ToSingle(x.Longitude) / 3600000); cord.coordinates.Add(Convert.ToSingle(x.Latitude) / 3600000); cord.type = "Point"; var details = VehicleDetailsService.Instance.Details.FirstOrDefault(y => y.Id == x.VehicleNumber); List <Properties> properties = null; if (details != null) { properties = new List <Properties> { new Properties() { id = "Beschreibung", address = details.Beschreibung }, new Properties() { id = "Vehiclenumber", address = details.Id.ToString() }, new Properties() { id = "Bemerkung", address = details.Besonderheiten?.Bemerkungen }, new Properties() { id = "Category", address = MapCategory(x, details) }, new Properties() { id = "Linie", address = patterns.patternTdiArrays.FirstOrDefault(y => y.Duid == x.PatternDuid?.Duid)?.ShortName } }; } geoJson.features.Add(new GeoJsonClasses.LocalFeature() { type = "Feature", geometry = cord, properties = properties }); }); return(geoJson); } catch (Exception e) { Console.Write(e.Message); } } } } return(null); }