Пример #1
0
    def __init__(self, lats, lngs, precision, **kwargs):
        '''
        Args:
            lats ([float]): Latitudes.
            lngs ([float]): Longitudes.
            precision (int): Number of digits after the decimal to round to for lat/lng values.

        Optional:

        Args:
            edge_color (str): Color of the polygon's edge. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            edge_alpha (float): Opacity of the polygon's edge, ranging from 0 to 1.
            edge_width (int): Width of the polygon's edge, in pixels.
            face_color (str): Color of the polygon's face. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            face_alpha (float): Opacity of the polygon's face, ranging from 0 to 1.
        '''
        self._points = [
            _format_LatLng(lat, lng, precision)
            for lat, lng in zip(lats, lngs)
        ]

        edge_color = kwargs.get('edge_color')
        self._edge_color = _get_hex_color(
            edge_color) if edge_color is not None else None

        self._edge_alpha = kwargs.get('edge_alpha')
        self._edge_width = kwargs.get('edge_width')

        face_color = kwargs.get('face_color')
        self._face_color = _get_hex_color(
            face_color) if face_color is not None else None

        self._face_alpha = kwargs.get('face_alpha')
Пример #2
0
    def __init__(self, lat, lng, radius, **kwargs):
        '''
        Args:
            lat (float): Latitude of the center of the circle.
            lng (float): Longitude of the center of the circle.
            radius (int): Radius of the circle, in meters.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the circle's edge.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the circle's edge, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the circle's edge, in pixels. Defaults to 1.
            color/c/face_color/fc (str): Color of the circle's face.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/face_alpha/fa (float): Opacity of the circle's face, ranging from 0 to 1. Defaults to 0.5.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        precision = _get_value(kwargs, ['precision'], 6)
        self._center = _format_LatLng(lat, lng, precision)
        self._radius = radius
        self._edge_color = _get_hex_color(_get_value(kwargs, ['color', 'c', 'edge_color', 'ec'], 'black'))
        self._edge_alpha = _get_value(kwargs, ['alpha', 'edge_alpha', 'ea'], 1.0)
        self._edge_width = _get_value(kwargs, ['edge_width', 'ew'], 1)
        self._face_color = _get_hex_color(_get_value(kwargs, ['color', 'c', 'face_color', 'fc'], 'black'))
        self._face_alpha = _get_value(kwargs, ['alpha', 'face_alpha', 'fa'], 0.5)
Пример #3
0
    def __init__(self, lat, lng, radius, precision, **kwargs):
        '''
        Args:
            lat (float): Latitude of the center of the circle.
            lng (float): Longitude of the center of the circle.
            radius (int): Radius of the circle, in meters.
            precision (int): Number of digits after the decimal to round to for lat/lng values.

        Optional:

        Args:
            edge_color (str): Color of the circle's edge. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            edge_alpha (float): Opacity of the circle's edge, ranging from 0 to 1.
            edge_width (int): Width of the circle's edge, in pixels.
            face_color (str): Color of the circle's face. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            face_alpha (float): Opacity of the circle's face, ranging from 0 to 1.
        '''
        self._center = _format_LatLng(lat, lng, precision)
        self._radius = radius

        edge_color = kwargs.get('edge_color')
        self._edge_color = _get_hex_color(
            edge_color) if edge_color is not None else None

        self._edge_alpha = kwargs.get('edge_alpha')
        self._edge_width = kwargs.get('edge_width')

        face_color = kwargs.get('face_color')
        self._face_color = _get_hex_color(
            face_color) if face_color is not None else None

        self._face_alpha = kwargs.get('face_alpha')
Пример #4
0
    def __init__(self, lat, lng, size, **kwargs):
        '''
        Args:
            lat (float): Latitude of the center of the '+'.
            lng (float): Longitude of the center of the '+'.
            size (int): Size of the '+', in meters.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the '+''s edge.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the '+''s edge, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the '+''s edge, in pixels. Defaults to 1.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        kwargs.setdefault('edge_color', _get_hex_color(_get_value(kwargs, ['color', 'c', 'edge_color', 'ec'], 'black')))
        kwargs.setdefault('edge_alpha', _get_value(kwargs, ['alpha', 'edge_alpha', 'ea'], 1.0))
        kwargs.setdefault('edge_width', _get_value(kwargs, ['edge_width', 'ew'], 1))
        kwargs.setdefault('precision', _get_value(kwargs, ['precision'], 6))

        # TODO: The following generates a '+' in Cartesian frame rather than in lat/lng; avoid this.
        delta_lat = (size / 1000.0 / _EARTH_RADIUS_IN_KM) * (180.0 / math.pi)
        delta_lng = delta_lat / math.cos(math.pi * lat / 180.0)

        self._horizontal_stroke = _Polyline([lat, lat], [lng - delta_lng, lng + delta_lng], **kwargs)
        self._vertical_stroke = _Polyline([lat - delta_lat, lat + delta_lat], [lng, lng], **kwargs)
Пример #5
0
    def __init__(self, lat, lng, **kwargs):
        '''
        Args:
            lat (float): Latitude of the marker.
            lng (float): Longitude of the marker.

        Optional:

        Args:
            color/c/face_color/fc (str): Marker color. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to red.
            title (str): Hover-over title of the marker.
            label (str): Label displayed on the marker.
            info_window (str): HTML content to be displayed in a pop-up `info window`_.
            draggable (bool): Whether or not the marker is `draggable`_. Defaults to False.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.

        .. _info window: https://developers.google.com/maps/documentation/javascript/infowindows
        .. _draggable: https://developers.google.com/maps/documentation/javascript/markers#draggable
        '''
        color = _get_hex_color(
            _get_value(kwargs, ['color', 'c', 'face_color', 'fc'],
                       'red',
                       pop=True))
        self._marker_icon = _MarkerIcon(color)

        self._info_window = _get_value(kwargs, ['info_window'], pop=True)
        if self._info_window is not None:
            self._marker_info_window = _MarkerInfoWindow(self._info_window)

        precision = _get_value(kwargs, ['precision'], 6, pop=True)
        self._raw_marker = _RawMarker(_format_LatLng(lat, lng, precision),
                                      self._marker_icon.get_name(), **kwargs)
Пример #6
0
    def __init__(self, lats, lngs, **kwargs):
        '''
        Args:
            lats ([float]): Latitudes.
            lngs ([float]): Longitudes.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the polyline.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the polyline, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the polyline, in pixels. Defaults to 1.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        self._color = _get_hex_color(
            _get_value(kwargs, ['color', 'c', 'edge_color', 'ec'], 'black'))
        self._edge_alpha = _get_value(kwargs, ['alpha', 'edge_alpha', 'ea'],
                                      1.0)
        self._edge_width = _get_value(kwargs, ['edge_width', 'ew'], 1)

        precision = _get_value(kwargs, ['precision'], 6)

        self._points = [
            _format_LatLng(lat, lng, precision)
            for lat, lng in zip(lats, lngs)
        ]
Пример #7
0
    def test_get_hex_color_code(self):
        # Test valid aliases of red:
        for color in ['r', 'red', '#FF0000']:
            self.assertEqual(_get_hex_color(color), '#FF0000',
                             "'%s' should be a valid alias for 'red'" % color)

        # Test invalid colours:
        INVALID_COLORS = ['colorthatdoesntexist', '#abc']

        for color in INVALID_COLORS:
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")

                self.assertEqual(_get_hex_color(color), '#000000',
                                 "'%s' should be an invalid color" % color)
                self.assertEqual(len(w), 1,
                                 "'%s' should raise a single warning" % color)
                self.assertTrue(issubclass(w[-1].category, UserWarning),
                                "'%s' should raise a 'UserWarning'" % color)
Пример #8
0
    def __init__(self, shape, lat, lng, size, **kwargs):
        '''
        Args:
            shape (str): Shape of the symbol, as 'o', 'x', or '+'.
            lat (float): Latitude of the center of the symbol.
            lng (float): Longitude of the center of the symbol.
            size (int): Size of the symbol, in meters.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the symbol's edge.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the symbol's edge, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the symbol's edge, in pixels. Defaults to 1.
            color/c/face_color/fc (str): Color of the symbol's face.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/face_alpha/fa (float): Opacity of the symbol's face, ranging from 0 to 1. Defaults to 0.5.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        kwargs.setdefault(
            'edge_color',
            _get_hex_color(
                _get_value(kwargs, ['color', 'c', 'edge_color', 'ec'],
                           'black')))
        kwargs.setdefault(
            'edge_alpha', _get_value(kwargs, ['alpha', 'edge_alpha', 'ea'],
                                     1.0))
        kwargs.setdefault('edge_width',
                          _get_value(kwargs, ['edge_width', 'ew'], 1))
        kwargs.setdefault(
            'face_color',
            _get_hex_color(
                _get_value(kwargs, ['color', 'c', 'face_color', 'fc'],
                           'black')))
        kwargs.setdefault(
            'face_alpha', _get_value(kwargs, ['alpha', 'face_alpha', 'fa'],
                                     0.5))
        kwargs.setdefault('precision', _get_value(kwargs, ['precision'], 6))

        self._symbol = self._SHAPES[shape](lat, lng, size, **kwargs)
Пример #9
0
    def test_get_hex_color(self):
        # Test valid hex colors:
        VALID_HEX_COLORS = ['#000000', '#FFCC00', '#ae44BB']

        for color in VALID_HEX_COLORS:
            self.assertEqual(_get_hex_color(color), color.upper(),
                             "'%s' should be formatted as uppercase" % color)

        # Test valid aliases of red:
        for color in ['r', 'red', '#FF0000']:
            self.assertEqual(_get_hex_color(color), '#FF0000',
                             "'%s' should be a valid alias for 'red'" % color)

        # Test invalid colors:
        INVALID_COLORS = [
            '#FC0', '#GFCC00', '#0000000', '11ee22', 'colorthatdoesntexist',
            '#abc'
        ]

        for color in INVALID_COLORS:
            with self.assertRaises(ValueError):
                _get_hex_color(color)
                self.fail("'%s' should be an invalid color" % color)

        # Test invalid types:
        INVALID_TYPES = [[], {}, 123]

        for color in INVALID_TYPES:
            with self.assertRaises(TypeError):
                _get_hex_color(color)
                self.fail("'%s' should be an invalid type" % color)
Пример #10
0
    def __init__(self, color):
        '''
        Args:
            color (str): Color of the marker icon.
        '''
        self._color = _get_hex_color(color)
        self._name = 'marker_icon_%s' % self._color[1:]

        # Get this marker icon as an embeddable image:
        get_marker_icon_path = lambda color: _COLOR_ICON_PATH % color[1:]
        marker_icon_path = get_marker_icon_path(self._color)

        if not os.path.exists(marker_icon_path):
            warnings.warn(" Marker color '%s' isn't supported." % self._color)
            marker_icon_path = get_marker_icon_path('#000000')

        self._icon = _get_embeddable_image(marker_icon_path)
Пример #11
0
    def __init__(self, lat, lng, text, precision, **kwargs):
        '''
        Args:
            lat (float): Latitude of the text label.
            lng (float): Longitude of the text label.
            text (str): Text to display.
            precision (int): Number of digits after the decimal to round to for lat/lng values.

        Optional:

        Args:
            color (str): Text color. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
        '''
        self._position = _format_LatLng(lat, lng, precision)
        self._text = text
        color = kwargs.get('color')
        self._color = _get_hex_color(color) if color is not None else None
        self._icon = _get_embeddable_image(_COLOR_ICON_PATH % 'clear')
Пример #12
0
    def __init__(self, color):
        '''
        Args:
            color (str): Marker icon color. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
        '''
        self._color = _get_hex_color(color)
        self._name = 'marker_icon_%s' % self._color[1:]

        # Get this marker icon as an embeddable image:
        get_marker_icon_path = lambda color: _COLOR_ICON_PATH % color[1:]
        marker_icon_path = get_marker_icon_path(self._color)

        if not os.path.exists(marker_icon_path):
            warnings.warn(
                " Marker color '%s' isn't supported; defaulting to black." %
                self._color)
            marker_icon_path = get_marker_icon_path('#000000')

        self._icon = _get_embeddable_image(marker_icon_path)
Пример #13
0
    def __init__(self, lat, lng, text, **kwargs):
        '''
        Args:
            lat (float): Latitude of the text label.
            lng (float): Longitude of the text label.
            text (str): Text to display.

        Optional:

        Args:
            color/c (str): Text color. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        precision = _get_value(kwargs, ['precision'], 6)
        self._position = _format_LatLng(lat, lng, precision)
        self._text = text
        self._color = _get_hex_color(
            _get_value(kwargs, ['color', 'c'], 'black'))
        self._icon = _get_embeddable_image(_COLOR_ICON_PATH % 'clear')