ThinkGeo.com    |     Documentation    |     Premium Support

Features out of order when overriding the DrawCore

I have some drawing tools and I have added a custom style. The shapes are added to the layer one at a time so the last one added is the one on top.

When the style is applied and DrawCore method is called the IEnumerable<Feature> features is not in the order that it was added but instead is grouped with the line shapes together even though they had a polygon in between them.



The layer had line, polygon, line; added in that order and I can verify that is correct when I look at that layers internal features. When the style is applied the collection of features is line, line, polygon and now the polygon coveres both of the lines. They look like they are in the wrong order.



My style override class:


public class GranularStyle : Style
   {       
       #region StyleOverrides
 
       protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
       {
           foreach (Feature feature in features)
           {
               var style = new StyleFactory().CreateStyle(feature);
               style.DrawShape(canvas);
           }
       }
 
       #endregion
   }



The shapes are added to my drawing layer from the track layer after the shape has finished drawing when the TrackEnded event fires


private void HandleDrawEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            MoveTrackOverlayToDrawingLayer();
        }
 
        private void MoveTrackOverlayToDrawingLayer(TextBoxDrawingControlViewModel textProperties = nullstring shapeId = null)
        {
            LayerOverlay layerOverlay = NewOrExistingLayerOverlay(_drawingGroup);
            //FeatureLayer featureLayer = (FeatureLayer)layerOverlay.Layers[_drawingLayer];
            InMemoryFeatureLayer featureLayer = (InMemoryFeatureLayer)layerOverlay.Layers[_drawingLayer];
 
            GeoCollection<Feature> featureCollection = _mapControl.TrackOverlay.TrackShapeLayer.InternalFeatures;
                     
            featureLayer.FeatureSource.Open();
            featureLayer.FeatureSource.BeginTransaction();
 
            foreach (Feature feature in featureCollection)
            {
 
                if (feature != null && feature.ColumnValues != null)
                {
 
                    feature.ColumnValues.Add(MapStyleAttributes.WidthColumnName, _lineWidth.ToString());
                    feature.ColumnValues.Add(MapStyleAttributes.ColorColumnName, _lineColor);
                    feature.ColumnValues.Add(MapStyleAttributes.TransparencyColumnName,
                                             string.Format("{0}", _fillOpacity));
                    if (textProperties != null)
                    {
                        feature.ColumnValues.Add(MapStyleAttributes.TextColumnName,
                                                 string.Format("{0}", textProperties.Text));
                        feature.ColumnValues.Add(MapStyleAttributes.RotationColumnName,
                                                 string.Format("{0}", textProperties.Rotation));
                        feature.ColumnValues.Add(MapStyleAttributes.FontFamilyColumnName,
                                                 string.Format("{0}", textProperties.FontFamily));
                        feature.ColumnValues.Add(MapStyleAttributes.FontStyleColumnName,
                                                 string.Format("{0}", textProperties.FontStyle));
                        feature.ColumnValues.Add(MapStyleAttributes.FontSizeColumnName,
                                                 string.Format("{0}", textProperties.FontSize));
                        feature.ColumnValues.Add(MapStyleAttributes.ShapeIdColumnName, shapeId);
                    }
                    //featureLayer.FeatureSource.AddFeature(feature);
                    featureLayer.InternalFeatures.Add(feature);
                    featureLayer.FeatureSource.UpdateFeature(feature);
 
                }
            }
                featureLayer.FeatureSource.CommitTransaction();
                featureLayer.FeatureSource.Close();
                _mapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
                _mapControl.Refresh(new Overlay[] {_mapControl.EditOverlay, _mapControl.TrackOverlay});
                _mapControl.Refresh(layerOverlay);
        }



Is there a way to force the custom style’s feature collection to be in the correct order?






Hi Scott, 
  
 Sorry I haven’t understood your problem and haven’t get more information from the code. 
  
 I think more detail description about your scenario should be helpful, a simple project is better. 
  
 Regards, 
  
 Don