function rect=display_rect_in_ref(fig_id,rect,ref)
    if class(ref.rota)=="string"
        r_rota=str2num(ref.rota);
        r_lat=str2num(ref.lat);
        r_lon=str2num(ref.lon);
        r_yaw=str2num(ref.yaw);
        r_perc=str2num(ref.perc);
        r_altitude=str2num(ref.altitude);
    else
        r_rota=ref.rota;
        r_lat=ref.lat;
        r_lon=ref.lon;
        r_yaw=ref.yaw;
        r_perc=ref.perc;
        r_altitude=ref.altitude;
    end  
    wgs84 = wgs84Ellipsoid("m");
    udata=get(rect,'UserData');
    distance_=[];
    angle=[];
    valid_idx=[];
    yaw=[];
    for idx=1:length(r_lat)
        if ismember(idx,r_rota)
            continue
        end
        [ls,az]=distance(r_lat(idx),r_lon(idx),udata.la,udata.lo,wgs84);
        distance_=[distance_,ls];
        if az<0
            az=az+360;
        end
        angle=[angle,az];
        valid_idx=[valid_idx,idx];
        yaw=[yaw,rad2deg(r_yaw(idx))];
        if yaw(end)<0
            yaw(end)=360+yaw(end);
        end
    end

    idx=find(distance_<=ref.range);
    angle=angle(idx);
    valid_idx=valid_idx(idx);
    yaw=yaw(idx);
    p=abs(abs(angle-yaw)-180)/90;
    [d,i]=min(abs(p-1));
    idx=valid_idx(i);
    axes(fig_id);
    posi=[1   ,r_perc(idx)*1024,1023,0.0099*1024];

    % Get local lat,lon
    llla=[];
    lllo=[];
    lld=[];
    for jdx=idx         
        lla=[];
        llo=[];
        ld=[];
        for i=0:100
            [la,lo,d]=getGeo_d(i/100,0.0,ref.range,...
                                      r_lat(jdx),...
                                      r_lon(jdx), ...
                                      r_altitude(jdx),...
                                      r_yaw(jdx),0.0);
            lla=[lla,la];
            llo=[llo,lo];
            ld=[ld,d];
        end
        llla=[llla;lla];
        lllo=[lllo;llo];
        lld=[lld;ld];
    end
    ep=sqrt((llla-udata.la).^2+(lllo-udata.lo).^2+1*(lld-udata.de).^2);
    [a,idx_x]=min(ep);
    if idx_x>0
        idx_x=idx_x-1;
    end

    posi(1)=idx_x*1024/100;
    posi(3)=0.02*1024;
    rect.UserData.geo_list=[rect.UserData.geo_list,...
            rectangle('Position',posi,'FaceColor',[1 1 0 0.0],'EdgeColor',[ 1 1 0 0.75],'LineWidth',2)];
    if ~rect.UserData.show
        set(rect.UserData.geo_list(end),"Visible","off");
    end
end
