forked from jstnhuang/ros-rviz
-
Notifications
You must be signed in to change notification settings - Fork 15
/
ros-rviz-occupancy-grid.html
96 lines (88 loc) · 2.53 KB
/
ros-rviz-occupancy-grid.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="imports.html">
<dom-module id="ros-rviz-occupancy-grid">
<template>
<paper-input label="Map topic" value="{{topic}}"></paper-input>
<paper-checkbox checked="{{continuous}}">Continuously update</paper-checkbox>
<paper-input label="Opacity" value="{{opacity}}"></paper-input>
</template>
<script>
Polymer({
is: 'ros-rviz-occupancy-grid',
properties: {
name: {
type: String,
value: 'Map',
},
topic: {
type: String,
value: '/map',
notify: true
},
continuous: {
type: Boolean,
value: true,
notify: true,
},
opacity: {
type: Number,
value: 1.0,
notify: true,
},
globalOptions: Object,
isShown: Boolean,
ros: Object,
tfClient: Object,
viewer: Object,
},
observers: [
'_optionsChanged(viewer, topic, continuous, opacity, ros)',
],
destroy: function() {
// Nothing to destroy.
},
hide: function() {
if (this.viewer && this._gridClient) {
this.viewer.scene.remove(this._gridClient.currentGrid);
}
if (this._gridClient) {
this._gridClient.unsubscribe();
this._gridClient = null;
}
},
show: function() {
if (this.viewer && this.isShown) {
if (!this._gridClient) {
this._updateDisplay();
}
}
},
_optionsChanged: function(viewer, topic, continuous, opacity, ros) {
this.hide();
this._updateDisplay();
this.show();
},
_updateDisplay: function(callback) {
if (!(this.ros && this.viewer && this.topic &&
(this.continuous || this.continuous === false) &&
(this.opacity || this.opacity === 0.0))) {
return;
}
if (this._gridClient) {
this._gridClient.unsubscribe();
}
this._gridClient = new ROS3D.OccupancyGridClient({
ros: this.ros,
topic: this.topic,
continuous: this.continuous,
rootObject: this.viewer.scene,
offsetPose: null, // Maybe implement in the future
color: {r: 255, g: 255, b: 255},
opacity: this.opacity
});
},
});
</script>
</dom-module>