Exemplo n.º 1
0
def map_click(click_lat_lng, n_clicks, data, polygons):
    trigger = dash.callback_context.triggered[0]["prop_id"]
    print(trigger)
    # The map was clicked, add a new point.
    if trigger.split(".")[1] == "click_lat_lng":
        if len(polygons) > 0:
            for polygon in polygons:
                # print(polygon['props']['positions'])
                sg_poly = sg.Polygon(polygon['props']['positions'])
                if (sg.Point(float(click_lat_lng[0]),
                             float(click_lat_lng[1])).within(sg_poly)):
                    print('you are within existing polygon')
                    return data, '', polygons

        data.append(click_lat_lng)
        markers = [
            dl.CircleMarker(center=pos, id={
                'role': 'marker',
                'index': i
            }) for i, pos in enumerate(data)
        ]
        polyline = dl.Polyline(positions=data)
        drawing = markers + [polyline]
    # A marker was clicked, close the polygon and reset drawing.
    else:
        polygons.append(dl.Polygon(positions=data))
        data, drawing = [], []
    print(data, drawing, polygons)
    return data, drawing, polygons
Exemplo n.º 2
0
def update_routes(agregation_option, routes):
    # Routes Layer Map
    df = df_routes.copy()
    df = df[df[agregation_option].isin(routes)]
    map_routes_children = []
    for row in df.itertuples():
        map_routes_children.append(dl.Polygon(positions = [(p[1], p[0]) for p in row.geometry.exterior.coords],
                                              children = dl.Tooltip(row.Route),
                                              color = dict_colors[row.Route],
                                              fillColor = dict_colors[row.Route]
                                              )
                                   )
    
    return dl.LayerGroup(map_routes_children),
Exemplo n.º 3
0
def build_vision_polygon(event_id, site_lat, site_lon, yaw, opening_angle,
                         dist_km):
    """
    This function allows to build the vision angle of a camera, ie. the zone covered by the detection device.

    It takes as input:

    - site_lat, the latitude of the detection device;

    - site_lon, the longitude of the detection device;

    - yaw, the orientation of the device expressed in degrees;

    - opening_angle, the width of the zone covered by the device expressed in degrees;

    - dist_km, the distance that the detection device is able to cover in kilometers.

    The function then builds and returns the zone covered by the detection device as a Dash Leaflet Polygon, which can
    be represented on the map.
    """

    # The center corresponds the point from which the vision angle "starts"
    center = [site_lat, site_lon]

    points1 = []
    points2 = []

    for i in reversed(range(1, opening_angle + 1)):
        yaw1 = (yaw - i / 2) % 360
        yaw2 = (yaw + i / 2) % 360

        point = geodesic(kilometers=dist_km).destination(
            Point(site_lat, site_lon), yaw1)
        points1.append([point.latitude, point.longitude])

        point = geodesic(kilometers=dist_km).destination(
            Point(site_lat, site_lon), yaw2)
        points2.append([point.latitude, point.longitude])

    points = [center] + points1 + list(reversed(points2))

    polygon = dl.Polygon(id={
        'type': 'vision_polygon',
        'index': str(event_id)
    },
                         color="#ff7800",
                         opacity=0.5,
                         positions=points)

    return polygon
Exemplo n.º 4
0
def update_output(value, start_date, end_date):
    if value is False:
        return None
    elif 'floods' in value:
        fl_coords_list = get_flood_polygons(bounds_uganda=bounds_uganda,
                                            start_date=start_date,
                                            end_date=end_date)
        return [
            dl.Polygon(positions=pol,
                       weight=1,
                       fill=True,
                       fillColor='red',
                       opacity=1,
                       color='red',
                       fillOpacity=0.5) for pol in fl_coords_list
        ]
    else:
        return None
Exemplo n.º 5
0
def render_example1():
    comment = """ Marker with default icon, marker with custom icon, circle marker (fixed pixel radius), 
    circle (fixed physical radius), polyline, polygon and rectangle, all supporting tooltips and popups. """
    return [
        html.H1("Example 1: Basic components"),
        html.P(comment),
        dl.Map(
            id=MAP_ID,
            style={
                'width': '1000px',
                'height': '500px'
            },
            center=[56.05, 10.25],
            zoom=10,
            children=[
                dl.TileLayer(id=BASE_LAYER_ID),
                # Marker with tool tip and popup.
                dl.Marker(position=[56, 9.8],
                          children=[
                              dl.Tooltip("Marker tooltip"),
                              dl.Popup([
                                  html.H1("Marker popup"),
                                  html.P("with inline html")
                              ])
                          ]),
                # Marker with custom icon.
                dl.Marker(position=[55.94, 9.96],
                          icon={
                              "iconUrl": "/assets/149059.svg",
                              "iconSize": [25, 25]
                          },
                          children=[dl.Tooltip("Marker with custom icon")]),
                # Circle marker (with fixed radius in pixel).
                dl.CircleMarker(center=[56.05, 10.15],
                                radius=20,
                                children=[dl.Popup('Circle marker, 20px')]),
                # Circle with fixed radius in meters.
                dl.Circle(center=[56.145, 10.21],
                          radius=2000,
                          color='rgb(255,128,0)',
                          children=[dl.Tooltip('Circle, 2km radius')]),
                # Polyline marker.
                dl.Polyline(id='polyline',
                            positions=[[56.06, 10.0], [56.056, 10.01],
                                       [56.064, 10.028], [56.0523, 10.0717],
                                       [56.044, 10.073]],
                            children=[dl.Tooltip('Polyline')]),
                # Polygon marker.
                dl.Polygon(id='polygon',
                           positions=[[56.013, 9.84], [56.0544, 9.939],
                                      [56.003, 10.001]],
                           children=[dl.Tooltip('Polygon')]),
                # Rectangle marker.
                dl.Rectangle(id='rectangle',
                             bounds=[[55.9, 10.2], [56.0, 10.5]],
                             children=[dl.Tooltip('Rectangle')])
            ]),
        dcc.RadioItems(id=BASE_LAYER_DROPDOWN_ID,
                       options=[{
                           "label":
                           i,
                           "value":
                           mapbox_url.format(id=i, access_token=mapbox_token)
                       } for i in mapbox_ids],
                       labelStyle={'display': 'inline-block'},
                       value=mapbox_url.format(id="light-v9",
                                               access_token=mapbox_token)),
        html.P("Coordinate (click on map):"),
        html.Div(id=COORDINATE_CLICK_ID),
    ]