Mapsui
Mapsui copied to clipboard
The method of GetFeatures from layers, and the problem of invalid transfer range parameters
In Class Layer: public override IEnumerable<IFeature> GetFeatures(MRect extent, double resolution) { return _cache.ToList(); }
I want to display the special symbols of the selected features in the layer, but this method can only obtain the features currently displayed in the map.
I try to obtain the elements of the corresponding range through the following methods, but the obtained results cannot be applied with symbolic.
public IEnumerable<IFeature> GetFeatures(MRect rect=null)
{
if (_layer==null)
{
return null;
}
if (rect==null)
{
rect = _layer.Extent;
}
FetchInfo fetchInfo = new FetchInfo(rect, 1);
return (_layer as Layer).DataSource.GetFeaturesAsync(fetchInfo).Result;
}
public ThemeStyle CreateThemeStyle(string colorName, List<IFeature> SelectedFeature) { return new ThemeStyle(feature => { VectorStyle style ;
style = new VectorStyle();
style.Fill = new Brush(Color.FromString(colorName));
style.Outline = new Pen(Color.Black);
//The elements are obtained through GetFeatures of method, but they are not the same. The following judgment is always false
if (SelectedFeature.Contains(feature))
{
style.Outline.Width = 2;
style.Outline.Color = Color.Blue;
}
return style;
});
}
Can you help me solve this problem, thank you
I want to display the special symbols of the selected features in the layer
I don't understand what you are trying to do exactly. Do you want a list of all symbols and show them somewhere outside the map? Or do you want to select a certain set of symbols within the map?
I want to get the FID or Objectid of the Feature
in ShapeFile Class ,Add one code " feature["FID"] = index;"
public Task<IEnumerable<IFeature>> GetFeaturesAsync(FetchInfo fetchInfo)
{
lock (_syncRoot)
{
Open();
try
{
//Use the spatial index to get a list of features whose BoundingBox intersects bbox
var objectList = GetObjectIDsInViewPrivate(fetchInfo.Extent);
var features = new List<GeometryFeature>();
foreach (var index in objectList)
{
var feature = _dbaseFile?.GetFeature(index, features);
if (feature != null)
{
feature["FID"] = index;
feature.Geometry = ReadGeometry(index);
if (feature.Geometry?.EnvelopeInternal == null) continue;
if (!feature.Geometry.EnvelopeInternal.Intersects(fetchInfo.Extent.ToEnvelope())) continue;
if (FilterDelegate != null && !FilterDelegate(feature)) continue;
features.Add(feature);
}
}
return Task.FromResult((IEnumerable<IFeature>)features);
}
finally
{
Close();
}
}
}
Sorry that we never answered this.
I think this is your problem:
//The elements are obtained through GetFeatures of method, but they are not the same. The following judgment is always false
if (SelectedFeature.Contains(feature))
Instead you could do:
if (SelectedFeature["FID"] == feature["FID"])
Perhaps you need a cast.