Skip to main content
Version: 1.5.3.X

Map View Events

Usage pattern

const control = globalThis.MaptaskrControlManager.getControl(controlId);

All examples below assume you already have a valid control reference.

MapViewCreated

Fires after a new map view is created.

Parameters:

  • viewId (string): The created map view ID.
  • viewName (string): The created map view name.

Usage:

const onMapViewCreated = (viewId, viewName) => {
console.log('MapViewCreated:', viewId, viewName);
};

control.on('MapViewCreated', onMapViewCreated);

await control.addOrUpdateMapView({
viewName: 'Field Team Start View',
isDefault: false,
options: {},
});
Response
{
"viewId": "bd40e9d0-8e64-4d3b-95eb-85493bf4b4f9",
"viewName": "Field Team Start View"
}

Removing Event Listener:

control.off('MapViewCreated', onMapViewCreated);

MapViewUpdated

Fires when an existing map view is updated.

Parameters:

  • viewId (string): The updated map view ID.
  • viewName (string): The updated map view name.

Usage:

const onMapViewUpdated = (viewId, viewName) => {
console.log('MapViewUpdated:', viewId, viewName);
};

control.on('MapViewUpdated', onMapViewUpdated);

const existing = control.getMapViews()[0];
if (existing?.viewId) {
await control.addOrUpdateMapView({
viewId: existing.viewId,
viewName: `${existing.viewName} (Updated)`,
isDefault: existing.isDefault,
options: existing.options,
});
}
Response
{
"viewId": "bd40e9d0-8e64-4d3b-95eb-85493bf4b4f9",
"viewName": "Field Team Start View (Updated)"
}

Removing Event Listener:

control.off('MapViewUpdated', onMapViewUpdated);

MapViewApplied

Fires after a saved map view is applied.

Parameters:

  • viewId (string): The applied map view ID.
  • viewName (string): The applied map view name.

Usage:

const onMapViewApplied = (viewId, viewName) => {
console.log('MapViewApplied:', viewId, viewName);
};

control.on('MapViewApplied', onMapViewApplied);

const first = control.getMapViews()[0];
if (first?.viewId) {
await control.applyMapView(first.viewId);
}
Response
{
"viewId": "bd40e9d0-8e64-4d3b-95eb-85493bf4b4f9",
"viewName": "Field Team Start View"
}

Removing Event Listener:

control.off('MapViewApplied', onMapViewApplied);

MapViewDeleted

Fires after a map view is deleted.

Parameters:

  • viewId (string): The deleted map view ID.
  • viewName (string): The deleted map view name.

Usage:

const onMapViewDeleted = (viewId, viewName) => {
console.log('MapViewDeleted:', viewId, viewName);
};

control.on('MapViewDeleted', onMapViewDeleted);

const temp = await control.addOrUpdateMapView({
viewName: 'Temporary Delete Example',
isDefault: false,
options: {},
});

if (temp?.viewId) {
await control.deleteMapView(temp.viewId);
}
Response
{
"viewId": "2d1f0e6e-9bf4-4545-8d66-4ca8ad0886a9",
"viewName": "Temporary Delete Example"
}

Removing Event Listener:

control.off('MapViewDeleted', onMapViewDeleted);

MapViewSetAsDefault

Fires when a map view becomes the default view.

Parameters:

  • viewId (string): The map view ID now set as default.
  • viewName (string): The map view name now set as default.

Usage:

const onMapViewSetAsDefault = (viewId, viewName) => {
console.log('MapViewSetAsDefault:', viewId, viewName);
};

control.on('MapViewSetAsDefault', onMapViewSetAsDefault);

const target = control.getMapViews().find((v) => v.viewName === 'Field Team Start View');
if (target?.viewId) {
await control.setDefaultMapView(target.viewId);
}
Response
{
"viewId": "bd40e9d0-8e64-4d3b-95eb-85493bf4b4f9",
"viewName": "Field Team Start View"
}

Removing Event Listener:

control.off('MapViewSetAsDefault', onMapViewSetAsDefault);

Subscribing and unsubscribing safely

Use stable function references when pairing on and off.

let createdCount = 0;

const handler = (viewId, viewName) => {
createdCount += 1;
console.log(`Created #${createdCount}:`, viewName, viewId);
};

control.on('MapViewCreated', handler);

await control.addOrUpdateMapView({
viewName: 'On-Off Example 1',
isDefault: false,
options: {},
});

control.off('MapViewCreated', handler);

await control.addOrUpdateMapView({
viewName: 'On-Off Example 2',
isDefault: false,
options: {},
});

UI-triggered events

These events are raised for user actions in the Map Views panel as well as API calls.

UI example: create from panel

const onCreatedFromUI = (viewId, viewName) => {
console.log('UI created view:', viewId, viewName);
};

control.on('MapViewCreated', onCreatedFromUI);

// Create a view from the Map Views panel in the UI.
// The same callback above will fire once creation completes.

UI example: apply from panel

const onAppliedFromUI = (viewId, viewName) => {
console.log('UI applied view:', viewId, viewName);
};

control.on('MapViewApplied', onAppliedFromUI);

// Apply a view from the Map Views panel in the UI.
// The same callback above will fire once apply completes.

UI example: delete from panel

const onDeletedFromUI = (viewId, viewName) => {
console.log('UI deleted view:', viewId, viewName);
};

control.on('MapViewDeleted', onDeletedFromUI);

// Delete a view from the Map Views panel in the UI.
// The same callback above will fire once deletion completes.
note

Event handlers are ideal for syncing custom UI, telemetry, or local state whenever map views change.