public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; using (var outputStream = new StreamWriter(context.Response.OutputStream)) { var cesiumWriter = new CesiumStreamWriter(); var output = new CesiumOutputStream(outputStream); output.PrettyFormatting = true; // The whole body of CZML must be wrapped in a JSON array, opened here. output.WriteStartSequence(); // The first packet (JSON object) of CZML must be the document packet. using (var entity = cesiumWriter.OpenPacket(output)) { entity.WriteId("document"); entity.WriteVersion("1.0"); } // write an entity for each rocket launch phase var rocketData = new RocketTrajectoryData(); var entities = rocketData.GetBetterRocketData(); // get each phase foreach (var stage in entities.stages) { var cartesianVelocitySet = GenerateCartesianVelocitySet(stage); var clr = GetNextColour(); var count = 0; foreach (var positions in cartesianVelocitySet.Item2) { count++; if (count % 100 == 0) { using (var packet = cesiumWriter.OpenPacket(output)) { using (var point = packet.OpenPointProperty()) { point.WriteColorProperty(Color.Yellow); point.WritePixelSizeProperty(10.0); } using (var desc = packet.OpenDescriptionProperty()) { desc.WriteString("x,y,z:" + positions.Value.ToString()); } using (var position = packet.OpenPositionProperty()) { position.WriteCartesian(positions.Value); } } } } using (var packet = cesiumWriter.OpenPacket(output)) { packet.WriteId("RocketLaunch"); using (var position = packet.OpenPositionProperty()) { position.WriteCartesianVelocity(cartesianVelocitySet.Item1, cartesianVelocitySet.Item2); } using (var description = packet.OpenDescriptionProperty()) { description.WriteString("This is the description of this element"); } using (var path = packet.OpenPathProperty()) { using (var material = path.OpenMaterialProperty()) { using (var outline = material.OpenSolidColorProperty()) { using (var colour = outline.OpenColorProperty()) { colour.WriteRgba(Color.DarkGoldenrod); } } } path.WriteWidthProperty(8); path.WriteLeadTimeProperty(10); path.WriteTrailTimeProperty(1000); path.WriteResolutionProperty(5); } } } output.WriteEndSequence(); } }
// convert the distance of the downrange into a distance from the launch site, at a specific trajectory /// <summary> /// This handles the HTTP request by writing some example CZML into the response. /// </summary> /// <param name="context">The current HttpContext</param> public void ProcessRequest(HttpContext context) { // A more complex example could examine context.Request here for // inputs coming from the client-side application. // Set the response type for CZML, which is JSON. context.Response.ContentType = "application/json"; // Create an output stream writer for the response. using (var outputStream = new StreamWriter(context.Response.OutputStream)) { var cesiumWriter = new CesiumStreamWriter(); var output = new CesiumOutputStream(outputStream); // Since this is a demo, turning on PrettyFormatting makes the response easier to view // with web browser developer tools. It just adds whitespace and newlines to the response, // so production environments would typically leave this turned off. output.PrettyFormatting = true; // The whole body of CZML must be wrapped in a JSON array, opened here. output.WriteStartSequence(); // The first packet (JSON object) of CZML must be the document packet. using (var entity = cesiumWriter.OpenPacket(output)) { entity.WriteId("document"); entity.WriteVersion("1.0"); } using (var entity = cesiumWriter.OpenPacket(output)) { entity.WriteId("canavitem"); using (var pos = entity.OpenPositionProperty()) { pos.WriteCartesian(CesiumDataManager.GetBaseCartesian()); } using (var point = entity.OpenPointProperty()) { point.WriteColorProperty(Color.Aqua); point.WritePixelSizeProperty(10.0); } } rocketData = new RocketTrajectoryData(); var entities = rocketData.GetStandardRocketTrajectoryData(); var cartList = new List <Cartesian>(); var dateList = new List <JulianDate>(); var now = DateTime.Now; for (int i = 0; i < entities.data[2].x.Count; i++) { var cartesian = CesiumDataManager.GenerateCartesian(entities.data[2].x[i], entities.data[2].y[i]); cartList.Add(cartesian); var julDate = new JulianDate(now + TimeSpan.FromSeconds(i * 2)); dateList.Add(julDate); } using (var thisEntity = cesiumWriter.OpenPacket(output)) { thisEntity.WriteId("testpath"); thisEntity.WriteDescriptionProperty("rocket launch path"); using (var position = thisEntity.OpenPositionProperty()) { position.WriteCartesian(dateList, cartList); position.WriteReferenceFrame("#referenceitem"); } //using (var model = thisEntity.OpenModelProperty()) //{ // model.WriteGltfProperty(new Uri("http://localhost:56332/Models/CesiumAir/Cesium_Air.gltf"),CesiumResourceBehavior.Embed); //} using (var path = thisEntity.OpenPathProperty()) { using (var material = path.OpenMaterialProperty()) { using (var outline = material.OpenSolidColorProperty()) { using (var colour = outline.OpenColorProperty()) { colour.WriteRgba(Color.DarkSeaGreen); } } } path.WriteWidthProperty(8); path.WriteLeadTimeProperty(10); path.WriteTrailTimeProperty(1000); path.WriteResolutionProperty(5); } } // Close the JSON array that wraps the entire CZML document. output.WriteEndSequence(); } }