pax_global_header 0000666 0000000 0000000 00000000064 14366753660 0014532 g ustar 00root root 0000000 0000000 52 comment=0e9fdd819abd24dfecfd3449dbf5002e7b626410
pyqtlet2-0.9.3/ 0000775 0000000 0000000 00000000000 14366753660 0013327 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/.github/ 0000775 0000000 0000000 00000000000 14366753660 0014667 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/.github/workflows/ 0000775 0000000 0000000 00000000000 14366753660 0016724 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/.github/workflows/unit_tests.yml 0000664 0000000 0000000 00000002330 14366753660 0021646 0 ustar 00root root 0000000 0000000 # This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- '**'
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-and-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install Qt
uses: jurplel/install-qt-action@v2
# Runs a single command using the runners shell
- name: "Creating env"
run: python -m pip install -r requirements.txt
# Runs a set of commands using the runners shell
- name: Running tests
run: python TestSuite.py
pyqtlet2-0.9.3/.gitignore 0000664 0000000 0000000 00000000201 14366753660 0015310 0 ustar 00root root 0000000 0000000 __pycache__
build
pyqtlet2.egg-info
*/__pycache__
*.swp
trial.py
docs/build
dist/*
.idea
.python-version
venv
/playground.py
pyqtlet2-0.9.3/LICENSE.txt 0000664 0000000 0000000 00000006021 14366753660 0015151 0 ustar 00root root 0000000 0000000 Copyright (c) 2021, Leon Friedmann
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the pyqtlet2 project.
--- Copyright of original project ---
Copyright (c) 2018, Samarth Hattangady, Skylark Drones
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the pyqtlet project.
pyqtlet2-0.9.3/README.md 0000664 0000000 0000000 00000007215 14366753660 0014613 0 ustar 00root root 0000000 0000000 # pyqtlet2
pyqtlet is a Leaflet map wrapper for Qt bindings. In construction and design, it mimics the [official leaflet api](http://leafletjs.com/reference-1.3.0.html) 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](https://github.com/spyder-ide/qtpy) to find out which Qt bindings can be used.
``` bash
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.
``` python
import os
os.environ['QT_API'] = 'pyqt5'
from qtpy import QtGui
```
Check if the installation was successful:
``` bash
# To test whether it is successfully working
python3
>>> from pyqtlet import L, MapWidget
>>> # No errors
```
## Usage
``` python
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
- Leaflet.draw (Version 0.4.14) - https://github.com/Leaflet/Leaflet.draw
- Leaflet.RotatedMarker (Version 0.2.0) - https://github.com/bbecquet/Leaflet.RotatedMarker
## 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.
``` python
# 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.
pyqtlet2-0.9.3/TestSuite.py 0000664 0000000 0000000 00000001477 14366753660 0015643 0 ustar 00root root 0000000 0000000 """
Credits to Ned Batchelder https://stackoverflow.com/a/1732477/3672365
"""
import unittest
def main():
test_modules = [
'tests.test_parser',
'tests.test_layer_elements',
]
suite = unittest.TestSuite()
for t in test_modules:
try:
# If the module defines a suite() function, call it to get the suite.
mod = __import__(t, globals(), locals(), ['suite'])
suitefn = getattr(mod, 'suite')
suite.addTest(suitefn())
except (ImportError, AttributeError):
# else, just load all the test cases from the module.
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(t))
result = unittest.TextTestRunner().run(suite)
if not result.wasSuccessful():
exit(1)
if __name__ == '__main__':
main()
pyqtlet2-0.9.3/UPLOAD_NOTES.txt 0000664 0000000 0000000 00000001160 14366753660 0016022 0 ustar 00root root 0000000 0000000 Before every upload, things to change:
=====================================
1. Version in `setup.py`
2. Version in `pyqtlet/__init__.py`
Build for pypi
--------------
1. re -rf dist/
2. python3 setup.pt sdist
3. Commit, tag, push with tags
Push to test pypi and test.
---------------------------
# NOTE: Test pypi takes some time to update
1. python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
2. pip install --index-url https://test.pypi.org/simple/ pyqtlet==version
Push to pypi
------------
1. python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
Done
----
pyqtlet2-0.9.3/docs/ 0000775 0000000 0000000 00000000000 14366753660 0014257 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/docs/Makefile 0000664 0000000 0000000 00000001140 14366753660 0015713 0 ustar 00root root 0000000 0000000 # Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = pyqtlet
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) pyqtlet2-0.9.3/docs/make.bat 0000664 0000000 0000000 00000001457 14366753660 0015673 0 ustar 00root root 0000000 0000000 @ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=pyqtlet
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
:end
popd
pyqtlet2-0.9.3/docs/source/ 0000775 0000000 0000000 00000000000 14366753660 0015557 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/docs/source/_templates/ 0000775 0000000 0000000 00000000000 14366753660 0017714 5 ustar 00root root 0000000 0000000 pyqtlet2-0.9.3/docs/source/_templates/nav.rst 0000664 0000000 0000000 00000000163 14366753660 0021232 0 ustar 00root root 0000000 0000000 Navigation
==========
.. toctree::
getting-started
api-docs
tutorials
examples
contributing
pyqtlet2-0.9.3/docs/source/api-docs.rst 0000664 0000000 0000000 00000004550 14366753660 0020014 0 ustar 00root root 0000000 0000000 API Documentation
=================
pyqtlet was designed to mimic the `Official Leaflet API `_
as much as possible, similar to how PyQt5 mimics Qt. This allows a large amount of
laziness when it actually comes to writing the API docs for the module.
The documentation will only cover what methods have been implemented in pyqtlet.
The details about functionality, options etc. should be obtained from the Leaflet site.
In case of any discrepancies or specially implemented features, they will be mentioned
here in the docs. Otherwise, expect the method to be identical to its JS counterpart.
L.Evented
---------
Baseclass for all pyqtlet objects. All objects will inherit these methods
Methods
^^^^^^^
* getJsResponse(str:js, function:callback)
Runs the javascript and then triggers callback with the response
* runJavaScript(str:js)
Runs the javascript in the leaflet runtime
L.map
-----
L.map should be initialised with the mapWidget instead of the id of the map div.
Signals
^^^^^^^
* clicked
* zoom
* drawCreated
Methods
^^^^^^^
* addControl
* addLayer
* flyTo
* getCenter `[requires callback]`
* getBounds `[requires callback]`
* getZoom `[requires callback]`
* getState: `[requires callback]`
gets center, zoom, bounds, minZoom, maxZoom, size, pixelBounds, pixelOrigin and pixelWorldBounds
* hasLayer
* panTo
* removeControl
* removeLayer
* setMaxBounds
* fitBounds
* setMaxZoom
* setMinZoom
* setView
L.Layer
-------
Base class for all layer classes
Methods
^^^^^^^
* addTo
* bindPopup
* bindTooltip
* removeFrom
* unbindPopup
* unbindTooltip
L.imageOverlay
--------------
L.tileLayer
-----------
L.marker
--------
Methods
^^^^^^^
* setLatLng
* setOpacity
L.circleMarker
--------------
L.polyline
----------
L.polygon
---------
L.rectangle
-----------
L.circle
--------
L.layerGroup
------------
Methods
^^^^^^^
* addLayer
* removeLayer
* clearLayers
* toGeoJSON
L.featureGroup
--------------
Inherits from layerGroup
Methods
^^^^^^^
* createAndAddDrawnLayer(drawnLayer, options=None)
creates and adds layer to the feature group
drawnLayer: dict as returned by the 'draw:created' event.
L.control.layers
----------------
L.control.draw
--------------
pyqtlet2-0.9.3/docs/source/conf.py 0000664 0000000 0000000 00000011610 14366753660 0017055 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# pyqtlet2 documentation build configuration file, created by
# sphinx-quickstart on Tue May 15 11:36:23 2018.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'pyqtlet2'
copyright = '2018, Skylark Drones'
author = 'Samarth Hattangady'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.2'
# The full version, including alpha/beta/rc tags.
release = 'beta'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_sidebars = {
'**': [
'about.html',
'relations.html',
'navigation.html',
'searchbox.html'
]
}
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {
# 'extra_nav_links': ['']
# }
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'pyqtletdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyqtlet2.tex', 'pyqtlet2 Documentation',
'Samarth Hattangady, Skylark Drones', 'manual'),
]
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pyqtlet2', 'pyqtlet2 Documentation',
[author], 1)
]
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyqtlet2', 'pyqtlet2 Documentation',
author, 'pyqtlet2', 'One line description of project.',
'Miscellaneous'),
]
pyqtlet2-0.9.3/docs/source/contributing.rst 0000664 0000000 0000000 00000001766 14366753660 0021032 0 ustar 00root root 0000000 0000000 Contributing
============
If you want to contribute to this project, please feel free to go ahead.
Some areas of contribution I'm looking for:
1. Solving the getJsResponse async problem as listed in :doc:`technical`.
2. Feature completeness. There are a lot of methods and signals that have not yet been
created. If you need to use any of them and are looking to add them, it is a fairly
straightforward process, and all help would be appreciated. It might also be an
interesting project to autogenerate all the code... I have no idea how one could
go about doing that, but I believe it might be possible
3. API documentation. Sphinx-apidoc doesn't seem to be able to do what I need. It treats all
methods, attributes and pyqtSignals as equal. I would like to see if its possible
to figure out an approach that is able to separate the signals and make a separate
list of them.
Any other contributions, in terms of bug reports, feature requests and anything else are
appreciated as well.
pyqtlet2-0.9.3/docs/source/examples.rst 0000664 0000000 0000000 00000001706 14366753660 0020133 0 ustar 00root root 0000000 0000000 Examples
========
Simple Setup App
----------------
This is a simple app that sets up pyqtlet and shows the basic functionality of the
package.
.. code:: python
import sys
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
from pyqtlet 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_())
pyqtlet2-0.9.3/docs/source/getting-started.rst 0000664 0000000 0000000 00000015214 14366753660 0021421 0 ustar 00root root 0000000 0000000 Getting Started
===============
.. image:: maps_are_beautiful2.jpg
:align: center
Maps are beautiful. They can convey information in a way that words and graphs cannot.
As a GIS company, we have many occassions where maps are absolutely critical to
show our outputs. Pyqtlet was partly built out of a frustration of having to use
Google Earth and KML files for all our mapping needs.
.. note::
pyqtlet was designed for people familiar with both `PyQt5 `_ and `Leaflet `_.
It is suggested you go through the respective guides if not already familiar. PySide6 is also supported.
Installation
------------
pyqtlet does not have any external dependencies apart from PyQt5 or PySide6. So if you already
have pyqtlet installed, then you just need to copy the pyqtlet folder into your
project folder. You may also install pyqtlet from pip. This will install PyQt5 if
it has not been installed already.
.. code:: sh
pip3 install pyqtlet
Now you're just an import statement away.
.. code:: python
from pyqtlet import L, MapWidget
Usage
-----
MapWidget should be used like any other QWidget. The first pyqtlet object to be
created needs to be the L.map, along with a reference to the map widget.
If you try creating any other pyqtlet object before the map, or the map without the
map widget, you will get an error.
.. code:: python
# within a QWidget
self.mapWidget = MapWidget()
self.map = L.map(self.mapWidget)
self.layout.addWidget(self.mapWidget)
Once this has been set up, :code:`self.map`, and pyqtlet as a whole have methods
very similar to leaflet itself. So in case you want to set the view, set a basemap,
and add some markers, the code would look something like this...
.. code:: python
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)
Similarly, a lot of the other leaflet objects can be found in the :code:`L` namespace.
So polygons, circle markers and feature groups can also be added using code that is
essentially identical to its JS counterpart.
Accessing state of the map
--------------------------
Sometimes, it is necessary to access different state attributes of the map. pyqtlet
allows this to be done. The variables cannot currently be directly returned by the
functions, so a callback approach is followed whenever we need to access state of
the map
.. code:: python
def setZoomWarning(self, event):
zoom = event['zoom']
if zoom < 6:
self.label.setText('Woah buddy. You\'re flying \
pretty high. Hope you don\'t have vertigo..')
else:
self.label.setText('Yup, no worries. A fall from \
here shoudn\'t hurt... too much.')
def setWarnings(self):
self.map.getZoom(self.setZoomWarning)
Similarly, we can access different state variables of Leaflet. There is also a custom
function called :code:`L.map.getState()` that allows you to get all of the map parameters
that leaflet allows you to access. This was written to prevent excessive callback depth
in case multiple map state variables are required.
Drawing
-------
Since a large benefit of having maps is allowing users to draw on them, pyqtlet includes
`Leaflet.draw` by default. Since editting is a fairly core functionality of drawing, and
setting it up in leaflet is a little cumbersome, pyqtlet sets it all up in case the user
doesn't want to.
.. code:: python
# in __init__ or elsewhere
self.drawControl = L.control.draw()
self.map.addControl(self.drawControl)
In order to get what the user has drawn, we will need to access the featureGroup of the
draw control. So to print what the user has drawn as a geojson.
.. code:: python
self.drawControl.featureGroup.toGeoJSON(lambda x: print(x))
Default initialisation of the draw control creates a `L.FeatureGroup` and adds it to the
map, and sets it as the edit
layer for `L.Draw`, and automatically takes care of adding all the drawn items to it.
It also sets the default position as :code:`'topleft'`, disables drawing of rectangles
and circles.
All of these can be overriden. So editting can be disabled by setting the :code:`'edit'`
key in the options as `False`. Similarly you can use your own featureGroup as the edittable
featureGroup by passing it as a parameter.
Additionally, if you want to handle what gets
added to the featureGroup, you can setting :code:`handleFeatureGroup` as :code:`False`
while initiating the draw control. Then using :code:`L.map.drawCreated` and :code:`L.featureGroup.createAndAddDrawnLayer`
you can manually handle all the drawn shapes that are added to the map.
Events and Signals
------------------
Leaflet and PyQt handle signals and events in different ways. pyqtlet follows the
PyQt system of :code:`pyqtSignal` and :code:`pyqtSlot` to pass around events. So
all the leaflet events have been appropriately mapped to a signal of the same name.
.. code:: python
self.map.clicked.connect(lambda x: print(x))
self.map.zoomend.connect(self.loadAssetByZoom)
Similarly any other can be accessed as a :code:`pyqtSignal`. The signals from Leaflet.draw
are all prefixed with `draw` and are camel cased accordingly. So :code:`'draw:created'`
becomes :code:`drawCreated` and so on.
Custom JS code
--------------
In case there is some JS code that needs to be run, which hasn't already been implemented
in pyqtlet, or is causing some kind of bug, that can also be done. If js objects need to
be used, their variable names in the leaflet runtime can be accessed from the :code:`.jsName`
attribute.
.. code:: python
self.map.runJavaScript('{map1}.addLayer({layer})'.format(
map1=self.map.jsName, layer=self.basemap.jsName))
If a response is expected from js, then the same callback approach will need to be followed
.. code:: python
self.map.getJsResponse('{map1}.getZoom()+1'.format(
map1=self.map.jsName), callback=self.handleNextZoomLevel)
With all the implemented pyqtlet functionality, `runJavaScript` and `getJsResponse`, pretty
much all the basic use cases have been covered.
****************
This should be enough to get you started and build all the basic functionality that you
might expect and need from a map. Further documentation on the API can be found on the
:doc:`api-docs` page. In case you are interested in the technical details and implementation details,
you can refer to the :doc:`technical` page. For going deeper into the different use cases
that pyqtlet allows, refer to the :doc:`tutorials` page.
pyqtlet2-0.9.3/docs/source/index.rst 0000664 0000000 0000000 00000002266 14366753660 0017426 0 ustar 00root root 0000000 0000000 Pyqtlet
=======
pyqtlet brings `Leaflet `_ maps to `PyQt5 `_ or PySide6.
`Leaflet `_ is the most popular mapping library on the web. It has most mapping features that you might need, excellent documentation, and a host of plugins. In contstruction and design, pyqtlet attempts to mimic the `official Leaflet API `_ as much as possible.
pyqtlet allows you to bring in these leaflet maps into PyQt5 or PySide6 in just a couple of lines. It provides a mapWidget (which is a QWidget) as well as a namespace (L) in order to mimic the Leaflet API.
.. code-block:: python
from pyqtlet import L, MapWidget
class Application(QMainWindow):
...
self.mapWidget = MapWidget()
self.map = L.map(self.mapWidget)
self.map.setView([12.97, 77.59], 10)
...
self.layout.add(self.mapWidget)
If you have are just starting out, you might want to start off with the :doc:`getting-started` page.
.. toctree::
:hidden:
getting-started
api-docs
examples
tutorials
technical
contributing
pyqtlet2-0.9.3/docs/source/maps_are_beautiful.jpg 0000664 0000000 0000000 00002476614 14366753660 0022134 0 ustar 00root root 0000000 0000000 PNG
IHDR , \ bKGD IDATxdY-u&=Dry5Hljpb[,u~7l0mnr%DEJ8b֭;d":ȇsNDZv`~
4侚rj)"∃@ĚѴj䘈 juLI!,M1yzQټ9`~᷿xdiw[ulǏ|Yw3!
6E}f-wL DDM )`jjFDČ j"j@