решение задания 5 + 6
This commit is contained in:
@@ -3,10 +3,11 @@ import requests
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def get_img_map(delta: float, cords: tuple, variant_map: str) -> None:
|
def get_img_map(delta: float, cords: tuple, variant_map: str, org_point: str) -> None:
|
||||||
"""
|
"""
|
||||||
Функция обращается к api yandex и создаёт картинку карты по переданным данным
|
Функция обращается к api yandex и создаёт картинку карты по переданным данным
|
||||||
|
|
||||||
|
:param org_point: str - координаты организации, куда надо точку поставить
|
||||||
:param delta: float - разрешение карты
|
:param delta: float - разрешение карты
|
||||||
:param cords: tuple - 2 координаты точки
|
:param cords: tuple - 2 координаты точки
|
||||||
:param variant_map: str - вариант карты
|
:param variant_map: str - вариант карты
|
||||||
@@ -15,7 +16,8 @@ def get_img_map(delta: float, cords: tuple, variant_map: str) -> None:
|
|||||||
params = {
|
params = {
|
||||||
"ll": ",".join([str(cords[0]), str(cords[1])]),
|
"ll": ",".join([str(cords[0]), str(cords[1])]),
|
||||||
"spn": ",".join([str(delta), str(delta)]),
|
"spn": ",".join([str(delta), str(delta)]),
|
||||||
"l": variant_map
|
"l": variant_map,
|
||||||
|
"pt": "{0},pm2dgl".format(org_point)
|
||||||
}
|
}
|
||||||
response = requests.get("http://static-maps.yandex.ru/1.x/", params=params)
|
response = requests.get("http://static-maps.yandex.ru/1.x/", params=params)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def search_organization_pos(search_text: str) -> tuple:
|
||||||
|
geocoder_api_server = "http://geocode-maps.yandex.ru/1.x/"
|
||||||
|
geocoder_params = {
|
||||||
|
"apikey": "40d1649f-0493-4b70-98ba-98533de7710b",
|
||||||
|
"geocode": search_text,
|
||||||
|
"format": "json"}
|
||||||
|
response = requests.get(geocoder_api_server, params=geocoder_params)
|
||||||
|
toponym = response.json()["response"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"]
|
||||||
|
point = [float(i) for i in toponym["Point"]["pos"].split(" ")]
|
||||||
|
toponym_longitude, toponym_lattitude = toponym["Point"]["pos"].split(" ")
|
||||||
|
return "{0},{1}".format(point[0], point[1]), toponym_longitude, toponym_lattitude
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 639 KiB After Width: | Height: | Size: 369 KiB |
@@ -4,6 +4,7 @@ import sys
|
|||||||
from PyQt5 import uic
|
from PyQt5 import uic
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from functions.get_img_map import get_img_map
|
from functions.get_img_map import get_img_map
|
||||||
|
from functions.search_organization_pos import search_organization_pos
|
||||||
|
|
||||||
|
|
||||||
class Window(QMainWindow):
|
class Window(QMainWindow):
|
||||||
@@ -17,12 +18,14 @@ class Window(QMainWindow):
|
|||||||
self.lon = 37.530887
|
self.lon = 37.530887
|
||||||
self.lat = 55.703118
|
self.lat = 55.703118
|
||||||
self.variant_map = "map"
|
self.variant_map = "map"
|
||||||
|
self.org_point = "0.0,0.0"
|
||||||
self.update()
|
self.update()
|
||||||
self.button_group = QButtonGroup()
|
self.button_group = QButtonGroup(None)
|
||||||
self.button_group.addButton(self.map)
|
self.button_group.addButton(self.map)
|
||||||
self.button_group.addButton(self.sat)
|
self.button_group.addButton(self.sat)
|
||||||
self.button_group.addButton(self.skl)
|
self.button_group.addButton(self.skl)
|
||||||
self.button_group.buttonClicked.connect(self.push_button)
|
self.button_group.buttonClicked.connect(self.push_button)
|
||||||
|
self.find.clicked.connect(self.search_organization)
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
try:
|
try:
|
||||||
@@ -49,7 +52,7 @@ class Window(QMainWindow):
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
get_img_map(self.delta, (self.lon, self.lat), self.variant_map)
|
get_img_map(self.delta, (self.lon, self.lat), self.variant_map, self.org_point)
|
||||||
self.pixmap = QPixmap('image.png')
|
self.pixmap = QPixmap('image.png')
|
||||||
self.label.setPixmap(self.pixmap)
|
self.label.setPixmap(self.pixmap)
|
||||||
self.label.resize(self.pixmap.width(), self.pixmap.height())
|
self.label.resize(self.pixmap.width(), self.pixmap.height())
|
||||||
@@ -62,6 +65,11 @@ class Window(QMainWindow):
|
|||||||
self.variant_map = button.text()
|
self.variant_map = button.text()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def search_organization(self):
|
||||||
|
# Москва, ул. Ак. Королева, 12
|
||||||
|
self.org_point, self.lon, self.lat = search_organization_pos(self.plainTextEdit.toPlainText())
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
App = QApplication(sys.argv)
|
App = QApplication(sys.argv)
|
||||||
window = Window()
|
window = Window()
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>550</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>70</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>450</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="find">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>610</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>191</width>
|
||||||
|
<height>71</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Искать</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QRadioButton" name="map">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>610</x>
|
||||||
|
<y>70</y>
|
||||||
|
<width>114</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>map</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QRadioButton" name="sat">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>610</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>114</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>sat</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QRadioButton" name="skl">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>610</x>
|
||||||
|
<y>130</y>
|
||||||
|
<width>114</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>skl</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPlainTextEdit" name="plainTextEdit">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>611</width>
|
||||||
|
<height>70</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>29</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user