Example #1
0
def get_precinct_overlay():
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    precinct_geojson_path = "data/geojson/stl-city/precincts_rw.geojson"
    with open(precinct_geojson_path) as read_file:
        precinct_geojson = json.load(read_file)
    precincts = dl.GeoJSON(
        data=precinct_geojson,
        options=dict(style=dict(color="blue", fillOpacity=0.5)),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2, dashArray="")),
        id="precincts-geojson",
    )
    precinct_overlay = dl.Overlay(precincts, name="precincts", checked=False)
    return precinct_overlay
Example #2
0
def get_precinct_overlay():
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    precinct_pbf_url = "dsadata/static/geobuf/stl-city-precincts.pbf"
    ns = Namespace("dlx", "choropleth")
    precincts = dl.GeoJSON(
        url=precinct_pbf_url,
        format="geobuf",
        options=dict(style=ns("style")),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2,
                                       dashArray="")),
        hideout=bootstrap_stuff.build_choropleth_hideout("total_donations"),
        id="precincts-geojson",
    )
    precinct_overlay = dl.Overlay(precincts, name="precincts", checked=False)
    return precinct_overlay
Example #3
0
def get_zip_overlay(mec_df, candidate):
    if candidate is not None:
        cand_df = contrib.sum_funds_by_zip(cand_zip_df)
    else:
        df = cand_zip_df[cand_zip_df[" MECID"] == candidate]
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    zip_geojson_path = "data/geojson/stl-region-zip_rw.geojson"
    gdf = gpd.read_file(zip_geojson_path)
    gdf = gdf.merge(cand_zip_df, left_on="ZCTA5CE10", right_on="ZIP5")
    if candidate is not None:
        df = contrib.sum_funds_by_zip(cand_zip_df)
    else:
        df = cand_zip_df[cand_zip_df[" MECID"] == candidate]
    with open(zip_geojson_path) as read_file:
        zip_geojson = json.load(read_file)
    zips = dl.GeoJSON(
        data=zip_geojson,
        options=dict(style=dict(color="purple", fillOpacity=0.5)),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2, dashArray="")),
        id="zips-geojson",
    )
    zip_overlay = dl.Overlay(zips, name="zips", checked=True)
    return zip_overlay
Example #4
0
         ),
 dbc.Row([dbc.Col(html.Div([dbc.Row(dbc.Col(dcc.Graph(id = 'temporal-analysis',
                                                      figure = {}
                                                      ),
                                            width = 12)
                                    ),
                            dbc.Row(dbc.Col(dl.Map(dl.LayersControl([dl.BaseLayer(dl.TileLayer(id = 'layer',
                                                                                               url = 'https://api.maptiler.com/maps/outdoor/256/{z}/{x}/{y}@2x.png?key=' + map_key,
                                                                                               attribution = '<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a> ' + '<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>',
                                                                                               ),
                                                                                  name = 'Base Map',
                                                                                  checked = True
                                                                                  ),
                                                                     dl.Overlay(children = [],
                                                                                name = 'Routes Polygons',
                                                                                checked = True,
                                                                                id = 'map-routes'
                                                                                ),
                                                                     dl.Overlay(id = 'map-events',
                                                                                children = [],
                                                                                name = 'Events Points',
                                                                                )
                                                                     ],
                                                                    ),
                                                   style = {'width': '800px', 'height': '400px'},
                                                   zoom = 4,
                                                   center = (37,15),
                                                   id = 'map-analysis'),
                                            width = {'offset' : 1}
                                            )
                                    )
def serve_layout():
    dd_variable = dcc.Dropdown(options=variable_options,
                               value=default_variable, id="dd_variable", clearable=False)
    minmax = get_minmax(default_variable)
    # # Create a colorbar.
    colorbar = dl.Colorbar(
        colorscale=csc_map[default_csc], id="colorbar", width=20, height=150, **minmax)
    
    geojson = dl.GeoJSON(data=get_data(default_variable), id="geojson",
                         format='geobuf',
                         cluster=True,  # when true, data are clustered
                         # how to draw clusters
                         clusterToLayer=ns("clusterToLayer"),
                         # how to draw points
                         options=dict(pointToLayer=ns("pointToLayer")),
                         superClusterOptions=dict(radius=50),  # adjust cluster size
                         hideout=dict(colorscale=csc_map[default_csc],
                                      colorProp=default_variable, **minmax))

    times = pd.date_range(start=pd.to_datetime('now', utc=True).round('15min') - pd.Timedelta('2hours'),
                          end=pd.to_datetime('now', utc=True).round(
                              '15min') - pd.Timedelta('15min'),
                          freq='5min')
    latest = times[-1].strftime('%Y-%m-%dT%H:%M:00.000Z')

    numdate = [x for x in range(len(times))]
    marks = {numd: date.strftime('%H:%M')
             for numd, date in zip(numdate, times)}

    slider = dcc.Slider(id='time_slider', min=numdate[0],
                        max=numdate[-1],
                        value=numdate[-1],
                        marks=marks)

    layout = html.Div([
        dl.Map([
            dl.LayersControl(
                [
                    dl.BaseLayer(dl.TileLayer(url=mapURL, attribution=attribution,
                                              tileSize=512, zoomOffset=-1), name='map', checked=True),
                    dl.Overlay(dl.WMSTileLayer(url="https://maps.dwd.de/geoserver/ows?",
                                               layers="dwd:SAT_EU_RGB",
                                               format="image/png",
                                               transparent=True, opacity=0.6,
                                               version='1.3.0',
                                               detectRetina=True), name='sat eu', checked=True),
                    dl.Overlay(dl.WMSTileLayer(id='radar_it',
                                               url="http://www.protezionecivile.gov.it/geowebcache/service/wms?tiled=True&time=%s" % latest,
                                               layers="radar:vmi",
                                               transparent=True,
                                               format="image/png",
                                               opacity=1.0,
                                               version='1.1.1'),
                      name='radar IT', checked=True),
                    dl.Overlay([geojson, colorbar], name='obs', checked=True)
                ]),
            geojson_countries,
        ], center=[41, 12], zoom=6),
        html.Div(id='date-div', style={'display': 'none'},
                 children=times.strftime('%Y-%m-%dT%H:%M:00.000Z')),
        html.Div([slider],
                 style={"position": "absolute", "bottom": "20px",
                        "left": "10px", "z-index": "1000", "width": "800px",
                        "background-color": 'rgba(1, 1, 1, 0.3)'}),
        html.Div([dd_variable],
                 style={"position": "absolute", "top": "300px", "right": "16px", "z-index": "1000", "width": "100px"})
    ], style={'width': '100%', 'height': '90vh', 'margin': "auto", "display": "block", "position": "relative"})

    return layout
Example #6
0
def serve_layout():
    minmax = get_minmax(default_variable)

    # Create a colorbar.
    colorbar = dl.Colorbar(colorscale=csc_map[default_csc],
                           id="colorbar",
                           width=20,
                           height=150,
                           **minmax)

    geojson = dl.GeoJSON(
        data=get_data(default_variable),
        id="geojson",
        format="geobuf",
        zoomToBounds=True,  # when true, zooms to bounds when data changes
        cluster=True,  # when true, data are clustered
        # how to draw clusters
        clusterToLayer=ns("clusterToLayer"),
        # when true, zooms to bounds of feature (e.g. cluster) on click
        zoomToBoundsOnClick=True,
        # how to draw points
        options=dict(pointToLayer=ns("pointToLayer")),
        superClusterOptions=dict(radius=20),  # adjust cluster size
        hideout=dict(colorscale=csc_map[default_csc],
                     colorProp=default_variable,
                     **minmax))

    layout = html.Div(
        [
            dl.Map([
                dl.LayersControl([
                    dl.BaseLayer(dl.TileLayer(url=mapURL,
                                              attribution=attribution,
                                              tileSize=512,
                                              zoomOffset=-1),
                                 name='map',
                                 checked=True),
                    dl.Overlay(dl.WMSTileLayer(
                        url="https://maps.dwd.de/geoserver/ows?",
                        layers="dwd:SAT_WELT_KOMPOSIT",
                        format="image/png",
                        transparent=True,
                        opacity=0.7,
                        version='1.3.0',
                        detectRetina=True),
                               name='sat world',
                               checked=True),
                    dl.Overlay(dl.WMSTileLayer(
                        url="https://maps.dwd.de/geoserver/ows?",
                        layers="dwd:SAT_EU_RGB",
                        format="image/png",
                        transparent=True,
                        opacity=0.7,
                        version='1.3.0',
                        detectRetina=True),
                               name='sat eu',
                               checked=True),
                    dl.Overlay(dl.WMSTileLayer(
                        url="https://maps.dwd.de/geoserver/ows?",
                        layers="dwd:WN-Produkt",
                        format="image/png",
                        transparent=True,
                        opacity=0.7,
                        version='1.3.0',
                        detectRetina=True),
                               name='radar DE',
                               checked=True),
                    dl.Overlay(
                        [geojson, colorbar], name='obs DE', checked=True)
                ]),
                geojson_countries,
            ]),
            html.Div(
                [dd_variable, dd_csc],
                style={
                    "position": "relative",
                    "bottom": "80px",
                    "left": "10px",
                    "z-index": "1000",
                    "width": "200px"
                })
        ],
        style={
            'width': '100%',
            'height': '90vh',
            'margin': "auto",
            "display": "block",
            "position": "relative"
        })

    return layout
Example #7
0
        )
wards = dl.GeoJSON(
    data=ward_geojson,  # TODO: Faster is to get PBFs
    options={"style": {
        "color": "red",
        "fillOpacity": 0.5,
        "weight": 2
    }},
    zoomToBoundsOnClick=
    True,  # when true, zooms to bounds of feature (e.g. polygon) on click
    hoverStyle=arrow_function(
        dict(weight=4, fillOpacity=0.2,
             dashArray="")),  # special style applied on hover)
    id="wards-geojson",
)
ward_overlay = dl.Overlay(dl.LayerGroup(wards), name="wards", checked=True)


# 	Wards: Show election info on click
@app.callback(
    Output("ward-info-panel", "children"),
    [Input("wards-geojson", "click_feature")],
    State("election-dropdown", "value"),
)
def ward_click(feature, election_selected):
    div_children = []
    races_per_election = dict(
        aug_2020=dict(
            rep1_dem=dict(
                name="U.S Congress MO-1 (Democratic Primary)",
                candidates=["Clay", "Bush"],