Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Worldmap screenfixed objects #262

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Frontend:

Worldmap:
* textbox scaling according to zoom (scale_to_max_zoom option) (issue #255)
* Feature: screen-fixed objects

1.9.20
Core:
Expand Down
23 changes: 23 additions & 0 deletions docs/en_US/worldmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,28 @@ <h2>Objects on worldmap and zoom</h2>
<td>scale_to_max_zoom</td><td>No</td><td>Scale the object size down to 50% for every zoom level below <code>max_zoom</code>. Only applicable to textboxes.</td>
</tr>
</table>

<h2>Screen-fixed objects</h2>

Screen-fixed objects <b>do not move</b> when a map is dragged or zoomed. Unlike any worldmap objects, those are placed to screen by pixels rather than geographical coordinates.

<table style="width:100%">
<tr>
<th>Parameter</th><th>Default</th><th>Description</th>
</tr>
<tr>
<td>worldmap_screenfixed_objects_from_map</td><td><i>none</i></td><td>Name of other regular map to load screen-fixed objects from.</td>
</tr>
</table>

To use the feature, create two maps:
<ol>
<li>This worldmap</li>
<li>Another <b>regular</b> map</li>
</ol>
On this worldmap (1), set <code>worldmap_screenfixed_objects_from_map=name_of_another_regular_map</code>. Objects from regular map (2) are now visible on this worldmap (1) and are always fixed to the same spot on the screen.

You may also want to set <code>show_in_lists=0</code> on the referred regular map.

</body>
</html>
19 changes: 10 additions & 9 deletions share/frontend/nagvis-js/js/ElementLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,14 @@ var ElementLine = Element.extend({
// the user moves the object, this dom node must not be re-created, because this
// would remove all event handlers
if (!this.obj.trigger_obj) {
var oLink = document.createElement('a');
if (this.obj.conf.url) {
var oLink = document.createElement('a');
oLink.href = this.obj.conf.url;
oLink.target = this.obj.conf.url_target;
} else {
var oLink = document.createElement('div');
oLink.style.cursor = 'pointer';
}
oLink.setAttribute('id', this.obj.conf.object_id+'-linelink');
oLink.className = 'linelink';
this.obj.trigger_obj = oLink;
Expand All @@ -302,12 +309,6 @@ var ElementLine = Element.extend({
this.clearActionContainer();
}
this.dom_obj.appendChild(oLink);
if (this.obj.conf.url) {
oLink.href = this.obj.conf.url;
oLink.target = this.obj.conf.url_target;
} else {
oLink.href = 'javascript:void(0)';
}
},

clearActionContainer: function() {
Expand Down Expand Up @@ -619,13 +620,13 @@ var ElementLine = Element.extend({
this.link_area.style.left = (x-5) + 'px';
this.link_area.style.top = (y-5) + 'px';

if (usesSource('worldmap'))
if (usesSource('worldmap') && this.obj.marker)
this.obj.marker._bringToFront();
} else {
remove_class(this.canvas, 'active');
this.link_area.style.display = 'none';

if (usesSource('worldmap'))
if (usesSource('worldmap') && this.obj.marker)
this.obj.marker._resetZIndex();
}
},
Expand Down
22 changes: 13 additions & 9 deletions share/frontend/nagvis-js/js/ViewMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ var ViewMap = View.extend({
},

addObject: function(attrs) {
let obj = this.constructObject(attrs);
this.objects[obj.conf.object_id] = obj;
},

constructObject: function(attrs) {
var obj;
switch (attrs.type) {
case 'host':
Expand Down Expand Up @@ -204,13 +209,12 @@ var ViewMap = View.extend({
return;
break;
}

// Save the number of unlocked objects
if (!obj.bIsLocked)
this.updateNumUnlocked(1);

// Put object to map objects array
this.objects[obj.conf.object_id] = obj;

return obj;
},

erase: function() {
Expand All @@ -225,7 +229,7 @@ var ViewMap = View.extend({
// FIXME: Are all these steps needed here?
obj.update();
obj.render();

// add eventhandling when enabled via event_on_load option
if (isset(oViewProperties.event_on_load) && oViewProperties.event_on_load == 1
&& obj.has_state && obj.hasProblematicState()) {
Expand All @@ -247,21 +251,21 @@ var ViewMap = View.extend({
this.dom_obj.appendChild(obj.dom_obj);
},

// Removes the given objects dom_obj from the maps dom_obj
// Removes the given objects dom_obj from the maps dom_obj
eraseObject: function(obj) {
this.dom_obj.removeChild(obj.dom_obj);
},

// Does initial rendering of map objects
initializeObjects: function(aMapObjectConf) {
eventlog("worker", "debug", "initializeObjects: Start setting map objects");

// Don't loop the first object - that is the summary of the current map
this.sum_obj = new NagVisMap(aMapObjectConf[0]);

for (var i = 1, len = aMapObjectConf.length; i < len; i++)
this.addObject(aMapObjectConf[i]);

// First parse the objects on the map
// Then store the object position dependencies.
// Before both can be done all objects need to be added
Expand Down
41 changes: 41 additions & 0 deletions share/frontend/nagvis-js/js/ViewWorldmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*****************************************************************************/

var ViewWorldmap = ViewMap.extend({
screenFixedObjects: [],

constructor: function(id) {
this.base(id);
},
Expand Down Expand Up @@ -111,6 +113,45 @@ var ViewWorldmap = ViewMap.extend({
let ltp = document.getElementsByClassName('leaflet-tile-pane');
if (ltp && saturate_percentage !== '')
ltp[0].style.filter = "saturate("+saturate_percentage+"%)";

let loadScreenfixedObjectsFrom = getViewParam('worldmap_screenfixed_objects_from_map');
if (loadScreenfixedObjectsFrom) {
call_ajax(oGeneralProperties.path_server + '?mod=Map&act=getMapObjects&show=' + loadScreenfixedObjectsFrom, {
response_handler : this.initializescreenFixedObjects.bind(this),
});
}

},

initializescreenFixedObjects: function(aMapObjectConf) {
// Counterfeit `ViewMap` instance instead of `ViewWorldmap` so that screen-fixed object's DOM elements get rendered out of Leaflet map
let g_view_tmp = g_view
g_view = new ViewMap(g_view_tmp.id)
g_view.init();

for (var i = 1, len = aMapObjectConf.length; i < len; i++) {
this.addScreenfixedObject(aMapObjectConf[i]);
}

for (var i in this.screenFixedObjects)
this.renderScreenfixedObject(i);

// restore original `ViewWorldmap` instance
g_view = g_view_tmp
},


addScreenfixedObject: function(attrs) {
attrs.context_menu = '0'; // no right-click context menu on screenfixed objects
attrs.z = Number(attrs.z) + 1000; // always on top of leaflet panes
let obj = this.constructObject(attrs);
this.screenFixedObjects[obj.conf.object_id] = obj;
},

renderScreenfixedObject: function(object_id) {
var obj = this.screenFixedObjects[object_id];
obj.update();
obj.render();
},

handleMoveStart: function(lEvent) {
Expand Down
2 changes: 1 addition & 1 deletion share/frontend/nagvis-js/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function showFrontendDialog(sUrl, sTitle, sWidth) {
response.url = sUrl;

if(typeof response !== 'undefined' && typeof response.code !== 'undefined') {
let width = data.sWidth || 450;
let width = data.sWidth || 650;
if (response.object_type === 'textbox') width = 800
popupWindow(data.title, response, width);
}
Expand Down
23 changes: 22 additions & 1 deletion share/server/core/classes/GlobalCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,35 @@ public function getListMaps() {
} catch(NagVisException $e) {
continue; // skip e.g. not read config files
}

if($MAPCFG->getValue(0, 'show_in_lists') == 1)
$list[$mapName] = $MAPCFG->getAlias();
}
natcasesort($list);
return array_keys($list);
}

public function getListRegularMaps() {
$list = array();
$maps = $this->getPermittedMaps();
foreach ($maps AS $mapName) {
$MAPCFG = new GlobalMapCfg($mapName);
try {
$MAPCFG->readMapConfig(ONLY_GLOBAL);
} catch(MapCfgInvalid $e) {
continue; // skip configs with broken global sections
} catch(NagVisException $e) {
continue; // skip e.g. not read config files
}

// maps with no 'sources=' in 'define global {}' section are regular
if($MAPCFG->getValue(0, 'sources') == [])
$list[$mapName] = $MAPCFG->getAlias();
}
natcasesort($list);
return array_keys($list);
}

/**
* Reads all map images in map path
*
Expand Down
5 changes: 5 additions & 0 deletions share/server/core/mapcfg/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function listMapNames() {
return $list;
}

function listRegularMapNames() {
global $CORE;
return $CORE->getListRegularMaps();
}

function listMapImages() {
global $CORE;
$options = $CORE->getAvailableBackgroundImages();
Expand Down
8 changes: 8 additions & 0 deletions share/server/core/sources/worldmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class WorldmapError extends MapSourceError {}
'default' => '',
'match' => MATCH_INTEGER_EMPTY,
),
'worldmap_screenfixed_objects_from_map' => array(
'must' => 0,
'default' => '',
'match' => MATCH_MAP_NAME_EMPTY,
'field_type' => 'dropdown',
'list' => 'listRegularMapNames',
),

/*** OBJECT OPTIONS ***/
'min_zoom' => array(
Expand All @@ -59,6 +66,7 @@ class WorldmapError extends MapSourceError {}
'worldmap_center' => null,
'worldmap_zoom' => null,
'worldmap_tiles_saturate' => null,
'worldmap_screenfixed_objects_from_map' => null,
),
),
);
Expand Down