Example #1
0
    def __init__(self,
                 data,
                 styledict,
                 name=None,
                 overlay=True,
                 control=True,
                 show=True):
        super(TimeSliderChoropleth, self).__init__(name=name,
                                                   overlay=overlay,
                                                   control=control,
                                                   show=show)
        self.data = GeoJson.process_data(GeoJson({}), data)

        if not isinstance(styledict, dict):
            raise ValueError('styledict must be a dictionary, got {!r}'.format(
                styledict))  # noqa
        for val in styledict.values():
            if not isinstance(val, dict):
                raise ValueError(
                    'Each item in styledict must be a dictionary, got {!r}'.
                    format(val))  # noqa

        # Make set of timestamps.
        timestamps = set()
        for feature in styledict.values():
            timestamps.update(set(feature.keys()))
        timestamps = sorted(list(timestamps))

        self.timestamps = timestamps
        self.styledict = styledict
    def __init__(self, data, styledict, name=None, overlay=True, control=True,
                 show=True, init_timestamp_index=0, highlight=True):
        super(TimeSliderChoropleth, self).__init__(name=name, overlay=overlay,
                                                   control=control, show=show)
        self.data = GeoJson.process_data(GeoJson({}), data)

        if not isinstance(styledict, dict):
            raise ValueError('styledict must be a dictionary, got {!r}'.format(styledict))  # noqa
        for val in styledict.values():
            if not isinstance(val, dict):
                raise ValueError('Each item in styledict must be a dictionary, got {!r}'.format(val))  # noqa

        # Make set of timestamps.
        timestamps = set()
        for feature in styledict.values():
            timestamps.update(set(feature.keys()))
        timestamps = sorted(list(timestamps))

        self.timestamps = timestamps
        self.styledict = styledict
        self.highlight = highlight
        if init_timestamp_index >= 0:
            assert init_timestamp_index < len(timestamps), (
                'init_timestamp_index cannot be {} since it is greater than the'
                ' number of timestamps, which is {}.'
            ).format(init_timestamp_index, len(timestamps))
        else:
            assert -len(timestamps) <= init_timestamp_index, (
                'When init_timestamp_index is negative, it must be in the range'
                ' `[-len(timestamps), -1]` but got {} instead.'
            ).format(init_timestamp_index)
        self.init_timestamp_index = init_timestamp_index
    def __init__(self,
                 data,
                 embed=True,
                 callback=None,
                 tooltip=True,
                 tooltip_callback=None,
                 name=None,
                 overlay=True,
                 control=True,
                 show=True):
        super(GeoJsonMarkers, self).__init__(name=name,
                                             overlay=overlay,
                                             control=control,
                                             show=show)

        self._name = 'GeoJsonMarkers'
        self.embed = embed
        self.embed_link = None
        self.tooltip = tooltip

        self.data = GeoJson.process_data(self, data)

        if callback is None:
            self.callback = """
                var callback = function (feature) {
                    var icon = L.AwesomeMarkers.icon();
                    var coords = feature.geometry.coordinates;
                    var marker = L.marker(new L.LatLng(coords[1], coords[0]));
                    marker.setIcon(icon);

                    return marker;
                };"""
        else:
            self.callback = 'var callback = {};'.format(callback)

        if tooltip_callback is None:
            self.tooltip_callback = """
                var tooltip_callback = function (feature) {
                    let handleObject = (feature)=>typeof(feature)=='object' ? JSON.stringify(feature) : feature;
                    return '<table>' +
                        String(
                            Object.keys(feature.properties).map(
                                columnname=>
                                    `<tr style="text-align: left;">
                                    <th style="padding: 4px; padding-right: 10px;">
                                        ${ handleObject(columnname).toLocaleString() }
                                    </th>
                                    <td style="padding: 4px;">
                                        ${ handleObject(feature.properties[columnname]).toLocaleString() }
                                    </td></tr>`
                            ).join('')
                        )
                        + '</table>'
                };
            """
        else:
            self.tooltip_callback = 'var tooltip_callback = {};'.format(
                tooltip_callback)
Example #4
0
    def __init__(self, data, styledict, name=None, overlay=True, control=True,
                 show=True):
        super(TimeSliderChoropleth, self).__init__(name=name, overlay=overlay,
                                                   control=control, show=show)
        self.data = GeoJson.process_data(GeoJson({}), data)

        if not isinstance(styledict, dict):
            raise ValueError('styledict must be a dictionary, got {!r}'.format(styledict))  # noqa
        for val in styledict.values():
            if not isinstance(val, dict):
                raise ValueError('Each item in styledict must be a dictionary, got {!r}'.format(val))  # noqa

        # Make set of timestamps.
        timestamps = set()
        for feature in styledict.values():
            timestamps.update(set(feature.keys()))
        timestamps = sorted(list(timestamps))

        self.timestamps = timestamps
        self.styledict = styledict