I’m really surprised to see there is no geojson attribute when working with plotly maps. It took me hours looking through the documentation to figure out what I have now. I’m currently receiving the following error in the web browser console when I add the mapbox
attribute to display my geojson layer.
Error:
Error: No valid mapbox style found, please set
mapbox.style
to one of: open-street-map, white-bg, carto-positron, carto-darkmatter, stamen-terrain, stamen-toner, stamen-watercolor or register a Mapbox access token to use a Mapbox-served style.
Python:
import plotly.graph_objects as go
import pandas as pd
import json
with open('fcRailroad.geojson') as json_file:
fcRailroad = json.load(json_file)
fig = go.Figure(go.Scattermapbox())
fig.update_layout(mapbox_style="stamen-terrain",
mapbox_zoom=10,
mapbox_center_lat = 40.58,
mapbox_center_lon = -105.08,
margin={"r":0,"t":0,"l":0,"b":0},
mapbox=go.layout.Mapbox(
layers=[{
'sourcetype': 'geojson',
'source': fcRailroad,
'type': 'line',
}]
))
fig.show()
geoJSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-825.0913953781128,
40.49348616373978
],
[
-825.0906443595885,
40.49508532104079
],
[
-825.0863313674927,
40.502411585011934
]
]
}
}
]
}
Any help would be greatly appreciated. Thank you.