Open ajay-dev-j opened 4 years ago
Library : react I need to toggle on/off the instructions by an external button.
const [toggleInstructions, setToggleInstructions] = useState(true);
`<button type="button" onClick={() => setToggleInstructions((prev) => !prev)}
Hide/Show `
const directions = new MapboxDirections({ accessToken: process.env.REACT_APP_MAPBOX_TOKEN, unit: 'metric', profile: 'mapbox/driving', interactive: false, controls: { inputs: false, profileSwitcher: false, instructions: toggleInstructions, }, });
map.on('load', () => { map.addControl(new mapboxgl.NavigationControl()); map.addControl(directions, 'top-left'); directions.setOrigin(start.address); wayPointsStatic.forEach((point, index) => { directions.addWaypoint(index, [point.lat, point.long]); // new mapboxgl.Marker().setLngLat([point.lat, point.long]).addTo(map); }); directions.setDestination(end.address); });
Seems like, this library doesn't work happily with React. Did you find a solution?
No solution! My bad :(
Library : react I need to toggle on/off the instructions by an external button.
const [toggleInstructions, setToggleInstructions] = useState(true);
`<button type="button" onClick={() => setToggleInstructions((prev) => !prev)}
const directions = new MapboxDirections({ accessToken: process.env.REACT_APP_MAPBOX_TOKEN, unit: 'metric', profile: 'mapbox/driving', interactive: false, controls: { inputs: false, profileSwitcher: false, instructions: toggleInstructions, }, });
map.on('load', () => { map.addControl(new mapboxgl.NavigationControl()); map.addControl(directions, 'top-left'); directions.setOrigin(start.address); wayPointsStatic.forEach((point, index) => { directions.addWaypoint(index, [point.lat, point.long]); // new mapboxgl.Marker().setLngLat([point.lat, point.long]).addTo(map); }); directions.setDestination(end.address); });