Flask code sample
unknown
plain_text
3 years ago
2.1 kB
55
Indexable
from pickle import TRUE
from flask import *
from flask_ngrok import run_with_ngrok
import folium
import requests
import googlemaps
import streamlit as st
from streamlit_folium import st_folium
from folium.plugins import MousePosition
from bs4 import BeautifulSoup
from geopy.geocoders import ArcGIS
import requests
import jyserver.Flask as jsf
from pynput.mouse import Listener
app = Flask(__name__)
##run_with_ngrok(app)
@jsf.use(app)
class App:
@jsf.task
def main(self):
starting_location = (35.8432, -100.0752)
world_map = folium.Map(
location=starting_location,
zoom_start = 5.0,
min_zoom = 5.0
)
world_map.add_child(folium.LatLngPopup())
world_map.add_child(folium.ClickForMarker())
map = st_folium(world_map, height=350, width=700)
formatter = "function(num) {return L.Util.formatNum(num, 3) + ' º ';};"
MousePosition().add_to(world_map)
#nom = ArcGIS()
#s = nom.geocode('seattle')
#print(s.latitude)
folium.Circle(
radius=100,
location=[45.5244, -122.6699],
popup="The Waterfront",
color="#3186cc",
fill=True,
fill_color="#3186cc",
).add_to(world_map)
## Open Up the Map in Index.html
self.js.document.getElementById("map").innerHTML = world_map._repr_html_()
## Stuck...Trying to get the Longitude and Latitude after clicking randomly on the Map
##When inspecting the element of the popup box, the class that the Longitude and Latitude lies inside is called "leaflet-popup-content"
def is_clicked(x, y, button, pressed):
if pressed:
popup = self.js.document.getElementsByClassName("leaflet-popup-content-wrapper").innerHTML
print(popup)
with Listener(on_click=is_clicked) as listener:
listener.join()
@app.route("/")
def index():
App.main()
return App.render(render_template("index.html"))
if __name__ == "__main__":
app.run(debug=TRUE)Editor is loading...