Locator
The Locator instance provides methods for displaying and positioning the locator icon. An instance is created via the UnitMap.locator() method.
An image of the locator icon.
This icon is used to highlight a single position on the map, most likely that of a user's geolocation, but can have other use cases and is not directly coupled to geo positioning data.
map.on("ready", function() {
// Create a Locator instance via `map.locator()`, which can only be called once the map has loaded.
var locator = map.locator();
});Locator.translate([point])
Moves the locator icon to the given position if provided. Otherwise returns the current position value.
Arguments
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| point | No | Array | undefined | An array representing an x and y coordinate pair of a position in map space. Example: [1, 5]. |
Returns
Either an [x, y] coordinates Array of the current position or the object chain.
Locator.color([color])
Sets the fill color of the locator icon if a color is provided. Otherwise returns the current color value.
Passing null restores the default color.
var locator = map.locator();
// Set the locator to orange:
locator.color("#FB4F14");
// Restore the default color:
locator.color(null);Arguments
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| color | No | String | #4196CA | Any CSS color value to fill the locator icon with. Example: #FB4F14. Pass null to restore the default color. |
Returns
Either a String of the current color or the object chain.
Locator.number([number])
Displays a number inside the locator icon if one is provided. Otherwise returns the current number value.
// Number each stop on a trip in visiting order:
trip.locations().each(function (location, index) {
location.locator().number(index + 1);
});Arguments
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| number | No | Number | null | A positive integer to display inside the locator icon. Example: 2. Pass null to remove the number. |
Values other than a positive integer ornullare ignored.
Returns
Either a Number of the current value, null if no number is set, or the object chain.
Locator.show()
Display the locator icon. This method is chainable.
Locator.hide()
Hide the locator icon. This method is chainable.
Updated 3 days ago

