Skip to main content

pyqtlet2

pyqtlet is a Leaflet map wrapper for Qt bindings. In construction and design, it mimics the official leaflet api as much as possible.

About

This is a fork of the repository pyqtlet from @skylarkdrones. Since the original repository is not further maintained. Since I find this package very useful for a map implementation in the QT environment, I want to further develop this package. If you want to extend this package feel free to get in contact with me or create an Issue/Pull Request with a change!

Installation

You as a user need to specify the Qt package you want to use. Please check qtpy to find out which Qt bindings can be used.

pip3 install "pyqtlet2[PyQt5]"
# or
pip3 install "pyqtlet2[PySide6]"

If you have multiple Qt bindings installed in your environment, please specify the necessary environment variable inside your code.

import os
os.environ['QT_API'] = 'pyqt5'
from qtpy import QtGui

Check if the installation was successful:

# To test whether it is successfully working
python3 
>>> from pyqtlet import L, MapWidget
>>> # No errors

Usage

import os
import sys
os.environ['QT_API'] = 'pyqt5'
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
from pyqtlet2 import L, MapWidget


class MapWindow(QWidget):
    def __init__(self):
        # Setting up the widgets and layout
        super().__init__()
        self.mapWidget = MapWidget()
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.mapWidget)
        self.setLayout(self.layout)

        # Working with the maps with pyqtlet
        self.map = L.map(self.mapWidget)
        self.map.setView([12.97, 77.59], 10)
        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(self.map)
        self.marker = L.marker([12.934056, 77.610029])
        self.marker.bindPopup('Maps are a treasure.')
        self.map.addLayer(self.marker)
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    widget = MapWindow()
    sys.exit(app.exec_())

Additional Leaflet Packages

Using Unimplemented Leaflet Features

At this time, there is none actively adding features to pyqtlet. This means that there are a lot of Leaflet features that are not implemented in pyqtlet. However, there is still a way to access these features via the runJavaScript api. This allows arbitrary code to be run within the map window.

For example, if we want to change the marker icon in the above example, add the following 2 lines of code after the self.map.addLayer(self.marker) statement.

        # Create a icon called markerIcon in the js runtime.
        self.map.runJavaScript('var markerIcon = L.icon({iconUrl: "https://leafletjs.com/examples/custom-icons/leaf-red.png"});')
        # Edit the existing python object by accessing it's jsName property
        self.map.runJavaScript(f'{self.marker.jsName}.setIcon(markerIcon);')

This technique will allow users to use all the features available in leaflet.

Contributors

A big thank you, goes to all the contributors of this project!

Contributing

In terms of contributing, there is a lot of work that still needs to be done. Specifically, there are a lot of leaflet features that need to be ported into pyqtlet. All contributions welcome.

Metadata

Release files for pyqtlet2 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqtlet2 0.9.3
File Size Uploaded
pyqtlet2-0.9.3.tar.gz 103.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyqtlet2 0.9.3
File Interpreter ABI Platform
pyqtlet2-0.9.3-py3-none-any.whl Python 3 none any Details

Total release size: 214.3 kB

Release files / pyqtlet2-0.9.3.tar.gz

Download URL pyqtlet2-0.9.3.tar.gz
Size 103.9 kB
Tags Source
SHA-256 checksum
How to use checksums
51b361bfb1305b63b4b10ff3f861881e3bd7894ed93e9dde294d5ba8a34784f5
BLAKE2b-256 checksum
How to use checksums
f7d5b9425b56506c8b2ddc64309bde30dce4adc371c602f9715f36a523bf983e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Release files / pyqtlet2-0.9.3-py3-none-any.whl

Download URL pyqtlet2-0.9.3-py3-none-any.whl
Size 110.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6ce718461cc4662b69623561d276975baac3cc2c17f5dddc8e448b91991c6ab
BLAKE2b-256 checksum
How to use checksums
14e8e3c1ee62759a87ba642409b96860f50c648ba1e898df8b4114fb2a01157a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.9.3 This release

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

1 release file

0.3.5

2 release files

0.3.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page