// TODO: Restrict to get and post. public object Any(FeatureLayerQuery request) { // Parse the object IDs into ints, if provided. Otherwise the value will be null. var objectIds = !string.IsNullOrWhiteSpace(request.objectIds) ? from s in Regex.Split(request.objectIds, @"\s*,\s*") select int.Parse(s) : null; object output; if (request.LayerId == _cameraLayerId) { //output = GetCameras(objectIds, request.outSR).ToResponse(request); // Return cameras grouped by point location. Many cameras are in the same point. int objectId = 0; output = from g in (from c in GetCameras(objectIds, request.outSR) group c by c.CameraLocation.ToPoint(false, request.outSR)) select new { geometry = g.Key, attributes = new { ObjectId = objectId++, cameras = g } }; } else { // throw new ArgumentException(string.Format("The specified LayerID is invalid: {0}.", request.LayerId)); output = new { code = 500, error = string.Format("The specified LayerID is invalid: {0}.", request.LayerId) }; } if (!string.IsNullOrWhiteSpace(request.f) && Regex.IsMatch(request.f, @"p?json", RegexOptions.IgnoreCase)) { this.Response.ContentType = "application/json"; output = JsonSerializer.SerializeToString <object>(output); } return(output); }
////public static Feature ToFeature(this ITrafficFeature trafficFeature) ////{ //// Type type = trafficFeature.GetType(); //// // Get a list of all of the properties of the traffic feature. //// PropertyInfo[] properties = type.GetProperties(); //// var attributes = (from prop in properties //// where prop.PropertyType.IsValueType //// select prop).ToDictionary(k => k.Name, pi => pi.GetValue(trafficFeature, null)); //// var roadwayLocation = properties.First(prop => prop.PropertyType == typeof(RoadwayLocation)).GetValue(trafficFeature, null) as RoadwayLocation; //// return new Feature //// { //// attributes = attributes, //// geometry = roadwayLocation != null ? roadwayLocation.ToPoint() : null //// }; ////} public static FeatureLayerQueryResponseBase ToResponse(this IEnumerable <Camera> trafficFeatures, FeatureLayerQuery request) { // Parse the object IDs into ints, if provided. Otherwise the value will be null. var objectIds = !string.IsNullOrWhiteSpace(request.objectIds) ? from s in Regex.Split(request.objectIds, @"\s*,\s*") select int.Parse(s) : null; if (request.returnCountOnly == true && objectIds == null) { return(new FeatureLayerQueryCountResponse { count = trafficFeatures.Count() }); } else if (request.returnIdsOnly == true && objectIds == null) { return(new FeatureLayerQueryObjectIdsResponse { objectIdFieldName = "CameraID", objectIds = from c in trafficFeatures select c.CameraID }); } else { return(new FeatureLayerQueryResponse { features = trafficFeatures.Select(c => c.ToFeature(outSR: request.outSR)), }); } }