/// <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> /// Sets the last selected trail /// </summary> private void SetSelectedTrail(Collection <FeatureTargetGeometry> selectedElements) { IFeatureGeometry selectedTrail = null; if (selectedElements.Count == 1) { var selection = selectedElements[0]; selectedTrail = LiteMapTrailViewModel.IsTrailFeature(selection.Feature) ? selection.TargetGeometry : null; } var items = Items; if (items != null) { foreach (var item in items) { item.CandidateStartWithGeometry = selectedTrail; } } }
/// <summary> /// Handle an activation request for geometry; actually transforming this into a new Go-To request on the databus /// </summary> private void HandleGeometryActivation(object sender, Feature feature, FeatureFieldDescriptor featureFieldDescriptor, IFeatureGeometry geometry) { if (geometry != null) { var geometryField = featureFieldDescriptor as FeatureGeometryFieldDescriptor; var envelope = geometry.Envelope; if (envelope != null && feature != null) { var request = new LiteGoToGeometryRequestMessage(sender, new FeatureTargetGeometry(feature, geometryField, geometry)) { DoHighlight = true, StoreInHistory = true }; Messenger.Send(request); } } }
/// <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> /// Returns the fields to be displayed for the specified feature and hovered geometry. /// Should return null in case no information should be displayed for this table /// </summary> /// <param name="feature">The feature to return fields for</param> /// <param name="geometry">The geometry being hovered</param> /// <returns>The fields to display information for</returns> protected override IEnumerable <FeatureFieldDescriptor> FieldsFor(Feature feature, IFeatureGeometry geometry) { // Get the table descriptor var tableDescriptor = feature.TableDescriptor; // Get all fields of the table descriptor var fields = tableDescriptor.FieldDescriptors; // filter the fields to only include visible alphanumeric fields return(fields.FindAll(a => a.FieldDescriptorType == FeatureFieldDescriptorType.Alpha && a.IsVisible)); }
/// <summary> /// Returns an edit element for the specified fieldDescriptor /// </summary> private RedliningElement ElementFor(FeatureGeometryFieldDescriptor fieldDescriptor, IFeatureGeometry geometry) { RedliningElement redliningElement = null; var model = this.DrawingModel; var selection = this.DrawingSelection; if (model != null && selection != null) { foreach (var element in model) { if ((element.Tag as FeatureGeometryFieldDescriptor) == fieldDescriptor) { redliningElement = element; break; } } if (redliningElement != null) { selection.Set(redliningElement); } else { if (geometry != null) { // Set the geometry to the correct coordinate system geometry = geometry.InCoordinateSystem(this.CoordinateSystem); // Get the redlining element redliningElement = RedliningElement.ElementFor(geometry); // Make sure the element is decorated MapView.EditGeometryLayer.DecorateElement(redliningElement); model.Add(redliningElement); selection.Set(redliningElement); } else { redliningElement = RedliningElement.Create(fieldDescriptor.FieldType.PhysicalType, CoordinateSystem); MapView.EditGeometryLayer.NewElement(redliningElement); } // Make sure we are using the cache properly redliningElement.Tag = fieldDescriptor; } } return(redliningElement); }
/// <summary> /// Constructs the request /// </summary> /// <param name="sender">The originator of the request</param> /// <param name="feature">The feature (recipe-holder) to show details for</param> public LiteNewFeatureRequestMessage(Object sender, FeatureTableDescriptor tableDescriptor, FeatureGeometryFieldDescriptor geomDescriptor, IFeatureGeometry startWithGeometry = null, Feature attachToFeature = null) : base(sender) { this.TableDescriptor = tableDescriptor; this.GeometryDescriptor = geomDescriptor; if (tableDescriptor.EditabilityProperties.AllowInsert) { var newFeature = tableDescriptor.NewTemplateFeature(); if (geomDescriptor != null && startWithGeometry != null) { StartedWithTrail = true; newFeature[geomDescriptor.Name] = startWithGeometry; } Feature = new EditableFeature(newFeature, false, attachToFeature); } }