Exemple #1
0
        private static (Operation operation, OperationMxProcessing operationPrescription) BuildTheGeoJsonOutput(RuleResult collectRuleResult, List <Value> values, Operation buildGeoJsonOperation = null)
        {
            var cityCount = values.Count;

            // Build the Javascript template for creating the entire GeoJSON Value
            var valueBody = "{\"type\":\"FeatureCollection\",\"features\":[";

            for (var ix = 0; ix < cityCount; ix++)
            {
                if (ix > 0)
                {
                    valueBody += ",";
                }
                valueBody += $"${{{ix}}}";
            }
            valueBody += "]}";
            var valueTemplate = $"{{JSON.parse('{valueBody}')}}";

            // Add an Operation to reference the collect Rule and merge all of the results into one GeoJSON
            if (buildGeoJsonOperation == null)
            {
                var opKey = values.OperandKey(EntityType.Value);

                buildGeoJsonOperation = collectRuleResult.CreateUpdateOperation(new[] { opKey }, GuidHelpers.NewTimeUuid(), valueTemplate);
            }
            else
            {
                var opKey = values.OperandKey(EntityType.Value, buildGeoJsonOperation.Operands[0].EntityId);

                buildGeoJsonOperation =
                    buildGeoJsonOperation.RecreateUpdateOperation(collectRuleResult, new[] { opKey }, valueTemplate);
            }

            var buildGeoJsonPrescription = buildGeoJsonOperation.AddUpdate();

            return(buildGeoJsonOperation, buildGeoJsonPrescription);
        }