DEMO 5-2: Geospatial COG and TIFF Viewer App

import gradio as gr
import leafmap.foliumap as leafmap

# Define a function to load COG and Tiff in leafmap
def split(text1,text2):
    url=str(text1)
    filepath=str(text2)
    Map = leafmap.Map()
    Map.add_tile_layer(url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', name='arcgisonline',attribution='attribution')
    if url !='':
        Map.add_cog_layer(url)
    if filepath!='':
        raster = "raster.tif"
        raster = leafmap.download_file(filepath, "raster.tif")
        Map.add_raster(raster,layer_name='insar')       
    return Map.to_gradio()

with gr.Blocks(theme='gradio/soft') as demo:
    gr.HTML("""
            <center> 
            <h1> Work with foliumap 🗺️ </h1>
            <b> jason.yu.mail@qq.com  📧<b>
            </center>
            """)  
    with gr.Row():
        input=gr.Textbox(label='Enter a COG Tile URL',interactive=True)
        input2=gr.Textbox(label='Enter a Tiff URL',interactive=True)
    with gr.Row():
        out=gr.HTML()

    input.change(split, inputs=[input,input2], outputs=out)
    input2.change(split, inputs=[input,input2], outputs=out)

demo.launch(debug=True)

# url='https://open.gishub.org/data/raster/cog.tif'
# path='https://github.com/JunchuanYu/Gradio_tutorial/blob/main/data/raster.tif'