Properties
All objects that are received from the server are cached in properties of the client object.
All objects that can be part of a map have an id
. Note that when an object is updated, the whole object is replaced in these properties, so be careful to not cache outdated versions of objects:
let myMarker = client.markers[myMarkerId];
setTimeout(() => {
// Bad! A client.markers[myMarkerId] might have been replaced if the marker
// has been changed in the meantime, and we are using the old version.
doSomethingWithMarker(myMarker);
}, 10000);
setTimeout(() => {
// Better! Always get objects directly from the client cache.
doSomethingWithMarker(client.markers[myMarkerId]);
});
// If you need to keep an object copy, make sure to keep it updated
client.on("marker", (marker) => {
if(marker.id == myMarkerId)
myMarker = marker;
});
mapId
The ID of the collaborative map that the client is connected to. Can be the read-only, writable or admin ID of an existing map.
Note that the ID can be changed in the settings. If in case of a mapData
event, the ID of the map has changed, this property is updated automatically.
Set: when calling setMapId
and in response to a mapData
event.
Type: string
readonly
true
if the map has been opened using its read-only ID. false
if the map is writable.
Set: during setMapId
.
Type: boolean
writable
2
if the map has been opened using its admin ID, 1
if if has been opened using the writable ID, 0
if the map is read-only.
Set: during setMapId
.
Type: number
deleted
true
if the map was deleted while this client was connected to it.
Set: in response to a deleteMap
event.
Type: boolean
mapData
The current settings of the map. writeId
and/or adminId
is null if if has been opened using another ID than the admin ID.
Set: in response to a mapData
event.
Type: MapData
markers
All markers that have been retrieved so far.
Set: in response to marker
and deleteMarker
events.
Type: { [markerId: number]: Marker }
lines
All lines of the map along with the track points that have been retrieved so far.
Set: in response to line
, linePoints
and deleteLine
events.
Type: { [lineId: number]: Line }
(with track points)
views
All views of the map.
Set: in response to view
and deleteView
events.
Type: { [viewId: number]: View }
types
All types of the map.
Set: in response to type
and deleteType
events.
Type: { [typeId: number]: Type }
history
All history entries that have been retrieved so far. Note that you have to subscribe to the history using listenToHistory()
.
Set: in response to history
events.
Type: { [entryId: number]: HistoryEntry }
route
Details and track points (simplified for the current bbox) for the active route set using setRoute()
with routeId
set to undefined
, or undefined
if no such route is active.
Set: during setRoute()
and in response to routePoints
events.
Type: Route
routes
Details and track points (simplified for the current bbox) for the active routes set using setRoute()
with routeId
set to a string.
Set: during setRoute()
and in response to routePoints
events.
Type: { [routeId: string]: Route }
serverError
If the opening the map failed (setMapId(mapId)
promise got rejected), the error message is stored in this property.
Set: in response to a serverError
event (fired during setMapId
).
Type: Error
loading
A number that indicates how many requests are currently pending (meaning how many async methods are currently running). You can use this to show a loading spinner or disable certain UI elements while the value is greater than 0.
Set: increased when any method is called and decreased when the method returns.
Type: number
disconnected
false
in the beginning, changed to true
as soon as the socket.io connection is made. May be false
temporarily if the connection is lost.
Set: in reaction to connect
and disconnect
events.
Type: boolean