File: icon.py

package info (click to toggle)
python-pyqtlet2 0.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,672 kB
  • sloc: python: 997; javascript: 88; makefile: 18; sh: 14
file content (30 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from ..layer import Layer
from ...core.Parser import Parser
import os


class Icon(Layer):
    def __init__(self, iconUrl: str, options=None):
        super().__init__()
        if isinstance(options, type(None)):
            options = {}
        self.iconUrl = iconUrl
        self.icon_found = False
        self.options = options
        self._check_icon_url()
        if self._map:
            self._initJs()

    def _check_icon_url(self):
        if "http" in self.iconUrl:
            self._log.info("Can't check if icon exists at url!")
            return
        if not os.path.isfile(self.iconUrl):
            self._log.error(f"Can't locate file at path: '{self.iconUrl}'. Current working directory is '{os.getcwd()}'")
            return
        self.icon_found = True

    def _initJs(self):
        leafletJsObject = 'L.icon({options});'.format(options=Parser.dict_for_js({"iconUrl": self.iconUrl,
                                                                                  **self.options}))
        self._createJsObject(leafletJsObject, self._map.mapWidgetIndex)