GithubHelp home page GithubHelp logo

dearpygui-map's Introduction

dearpygui-map

Map widget for Dear PyGui

Installation

Requirements

  • Python >= 3.10
  • Dear PyGui >= 1.3.1

Option 1 - pip

You can install this package from pip, with

pip install dearpygui-map

Option 2 - Local install from sources

Clone code repository from your local machine, install from there. Poetry is required.

git clone https://github.com/mkouhia/dearpygui-map.git
cd dearpygui-map
poetry build
# take note of the build step output, install package from the dist folder
pip install dist/PRODUCED_PACKAGE.whl

Usage

This basic example creates a map widget with defined size, initial center point (latitude, longitude) and initial zoom level. The zoom levels are same as on tiled maps, for example 12 could represent a town-sized view. Larger is more zoomed in.

import dearpygui.dearpygui as dpg
import dearpygui_map as dpg_map

dpg.create_context()

with dpg.window(label="Map demo"):
    dpg_map.add_map_widget(
        width=700,
        height=500,
        center=(60.1641, 24.9402),
        zoom_level=12)

dpg.create_viewport(title="Dear PyGui map widget demo", width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

The function add_map_widget places a Dear PyGui drawlist with map contents, return value is the drawlist tag.

By default, OpenStreetMap is used as the map tile source. This can be configured with add_map_widget argument tile_source, with similar source definition:

OpenStreetMap = TileServer(
    name="OpenStreetMap",
    base_url="http://{subdomain}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    subdomains=["a", "b", "c"],
    max_zoom_level=19,
    license_text="© OpenStreetMap contributors",
    thread_limit=2,
)

Technical details

Tiles are downloaded from the supplier on a background thread. Whenever map is zoomed or moved, more tiles are downloaded. The tiles are cached to local storage path in user cache directory - for different platforms, cache directories are:

Windows:    C:\Users\<username>\AppData\Local\dearpygui_map\Cache
Mac OS X:   ~/Library/Caches/dearpygui_map
Other:      ~/.cache/dearpygui_map

Known issues

As for now, dearpygui-map is in its early design phase and contains some items that may not be acceptable in production environments. These issues will be addressed later

  • Tile download threads are created every time TileManager.draw_layer is called.
  • Non-visible tiles are not removed from dearpygui
  • Zooming and panning leads to wait times before tiles are ready to be shown.

Development

Environment

Poetry is required for development (see installation instructions)

  1. Create development environment with poetry install
  2. Enter environment with poetry shell

Code quality and testing

All code is to be formatted with black:

black dearpygui_map

and code quality checked with pylint:

pylint dearpygui_map

Tests should be written in pytest, targeting maximum practical code coverage. Tests are run with:

pytest

and test coverage checked with

pytest --cov

Optionally, html test coverage reports can be produced with

pytest --cov dearpygui_map --cov-report html

Contributions

Contributions are welcome. Please also see GitHub issues and milestones.

dearpygui-map's People

Contributors

mkouhia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mustafa-gokce

dearpygui-map's Issues

Free zooming

Free zooming, switch level when scale factor would be >1 or <0.5

Error downloading first tile

Sometiimes, first tile is not displayed (top left corner) and following error message is displayed:

ERROR:root:<built-in function pop_container_stack> returned a result with an exception set
Exception: Error: [1009] Message: 	No container to pop.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mikko/Documents/softaprojektit/dearpygui_map/dearpygui_map/io.py", line 55, in run
    self.callback(result)
  File "/home/mikko/Documents/softaprojektit/dearpygui_map/dearpygui_map/widget.py", line 198, in draw_tile
    tile.draw_image(parent=self.tile_draw_node_id)
  File "/home/mikko/Documents/softaprojektit/dearpygui_map/dearpygui_map/widget.py", line 249, in draw_image
    with dpg.texture_registry():
  File "/home/mikko/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 142, in __exit__
    next(self.gen)
  File "/home/mikko/.cache/pypoetry/virtualenvs/dearpygui-map-AAtoTuFr-py3.10/lib/python3.10/site-packages/dearpygui/dearpygui.py", line 2523, in texture_registry
    internal_dpg.pop_container_stack()
SystemError: <built-in function pop_container_stack> returned a result with an exception set

Add drawing layer on map

First available feature: marker without data. Add more features later.

At first, no user interaction is required. Make separate issue of that.

Increase test coverage

Test all compute methods. For dpg interaction, try to see if tests can be done without actually starting dpg.

Add api keys to tile sources

class TileServer:

    ...

    def with_api_key(api_key: str) -> TileServer:
        """Return new instance with API key set"""
        ...

Dear PyGui showcase

Hey, dearpygui-map looks like it could be a nice addition to the Dear PyGui showcase. Would you be willing to make a short GIF (<8Mb) of the app?

I'm not familiar with poetry, but I cannot get the app to run on my computer or I'd probably make the GIF myself.

Rethink callback item

Which item is best for init return value? This is the item for which the user will set callbacks. Maybe the rect?

How would it be possible to set clicked coordinates for app_data?

Refer also to #11

Rethink public api

Even in 0.1.0, api should be somewhat sane.

Try to follow dearpygui conventions for context managers and add_ methods

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.