Translate the resources into markers
Convert the resources into markers so they render on the map in the required format.
Vorbereitungen
Role required: admin
Warum und wann dieser Vorgang ausgeführt wird
In this procedure we're updating the DispatcherWorkspaceMapUtil (Server-Side) in the file sys_script_include_86f348840fdf10105cbf3694ba767ef2.xml.
Prozedur
Add the following code to a script includes.
#### New Methods:
- **`getResourceMarkers(resourceData, resourceIds, markersMap, keyMap, max)`**
- Purpose: Adds FSM resources to the map
- Pattern: Follows same pattern as `getAgentMarkers()` in base class
- Dependencies: Uses inherited `_getMarker()` and `_addMarker()` from parent
- Returns: `{count, markers, showWarning}`
```javascript
getResourceMarkers: function(resourceData, resourceIds, markersMap, keyMap, max) {
var markers = [];
var count = 0;
var resourceFields = this._getResourceFields();
for (var i=0; i < resourceIds.length; i++) {
if (count >= max) return {count: count, markers: markers, showWarning: true};
if(gs.nil(resourceData[resourceIds[i]]) || gs.nil(resourceData[resourceIds[i]]["loc"]))
continue;
var lat = resourceData[resourceIds[i]]["loc"]["lat"];
var lng = resourceData[resourceIds[i]]["loc"]["lng"];
var address = resourceData[resourceIds[i]]["address"];
if (resourceData[resourceIds[i]] && !gs.nil(lat) && !gs.nil(lng)) {
var key = lat + lng;
var marker = this._getMarker({
sysId: resourceIds[i],
table: 'sn_fsm_resource',
displayValue: resourceData[resourceIds[i]]["displayValue"],
type: 'FSM Resource',
fields: resourceFields,
lat: lat,
lng: lng,
address: address
});
markers = this._addMarker(key, marker, markersMap, markers);
keyMap[key] = 'set';
}
count++;
}
return {count: count, markers: markers};
}
```
- **`_getResourceFields()`**
- Purpose: Returns GraphQL field definitions for resource queries
- Returns: String with GraphQL field schema for resource data
```javascript
_getResourceFields: function() {
return 'name { label value displayValue } \
resource_type { label value displayValue } \
status { label value displayValue } \
location { label value displayValue } \
mobile_phone { label value displayValue }';
}
```
#### Overridden Methods:
- **`getMarkerIcon(markers)`**
- **How to override**: Copy the ENTIRE method from parent `DispatcherWorkspaceMapUtilSNC`, then modify specific sections
- **Modification**: Changed resource marker images to use proper resource icons (`resource-default.svg`, `resource-hover.svg`, `resource-selected.svg` for single resources; `resources-default.svg`, `resources-hover.svg`, `resources-selected.svg` for multiple colocated resources)
**Change 1: In the items.forEach() loop, add resource handling after the wm_crew case**
```javascript
// ... after handling wm_crew
} else if (item.table == 'wm_crew') {
has_crew = true;
agent_count++;
marker.image = 'sn_fsm_disp_wrkspc.agent-default.svg';
marker.hoverIcon = 'sn_fsm_disp_wrkspc.agent-hover.svg';
marker.highlightedIcon = 'sn_fsm_disp_wrkspc.agent-selected.svg';
} else if (item.table == 'sn_fsm_resource') {
// CUSTOMIZATION: Use proper resource icons based on resource count
has_resource = true;
resource_count++;
marker.image = 'sn_fsm_disp_wrkspc.resource-default.svg';
marker.hoverIcon = 'sn_fsm_disp_wrkspc.resource-hover.svg';
marker.highlightedIcon = 'sn_fsm_disp_wrkspc.resource-selected.svg';
}
```
**Change 2: In the icon assignment section, add resourceOnly handling after the agents condition**
```javascript
// ... after handling multiple agents
} else if ((!hasMultipleTables && (agent_count > 1 || has_crew)) || (has_agent && has_crew && !has_task)) {
marker.image = 'sn_fsm_disp_wrkspc.agents-default.svg';
marker.hoverIcon = 'sn_fsm_disp_wrkspc.agents-hover.svg';
marker.highlightedIcon = 'sn_fsm_disp_wrkspc.agents-selected.svg';
} else if (resourceOnly) {
// CUSTOMIZATION: Use proper resource icons
if (resource_count == 1) {
marker.image = 'sn_fsm_disp_wrkspc.resource-default.svg';
marker.hoverIcon = 'sn_fsm_disp_wrkspc.resource-hover.svg';
marker.highlightedIcon = 'sn_fsm_disp_wrkspc.resource-selected.svg';
} else {
marker.image = 'sn_fsm_disp_wrkspc.resources-default.svg';
marker.hoverIcon = 'sn_fsm_disp_wrkspc.resources-hover.svg';
marker.highlightedIcon = 'sn_fsm_disp_wrkspc.resources-selected.svg';
}
marker.infoWindowContent = marker.items[0].displayValue;
if (marker.items[0].company)
marker.infoWindowContent += "<BR/>" + marker.items[0].company;
if (marker.address)
marker.infoWindowContent += "<BR/>" + marker.address;
}
```