public MapEdge getClosestRoad(double x, double y, boolean withName) {
        x = outOfBoundsX(x);
        y = outOfBoundsY(y);
        MapEdge ed;
        String ID = getID(x, y);
        double distance;
        ArrayList<MapEdge> a = getBranch(ID).getEdges();
        if(a.isEmpty()) a = this.getParent(getBranch(ID)).getEdges();
        
        ed = a.get(0);
        MapNode edfn = nodes.get(ed.getFNode());
        MapNode edtn = nodes.get(ed.getTNode());
        distance = distanceFromLine(edfn.getX(), edfn.getY(), edtn.getX(), edtn.getY(), x, y);
        
        for(MapEdge e: a){
            MapNode fn = nodes.get(e.getFNode());
            MapNode tn = nodes.get(e.getTNode());
            double d = distanceFromLine(fn.getX(), fn.getY(), tn.getX(), tn.getY(), x, y);
            if(withName) {
                if(d < distance && !(e.getName().equals(""))) {
                    distance = d;
                    ed = e;
                }
            }
            else {
                if(d < distance) {
                distance = d;
                ed = e;
                }
            }
        }
        return ed;
    }