Maps SDK for Web

Class L.RouteInputs

This widget allows you to manage many search boxes.

Constructor

L.RouteInputs([options])

Parameters
Name Description Required Type/Values Default
options Options to be passed to the routeInputs control No Object None
options.searchBoxes Number of searchBoxes to be created No Number 2
options.position Position of the control on the map No "topright" | "topleft" | "bottomright" | "bottomleft" "topleft"
options.location Definition of place of creation location control. Should be equal to one of the values in the Location property. No String L.RouteInputs.Location.Start
options.enableSearchBoxesModifcation Determines whether control should expose functionality of adding or removing waypoints by internal controls No String false
options.waypointPlacement Determines the place where the new waypoint will added to. Should be equal to one of the values in the WaypointPlacement property. No String L.RouteInputs.WaypointPlacement.BeforeLast
options.searchOptions Options for the L.SearchBox instances No Object None
options.searchOptions.collapsible Decide if the search boxes should be collapsed No Object false
Example
// Route inputs with two search boxes and location control
var widget = new L.RouteInputs({
  searchBoxes: 2,
  location: L.RouteInputs.Location.Start
})
widget.addTo(map);

Properties

Location: Object

Determines the position that location icon will be added to. Possible options are:
  • Location.Start - location will be added to the first searchBox in the list.
  • Location.End - location will be added to the last searchBox in the list.
Example
var widget = new L.RouteInputs({
  location: L.RouteInputs.Location.Start
});
widget.addTo(map);

WaypointPlacement: Object

Determines the position where waypoint will be added to. Possible options are:
  • WaypointPlacement.BeforeLast - new waypoint will be added before the last searchBox.
  • WaypointPlacement.Last - new waypoint will be added as the last element in the list.
Example
var widget = new L.RouteInputs({
  waypointPlacement: L.RouteInputs.WaypointPlacement.BeforeLast
});
widget.addTo(map);

Methods

addInput([index])

Method used to add searchBox to the specific position (index).

Parameters
Name Description Required Type/Values Default
index Represents position where search box should be added to. Not passing any index will cause adding a searchBox at the end of list or just before the last search box. No Number None
Example
var widget = new L.RouteInputs();
widget.addTo(map);
widget.addInput(0);
widget.addInput();

addSearchBoxEventHandlers(searchBox)

Method used to add handlers for given search box. If obtaining user's current location fails, LocationError is fired.

Parameters
Name Description Required Type/Values Default

createContainer( ): HTMLElement

Method used to create the container for the search boxes.

Returns

Container for search boxes

createSearchBox(index): L.SearchBox

Method used to initialize search box by adding element to the container and applying event handlers on it.

Parameters
Name Description Required Type/Values Default
index Index of the search box (starting from 0) Yes Number None
Returns

Modified search box object

getIconClassName(index): String

Method used to get search box icon's class name, depending on its position (index).

The returned class name should be added to the input.

Parameters
Name Description Required Type/Values Default
index Yes Number None
Returns

needsLocationIcon(searchBoxIndex): Boolean

Method used to check if search box needs location element.

Parameters
Name Description Required Type/Values Default
searchBoxIndex Index of the given search box (starting from 0) Yes Number None
Returns

Returns information of presence of location element

onLocationChange(eventObject)

Method used to manage changing state of search boxes. Depending on the content of the searchBox, there might be fired one of these two events:

Parameters
Name Description Required Type/Values Default
eventObject Object that contains event's information Yes Object None
eventObject.target Box instance Yes L.SearchBox None
eventObject.data Yes Object None
eventObject.data.position Position of the box Yes Number None

removeInput(searchBox)

Method used to remove searchBox from the specific position (index).

Parameters
Name Description Required Type/Values Default
Example
var widget = new L.RouteInputs();
widget.addTo(map)
widget.removeInput(0);
widget.removeInput();

removeSearchBox(index): L.SearchBox

Method used to remove given search box from the view by specific index.

Parameters
Name Description Required Type/Values Default
index Index of the search box (starting from 0) Yes Number None
Returns

Modified search box object

showLocationNotFoundMessageBox( )

Method used to show notification when looking for current location fails.

Events

All the class events are keys of the Events static member.

To learn more about how to listen events please refer to this documentation.

LocationError

Event that is fired when obtaining user's current location fails.
Properties
Name Description Type/Values Default
eventObject All failure information Object None
type Event's name String "locationError"
target Event's target. Element None
Example
var widget = new L.RouteInputs();
widget.addTo(map);
widget.on(L.RouteInputs.Events.LocationError, function (eventObject) {
  console.log(eventObject);
});

LocationsCleared

Event that is fired when locations in all searchBoxes are being removed.
Properties
Name Description Type/Values Default
points Array of points that represents locations from all searchBoxes, even if they are undefined. Array None
type Event's name String "locationsCleared"
target Event's target. Element None
Example
var widget = new L.RouteInputs();
widget.addTo(map);
widget.on(L.RouteInputs.Events.LocationsCleared, function (eventObject) {
  console.log(eventObject.points);
});

LocationsFound

Event that is fired when locations in all searchBoxes are changing.
Properties
Name Description Type/Values Default
points Array of points that represents locations from all searchBoxes, even if they are undefined. Array None
type Event's name String "locationsFound"
target Event's target. Element None
Example
var routeInputInstance = (new L.RouteInputs()).addTo(map);
routeInputInstance.on(L.RouteInputs.Events.LocationsFound, function (eventObject) {
     console.log(eventObject.points);
});