I am not sure this is possible with the Scattermapbox plot. If you only need points, you could use the Dash Leaflet component instead. It has no compass component included by default, but it should be doable to port a Leaflet one, e.g.
@Emil Thanks a lot. I looked at one of the leaflet example and really did not get how it can be used in place of compass. Here is code i am looking at:
import dash
import dash_leaflet as dl
import dash_html_components as html
The code that you have pasted should render the map itself. Before you can add a compass, you need to write a light wrapper of the leaflet compass component that you decide to use. Once the wrapper is in place, you can add the compas to the map by attaching it as a child to the Map component.
This will take me forever to understand how to add compass to these maps. I tried the example u have shared and there is no compass else i would have figured out a way to incorporate same to my map. If u could give me direct example i can use straightaway in my code that will be really helpful. This is my code for scattermapbox. i am plotting lat/lon data on mapbox. Then passing data and layout to figure.
data =
for event in event_types:
event_data = dict(
lat = df.loc[df[‘EVENT_TYPE’] == event,‘BEGIN_LAT’],
lon = df.loc[df[‘EVENT_TYPE’] == event,‘BEGIN_LON’],
name = event,
marker = dict(size = 8, opacity = 0.5),
type = ‘scattermapbox’
)
data.append(event_data)
In that case can we atleast show a compass that is static always pointing to North so users get a fair idea and indication that maps are always pointing in north. Any setting on scattermapbox we could enable???
there is no setting on mapbox for this, but you could add some text above the map or you could include an image with html.Img and position it absolutely over the map with css
@RenaudLN
in that case can u let us know if we can add compass to these maps? I know mapbox has a setting to enable compass for android apps. You know if we can do same in Dash as well.
var aMapbox = new mapboxgl.Map(…);
aMapbox.addControl(new mapboxgl.NavigationControl(), ‘top-left’);
Introspecting go.Mapbox and go.Scattermapbox, I did not see any attribute or method getting the native mapbox object. If anyone knows an internal to get the native mapbox object when using ScatterMapbox…
This is my layout definition. Can you tell me how to fit above code into this. Thanks
layout = dict(
height = 420,
# top, bottom, left and right margins
margin = dict(t = 0, b = 0, l = 0, r = 0),
font = dict(color = ‘black’, size = 12, family = ‘Arial, Helvetica, sans-serif’),
paper_bgcolor = ‘white’,
legend=dict(orientation=‘h’, x = 0, y = -0.055),
mapbox = dict(
# here you need the token from Mapbox
accesstoken = mapbox_access_token,
bearing = 0,
# where we want the map to be centered
center = dict(
lat = 38,
lon = -94
),
# we want the map to be “parallel” to our screen, with no angle
pitch = 0,
# default level of zoom
zoom = 2.5,
# default map style
style = ‘light’
)
)
@RenaudLN Yes mapbox plots can be rotated but not real time i believe. we have to set the pitch or bearing values to accomplish that still the map will remain static with that angle i think. Please see below layout definition.
Unfortunately, compass is not set with init parameter of Mapbox creation : the mapbox dict of Layout. It is set with a method in mapbox object.
According to me there is no way to set compass with Layout.