You are viewing an older version of MapQuest.js. Check out the latest version.
A control that adds route narratives to the map from a directions response. It is also interactive where clicks on the narrative will bring up narrative popups along the route.
When creating a route, a boolean option enhancedNarrative
can be set.
The response will contain Intersection Counts, Previous Intersection, and Next Intersection/Gone Too Far advice, which will be added to the narrativeControl.
L.mapquest.key = 'KEY';
var directions = L.mapquest.directions();
directions.route({
start: 'Denver, CO',
end: 'Boulder, CO',
options: {
enhancedNarrative: true
}
}, createMap);
function createMap(error, response) {
var map = L.mapquest.map('map', {
center: [0,0],
layers: L.mapquest.tileLayer('map'),
zoom: 7
});
var directionsLayer = L.mapquest.directionsLayer({
directionsResponse: response
}).addTo(map);
var narrativeControl = L.mapquest.narrativeControl({
directionsResponse: response,
compactResults: false,
interactive: true
});
narrativeControl.setDirectionsLayer(directionsLayer);
narrativeControl.addTo(map);
}
An object containing any of the following key value options: directionsResponse, position, className, interactive, and compactResults.
The response object from a directions route that populates the narrative.
The position of the control (one of the map corners).
Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'.
A custom CSS class name to assign to the control.
Determines if the control is interactive. When it is interactive, the narrative maneuvers are clickable and place via points and popups on the map.
Determines if a compact layout of the route narrative should be used.
{
position: 'bottomright',
className: '',
compactResults: false,
interactive: true,
directionsResponse: {}
}
Assigns a directionsLayer object to the narrativeControl.
When the directionsLayer fires a directions_changed
event, the narrative control will automatically update the narrative.
If no directionsLayer is set, the narrative control is static and won't change if the directionsLayer changes.
var directionsLayer = L.mapquest.directionsLayer({
directionsResponse: response
}).addTo(map);
var narrativeControl = L.mapquest.narrativeControl({
directionsResponse: response,
compactResults: false,
interactive: true
});
narrativeControl.setDirectionsLayer(directionsLayer);
narrativeControl.addTo(map);
An L.Control object that can be added to a map with the addControl() function.