}
Coordinate snappedCoordinate = coordinate;
double snappedDistance = Double.MAX_VALUE;
for (int i = 0; i < rules.size(); i++) {
SnappingRuleInfo rule = rules.get(i);
// Check for supported snapping algorithms: TODO use factory
if (rule.getType() != SnappingType.CLOSEST_ENDPOINT && rule.getType() != SnappingType.NEAREST_POINT) {
throw new IllegalArgumentException("Unknown snapping rule type was found: " + rule.getType());
}
// Get the target snap layer:
VectorLayer snapLayer;
try {
snapLayer = mapModel.getVectorLayer(rule.getLayerId());
} catch (Exception e) {
throw new IllegalArgumentException("Target snapping layer (" + rule.getLayerId()
+ ") was not a vector layer.");
}
SnapMode tempMode = this.mode;
if (snapLayer.getLayerInfo().getLayerType() != LayerType.POLYGON