Skip to content

Commit

Permalink
Uavhandler (#4)
Browse files Browse the repository at this point in the history
* Fix backend config file

* Update react-leaflet to 3.2.5

* Interface fixes; code cleanup

* Client code cleanup and restructure

* Add map getter script

* Add modal UI component

* Backend connection popup

* More merging problems

Co-authored-by: Krishnan Shankar <krishnans2006@gmail.com>
  • Loading branch information
pizzalemon and krishnans2006 committed Jun 6, 2022
1 parent e7d2784 commit ee8c463
Show file tree
Hide file tree
Showing 23 changed files with 445 additions and 217 deletions.
144 changes: 65 additions & 79 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-leaflet": "^3.2.5",
"react-router-dom": "^5.3.0",
"react-scripts": "^4.0.3",
"reactstrap": "^9.0.2",
"regex-parser": "^2.2.11",
"socket.io": "^3.0.3",
"socket.io-client": "^3.0.3",
Expand Down
1 change: 1 addition & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="modal-root" style="z-index: 999; position: relative;"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
69 changes: 69 additions & 0 deletions client/public/slippy_map_getter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import math
import os
import requests
import time

# https://tile.openstreetmap.org/{z}/{x}/{y}.png

# window position and zoom for the auvsi suas base, webster field
# zoom 17
# top lat: 38.15163
# bot lat: 38.14177

def main():
lon = -76.428038
lat = 38.1458611
deg_distance = 0.016
zoom = 17

lon_in = input("Longitude of center? [default: " + str(lon) + "] ")
if lon_in != "":
lon = float(lon_in)

lat_in = input("Latitude of center? [default: " + str(lat) + "] ")
if lat_in != "":
lat = float(lat_in)

zoom_deg_in = input("Zoom and degree? [default: " + str(zoom) + " " + str(deg_distance) + "] ")
if zoom_deg_in != "":
zoom_in, deg_in = zoom_deg_in.split()
if zoom_in != "" and deg_in != "":
zoom = int(zoom_in)
deg_distance = float(deg_in)

print()
for i in range(9, 19):
zoom_deg = deg_distance * (2**(zoom - i))
# assuming in northwest hemisphere
x1, y1 = convert_to_slippy(lat + deg_distance, lon - deg_distance, i)
x2, y2 = convert_to_slippy(lat - deg_distance, lon + deg_distance, i)

for j in range(x1, x2 + 1):
for k in range(y1, y2 + 1):
if not os.path.isfile(f"./map/{i}/{j}/{k}.png"):
if not os.path.exists(f"./map/{i}/{j}"):
os.makedirs(f"./map/{i}/{j}")

print("Downloading: [x: " + str(j) + ", y: " + str(k) + ", zoom: " + str(i) + "]")
url = f"https://tile.openstreetmap.org/{i}/{j}/{k}.png"
r = requests.get(url, allow_redirects=False)
file = open(f"./map/{i}/{j}/{k}.png", "wb")
file.write(r.content)
file.close()

time.sleep(1/1000)

def convert_to_slippy(lat, lon, zoom):
x = lon*math.pi/180
y = math.log(math.tan(lat*math.pi/180) + 1/math.cos(lat*math.pi/180)) # natural log

x = (1 + x/math.pi)/2
y = (1 - y/math.pi)/2

x = int(x * (2**zoom))
y = int(y * (2**zoom))

return (x, y)

if __name__ == "__main__":
main()
10 changes: 9 additions & 1 deletion client/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ const httppost = async (endpoint, data, func) => {
return response
}

export { httpget, httppost }
const getUrl = () => {
return url
}

const setUrl = (u) => {
url = u;
}

export { httpget, httppost, getUrl, setUrl }
Loading

0 comments on commit ee8c463

Please sign in to comment.