本文整理汇总了C#中ILayer.GetFeaturesInView方法的典型用法代码示例。如果您正苦于以下问题:C# ILayer.GetFeaturesInView方法的具体用法?C# ILayer.GetFeaturesInView怎么用?C# ILayer.GetFeaturesInView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILayer
的用法示例。
在下文中一共展示了ILayer.GetFeaturesInView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IterateLayer
private static void IterateLayer(IViewport viewport, ILayer layer,
Action<IViewport, IStyle, IFeature> callback)
{
var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();
var layerStyles = layer.Style is StyleCollection ? (layer.Style as StyleCollection).ToArray() : new [] {layer.Style};
foreach (var layerStyle in layerStyles)
{
var style = layerStyle; // This is the default that could be overridden by an IThemeStyle
foreach (var feature in features)
{
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.RenderResolution) || (style.MaxVisible < viewport.RenderResolution)) continue;
callback(viewport, style, feature);
}
}
foreach (var feature in features)
{
var featureStyles = feature.Styles ?? Enumerable.Empty<IStyle>();
foreach (var featureStyle in featureStyles)
{
if (feature.Styles != null && featureStyle.Enabled)
{
callback(viewport, featureStyle, feature);
}
}
}
}
示例2: IterateVectorLayer
private static void IterateVectorLayer(IViewport viewport, ILayer layer, StyleContext context,
Action<IViewport, IStyle, IFeature, StyleContext> callback)
{
var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution)
.Select((f, i) =>
{
ReleaseLoad(i);
return f;
})
.Where(f =>
{
if (f.Geometry is Mapsui.Geometries.Point) return true;
var boundingBox = f.Geometry.GetBoundingBox();
return boundingBox.Height / viewport.Resolution > 0.1 ||
boundingBox.Width / viewport.Resolution > 0.1;
})
.ToList();
var layerStyles = layer.Style is StyleCollection ? (layer.Style as StyleCollection).ToArray() : new[] { layer.Style };
foreach (var layerStyle in layerStyles)
{
var style = layerStyle; // This is the default that could be overridden by an IThemeStyle
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.RenderResolution) || (style.MaxVisible < viewport.RenderResolution)) continue;
for (int i = 0; i < features.Count; i++)
{
var feature = features[i];
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
callback(viewport, style, feature, context);
ReleaseLoad(i);
}
}
for (int i = 0; i < features.Count; i++)
{
var feature = features[i];
if (feature.Styles != null)
{
foreach (var featureStyle in feature.Styles)
{
if (feature.Styles != null && featureStyle.Enabled)
{
callback(viewport, featureStyle, feature, context);
}
}
}
ReleaseLoad(i);
}
ReleaseLoad(0);
}
示例3: RenderVectorLayer
private static Canvas RenderVectorLayer(IViewport viewport, ILayer layer, bool rasterizing = false)
{
// todo:
// find solution for try catch. Sometimes this method will throw an exception
// when clearing and adding features to a layer while rendering
try
{
var canvas = new Canvas
{
Opacity = layer.Opacity,
IsHitTestVisible = false
};
var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();
var layerStyles = BaseLayer.GetLayerStyles(layer);
foreach (var layerStyle in layerStyles)
{
var style = layerStyle; // This is the default that could be overridden by an IThemeStyle
foreach (var feature in features)
{
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue;
RenderFeature(viewport, canvas, feature, style, rasterizing);
}
}
foreach (var feature in features)
{
var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
foreach (var style in styles)
{
if (feature.Styles != null && style.Enabled)
{
RenderFeature(viewport, canvas, feature, style, rasterizing);
}
}
}
return canvas;
}
catch (Exception)
{
return new Canvas { IsHitTestVisible = false };
}
}
示例4: RenderVectorLayerFeatures
private static List<IFeature> RenderVectorLayerFeatures(IViewport viewport, ILayer layer)
{
try
{
var features = new List<IFeature>();
if(layer.Name.Equals("Open Street Map"))
{
Console.WriteLine("");
features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToList();
}else
{
features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToList();
}
//Console.WriteLine("Layer " + layer.Name + " Features.Count = " + features.Count);
//if(layer.Name.Equals("Open Street Map") && features.Count > 0)
Console.WriteLine("");
if(layer.Style != null)
{
var style = layer.Style; // This is the default that could be overridden by an IThemeStyle
foreach (var feature in features)
{
if (layer.Style is IThemeStyle) style = (layer.Style as IThemeStyle).GetStyle(feature);
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue;
RenderFeature(viewport, style, feature, layer.Name);
}
}
foreach (var feature in features)
{
var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
foreach (var style in styles)
{
if (feature.Styles != null && style.Enabled)
{
RenderFeature(viewport, style, feature, layer.Name);
}
}
}
return features;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
示例5: RenderVectorLayer
private static Canvas RenderVectorLayer(IViewport viewport, ILayer layer, bool rasterizing = false)
{
// todo:
// find solution for try catch. Sometimes this method will throw an exception
// when clearing and adding features to a layer while rendering
var canvas = new Canvas
{
Opacity = layer.Opacity,
IsHitTestVisible = false
};
try
{
var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();
var layerStyles = BaseLayer.GetLayerStyles(layer);
var brushCache = new BrushCache();
foreach (var layerStyle in layerStyles)
{
var style = layerStyle; // This is the default that could be overridden by an IThemeStyle
foreach (var feature in features)
{
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) ||
(style.MaxVisible < viewport.Resolution)) continue;
RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
}
}
foreach (var feature in features)
{
var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
foreach (var style in styles)
if ((feature.Styles != null) && style.Enabled)
RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
}
return canvas;
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, "Unexpected error in renderer", ex);
return canvas;
// If exception happens inside RenderFeature function after
// at -least one child has been added to the canvas,
// returning new canvas will leave the previously created (but
// not yet added to parent canvas) canvas abandoned, that will
// cause the exception when resuing RenderedGeometry object, because
// at -least one RenderedGeometry was attached to that abandoned canvas.
// returning the same canvas will solve this error, as it will
// be clear this canvas childs on next render call.
// return new Canvas { IsHitTestVisible = false };
}
}
示例6: RenderLayer
private static void RenderLayer(Graphics graphics, IViewport viewport, ILayer layer, AbortRenderDelegate abortRender)
{
int counter = 0;
const int step = 100;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
foreach (var layerStyle in layer.Styles)
{
var style = layerStyle;
var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution);
//Linestring outlines is drawn by drawing the layer once with a thicker line
//before drawing the "inline" on top.
var enumerable = features as IList<IFeature> ?? features.ToList();
foreach (var feature in enumerable)
{
if ((counter++ % step == 0) && abortRender != null && abortRender()) return;
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
if ((style is VectorStyle) && ((style as VectorStyle).Outline != null))
{
GdiGeometryRenderer.RenderGeometryOutline(graphics, viewport, feature.Geometry, style as VectorStyle);
}
}
foreach (var feature in enumerable)
{
if ((counter++ % step == 0) && abortRender != null && abortRender()) return;
if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
RenderGeometry(graphics, viewport, feature.Geometry, style as VectorStyle);
}
}
}