Simplify Map Vector Items
- 2 minutes to read
The Map Control provides Map Editor API and Simplifiers to simplify detailed vector items, reduce memory consumption, and enhance a map’s responsiveness. To simplify an item, the Map Control decreases the number of item vertices. The resulting shape’s resolution depends on the tolerance parameter that defines the percentage of vertices that should remain after simplification.
Use one of the following approaches for item simplification:
Use Map Editor API
This approach allows you to use the Undo/Redo command to cancel/restore item simplification actions. These commands are available only when MapEditor.AllowSaveActions is enabled.
Call the MapEditor.SimplifyItems method to simplify a collection of items with the tolerance value you specified. This method uses the VisvalingamShapeSimplifier algorithm internally.
The following example shows how to simplify items and use TrackBarEdit to change the tolerance:
using System;
using System.Windows;
namespace SvgDataAdapterSample {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void OnTrackbarEditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e) {
double tolerance = Convert.ToDouble(toleranceTrackbar.EditValue);
mapControl.MapEditor.SimplifyItems(adapter.DisplayItems, tolerance);
}
}
}
Use Simplifiers
You can use the ShapeSimplifierBase.Simplify method to simplify items before they are displayed on a layer.
- Create a VisvalingamShapeSimplifier or DouglasPeuckerShapeSimplifier instance. The Douglas-Peucker algorithm improves the smoothness of the resulting polyline and the Visvalingam algorithm increases performance when you process a polyline with a large number of vertices.
- Call the Simplify method in an adapter’s ShapesLoaded (for example, ShapefileDataAdapter.ShapesLoaded or SvgFileDataAdapter.ShapesLoaded) event handler.
private void OnShapesLoaded(object sender, ShapesLoadedEventArgs e) {
VisvalingamShapeSimplifier simplifier = new VisvalingamShapeSimplifier();
simplifier.Simplify(items: e.Shapes, tolerance: 20);
}