qmaps 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qmaps/__init__.py +3 -0
- qmaps/base.py +140 -0
- qmaps/googlemaps.py +167 -0
- qmaps/leaflet.py +173 -0
- qmaps/openlayers.py +118 -0
- qmaps/py.typed +0 -0
- qmaps/resources/googlemaps_googlemaps.htm +190 -0
- qmaps/resources/googlemaps_osm.htm +246 -0
- qmaps/resources/leaflet_osm.htm +190 -0
- qmaps/resources/openlayers_osm.htm +165 -0
- qmaps-0.0.1.dist-info/METADATA +44 -0
- qmaps-0.0.1.dist-info/RECORD +14 -0
- qmaps-0.0.1.dist-info/WHEEL +4 -0
- qmaps-0.0.1.dist-info/licenses/LICENSE +21 -0
qmaps/__init__.py
ADDED
qmaps/base.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import webbrowser
|
|
4
|
+
from typing import Any, Optional, Sequence
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from PySide6 import QtCore, QtGui, QtWidgets
|
|
8
|
+
from PySide6.QtWebChannel import QWebChannel
|
|
9
|
+
from PySide6.QtWebEngineCore import QWebEnginePage
|
|
10
|
+
from PySide6.QtWebEngineWidgets import QWebEngineView
|
|
11
|
+
except ImportError:
|
|
12
|
+
from PySide2 import QtCore, QtGui, QtWidgets
|
|
13
|
+
from PySide2.QtWebChannel import QWebChannel
|
|
14
|
+
from PySide2.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
logmap = {
|
|
18
|
+
QWebEnginePage.JavaScriptConsoleMessageLevel.InfoMessageLevel: logging.INFO,
|
|
19
|
+
QWebEnginePage.JavaScriptConsoleMessageLevel.WarningMessageLevel: logging.WARNING,
|
|
20
|
+
QWebEnginePage.JavaScriptConsoleMessageLevel.ErrorMessageLevel: logging.ERROR,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
jslog = logging.getLogger("javascript")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def jsrepr(obj: Any) -> str:
|
|
27
|
+
if obj is None:
|
|
28
|
+
return "null"
|
|
29
|
+
elif isinstance(obj, str):
|
|
30
|
+
return repr(obj)
|
|
31
|
+
elif isinstance(obj, bool): # handle bool before int, since a bool is a int
|
|
32
|
+
return "true" if obj else "false"
|
|
33
|
+
elif isinstance(obj, (int, float)):
|
|
34
|
+
return str(obj)
|
|
35
|
+
else:
|
|
36
|
+
raise TypeError(f"Unhandled type: {type(obj)}")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def js_func_call(name: str, args: Sequence[Any]) -> str:
|
|
40
|
+
args = ", ".join(map(jsrepr, args))
|
|
41
|
+
return f"{name}({args});"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class QMapBasePage(QWebEnginePage):
|
|
45
|
+
accept_language = "en-US,en;q=0.9"
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self, channel: QWebChannel, cache_dir: str, persistent_dir: str, parent: Optional[QtWidgets.QWidget] = None
|
|
49
|
+
) -> None:
|
|
50
|
+
QWebEnginePage.__init__(self, parent)
|
|
51
|
+
|
|
52
|
+
self.profile().setCachePath(cache_dir)
|
|
53
|
+
self.profile().setPersistentStoragePath(persistent_dir)
|
|
54
|
+
self.profile().setHttpAcceptLanguage(self.accept_language) # important! otherwise OSM requests are blocked
|
|
55
|
+
|
|
56
|
+
self.setWebChannel(channel)
|
|
57
|
+
|
|
58
|
+
def acceptNavigationRequest(self, url: QtCore.QUrl, type: QWebEnginePage.NavigationType, isMainFrame: bool) -> bool:
|
|
59
|
+
scheme = url.scheme()
|
|
60
|
+
if type == QWebEnginePage.NavigationType.NavigationTypeLinkClicked and scheme in ("http", "https"):
|
|
61
|
+
urlstr = url.toEncoded()
|
|
62
|
+
logging.warning("Open <%s> in browser", urlstr)
|
|
63
|
+
webbrowser.open(urlstr)
|
|
64
|
+
return False
|
|
65
|
+
return True
|
|
66
|
+
|
|
67
|
+
def javaScriptConsoleMessage(
|
|
68
|
+
self, level: QWebEnginePage.JavaScriptConsoleMessageLevel, message: str, lineNumber: int, sourceID: str
|
|
69
|
+
) -> None:
|
|
70
|
+
sourceID = self.parent().clean_log_url(sourceID)
|
|
71
|
+
|
|
72
|
+
if sourceID.startswith("data:"):
|
|
73
|
+
sourceID = sourceID[:20] + "..."
|
|
74
|
+
|
|
75
|
+
extra = {"sourceID": sourceID, "lineNumber": lineNumber}
|
|
76
|
+
jslog.log(logmap[level], message, extra=extra)
|
|
77
|
+
|
|
78
|
+
def run_script_async(self, script: str) -> None:
|
|
79
|
+
self.runJavaScript(script)
|
|
80
|
+
|
|
81
|
+
def run_script_sync(self, script: str) -> Any:
|
|
82
|
+
loop = QtCore.QEventLoop()
|
|
83
|
+
result: Optional[str] = None
|
|
84
|
+
|
|
85
|
+
def callback(arg: Optional[str]) -> None:
|
|
86
|
+
nonlocal result
|
|
87
|
+
result = arg
|
|
88
|
+
loop.quit()
|
|
89
|
+
|
|
90
|
+
self.runJavaScript(script, 0, callback)
|
|
91
|
+
loop.exec_()
|
|
92
|
+
if isinstance(result, str):
|
|
93
|
+
return json.loads(result)
|
|
94
|
+
else:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class QMapBase(QWebEngineView):
|
|
99
|
+
def __init__(
|
|
100
|
+
self,
|
|
101
|
+
channel_name: str,
|
|
102
|
+
cache_dir: str = "cache",
|
|
103
|
+
persistent_dir: str = "persistent",
|
|
104
|
+
) -> None:
|
|
105
|
+
QWebEngineView.__init__(self)
|
|
106
|
+
self.initialized = False
|
|
107
|
+
|
|
108
|
+
channel = QWebChannel(self)
|
|
109
|
+
page = QMapBasePage(channel, cache_dir, persistent_dir, self)
|
|
110
|
+
self.setPage(page)
|
|
111
|
+
self.loadFinished.connect(self.on_load_finished)
|
|
112
|
+
|
|
113
|
+
channel.registerObject(channel_name, self)
|
|
114
|
+
|
|
115
|
+
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: # disable default QWebEngineView context menu
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
def clean_log_url(self, url: str) -> str:
|
|
119
|
+
return url
|
|
120
|
+
|
|
121
|
+
def wait_until_ready(self) -> None:
|
|
122
|
+
if not self.initialized:
|
|
123
|
+
loop = QtCore.QEventLoop()
|
|
124
|
+
self.loadFinished.connect(loop.quit)
|
|
125
|
+
loop.exec_()
|
|
126
|
+
|
|
127
|
+
@QtCore.Slot(bool)
|
|
128
|
+
def on_load_finished(self, ok: bool) -> None:
|
|
129
|
+
if not ok:
|
|
130
|
+
raise RuntimeError("Could not initialize map")
|
|
131
|
+
|
|
132
|
+
self.initialized = True
|
|
133
|
+
|
|
134
|
+
def run_func_async(self, name: str, *args) -> None:
|
|
135
|
+
script = js_func_call(name, args)
|
|
136
|
+
self.page().run_script_async(script)
|
|
137
|
+
|
|
138
|
+
def run_func_sync(self, name: str, *args) -> Any:
|
|
139
|
+
script = js_func_call(name, args)
|
|
140
|
+
return self.page().run_script_sync(script)
|
qmaps/googlemaps.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from typing import Optional, Tuple
|
|
2
|
+
|
|
3
|
+
from importlib_resources import files
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from PySide6.QtCore import Signal, Slot
|
|
7
|
+
except ImportError:
|
|
8
|
+
from PySide2.QtCore import Signal, Slot
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from .base import QMapBase
|
|
12
|
+
|
|
13
|
+
""" GoogleMaps QWebEngineView supporting GoogleMaps, OSM
|
|
14
|
+
Google Maps JavaScript API: https://developers.google.com/maps/documentation/javascript/overview
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class QGoogleMapsBase(QMapBase):
|
|
19
|
+
map_click = Signal(float, float)
|
|
20
|
+
map_contextmenu = Signal(float, float)
|
|
21
|
+
map_dblclick = Signal(float, float)
|
|
22
|
+
map_move = Signal(float, float)
|
|
23
|
+
map_moveend = Signal(float, float)
|
|
24
|
+
map_movestart = Signal(float, float)
|
|
25
|
+
map_rightclick = Signal(float, float)
|
|
26
|
+
map_zoom = Signal(int)
|
|
27
|
+
|
|
28
|
+
marker_move = Signal(str, float, float)
|
|
29
|
+
marker_moveend = Signal(str, float, float)
|
|
30
|
+
marker_movestart = Signal(str, float, float)
|
|
31
|
+
marker_click = Signal(str, float, float)
|
|
32
|
+
marker_dblclick = Signal(str, float, float)
|
|
33
|
+
marker_rightclick = Signal(str, float, float)
|
|
34
|
+
|
|
35
|
+
# JavaScript API
|
|
36
|
+
|
|
37
|
+
@Slot(float, float)
|
|
38
|
+
def on_click(self, lat: float, lng: float) -> None:
|
|
39
|
+
self.map_click.emit(lat, lng)
|
|
40
|
+
|
|
41
|
+
@Slot(float, float)
|
|
42
|
+
def on_contextmenu(self, lat: float, lng: float) -> None:
|
|
43
|
+
self.map_contextmenu.emit(lat, lng)
|
|
44
|
+
|
|
45
|
+
@Slot(float, float)
|
|
46
|
+
def on_dblclick(self, lat: float, lng: float) -> None:
|
|
47
|
+
self.map_dblclick.emit(lat, lng)
|
|
48
|
+
|
|
49
|
+
@Slot(float, float)
|
|
50
|
+
def on_move(self, lat: float, lng: float) -> None:
|
|
51
|
+
self.map_move.emit(lat, lng)
|
|
52
|
+
|
|
53
|
+
@Slot(float, float)
|
|
54
|
+
def on_moveend(self, lat: float, lng: float) -> None:
|
|
55
|
+
self.map_moveend.emit(lat, lng)
|
|
56
|
+
|
|
57
|
+
@Slot(float, float)
|
|
58
|
+
def on_movestart(self, lat: float, lng: float) -> None:
|
|
59
|
+
self.map_movestart.emit(lat, lng)
|
|
60
|
+
|
|
61
|
+
@Slot(float, float)
|
|
62
|
+
def on_rightclick(self, lat: float, lng: float) -> None:
|
|
63
|
+
self.map_rightclick.emit(lat, lng)
|
|
64
|
+
|
|
65
|
+
@Slot(int)
|
|
66
|
+
def on_zoom(self, zoom: int) -> None:
|
|
67
|
+
self.map_zoom.emit(zoom)
|
|
68
|
+
|
|
69
|
+
@Slot(str, float, float)
|
|
70
|
+
def on_marker_move(self, key: str, lat: float, lng: float) -> None:
|
|
71
|
+
self.marker_move.emit(key, lat, lng)
|
|
72
|
+
|
|
73
|
+
@Slot(str, float, float)
|
|
74
|
+
def on_marker_moveend(self, key: str, lat: float, lng: float) -> None:
|
|
75
|
+
self.marker_moveend.emit(key, lat, lng)
|
|
76
|
+
|
|
77
|
+
@Slot(str, float, float)
|
|
78
|
+
def on_marker_movestart(self, key: str, lat: float, lng: float) -> None:
|
|
79
|
+
self.marker_movestart.emit(key, lat, lng)
|
|
80
|
+
|
|
81
|
+
@Slot(str, float, float)
|
|
82
|
+
def on_marker_click(self, key: str, lat: float, lng: float) -> None:
|
|
83
|
+
self.marker_click.emit(key, lat, lng)
|
|
84
|
+
|
|
85
|
+
@Slot(str, float, float)
|
|
86
|
+
def on_marker_dblclick(self, key: str, lat: float, lng: float) -> None:
|
|
87
|
+
self.marker_dblclick.emit(key, lat, lng)
|
|
88
|
+
|
|
89
|
+
@Slot(str, float, float)
|
|
90
|
+
def on_marker_rightclick(self, key: str, lat: float, lng: float) -> None:
|
|
91
|
+
self.marker_rightclick.emit(key, lat, lng)
|
|
92
|
+
|
|
93
|
+
# Python API
|
|
94
|
+
|
|
95
|
+
def get_center(self) -> Tuple[float, float]:
|
|
96
|
+
lat, lon = self.run_func_sync("get_center")
|
|
97
|
+
return (lat, lon)
|
|
98
|
+
|
|
99
|
+
def set_center(self, latitude: float, longitude: float) -> None:
|
|
100
|
+
self.run_func_async("set_center", latitude, longitude)
|
|
101
|
+
|
|
102
|
+
def set_zoom(self, zoom: int) -> None:
|
|
103
|
+
self.run_func_async("set_zoom", zoom)
|
|
104
|
+
|
|
105
|
+
def move_marker(self, key: str, latitude: float, longitude: float) -> None:
|
|
106
|
+
self.run_func_async("move_marker", key, latitude, longitude)
|
|
107
|
+
|
|
108
|
+
def change_marker(
|
|
109
|
+
self,
|
|
110
|
+
key: str,
|
|
111
|
+
clickable: bool = True,
|
|
112
|
+
draggable: bool = False,
|
|
113
|
+
label: Optional[str] = None,
|
|
114
|
+
title: Optional[str] = None,
|
|
115
|
+
) -> None:
|
|
116
|
+
self.run_func_async("change_marker", key, clickable, draggable, label, title)
|
|
117
|
+
|
|
118
|
+
def delete_marker(self, key: str) -> None:
|
|
119
|
+
self.run_func_async("delete_marker", key)
|
|
120
|
+
|
|
121
|
+
def add_marker(
|
|
122
|
+
self,
|
|
123
|
+
key: str,
|
|
124
|
+
latitude: float,
|
|
125
|
+
longitude: float,
|
|
126
|
+
clickable: bool = True,
|
|
127
|
+
draggable: bool = False,
|
|
128
|
+
label: Optional[str] = None,
|
|
129
|
+
title: Optional[str] = None,
|
|
130
|
+
) -> None:
|
|
131
|
+
self.run_func_async("add_marker", key, latitude, longitude, clickable, draggable, label, title)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class QGoogleMapsOSM(QGoogleMapsBase):
|
|
135
|
+
"""QWidget (QWebEngineView) which renders OpenStreetMap using GoogleMaps"""
|
|
136
|
+
|
|
137
|
+
HTML = files(__package__).joinpath("resources/googlemaps_osm.htm").read_text(encoding="utf-8")
|
|
138
|
+
|
|
139
|
+
def __init__(self, latitude: float = 0, longitude: float = 0, zoom: int = 0) -> None:
|
|
140
|
+
super().__init__("qGoogleMaps")
|
|
141
|
+
|
|
142
|
+
html = self.HTML
|
|
143
|
+
html = html.replace("'<latitude>'", str(latitude))
|
|
144
|
+
html = html.replace("'<longitude>'", str(longitude))
|
|
145
|
+
html = html.replace("'<zoom>'", str(zoom))
|
|
146
|
+
self.page().setHtml(html)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class QGoogleMapsGoogleMaps(QGoogleMapsBase):
|
|
150
|
+
"""QWidget (QWebEngineView) which renders GoogleMaps using GoogleMaps"""
|
|
151
|
+
|
|
152
|
+
HTML = files(__package__).joinpath("resources/googlemaps_googlemaps.htm").read_text(encoding="utf-8")
|
|
153
|
+
|
|
154
|
+
def __init__(self, api_key: str, latitude: float = 0, longitude: float = 0, zoom: int = 0) -> None:
|
|
155
|
+
super().__init__("qGoogleMaps")
|
|
156
|
+
|
|
157
|
+
self.api_key = api_key
|
|
158
|
+
|
|
159
|
+
html = self.HTML
|
|
160
|
+
html = html.replace("<YOUR_API_KEY>", api_key)
|
|
161
|
+
html = html.replace("'<latitude>'", str(latitude))
|
|
162
|
+
html = html.replace("'<longitude>'", str(longitude))
|
|
163
|
+
html = html.replace("'<zoom>'", str(zoom))
|
|
164
|
+
self.page().setHtml(html)
|
|
165
|
+
|
|
166
|
+
def clean_log_url(self, url: str) -> str:
|
|
167
|
+
return url.replace(self.api_key, "<redacted>")
|
qmaps/leaflet.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Optional, Sequence, Tuple, Union
|
|
3
|
+
|
|
4
|
+
from importlib_resources import files
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from PySide6 import QtCore
|
|
8
|
+
except ImportError:
|
|
9
|
+
from PySide2 import QtCore
|
|
10
|
+
|
|
11
|
+
from .base import QMapBase
|
|
12
|
+
|
|
13
|
+
""" Leaflet QWebEngineView supporting OSM
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
CoordsT = Sequence[Tuple[float, float]]
|
|
17
|
+
NumberT = Union[int, float]
|
|
18
|
+
|
|
19
|
+
DEFAULT_MARKER_TITLE: str = ""
|
|
20
|
+
DEFAULT_MARKER_OPACITY: NumberT = 1.0
|
|
21
|
+
DEFAULT_PATH_COLOR: str = "#3388ff"
|
|
22
|
+
DEFAULT_PATH_WEIGHT: NumberT = 3
|
|
23
|
+
DEFAULT_PATH_FILL_COLOR: str = "*"
|
|
24
|
+
DEFAULT_PATH_FILL_OPACITY: NumberT = 0.2
|
|
25
|
+
DEFAULT_PATH_OPACITY: NumberT = 1.0
|
|
26
|
+
DEFAULT_IMAGEOVERLAY_OPACITY: NumberT = 1.0
|
|
27
|
+
DEFAULT_IMAGEOVERLAY_INTERACTIVE: bool = False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class QLeafletOSM(QMapBase):
|
|
31
|
+
"""QWidget (QWebEngineView) which renders OpenStreetMap using Leaflet"""
|
|
32
|
+
|
|
33
|
+
HTML = files(__package__).joinpath("resources/leaflet_osm.htm").read_text(encoding="utf-8")
|
|
34
|
+
|
|
35
|
+
map_move = QtCore.Signal(float, float)
|
|
36
|
+
map_moveend = QtCore.Signal(float, float)
|
|
37
|
+
map_movestart = QtCore.Signal(float, float)
|
|
38
|
+
map_click = QtCore.Signal(float, float)
|
|
39
|
+
map_contextmenu = QtCore.Signal(float, float)
|
|
40
|
+
map_dblclick = QtCore.Signal(float, float)
|
|
41
|
+
map_zoom = QtCore.Signal(float, float, int)
|
|
42
|
+
|
|
43
|
+
def __init__(self, latitude: float = 0, longitude: float = 0, zoom: int = 0) -> None:
|
|
44
|
+
super().__init__("qOSM")
|
|
45
|
+
|
|
46
|
+
html = self.HTML
|
|
47
|
+
html = html.replace("'<latitude>'", str(latitude))
|
|
48
|
+
html = html.replace("'<longitude>'", str(longitude))
|
|
49
|
+
html = html.replace("'<zoom>'", str(zoom))
|
|
50
|
+
self.page().setHtml(html)
|
|
51
|
+
|
|
52
|
+
# JavaScript API
|
|
53
|
+
|
|
54
|
+
@QtCore.Slot(float, float)
|
|
55
|
+
def on_move(self, lat: float, lng: float) -> None:
|
|
56
|
+
self.map_move.emit(lat, lng)
|
|
57
|
+
|
|
58
|
+
@QtCore.Slot(float, float)
|
|
59
|
+
def on_moveend(self, lat: float, lng: float) -> None:
|
|
60
|
+
self.map_moveend.emit(lat, lng)
|
|
61
|
+
|
|
62
|
+
@QtCore.Slot(float, float)
|
|
63
|
+
def on_movestart(self, lat: float, lng: float) -> None:
|
|
64
|
+
self.map_movestart.emit(lat, lng)
|
|
65
|
+
|
|
66
|
+
@QtCore.Slot(float, float)
|
|
67
|
+
def on_click(self, lat: float, lng: float) -> None:
|
|
68
|
+
self.map_click.emit(lat, lng)
|
|
69
|
+
|
|
70
|
+
@QtCore.Slot(float, float)
|
|
71
|
+
def on_contextmenu(self, lat: float, lng: float) -> None:
|
|
72
|
+
self.map_contextmenu.emit(lat, lng)
|
|
73
|
+
|
|
74
|
+
@QtCore.Slot(float, float)
|
|
75
|
+
def on_dblclick(self, lat: float, lng: float) -> None:
|
|
76
|
+
self.map_dblclick.emit(lat, lng)
|
|
77
|
+
|
|
78
|
+
@QtCore.Slot(float, float, int)
|
|
79
|
+
def on_zoom(self, lat: float, lng: float, zoom: int) -> None:
|
|
80
|
+
self.map_zoom.emit(lat, lng, zoom)
|
|
81
|
+
|
|
82
|
+
# Sync Python API
|
|
83
|
+
|
|
84
|
+
def get_center(self) -> dict:
|
|
85
|
+
return self.run_func_sync("get_center")
|
|
86
|
+
|
|
87
|
+
def get_zoom(self) -> int:
|
|
88
|
+
return self.run_func_sync("get_zoom")
|
|
89
|
+
|
|
90
|
+
def get_bounds(self) -> Tuple[dict, dict]:
|
|
91
|
+
a, b = self.run_func_sync("get_bounds")
|
|
92
|
+
return a, b
|
|
93
|
+
|
|
94
|
+
# Async Python API
|
|
95
|
+
|
|
96
|
+
def set_view(self, lat: float, lng: float, zoom: int) -> None:
|
|
97
|
+
self.run_func_async("set_view", lat, lng, zoom)
|
|
98
|
+
|
|
99
|
+
def set_zoom(self, zoom: int) -> None:
|
|
100
|
+
self.run_func_async("set_zoom", zoom)
|
|
101
|
+
|
|
102
|
+
def fit_bounds(self, lat1: float, lng1: float, lat2: float, lng2: float) -> None:
|
|
103
|
+
self.run_func_async("fit_bounds", lat1, lng1, lat2, lng2)
|
|
104
|
+
|
|
105
|
+
def pan_to(self, lat: float, lng: float) -> None:
|
|
106
|
+
self.run_func_async("pan_to", lat, lng)
|
|
107
|
+
|
|
108
|
+
def add_marker(
|
|
109
|
+
self,
|
|
110
|
+
key: str,
|
|
111
|
+
lat: float,
|
|
112
|
+
lng: float,
|
|
113
|
+
title: str = DEFAULT_MARKER_TITLE,
|
|
114
|
+
opacity: NumberT = DEFAULT_MARKER_OPACITY,
|
|
115
|
+
popup: Optional[str] = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
self.run_func_async("add_marker", key, lat, lng, title, opacity, popup)
|
|
118
|
+
|
|
119
|
+
def add_circle(
|
|
120
|
+
self,
|
|
121
|
+
key: str,
|
|
122
|
+
lat: float,
|
|
123
|
+
lng: float,
|
|
124
|
+
radius: int,
|
|
125
|
+
color: str = DEFAULT_PATH_COLOR,
|
|
126
|
+
fill_color: str = DEFAULT_PATH_FILL_COLOR,
|
|
127
|
+
fill_opacity: NumberT = DEFAULT_PATH_FILL_OPACITY,
|
|
128
|
+
popup: Optional[str] = None,
|
|
129
|
+
) -> None:
|
|
130
|
+
self.run_func_async("add_circle", key, lat, lng, radius, color, fill_color, fill_opacity, popup)
|
|
131
|
+
|
|
132
|
+
def add_polygon(
|
|
133
|
+
self,
|
|
134
|
+
key: str,
|
|
135
|
+
latlngs: Union[CoordsT, Sequence[CoordsT], Sequence[Sequence[CoordsT]]],
|
|
136
|
+
smooth_factor: NumberT = 1.0,
|
|
137
|
+
color: str = DEFAULT_PATH_COLOR,
|
|
138
|
+
weight: NumberT = DEFAULT_PATH_WEIGHT,
|
|
139
|
+
popup: Optional[str] = None,
|
|
140
|
+
) -> None:
|
|
141
|
+
latlng_list = json.dumps(latlngs)
|
|
142
|
+
self.run_func_async("add_polygon", key, latlng_list, smooth_factor, color, weight, popup)
|
|
143
|
+
|
|
144
|
+
def add_polyline(
|
|
145
|
+
self,
|
|
146
|
+
key: str,
|
|
147
|
+
latlngs: Union[CoordsT, Sequence[CoordsT]],
|
|
148
|
+
smooth_factor: NumberT = 1.0,
|
|
149
|
+
color: str = DEFAULT_PATH_COLOR,
|
|
150
|
+
weight: NumberT = DEFAULT_PATH_WEIGHT,
|
|
151
|
+
popup: Optional[str] = None,
|
|
152
|
+
) -> None:
|
|
153
|
+
latlng_list = json.dumps(latlngs)
|
|
154
|
+
self.run_func_async("add_polyline", key, latlng_list, smooth_factor, color, weight, popup)
|
|
155
|
+
|
|
156
|
+
def add_image_url(
|
|
157
|
+
self,
|
|
158
|
+
key: str,
|
|
159
|
+
image_url: str,
|
|
160
|
+
lat1: float,
|
|
161
|
+
lng1: float,
|
|
162
|
+
lat2: float,
|
|
163
|
+
lng2: float,
|
|
164
|
+
opacity: NumberT = DEFAULT_IMAGEOVERLAY_OPACITY,
|
|
165
|
+
interactive: bool = DEFAULT_IMAGEOVERLAY_INTERACTIVE,
|
|
166
|
+
) -> None:
|
|
167
|
+
self.run_func_async("add_image_url", key, image_url, lat1, lng1, lat2, lng2, opacity, interactive)
|
|
168
|
+
|
|
169
|
+
def remove_layer(self, key: str) -> None:
|
|
170
|
+
self.run_func_async("remove_layer", key)
|
|
171
|
+
|
|
172
|
+
def open_popup(self, key: str) -> None:
|
|
173
|
+
self.run_func_async("open_popup", key)
|
qmaps/openlayers.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from importlib_resources import files
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from PySide6 import QtCore
|
|
7
|
+
except ImportError:
|
|
8
|
+
from PySide2 import QtCore
|
|
9
|
+
|
|
10
|
+
from .base import QMapBase
|
|
11
|
+
|
|
12
|
+
""" OpenLayers QWebEngineView supporting OSM
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class QOpenLayersOSM(QMapBase):
|
|
17
|
+
"""QWidget (QWebEngineView) which renders OpenStreetMap using OpenLayers"""
|
|
18
|
+
|
|
19
|
+
HTML = files(__package__).joinpath("resources/openlayers_osm.htm").read_text(encoding="utf-8")
|
|
20
|
+
|
|
21
|
+
map_click = QtCore.Signal(float, float)
|
|
22
|
+
map_dblclick = QtCore.Signal(float, float)
|
|
23
|
+
map_error = QtCore.Signal()
|
|
24
|
+
map_loadend = QtCore.Signal()
|
|
25
|
+
map_loadstart = QtCore.Signal()
|
|
26
|
+
map_moveend = QtCore.Signal(float, float, float, float)
|
|
27
|
+
map_movestart = QtCore.Signal(float, float, float, float)
|
|
28
|
+
map_pointerdrag = QtCore.Signal()
|
|
29
|
+
map_pointermove = QtCore.Signal()
|
|
30
|
+
map_postcompose = QtCore.Signal()
|
|
31
|
+
map_postrender = QtCore.Signal()
|
|
32
|
+
map_precompose = QtCore.Signal()
|
|
33
|
+
map_rendercomplete = QtCore.Signal()
|
|
34
|
+
map_singleclick = QtCore.Signal(float, float)
|
|
35
|
+
|
|
36
|
+
def __init__(self, latitude: float = 0, longitude: float = 0, zoom: int = 0) -> None:
|
|
37
|
+
super().__init__("qOSM")
|
|
38
|
+
|
|
39
|
+
html = self.HTML
|
|
40
|
+
html = html.replace("'<latitude>'", str(latitude))
|
|
41
|
+
html = html.replace("'<longitude>'", str(longitude))
|
|
42
|
+
html = html.replace("'<zoom>'", str(zoom))
|
|
43
|
+
self.page().setHtml(html)
|
|
44
|
+
|
|
45
|
+
# JavaScript API
|
|
46
|
+
|
|
47
|
+
@QtCore.Slot(float, float)
|
|
48
|
+
def on_click(self, lat, lng) -> None:
|
|
49
|
+
self.map_click.emit(lat, lng)
|
|
50
|
+
|
|
51
|
+
@QtCore.Slot(float, float)
|
|
52
|
+
def on_dblclick(self, lat, lng) -> None:
|
|
53
|
+
self.map_dblclick.emit(lat, lng)
|
|
54
|
+
|
|
55
|
+
@QtCore.Slot()
|
|
56
|
+
def on_error(self) -> None:
|
|
57
|
+
self.map_error.emit()
|
|
58
|
+
|
|
59
|
+
@QtCore.Slot()
|
|
60
|
+
def on_loadend(self) -> None:
|
|
61
|
+
self.map_loadend.emit()
|
|
62
|
+
|
|
63
|
+
@QtCore.Slot()
|
|
64
|
+
def on_loadstart(self) -> None:
|
|
65
|
+
self.map_loadstart.emit()
|
|
66
|
+
|
|
67
|
+
@QtCore.Slot(float, float, float, float)
|
|
68
|
+
def on_moveend(self, minlat: float, minlon: float, maxlat: float, maxlon: float) -> None:
|
|
69
|
+
self.map_moveend.emit(minlat, minlon, maxlat, maxlon)
|
|
70
|
+
|
|
71
|
+
@QtCore.Slot(float, float, float, float)
|
|
72
|
+
def on_movestart(self, minlat: float, minlon: float, maxlat: float, maxlon: float) -> None:
|
|
73
|
+
self.map_movestart.emit(minlat, minlon, maxlat, maxlon)
|
|
74
|
+
|
|
75
|
+
@QtCore.Slot()
|
|
76
|
+
def on_pointerdrag(self) -> None:
|
|
77
|
+
self.map_pointerdrag.emit()
|
|
78
|
+
|
|
79
|
+
@QtCore.Slot()
|
|
80
|
+
def on_pointermove(self) -> None:
|
|
81
|
+
self.map_pointermove.emit()
|
|
82
|
+
|
|
83
|
+
@QtCore.Slot()
|
|
84
|
+
def on_postcompose(self) -> None:
|
|
85
|
+
self.map_postcompose.emit()
|
|
86
|
+
|
|
87
|
+
@QtCore.Slot()
|
|
88
|
+
def on_postrender(self) -> None:
|
|
89
|
+
self.map_postrender.emit()
|
|
90
|
+
|
|
91
|
+
@QtCore.Slot()
|
|
92
|
+
def on_precompose(self) -> None:
|
|
93
|
+
self.map_precompose.emit()
|
|
94
|
+
|
|
95
|
+
@QtCore.Slot()
|
|
96
|
+
def on_rendercomplete(self) -> None:
|
|
97
|
+
self.map_rendercomplete.emit()
|
|
98
|
+
|
|
99
|
+
@QtCore.Slot(float, float)
|
|
100
|
+
def on_singleclick(self, lat, lng) -> None:
|
|
101
|
+
self.map_singleclick.emit(lat, lng)
|
|
102
|
+
|
|
103
|
+
# Python API
|
|
104
|
+
|
|
105
|
+
def get_center(self) -> List[float]:
|
|
106
|
+
return self.run_func_sync("get_center")
|
|
107
|
+
|
|
108
|
+
def get_zoom(self) -> float:
|
|
109
|
+
return self.run_func_sync("get_zoom")
|
|
110
|
+
|
|
111
|
+
def add_layer_point(self, latitude: float, longitude: float) -> None:
|
|
112
|
+
self.run_func_async("add_layer_point", latitude, longitude)
|
|
113
|
+
|
|
114
|
+
def add_overlay_text(self, latitude: float, longitude: float, text: str) -> None:
|
|
115
|
+
self.run_func_async("add_overlay_text", latitude, longitude, text)
|
|
116
|
+
|
|
117
|
+
# def pan_to(self, lat: float, lng: float) -> None:
|
|
118
|
+
# self.run_func_async("centerOn", coordinate, size, position)
|
qmaps/py.typed
ADDED
|
File without changes
|