!layer.getInteraction(Interaction.EDIT)
|| !layer.isVisible() )
return null;
ILayer editLayer = context.getEditManager().getEditLayer();
SimpleFeature editFeature=context.getEditManager().getEditFeature();
String editFeatureID=null;
if( editFeature!=null )
editFeatureID=editFeature.getID();
Envelope bbox = context.getBoundingBox(
new java.awt.Point(centerPoint.getX(), centerPoint.getY()),
PreferenceUtil.instance().getSnappingRadius() * 2);
try {
Coordinate tmp = context.pixelToWorld(centerPoint.getX(), centerPoint.getY());
Coordinate layerCenter = JTS.transform(tmp, new Coordinate(), layer
.mapToLayerTransform());
FeatureCollection<SimpleFeatureType, SimpleFeature> features = context.getFeaturesInBbox(layer, bbox);
FeatureIterator<SimpleFeature> iter = null;
try {
Coordinate closest = null;
double minDist = Integer.MAX_VALUE;
for( iter = features.features(); iter.hasNext(); ) {
SimpleFeature feature = iter.next();
if( feature.getID().equals(editFeatureID) && layer==editLayer )
continue;
Coordinate[] result = new Coordinate[1];
EditUtils.instance.getClosest((Geometry) feature.getDefaultGeometry(), layerCenter, result);
double x = layerCenter.x - result[0].x;
double y = layerCenter.y - result[0].y;
double distNew = Math.sqrt(x * x + y * y);
if (distNew < minDist) {