Apply Overrides Event
The apply-overrides
event provides a mechanism to dynamically and programmatically override configurations (such as layer properties, settings, etc.).
Properties
Property | Type | Required | Summary |
---|---|---|---|
layers | object | false | A mapping of layer IDs to override properties |
settings | object | false | A mapping of application settings to override |
displaySettings | object | false | A mapping of display settings to apply |
Layer Overrides
The layers
property is a key value pair of layer ID to overrides. Any overrides provided will directly be assigned to the given layer (by ID), if it exists.
Note: if the layer is removed and added again, the overrides will not get applied to the newly added layer.
Overrides can be assigned to all layers by using the *
key.
"*": {...overrides...}
Examples
Apply change by layer ID
Changes the title for layer with ID 'my-layer'
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
'my-layer': {
title: 'New Title'
}
}
}
},
'*'
);
Apply by service URL
Apply to all layers in a given map service
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
// Apply overrides for all layers in this map service
'https://arcgis.rizing.dev/server/YourService/MapServer': {
actionsInfo: {
actions: [
{
title: 'View in SAM',
type: 'nativescript-event',
eventName: 'ShowFeature'
}
]
}
}
}
}
},
'*'
);
Apply by layer URL
Apply actions to the layer with layer ID 42
in the service YourService
.
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
// Apply overrides to layer 42 in the given map service.
'https://arcgis.rizing.dev/server/YourService/MapServer/42': {
actionsInfo: {
actions: [
{
title: 'View in SAM',
type: 'native-script-event',
eventName: 'ShowFeature'
}
]
}
}
}
}
},
'*'
);
Apply to all layers
Using a *
will match all layers.
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
'*': {
actionsInfo: {
actions: [
{
title: 'View in SAM',
type: 'native-script-event',
eventName: 'ShowFeature'
}
]
}
}
}
}
},
'*'
);
Apply to layers using filter
Including a $filter
field in the layer definition will filter the targeted layers to include only the layers that meet the specified criteria.
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
// Will match all layers where the layer has a field named 'SOME_FIELD'.
'*': {
$filter: { hasField: 'SOME_FIELD' },
actionsInfo: {
// $append will append to existing actions rather than overwrite them.
$append: true,
actions: [
{
title: 'View in SAM',
type: 'native-script-event',
eventName: 'ShowFeature'
}
]
}
},
// Will match all layers in the given map service where the layer has a field named 'FIELD2'
'https://arcgis.rizing.dev/server/YourService/MapServer': {
actionsInfo: {
$filter: { hasField: 'FIELD2' },
actions: [
{
title: 'View in SAM',
type: 'nativescript-event',
eventName: 'ShowFeature'
}
]
}
}
}
}
},
'*'
);
Apply application settings
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
settings: {
coreConfig: {
unitSystem: 'metric'
},
omniConfig: {
showWarnings: false
}
}
}
},
'*'
);
Apply display settings
See Display Settings documentation for more details.
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
displaySettings: {
toolbar: {
visible: false
},
leftMenu: {
visible: false
},
rightMenu: {
visible: false
}
}
}
},
'*'
);
Apply multiple options
Example of apply my multiple options at once (ex: layers, settings, display settings).
postMessage(
{
source: 'SAM',
eventName: 'apply-overrides',
data: {
layers: {
'my-layer': {
// Changes layer 'my-layer' title to "New Title"
title: 'New Title'
},
'*': {
// Adds action to all layers.
actionsInfo: {
actions: [
{
title: 'View in SAM',
type: 'native-script-event',
eventName: 'ShowFeature'
}
]
}
}
},
// Sets the app's unit system to "metric"
settings: {
coreConfig: {
unitSystem: 'metric'
}
},
// Hides toolbar, leftMenu, and rightMenu components.
displaySettings: {
toolbar: {
visible: false
},
leftMenu: {
visible: false
},
rightMenu: {
visible: false
}
}
}
},
'*'
);