Constructor
# new PositionControl(element, options)
Attach position control to an HTML element that when clicked (or permission already given) will show current position on the map.
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | An element to hold the position control that should be added to the map |
options |
PositionControlOptions |
Example
// Create element to hold the position control
const myPositionControlElm = document.createElement('div');
// Create position control and attach it to element
new mapsindoors.PositionControl(myPositionControlElm, { mapsIndoors: myMapsIndoors, maxAccuracy: 125 });
// Add the element now holding position control to your map:
// For Google Maps:
myMapsIndoorsInstance.getMap().controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(myPositionControlElm);
// For Mapbox:
myMapsIndoorsInstance.getMap().addControl({ onAdd: function () { return myPositionControlElm }, onRemove: function () { } });
Members
GeolocationPosition
# currentPosition
The current position of the device if received (GeolocationPosition).
Methods
# panToCurrentPosition()
Pan map to center on the current position.
Example
// Create position control and always follow current position
const myPositionControlElm = document.createElement('div');
const myPositionControl = new mapsindoors.PositionControl(myPositionControlElm, { mapsIndoors: myMapsIndoors });
...
myPositionControl.addListener(myMapsindoors, 'position_received', () => {
myPositionControl.panToCurrentPosition();
});
# watchPosition(selfInvokedopt)
Request for current position, emit events and show position on map based on result.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
selfInvoked |
boolean |
<optional> |
false | Used to track if call was invoked by clicking on position control or not. |
Events
Object
# position_error
Position error event. Fired in case of a positioning error.
Properties:
Name | Type | Description |
---|---|---|
code |
number | 1-3: GeolocationError code. 10: Geolocation not available. 11: Inaccurate position |
message |
string | Error message |
Example
myPositionControl.on('position_error', reason => {
// Do something with error reason { code: <number>, message: <string> }
});
Object
# position_received
Position received event. Fired whenever position is retreived or updated.
Properties:
Name | Type | Description |
---|---|---|
selfInvoked |
boolean | If the position request was invoked by clicking on the position control. |
accurate |
boolean | If the position is accurate (below the maxAccuracy set in options) |
position |
GeolocationPosition | GeolocationPosition |
Example
myPositionControl.on('position_received', payload => {
// Do something with eg. payload.position
});