/// <summary> /// Returns a LiteNwFeatureRequestMessage for this item /// </summary> internal LiteNewFeatureRequestMessage ToNewFeatureRequest(FeatureTargetGeometry forceAttachFeature = null) { LiteNewFeatureRequestMessage request = null; var doAttachTo = forceAttachFeature ?? AttachTo; var allowActivation = true; if (IsAttachRequired && doAttachTo == null) { allowActivation = false; } if (allowActivation) { var table = TableDescriptor; var primaryField = PrimaryGeometryDescriptor; SpatialEye.Framework.Geometry.IFeatureGeometry startWithGeometry = CandidateStartWithGeometry; if (startWithGeometry != null) { if (primaryField == null || primaryField.FieldType != startWithGeometry.GeometryType) { startWithGeometry = null; } } var attachToFeature = doAttachTo != null ? doAttachTo.Feature : null; request = new LiteNewFeatureRequestMessage(this, table, primaryField, startWithGeometry, attachToFeature); } return(request); }
/// <summary> /// Sets a potential attachment /// </summary> internal void SetAttachmentCandidate(Collection <FeatureTargetGeometry> targetGeometryCollection) { if (IsAttachPossible) { FeatureTargetGeometry newTo = null; // Set the target geometry from the full collection of candidates var attachCandidate = targetGeometryCollection != null && targetGeometryCollection.Count == 1 ? targetGeometryCollection[0] : null; if (attachCandidate != null) { var candidateTables = TableDescriptor.CandidateTableDescriptorsForAttach(); if (candidateTables != null) { foreach (var attach in candidateTables) { if (attachCandidate.Feature.TableDescriptor.Name == attach.Name) { newTo = attachCandidate; } } } } AttachTo = newTo; CalculateState(); } }
/// <summary> /// Constructs the request to jump to specified envelope of the feature /// </summary> /// <param name="sender">The originator of the request</param> /// <param name="envelope">The extent to jump to</param> /// <param name="feature">The feature that the extent belongs to</param> public LiteGoToGeometryRequestMessage(Object sender, FeatureTargetGeometry targetGeometry) : base(sender) { this.Description = DescriptionFor(targetGeometry.Feature); this.Envelope = targetGeometry.Envelope; this.StoreInHistory = false; this.DoRocketJump = true; this.DoHighlight = false; this.HighlightFeatureTargetGeometry = targetGeometry; }
/// <summary> /// Select an element on the map /// </summary> private async void SelectElement(FeatureTargetGeometry element) { var map = CurrentMap; if (map != null) { // Allow the UI to finish its current action await TaskFunctions.Yield(); // Set the map selection directly (we could have done this via the messenger as well) // An example of a tighter coupling, using the API of the MapViewModel directly map.SelectedFeatureGeometry.Set(element); } }
/// <summary> /// Constructs the request to highlight a specified geometry on the active map /// </summary> /// <param name="sender">The originator of the request</param> /// <param name="targetGeometry">The geometry to highlight on the map</param> public LiteHighlightGeometryRequestMessage(Object sender, IFeatureGeometry geometry) : base(sender) { if (geometry == null) { throw new ArgumentException("Invalid geometry"); } // Create a feature for the geometry var feature = new Feature(GeometryTableDescriptor(geometry.GeometryType), new object[] { geometry }); // Create a feature target geometry for this feature, with the specified geometry selected FeatureTargetGeometry = new FeatureTargetGeometry(feature, 0); }
/// <summary> /// Handler for custom selection request /// </summary> /// <param name="message">The custom selection request</param> private async void HandleCustomSelectionRequest(LiteCustomSelectionRequestMessage message) { if (message.Args != null) { // Get the table var table = await EnsureTableDescriptorAsync(); if (table != null) { // Get the field descriptor var field = table.FieldDescriptors[FieldName] as FeatureGeometryFieldDescriptor; // Build up the predicate var searchLocation = message.Args.Location; // CS( 3785 ) var csExpression = glf.Function(GeoLinqExpressionType.SpatialCS, glf.Constant(searchLocation.CoordinateSystem.EPSGCode)); // Point( CS(3785), X, Y) var locationExpression = glf.Function(GeoLinqExpressionType.SpatialPoint, csExpression, glf.Constant(searchLocation.Coordinate.X), glf.Constant(searchLocation.Coordinate.Y)); // <field>.WithinDistance(Point( CS(3785), X, Y), 100.0) var predicate = glf.Spatial.WithinDistance(glf.Data.Field(field), locationExpression, MaxDistance); // Get the resulting elements (only 100) var result = await table.Collection.Where(predicate).Take(100).EvaluateAsync(); if (result != null && result.Count > 0) { // Filter by getting the closest only (could use them all if interesting) // Initiate vars for getting the closest double foundDistance = double.MaxValue; Feature foundFeature = null; IFeatureGeometry foundGeometry = null; foreach (var element in result) { // Get the geometry and its distance to our search location var geometry = element[FieldName] as IFeatureGeometry; var testDistance = geometry.DistanceTo(searchLocation); // If closer than the last closest, set as current if (geometry != null && testDistance < foundDistance) { foundFeature = element; foundDistance = testDistance; foundGeometry = geometry; } } // If we've found a feature, select it on the Map that the request took place on if (foundFeature != null) { var target = new FeatureTargetGeometry(foundFeature, field, foundGeometry); message.Map.SelectedFeatureGeometry.Set(target); } } } } }
/// <summary> /// Constructs the request to highlight a specified geometry on the active map /// </summary> /// <param name="sender">The originator of the request</param> /// <param name="targetGeometry">The geometry to highlight on the map</param> public LiteHighlightGeometryRequestMessage(Object sender, FeatureTargetGeometry targetGeometry) : base(sender) { this.FeatureTargetGeometry = targetGeometry; }