Replies: 1 comment 4 replies
-
There is no out-of-box spatial data input widget for now in PyWebIO, you can use import json
import pywebio
from pywebio.input import *
from pywebio.output import *
from pywebio.session import *
from pywebio.session import next_client_event
GET_POS_JS = """
navigator.geolocation.getCurrentPosition(function (res) {
let crd = res.coords;
WebIO.sendMessage({
event: "js_yield",
task_id: WebIOCurrentTaskID,
data: {
latitude:crd.latitude,
longitude:crd.longitude,
accuracy:crd.accuracy,
}
});
});
"""
def get_pos():
run_js(GET_POS_JS)
res = next_client_event()
assert res['event'] == 'js_yield'
return res['data']
def main():
"""Get the location directly"""
pos = get_pos()
put_code(json.dumps(pos, indent=4), 'json')
def pos_input():
"""Geolocation input widget"""
def on_click(set_value):
pos = get_pos()
label = '(%f, %f)' % (pos['latitude'], pos['longitude'])
set_value(pos, label)
pos = input('Geolocation', action=("Get Position", on_click), readonly=True)
put_code(json.dumps(pos, indent=4), 'json')
if __name__ == '__main__':
pywebio.start_server([main, pos_input], port=8080, debug=True) In fact, it's better to use In fact, Later I will adjust |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
It would be nice to be able to insert spatial data, like a location (taken with getCurrentPosition or using leaflet-locatecontrol maybe) and/or have a GeoJSON input using leaflet-geoman.
Beta Was this translation helpful? Give feedback.
All reactions