File size: 5,207 Bytes
14b31f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0edcae
14b31f3
bf4e836
f0edcae
 
 
 
 
 
 
14b31f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0edcae
14b31f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import folium
import streamlit as st
import pandas as pd#, geopandas as gpd
import base64
from streamlit_folium import st_folium
from folium.plugins import Draw
from st_aggrid import AgGrid, ColumnsAutoSizeMode, GridUpdateMode, JsCode
from st_aggrid.grid_options_builder import GridOptionsBuilder
# from shapely.geometry import Polygon
from shapely.wkt import loads as wkt_loads


# display PDF
PDF_HTML_iframe_template = (
    """<iframe src="{pdf_url}" width="100%" height="800"></iframe>"""
)

def display_PDF(st, pdf_url='proforma-example.pdf'):
    # /Users/junxiong/Documents/aire/acToolV2/due-diligence-check-example.pdf
    pdf_file = open(pdf_url, 'rb')
    base64_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
    pdf_display = f'<embed src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf">' 
    st.markdown(pdf_display, unsafe_allow_html=True)
    # pdf_content = PDF_HTML_iframe_template.format(
    #     pdf_url=pdf_url
    # )
    # st.markdown(pdf_content, unsafe_allow_html=True)


# import matplotlib.pyplot as plt
# import docx

# ------ Main UI ------
st.set_page_config(page_title="AcTool V2 live-mockup", layout="wide")
# Hide Streamlit deploy menu
st.markdown(
    """
    <style>
        .reportview-container {
            margin-top: -2em;
        }
        #MainMenu {visibility: hidden;}
        .stDeployButton {display:none;}
        footer {visibility: hidden;}
        #stDecoration {display:none;}
    </style>
""",
    unsafe_allow_html=True,
)

st.markdown("""This is the live-mockup of AcTool V2. Please use [Roadmap link](https://aireflags.larksuite.com/docx/XNHgdD8S4o7C28xjt7uuiNGSsGh) to add any new requested features.
- [x] Every panel can be expand/hide to focus on interested block.""")


left, right = st.columns((1, 1))

cols = ['WKT','County','Post_Code','FullMailin']
df = pd.read_csv('sample.csv')[cols]
df['rank'] = 0
geoms = df['WKT'].apply(wkt_loads)
df = df.drop(columns=['WKT'])
# print(type(geoms))
# print(geoms.iloc[0])

# geoms = (gpd.GeoSeries(geoms))
# print(dir(geoms))
# print(geoms.to_json())
# pause

js_handle_value_change_event = JsCode("""
function(e) {
    let api = e.api;
    let rowIndex = e.rowIndex;
    let col = e.column.colId;

    let rowNode = api.getDisplayedRowAtIndex(rowIndex);
    api.flashCells({
        rowNodes: [rowNode],
        columns: [col],
        flashDelay: 10000000000
    });

};
""")

pinned_col_cellsytle_jscode = JsCode("""
function(params) {
    return {
        'backgroundColor': 'lightgrey'
    }
};
""")

with left:
    roi_section = st.expander("Interested Collection", expanded=True)
    with roi_section:
        gd = GridOptionsBuilder.from_dataframe(df)

        gd.configure_pagination(
            enabled=True,
            paginationAutoPageSize=False,
            paginationPageSize=10
        )
        gd.configure_default_column(
            editable=True,
            groupable=True,
            resizable=True,
        )
        gd.configure_selection(
            selection_mode="single",
            pre_selected_rows=[0]  # 默认选择第一行
        )
        gd.configure_grid_options(
            onCellValueChanged=js_handle_value_change_event
        )

        gd.configure_auto_height(autoHeight=False)
        gd.configure_column("view", pinned="right")
        gd.configure_column("note", pinned="right", minWidth=200)
        gd.configure_columns(["view", "note"], cellStyle=pinned_col_cellsytle_jscode)
        gridOptions = gd.build()

        grid_table = AgGrid(
            df,
            gridOptions=gridOptions,
            update_mode=GridUpdateMode.SELECTION_CHANGED | GridUpdateMode.VALUE_CHANGED,
            columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
            allow_unsafe_jscode=True,
            theme="streamlit",
        )
    note_section = st.expander("Photoes & Notes history​", expanded=True)
    with note_section:
        # st.write("Photoes & Notes history/n")
        st.image("photo.jpg", caption="Photo 1")
    ddcheck_section = st.expander("due diligence check​", expanded=True)
    with ddcheck_section:
        pdf_container = st.container()
        with pdf_container:
            display_PDF(st)
    sb9_section = st.expander("SB9/ADU potentials​", expanded=True)
    with sb9_section:
        st.write("SB9 ADU potentials​(TBD)")
    proforma_section = st.expander("proforma​", expanded=True)
    with proforma_section:
        pdf_container = st.container()
        with pdf_container:
            display_PDF(st, pdf_url='proforma-example.pdf')


with right:
    lat, lon = 37.302606062505,-122.029462962451
    m = folium.Map(
        location=[lat, lon],
        tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
        attr='(C) World Imagery contributors',
        name='Esri Satellite',
        max_zoom=21,
        zoom_start=19
    )

    Draw().add_to(m)
    # folium.GeoJson(data=geoms.to_json()).add_to(m)
    # st.header("Street Map Views")
    st.markdown("""Map: show the parcels of selected properties on the Street View.""")
    st_folium(m, width=900, height=1000, returned_objects=[])