예제 #1
0
def test_mulyipolyline():
    m = Map()

    locations = [[[45.51, -122.68], [37.77, -122.43], [34.04, -118.2]],
                 [[40.78, -73.91], [41.83, -87.62], [32.76, -96.72]]]

    multipolyline = PolyLine(locations=locations, popup='MultiPolyLine')
    multipolyline.add_to(m)

    expected_options = {
        'smoothFactor': 1.0,
        'noClip': False,
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'opacity': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polyline(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations,
               name=multipolyline.get_name(),
               map=m.get_name())

    rendered = multipolyline._template.module.script(multipolyline)
    assert normalize(rendered) == normalize(expected_rendered)
    assert multipolyline.get_bounds() == get_bounds(locations)
    assert json.dumps(multipolyline.to_dict()) == multipolyline.to_json()
    assert multipolyline.options == expected_options
예제 #2
0
def test_polyline():
    m = Map()
    locations = [[40, -80], [45, -80]]
    polyline = PolyLine(locations=locations, popup='I am PolyLine')
    polyline.add_to(m)

    expected_options = {
        'smoothFactor': 1.0,
        'noClip': False,
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'opacity': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polyline(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations, name=polyline.get_name(), map=m.get_name())

    rendered = polyline._template.module.script(polyline)
    assert _normalize(rendered) == _normalize(expected_rendered)
    assert polyline.get_bounds() == get_bounds(locations)
    assert json.dumps(polyline.to_dict()) == polyline.to_json()
    assert polyline.options == json.dumps(expected_options,
                                          sort_keys=True,
                                          indent=2)  # noqa
예제 #3
0
def test_mulyipolyline():
    m = Map()

    locations = [[[45.51, -122.68], [37.77, -122.43], [34.04, -118.2]],
                 [[40.78, -73.91], [41.83, -87.62], [32.76, -96.72]]]

    multipolyline = PolyLine(locations=locations, popup='MultiPolyLine')
    multipolyline.add_to(m)

    expected_options = {
        'smoothFactor': 1.0,
        'noClip': False,
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'opacity': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polyline(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations, name=multipolyline.get_name(), map=m.get_name())

    rendered = multipolyline._template.module.script(multipolyline)
    assert normalize(rendered) == normalize(expected_rendered)
    assert multipolyline.get_bounds() == get_bounds(locations)
    assert json.dumps(multipolyline.to_dict()) == multipolyline.to_json()
    assert multipolyline.options == expected_options
예제 #4
0
def test_polyline():
    m = Map()
    locations = [[40.0, -80.0], [45.0, -80.0]]
    polyline = PolyLine(locations=locations, popup='I am PolyLine')
    polyline.add_to(m)

    expected_options = {
        'smoothFactor': 1.0,
        'noClip': False,
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'opacity': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polyline(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations, name=polyline.get_name(), map=m.get_name())

    rendered = polyline._template.module.script(polyline)
    assert normalize(rendered) == normalize(expected_rendered)
    assert polyline.get_bounds() == get_bounds(locations)
    assert json.dumps(polyline.to_dict()) == polyline.to_json()
    assert polyline.options == expected_options
예제 #5
0
    def __init__(self,
                 positions,
                 colors,
                 colormap=None,
                 nb_steps=12,
                 weight=None,
                 opacity=None,
                 **kwargs):
        super(ColorLine, self).__init__(**kwargs)
        self._name = 'ColorLine'

        if colormap is None:
            cm = LinearColormap(
                ['green', 'yellow', 'red'],
                vmin=min(colors),
                vmax=max(colors),
            ).to_step(nb_steps)
        elif isinstance(colormap, LinearColormap):
            cm = colormap.to_step(nb_steps)
        elif isinstance(colormap, list) or isinstance(colormap, tuple):
            cm = LinearColormap(
                colormap,
                vmin=min(colors),
                vmax=max(colors),
            ).to_step(nb_steps)
        else:
            cm = colormap
        out = {}
        for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1],
                                                     positions[1:],
                                                     colors):  # noqa
            out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
        for key, val in out.items():
            self.add_child(
                PolyLine(val, color=key, weight=weight,
                         opacity=opacity))  # noqa
roads = roads.to_crs(epsg=4326) # reproject to WGS84
RoadsLayer = folium.FeatureGroup(name="Roads")
RoadsLayer.add_child(folium.GeoJson(roads, style_function=lambda feature:{
        'fillColor': 'blue',    
        'fillOpacity': 0.6,
        'weight': 4,
        'color': 'darkblue'
        }))
wageningenMap.add_child(RoadsLayer)

# Create layer, add polyline and add layer to map
RouteLayer = folium.FeatureGroup(name="Route from campus to shopping center")
polylineLocations = [[51.987384, 5.666505], [51.986899, 5.666848], [51.985501, 5.661650], 
                     [51.981741, 5.664579], [51.979521, 5.664321], [51.979455, 5.663795],
                     [51.979078, 5.663753], [51.978761, 5.663023]]
RouteLayer.add_child(PolyLine(locations=polylineLocations, popup="Path from Gaia to Shopping Center", 
                              color="red", weight=2.5, opacity=1))
wageningenMap.add_child(RouteLayer)

# Overlay raster on top of map
orthophotoLayer = folium.FeatureGroup(name="Infrared Orthophoto of Wageningen")
orthophotoLayer.add_child(ImageOverlay(imageFilename, [[min_lat, min_lon], [max_lat, max_lon]], opacity=0.6))
wageningenMap.add_child(orthophotoLayer)

# Add measurement control and layer control
wageningenMap.add_child(MeasureControl())
wageningenMap.add_child(folium.LayerControl())

# Visualize map
wageningenMap # Jupyter Notebook allows interactive visualization in the Notebook
wageningenMap.save('output/wageningenMap.html') # The folium map can be stored as an HTML file and viewed by opening the HTML file