Engine tools to achieve snapping (capture)

Source: Internet
Author: User

In the engine's tool (Itool):

In the OnClick event handler function:

First you need to get a layer, as a reference to the snapping,

Ifeaturelayer Targetlayer

Then declare a imovepointfeedback as the display of the snap point as the mouse moves:

Imovepointfeedback M_pmoveptfeed =NewMovepointfeedback (); Mfeedback=(Idisplayfeedback) m_pmoveptfeed; Isimplemarkersymbol Simplemarkersymbol=NewSimplemarkersymbolclass (); Irgbcolor Prgbcolor=NewRgbcolorclass (); Prgbcolor.red=0; Prgbcolor.green=0; Prgbcolor.blue=0; Simplemarkersymbol.color=Prgbcolor; Simplemarkersymbol.size=3; Simplemarkersymbol.style=ESRI.  ArcGIS.Display.esriSimpleMarkerStyle.esriSMSSquare; Isymbol symbol= Simplemarkersymbol asIsymbol; Symbol. ROP2=Esrirasteropcode.esriropnotxorpen; //symbol.  ROP2 = Esrirasteropcode.; M_pmoveptfeed.symbol = (isymbol) Simplemarkersymbol;

Then, start the display of feedback (Tmppoint refers to the beginning of the point, in fact, the impact is not small, if you do not want the source point on the screen, you can take a point outside the screen):

M_pmoveptfeed.display =

In the OnMouseMove event:

NULL ;   = PMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint (x, y);   Ten );   if NULL )  = ppoint;  ((Imovepointfeedback) mfeedback). MoveTo (PPoint2);  

Where the snapping function is the most important lookup function, its function is to find the closest point on the target layer based on the input point coordinates (that is, the point that needs to be snapped), return the point, or null if not found, and the last parameter means, on the map control, Finds the snapping point in the perimeter, in number of pixels.

 PublicIPoint Snapping (DoubleXDoubleY, Ifeaturelayer Ifeaturelyr, IMapControl3 axMapControl1,DoubleSnappingdis) {IPoint Ihitpoint=NULL; IMAP IMAP=Axmapcontrol1.map; Iactiveview IView=Axmapcontrol1.activeview; Ifeatureclass IFCLSS=Ifeaturelyr.featureclass; IPoint Point=NewPointclass (); Point.      Putcoords (x, y); DoubleLength =convertpixelstomapunits (Axmapcontrol1.activeview, Snappingdis); Itopologicaloperator Ptopo= Point asItopologicaloperator; Igeometry Pgeometry= Ptopo.buffer (length). Envelope asIgeometry; Ispatialfilter Spatialfilter=NewSpatialfilterclass (); Spatialfilter.geometryfield=IFeatureLyr.FeatureClass.ShapeFieldName; Spatialfilter.spatialrel=esrispatialrelenum.esrispatialrelintersects; Spatialfilter.geometry=Pgeometry; Ifeaturecursor cursor= Ifclss.search (Spatialfilter,false); IFeature IF=cursor.      Nextfeature (); if(IF = =NULL)return NULL; IPoint ihitpt=NewESRI.      ArcGIS.Geometry.Point (); Ihittest ihittest= If.shape asihittest; DoubleHitdist =0; intPartindex =0; intVertexindex =0; BOOLBvertexhit =false; //tolerance in pixels for line hits    DoubleTol =convertpixelstomapunits (IView, Snappingdis); if(Ihittest.hittest (Point, Tol, Esrigeometryhitparttype.esrigeometrypartboundary, IHITPT,refHitdist,refPartindex,refVertexindex,refbvertexhit)) {Ihitpoint=ihitpt; }      //AxMapControl1.ActiveView.Refresh ();     returnIhitpoint; }   Public DoubleConvertpixelstomapunits (Iactiveview Pactiveview,Doublepixelunits) {      Doublerealworlddisplayextent; intpixelextent; DoubleSizeofonepixel; Pixelextent= PActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame (). Right-PActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame (). Left; Realworlddisplayextent=PActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width; Sizeofonepixel= Realworlddisplayextent/pixelextent; returnPixelunits *Sizeofonepixel; }

This allows the mouse to capture objects on the target layer in real time, and can be called in the appropriate event (for example, onmousedown or Ondbclick) if you need to get a snap point at the current location:

IPoint ppoint = ((imovepointfeedback) mfeedback). Stop ();

Real-time snapping will stop, and if you need to start snapping again, you can call these statements later:

// start snap  again New Pointclass ();   1 1 );   = (Imovepointfeedback) mfeedback;   = PMap.ActiveView.ScreenDisplay;  M_pmoveptfeed.start (Tmppoint, tmppoint);  

Engine tools to achieve snapping (capture)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.