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
|
import json
import algorithms
import store
from lib import run_server, get, post, read_html
@get('/')
def index():
return read_html('templates/index.html')
@get('/show-area')
def show_area():
all = dict()
for (k, node) in enumerate(store.select_nodes_in_rectangle(store.extract_osm_nodes("university.osm"), 58.3984, 58.3990, 15.5733, 15.576)):
all[node.id] = node.coord_tuple()
return json.dumps(all)
@post('/shortest-path')
def shortest_path(body):
body = json.loads(body)
source_id = algorithms.get_closest_node_id(store.nodes, store.Node(-1, body['lat1'], body['lng1']))
target_id = algorithms.get_closest_node_id(store.nodes, store.Node(-1, body['lat2'], body['lng2']))
print(source_id, target_id)
source_node = store.nodes[source_id]
target_node = store.nodes[target_id]
path = [(source_node.lat, source_node.lng), (target_node.lat, target_node.lng)]
response = {'path': path}
return json.dumps(response)
run_server()
|