csharp
using MapSuite.Geometries; // geometry classes using MapSuite.GisEditor; // editor interfaces public class MyPolygonTool : MapTool // or appropriate base { public override string Id => “MyPolygonToolId”; public override string Name => “Digitize Polygon with Attribute”; private List<Coordinate> vertices = new List<Coordinate>(); public override void OnMouseDown(MapMouseEventArgs e) { if (e.Button == MouseButtons.Left) { vertices.Add(new Coordinate(e.MapX, e.MapY)); // optionally draw a temporary rubberband } else if (e.Button == MouseButtons.Right) { FinishPolygon(); } } private void FinishPolygon() { if (vertices.Count < 3) { vertices.Clear(); return; } var ring = new LinearRing(vertices.ToArray()); var poly = new Polygon(ring); AddFeatureToActiveLayer(poly); vertices.Clear(); } }
Notes:
- Use the SDK’s map coordinate conversion and drawing helpers for rubberband and snapping.
- Hook to mouse move to update preview.
4 — Add attribute-adding and saving logic
When adding the feature, ensure the target layer supports editing and has the attribute fields you need.
Example add-and-attribute:
csharp
private void AddFeatureToActiveLayer(Polygon poly) { var layer = GisEditor.ActiveMap.GetFirstEditableLayer(); // example helper if (layer == null) return; var feature = layer.FeatureSource.ConstructNewFeature(); feature.Geometry = poly; // set or create attribute field, e.g., “Category” if (!layer.FeatureSource.HasColumn(“Category”)) { layer.FeatureSource.AddColumn(new Column(“Category”, typeof(string))); } feature[“Category”] = “Surveyed”; layer.FeatureSource.AddFeature(feature); layer.Save(); // or commit transaction according to SDK }
Important:
- Some data sources require transactions or special save calls (shapefile, database).
- Validate projection/coordinate systems when adding geometry.
5 — Build, install, and test
- Build the plugin DLL.
- Copy the DLL (and any dependent resources like icons) into the Map Suite GIS Editor plugins folder (check GIS Editor’s documentation for the correct path).
- Restart GIS Editor. The new tool should appear in the toolbox or menu.
- Test by activating the tool, digitizing a polygon, and confirming attribute value and persistence.
Debugging tips
- Use logging or MessageBox during development to confirm method calls.
- Test with a simple shapefile layer to avoid complex datasource transactions.
- Verify field types before writing attribute values.
- Use small commits and check the layer’s editability flags.
Example enhancements
- Add a dialog to let users choose attribute values before finishing polygon.
- Implement snapping to existing features.
- Support multi-select and batch attribute updates.
- Provide undo/redo by integrating with GIS Editor’s undo stack if available.
Summary
You now have a concise path to build a Map Suite GIS Editor plugin: set up a class library, register a tool, implement digitizing and attribute logic, handle layer-specific save rules, and deploy the DLL to the plugins folder. Adjust API calls and namespaces to match your installed Map Suite SDK version.
Leave a Reply