예제 #1
0
        /// <summary>
        /// Handles the collection restriction before evaluating the result
        /// </summary>
        /// <param name="collection">A collection to further restrict</param>
        /// <returns>A further restricted collection</returns>
        private FeatureCollection RestrictedCollection(FeatureCollection collection)
        {
            if (collection != null && LiteClientSettingsViewModel.Instance.QueriesUseRestrictionAreas)
            {
                // Check whether we can restrict the collection
                var message = new LiteRestrictFeatureCollectionRequestMessage(this, collection);

                // Ask other viewModels via the messenger
                Messenger.Send(message);

                // Get the restricted collection from the message
                collection = message.RestrictedCollection;
            }

            return(collection);
        }
        /// <summary>
        /// Handle the restriction of a feature collection
        /// </summary>
        private void HandleRestrictFeatureCollection(LiteRestrictFeatureCollectionRequestMessage restrictionRequest)
        {
            // The sample behavior is to restrict the collection based on the MapLayerAreas that have been
            // set up for this user (its groups). In case there are restriction areas set up, the extra restriction
            // will be set on geometry fields that are set up in the restriction data collection

            // Restrict the Town collection
            var restrictionGeometry = LiteClientSettingsViewModel.Instance.RestrictionGeometry;
            var sourceCollection    = restrictionRequest.RestrictedCollection;

            if (restrictionGeometry != null && sourceCollection != null)
            {
                var table = sourceCollection.TableDescriptor;
                if (table != null)
                {
                    string fieldName;
                    if (_tableFieldNamesToRestrictByArea.TryGetValue(table.Name, out fieldName))
                    {
                        // Do explicit restriction via the table/field combination
                        var coverageField = table.FieldDescriptors[fieldName];
                        if (coverageField != null && coverageField.IsGeometry)
                        {
                            var extraRestriction = glf.Spatial.Interacts(glf.Data.Field(coverageField), glf.Constant(restrictionGeometry));
                            restrictionRequest.RestrictedCollection = sourceCollection.Where(extraRestriction);
                        }
                    }
                    else if (IncludeDefaultRestrictions)
                    {
                        // Try to restrict by investigating the geometry fields of the collection
                        // If there is a GeoGraphic field, let's try and restrict the lot according to our areas
                        if (table.FieldDescriptors.FirstOrDefault(f =>
                        {
                            var geometryField = f as FeatureGeometryFieldDescriptor;
                            return(geometryField != null && geometryField.IsSelectableGeometry && geometryField.IsGeographic);
                        }) != null)
                        {
                            var extraRestriction = glf.Function(SpatialEye.Framework.Features.Expressions.GeoLinqExpressionType.SpatialAnyInteracts, glf.Data.Table(table), glf.Constant(restrictionGeometry));
                            restrictionRequest.RestrictedCollection = sourceCollection.Where(extraRestriction);
                        }
                    }
                }
            }
        }