ThinkGeo.com    |     Documentation    |     Premium Support

Editor support - Snapping

Hi Guys,


Will the upcomming editor functionality include snapping support?  If so will it also allow you to 'snap' to other feature layers? 


The image below shows a "line feature layer" being edited, the snapping points are those in yellow which represent the origin and destination points of the other lines in the layer.  When editing the line in red, you are able to move point 1 and drop it over a yellow marker and have it 'snap' to the exact position. 



Regards


John



Hey John. Would this not be possible to do by overriding the MouseUp event? A quick query to find any "snappable" markers within a certain distance should allow you to get the new X and Y position to set on the shape you are dragging. 
  
 Just a thought. Sound workable?

Hi Brendan,


Thanks for reply, sure it sounds feasible, I was more interested to know if it's going to be supported "out of the box".  We are evaluating ThinkGeo at the moment and comparing it to others, all of these have built in snapping support.


Regards


John





Sorry, I can’t help you with their roadmap… I’m just another developer using the product:P Why wait is what I always say. If you want I could help you with the code. It’s easy enough. With a class that overrides the map you can hide the logic quite nicely as well. 
  


Hi Brendan,


Thanks for the offer, much appreciate.  Full blooded snapping support is not as trrivial as it first seems, you only have to look at ArcMap or the TatkGis Editor to realise that it's a bit more complicated if you want to make it full featured and easy to use.


The screen shot above is taken from editing a single polyline on a layer of polylines.  The first thing that happens is the snapping points (the intersections etc) all get markers and that applies to the whole layer.  The mouse needs to snap to these points when it gets close to one to give a visible indication that snapping is possible and it goes on...


If nothing is forthcoming from the ThinkGeo guys, I'll get back to you and would be grateful of any help if we have to implement it.  I'm just starting to get to grips with ThinkGeo, things are totally different with this library compared to our existing stuff, its a huge learning curve.


Regards


John


 



John, 


I’m afraid we will not implement it very soon, as we have had a big list of features to add in the next couple month to this Beta. Sure we will keep adding new features after that but just let you know this may not be added in the very near future.
 
It’s easier to snap on a point based shape (as Brendan mentioned), if you want to snap to a vertex in Polygon or Polyline, all vertices should better be added to an index file so you can find the nearest point quickly. You can create a shape file, adding all the vertices and building index for it. Another way is to find the nearest Polygon/Polyline, get all the vertices within that and find the nearest one on the fly. This would be slower but easier to implement. I agree with you that maybe it’s easier to be accomplished in a particular project, but it’s a bit more complicated to built in a product, make it full featured and easy to use.
 
Here are some codes you may need if you want to implement it yourself.

 



    PolygonShape polygonShape;
            LineShape lineShape;
            MultilineShape multiLineShape;
            MultipolygonShape multiPolygonShape;

            // Vertices within a Polygon, within OuterRing and InnerRings 
            polygonShape.OuterRing.Vertices;
            foreach (RingShape innerRing in polygonShape.InnerRings)
            {
                innerRing.Vertices;
            }

            // Vertices within a lineShape
            lineShape.Vertices;

            // Lines within a multiLine
            multiLineShape.Lines;

            // Polygons within a multiPolygon
            multiPolygonShape.Polygons; 

// Create a new shape file
            ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Point, "tmp.shp", new DbfColumn[] { });
           // Build index for a shape file 
ShapeFileFeatureLayer.BuildIndexFile("tmp.shp");


 


Try to make your learning easier, just let you know that generally all the classes within MapSuite.Core namespace belong to one of the following 5 groups.
 
Shape: represent a shape data; like PolygonShape, PointShape
Data:   represent the high level data (Shape data and tabular data) related classes, like FeatureSource, RasterSource, DataColumn
Style:    represent how to render the data (Not for RasterSource): like LineStyle, PointStyle.
Layer:  A holder of a data and a style: like ShapeFileFeatureLayer, MrSidRasterLayer
Drawing: represents all the drawing related elements, like GeoPen, GeoSolidBrush, GeoCanvas

 



You can learn from the above graph that
Layer is added to Overlay, Overlay is added to map
Layer is made of Data and Style, data represents what to draw and style represents how to draw
Shape data is one main component of the data
Style includes all drawing logic, so with a data, a style can draw properly.
 
This is only a draft graph try to make you easier understand the general structure of Map Suite Classes. Let me know if there is anything else we can do to make your learning easier.
 
Ben.

Brendan, 
  
 Always appreciate your helpful and informative replies. 
  
 Ben. 


Hi Ben,


Thanks forr the Info, that makes things clearer.  Will wait for the editor suppot in the next beta and then see what is possible, I guess it will also depend on what functionality the editor has.


Regards


John



That’s true. Hope we can get it earlier. :)

John 
  
 There are probably a few things to work through in order to get the kind of snapping you would like… but i’m sure we could work through this in just a couple of hours. It might be something that we’d look to use down the line so i’m likely to code it up in any case.  
  
 If you want to give it a go in the mean time… here’s a good article on snapping (snapping the mouse to the control) codeproject.com/KB/buttons/StickySnapControls.aspx. We’d obviously change this logic. All we really need from here is the basic idea of changing the cursor’s location, and releasing it after a few milliseconds. 
  
 I’m will be away until the 28th. If you are still interested then, I will see if I can put up a sample here. I started this morning (and so far it looks simple enough), but I have too much other stuff to do and I won’t have a working sample before I head out. 
  
 Good luck… and enjoy. 
  
  
  
 Ben 
  
 Thanks. The more participation we have here, the better it is for everyone involved.

Hi,


Thanks for the help, I'm definitely interested.


What we do here is to manage a route network for the Worlds Oceans, as you can imagine that results in one or two layers with the odd line or two on them  Snapping plays a vital part in ensuring that the route network integrity is maintained.


In our case snapping can involve a line from one side of the Pacific to the other and ensuring that it is snapped to the correct waypoint on the other side, hence the need for visual clues.  With hundreds of thousands of waypoints and routes, life can get interesting rather quickly.


Enjoy your break and compilments of the season to you and yours.


John



Brendan,  
  
 That’s definitely true. Thanks for your sharing in forum and enjoy your break. 
  
 Ben