Измените свойство Geojson, нажав на карту, используя Dash и ListletPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Измените свойство Geojson, нажав на карту, используя Dash и Listlet

Сообщение Anonymous »

В настоящее время мой код выглядит следующим образом: < /p>

Код: Выделить всё

import dash
from dash import Output, Input, State, html, no_update
import dash_leaflet as dl
import osmnx as ox
import json

from numpy import dtype

# Style-Funktion für GeoJSON-Features
def get_style(feature):
return {
"color": "rgba(0,0,0,0)",  # Transparent
"weight": 5,
"opacity": 1,
"fillOpacity": 0
}

# create a style for the GeoJSON features where the color is dependent on the "use" attribute
def get_style_with_use(feature):
if feature['properties']['use'] == True:
return {
"color": "rgba(0,0,0,0)",
"weight": 2,
"opacity": 0.7,
"fillOpacity": 0
}
else:
return {
"color": "green",
"weight": 5,
"opacity": 0.9,
"fillOpacity": 0
}

# Hover-Style (blau)
hover_style = {
"color": "blue",
"weight": 7,
"opacity": 1,
"fillOpacity": 0.5
}

# GeoJSON with Dresdner streets
G = ox.load_graphml("dresden_saxony_germanyroad_network.graphml")

# add a attribute to the edges called "use" and set it to "TRUE"
for u, v, key, data in G.edges(keys=True, data=True):
data['use'] = True

geojson_data = ox.graph_to_gdfs(G, nodes=False, edges=True, fill_edge_geometry=True).to_json()
data = json.loads(geojson_data)
meta = data['features']

mapping = {}
for i in range(len(meta)):
mapping[meta[i]['id']] = i

# print the Name of the Street on the Dash App as text below the map
# Dash-App mit Leaflet-Karte
app = dash.Dash(__name__)

app.layout = html.Div([
html.H1("Dresden Streets Map"),
dl.Map([
dl.TileLayer(),
dl.GeoJSON(
data=data,
id="geojson-dresden-streets",
style={
"color": "rgba(0,0,0,0)",
"weight": 5,
"opacity": 1,
"fillOpacity": 0
},
hoverStyle=hover_style
)
], style={'width': '1000px', 'height': '500px'}, center=[51.0504, 13.7373], zoom=12),
html.Div(id='container-output-text',
children='Enter a value and press submit')
])

@app.callback(
Output('container-output-text', 'children'),
Input('geojson-dresden-streets', 'n_clicks'),
State('geojson-dresden-streets', 'clickData'),
prevent_initial_call=True
)
def f1(input_, state_):
print(json.dumps(input_))
print(json.dumps(state_))

# id = mapping.get(str(state_['id']))
# print(state_['id'])
# print(id)
# # print datatype of data['features']
# print(type(data['features']))
# print(data['features'][id])
# data['features'][id]['properties']['use'] = False

print()

if __name__ == "__main__":
app.run(debug=True)
< /code>
Что я хочу сделать: < /p>
[list]
 Создание карты (здесь как образец для Дрездена, Германия): Готово < /li>
 Напорочные улицы должны быть синими. /> [/list]
Что я попробовал для «щелчка на улице»:

 Добавлена ​​функция «Использовать» из True 
to false или vise sters>

Подробнее здесь: https://stackoverflow.com/questions/796 ... nd-leaflet
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»