Ejemplo n.º 1
0
Archivo: map.py Proyecto: pmains/folium
    def __init__(self, location, popup=None, tooltip=None, icon=None):
        super(Marker, self).__init__()
        self._name = 'Marker'
        self.tooltip = tooltip
        self.location = _validate_coordinates(location)
        if icon is not None:
            self.add_child(icon)
        if isinstance(popup, text_type) or isinstance(popup, binary_type):
            self.add_child(Popup(popup))
        elif popup is not None:
            self.add_child(popup)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}

            var {{this.get_name()}} = L.marker(
                [{{this.location[0]}}, {{this.location[1]}}],
                {
                    icon: new L.Icon.Default()
                    }
                )
                {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
                .addTo({{this._parent.get_name()}});
            {% endmacro %}
            """)
Ejemplo n.º 2
0
    def __init__(self,
                 data,
                 callback=None,
                 name=None,
                 overlay=True,
                 control=True,
                 show=True):
        super(FastMarkerCluster, self).__init__(name=name,
                                                overlay=overlay,
                                                control=control,
                                                show=show)
        self._name = 'FastMarkerCluster'
        self._data = _validate_coordinates(data)

        if callback is None:
            self._callback = ('var callback;\n' +
                              'callback = function (row) {\n' +
                              '\tvar icon, marker;\n' +
                              '\t// Returns a L.marker object\n' +
                              '\ticon = L.AwesomeMarkers.icon();\n' +
                              '\tmarker = L.marker(new L.LatLng(row[0], ' +
                              'row[1]));\n' + '\tmarker.setIcon(icon);\n' +
                              '\treturn marker;\n' + '};')
        else:
            self._callback = 'var callback = {};'.format(callback)
Ejemplo n.º 3
0
    def __init__(self, locations, color=None, weight=None,
                 opacity=None, popup=None):
        super(PolyLine, self).__init__()
        self._name = 'PolyLine'
        self.data = _validate_coordinates(locations)
        self.color = color
        self.weight = weight
        self.opacity = opacity
        if isinstance(popup, text_type) or isinstance(popup, binary_type):
            self.add_child(Popup(popup))
        elif popup is not None:
            self.add_child(popup)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}
                var {{this.get_name()}} = L.polyline(
                    {{this.data}},
                    {
                        {% if this.color != None %}color: '{{ this.color }}',{% endif %}
                        {% if this.weight != None %}weight: {{ this.weight }},{% endif %}
                        {% if this.opacity != None %}opacity: {{ this.opacity }},{% endif %}
                        });
                {{this._parent.get_name()}}.addLayer({{this.get_name()}});
            {% endmacro %}
            """)  # noqa
Ejemplo n.º 4
0
Archivo: map.py Proyecto: rylwcw/folium
    def __init__(self, location, popup=None, icon=None):
        super(Marker, self).__init__()
        self._name = 'Marker'
        # Must be _validate_coordinates b/c some markers are defined with
        # multiple coordinates values, like Polygons.
        self.location = _validate_coordinates(location)
        if icon is not None:
            self.add_child(icon)
        if isinstance(popup, text_type) or isinstance(popup, binary_type):
            self.add_child(Popup(popup))
        elif popup is not None:
            self.add_child(popup)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}

            var {{this.get_name()}} = L.marker(
                [{{this.location[0]}},{{this.location[1]}}],
                {
                    icon: new L.Icon.Default()
                    }
                )
                .addTo({{this._parent.get_name()}});
            {% endmacro %}
            """)
Ejemplo n.º 5
0
    def __init__(self, data, callback=None):
        super(FastMarkerCluster, self).__init__([])
        self._name = 'FastMarkerCluster'
        self._data = _validate_coordinates(data)

        if callback is None:
            self._callback = ('var callback;\n' +
                              'callback = function (row) {\n' +
                              '\tvar icon, marker;\n' +
                              '\t// Returns a L.marker object\n' +
                              '\ticon = L.AwesomeMarkers.icon();\n' +
                              '\tmarker = L.marker(new L.LatLng(row[0], ' +
                              'row[1]));\n' + '\tmarker.setIcon(icon);\n' +
                              '\treturn marker;\n' + '};')
        else:
            self._callback = 'var callback = {};'.format(callback)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}
            {{this._callback}}

            (function(){
                var data = {{this._data}};
                var map = {{this._parent.get_name()}};
                var cluster = L.markerClusterGroup();

                for (var i = 0; i < data.length; i++) {
                    var row = data[i];
                    var marker = callback(row);
                    marker.addTo(cluster);
                }

                cluster.addTo(map);
            })();
            {% endmacro %}""")
Ejemplo n.º 6
0
    def __init__(self, location, popup=None, tooltip=None, icon=None):
        super(Marker, self).__init__()
        self._name = 'Marker'
        self.tooltip = tooltip
        self.location = _validate_coordinates(location)
        if icon is not None:
            self.add_child(icon)
        if isinstance(popup, text_type) or isinstance(popup, binary_type):
            self.add_child(Popup(popup))
        elif popup is not None:
            self.add_child(popup)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}

            var {{this.get_name()}} = L.marker(
                [{{this.location[0]}}, {{this.location[1]}}],
                {
                    icon: new L.Icon.Default()
                    }
                )
                {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
                .addTo({{this._parent.get_name()}});
            {% endmacro %}
            """)
Ejemplo n.º 7
0
    def __init__(self,
                 bounds,
                 color='black',
                 weight=1,
                 fill_color='black',
                 fill_opacity=0.6,
                 popup=None):
        """
        Creates a RectangleMarker object for plotting on a Map.

        Parameters
        ----------
        bounds: tuple or list, default None
            Latitude and Longitude of Marker (southWest and northEast)
        color: string, default ('black')
            Edge color of a rectangle.
        weight: float, default (1)
            Edge line width of a rectangle.
        fill_color: string, default ('black')
            Fill color of a rectangle.
        fill_opacity: float, default (0.6)
            Fill opacity of a rectangle.
        popup: string or folium.Popup, default None
            Input text or visualization for object.

        Returns
        -------
        folium.features.RectangleMarker object

        Example
        -------
        >>> RectangleMarker(
        ...  bounds=[[35.681, 139.766], [35.691, 139.776]],
        ...  color='blue', fill_color='red', popup='Tokyo, Japan'
        ... )

        """
        super(RectangleMarker, self).__init__(_validate_coordinates(bounds),
                                              popup=popup)
        self._name = 'RectangleMarker'
        self.color = color
        self.weight = weight
        self.fill_color = fill_color
        self.fill_opacity = fill_opacity
        self._template = Template(u"""
            {% macro script(this, kwargs) %}
            var {{this.get_name()}} = L.rectangle(
                                  [[{{this.location[0]}},{{this.location[1]}}],
                                  [{{this.location[2]}},{{this.location[3]}}]],
                {
                    color: '{{ this.color }}',
                    fillColor: '{{ this.fill_color }}',
                    fillOpacity: {{ this.fill_opacity }},
                    weight: {{ this.weight }}
                }).addTo({{this._parent.get_name()}});

            {% endmacro %}
            """)
Ejemplo n.º 8
0
 def __init__(self, location, popup=None, tooltip=None, icon=None):
     super(Marker, self).__init__()
     self._name = 'Marker'
     self.tooltip = tooltip
     self.location = _validate_coordinates(location)
     if icon is not None:
         self.add_child(icon)
     if isinstance(popup, text_type) or isinstance(popup, binary_type):
         self.add_child(Popup(popup))
     elif popup is not None:
         self.add_child(popup)
Ejemplo n.º 9
0
 def __init__(self, location, popup=None, tooltip=None, icon=None):
     super(Marker, self).__init__()
     self._name = 'Marker'
     self.tooltip = tooltip
     self.location = _validate_coordinates(location)
     if icon is not None:
         self.add_child(icon)
     if isinstance(popup, text_type) or isinstance(popup, binary_type):
         self.add_child(Popup(popup))
     elif popup is not None:
         self.add_child(popup)
Ejemplo n.º 10
0
    def __init__(self, data, callback=None,
                 name=None, overlay=True, control=True, show=True):
        super(FastMarkerCluster, self).__init__(name=name, overlay=overlay,
                                                control=control, show=show)
        self._name = 'FastMarkerCluster'
        self._data = _validate_coordinates(data)

        if callback is None:
            self._callback = """
                var callback = function (row) {
                    var icon = L.AwesomeMarkers.icon();
                    var marker = L.marker(new L.LatLng(row[0], row[1]));
                    marker.setIcon(icon);
                    return marker;
                };"""
        else:
            self._callback = 'var callback = {};'.format(callback)
Ejemplo n.º 11
0
 def __init__(self,
              location,
              popup=None,
              tooltip=None,
              icon=None,
              draggable=False):
     super(Marker, self).__init__()
     self._name = 'Marker'
     self.location = _validate_coordinates(location)
     self.draggable = draggable
     if icon is not None:
         self.add_child(icon)
     if isinstance(popup, text_type) or isinstance(popup, binary_type):
         self.add_child(Popup(popup))
     elif popup is not None:
         self.add_child(popup)
     if isinstance(tooltip, Tooltip):
         self.add_child(tooltip)
     elif tooltip is not None:
         self.add_child(Tooltip(tooltip.__str__()))
Ejemplo n.º 12
0
    def __init__(self, data, callback=None, options=None,
                 name=None, overlay=True, control=True, show=True, **kwargs):
        if options is not None:
            kwargs.update(options)  # options argument is legacy
        super(FastMarkerCluster, self).__init__(name=name, overlay=overlay,
                                                control=control, show=show,
                                                **kwargs)
        self._name = 'FastMarkerCluster'
        self._data = _validate_coordinates(data)

        if callback is None:
            self._callback = """
                var callback = function (row) {
                    var icon = L.AwesomeMarkers.icon();
                    var marker = L.marker(new L.LatLng(row[0], row[1]));
                    marker.setIcon(icon);
                    return marker;
                };"""
        else:
            self._callback = 'var callback = {};'.format(callback)
Ejemplo n.º 13
0
    def __init__(self, data, callback=None,
                 name=None, overlay=True, control=True, show=True):
        super(FastMarkerCluster, self).__init__(name=name, overlay=overlay,
                                                control=control, show=show)
        self._name = 'FastMarkerCluster'
        self._data = _validate_coordinates(data)

        if callback is None:
            self._callback = ('var callback;\n' +
                              'callback = function (row) {\n' +
                              '\tvar icon, marker;\n' +
                              '\t// Returns a L.marker object\n' +
                              '\ticon = L.AwesomeMarkers.icon();\n' +
                              '\tmarker = L.marker(new L.LatLng(row[0], ' +
                              'row[1]));\n' +
                              '\tmarker.setIcon(icon);\n' +
                              '\treturn marker;\n' +
                              '};')
        else:
            self._callback = 'var callback = {};'.format(callback)

        self._template = Template(u"""
            {% macro script(this, kwargs) %}
            {{this._callback}}

            (function(){
                var data = {{this._data}};
                var map = {{this._parent.get_name()}};
                var cluster = L.markerClusterGroup();

                for (var i = 0; i < data.length; i++) {
                    var row = data[i];
                    var marker = callback(row);
                    marker.addTo(cluster);
                }

                cluster.addTo(map);
            })();
            {% endmacro %}""")