Пример #1
0
 /// <summary>
 /// Creates a new <see cref="AttributePresenter"/> with the given map and view.
 /// </summary>
 /// <param name="map">The map model to observe and control.</param>
 /// <param name="view">The view to use to display attribute data.</param>
 public AttributePresenter(Map map, IAttributeView view)
     : base(map, view)
 {
     Trace.Info(TraceCategories.Presentation, "Creating AttributePresenter");
     View.FeaturesHighlightedChanged += handleViewFeaturesHighlightedChanged;
     View.Layers = Map.Layers;
 }
Пример #2
0
        //private void handleLayersChanged(Object sender, ListChangedEventArgs e)
        //{
        //    IFeatureLayer newLayer = null;
        //    IFeatureLayer oldLayer = null;

        //    if (e.NewIndex >= 0 && e.NewIndex < Map.Layers.Count)
        //    {
        //        newLayer = Map.Layers[e.NewIndex] as IFeatureLayer;
        //    }

        //    if (e.OldIndex >= 0 && e.OldIndex < Map.Layers.Count && _highlightUpdating)
        //    {
        //        oldLayer = Map.Layers[e.OldIndex] as IFeatureLayer;
        //    }

        //    if (newLayer != null && e.ListChangedType == ListChangedType.ItemAdded)
        //    {
        //        wireupFeatureLayer(newLayer);
        //    }

        //    // BUG: this shouldn't work... e.OldIndex won't be the old layer
        //    // index if it was deleted...
        //    // TODO: make unit test which confirms or refutes the above bug
        //    if (oldLayer != null &&
        //        e.NewIndex < 0 &&
        //        e.ListChangedType == ListChangedType.ItemDeleted)
        //    {
        //        unwireFeatureLayer(oldLayer);
        //    }
        //}

        private void handleViewFeaturesHighlightedChanged(Object sender,
                                                          FeaturesHighlightedChangedEventArgs e)
        {
            Trace.Info(TraceCategories.Presentation, "AttributePresenter handling " +
                       "view features highlighted changed");
#if DEBUG
            Trace.Debug(TraceCategories.Presentation, "Layer on which highlight change: " +
                        e.LayerName);
            Trace.Debug(TraceCategories.Presentation, "Highlighted features: " +
                        EnumerablePrinter.Print(e.HighlightedFeatures));
#endif

            if (_highlightUpdating)
            {
                return;
            }

            ILayer layer = Map.Layers[e.LayerName];

            IFeatureLayer featureLayer = layer as IFeatureLayer;

            if (featureLayer == null)
            {
                LayerGroup group = layer as LayerGroup;

                if (group != null)
                {
                    featureLayer = group.MasterLayer as IFeatureLayer;
                }
            }

            Assert.IsNotNull(featureLayer);

            FeatureQueryExpression viewDefinition = featureLayer.HighlightedFilter;

            IEnumerable             oids          = getFeatureIdsFromIndexes(featureLayer, e.HighlightedFeatures);
            OidCollectionExpression oidExpression = new OidCollectionExpression(oids);

            if (viewDefinition == null)
            {
                viewDefinition = new FeatureQueryExpression(new AllAttributesExpression(),
                                                            oidExpression, null);
            }
            else
            {
                ProjectionExpression projection = viewDefinition.Projection;

                if (viewDefinition.SpatialPredicate == null)
                {
                    viewDefinition = new FeatureQueryExpression(projection, oidExpression, null);
                }
                else
                {
                    PredicateExpression predicate = new BinaryExpression(viewDefinition.SpatialPredicate,
                                                                         BinaryOperator.And,
                                                                         oidExpression);
                    viewDefinition = new FeatureQueryExpression(projection, predicate, null);
                }
            }

            _highlightUpdating             = true;
            featureLayer.HighlightedFilter = viewDefinition;
            _highlightUpdating             = false;
        }