Skip to content

Commit cc96192

Browse files
committed
Merge pull request #388 from OpenGeoscience/visibility-off
Toggling visibility binds/unbinds mouse handlers
2 parents 455829a + a19fc56 commit cc96192

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

src/core/feature.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ geo.feature = function (arg) {
378378
} else {
379379
m_visible = val;
380380
m_this.modified();
381+
382+
// bind or unbind mouse handlers on visibility change
383+
if (m_visible) {
384+
m_this._bindMouseHandlers();
385+
} else {
386+
m_this._unbindMouseHandlers();
387+
}
388+
381389
return m_this;
382390
}
383391
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
overflow: hidden;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id='map'></div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
window.startTest = function (done) {
3+
'use strict';
4+
5+
window.geo_mouse_moves = 0;
6+
$('#map').attr('geo-moves', window.geo_mouse_moves);
7+
var map = window.geoTests.createOsmMap({}, {}, true);
8+
var feature = map.createLayer('feature').createFeature('point', {selectionAPI: true});
9+
10+
feature.data([0])
11+
.position(function () { return {x: 0, y: 0}; })
12+
.style({radius: 1000})
13+
.geoOn(geo.event.feature.mousemove, function () {
14+
// keep track of the number of mouse moves triggered
15+
window.geo_mouse_moves += 1;
16+
$('#map').attr('geo-moves', window.geo_mouse_moves);
17+
});
18+
window.geo_feature = feature;
19+
map.draw();
20+
done();
21+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
3+
from selenium_test import FirefoxTest, ChromeTest,\
4+
setUpModule, tearDownModule
5+
6+
7+
class Visibility(object):
8+
testCase = ('osmLayer',)
9+
testRevision = 1
10+
11+
def getCount(self):
12+
return self.runScript('return window.geo_mouse_moves')
13+
14+
def loadPage(self):
15+
self.resizeWindow(640, 480)
16+
self.loadURL('featureVisible/index.html')
17+
self.wait()
18+
19+
def test_visibility_toggle(self):
20+
self.loadPage()
21+
22+
self.hover('#map', offset=(25, 25))
23+
initial = self.getCount()
24+
25+
self.hover('#map', offset=(50, 50))
26+
count = self.getCount()
27+
28+
self.assertTrue(count > initial, 'Initial mouse movements')
29+
30+
self.runScript('window.geo_feature.visible(false)')
31+
initial = self.getCount()
32+
self.hover('#map', offset=(75, 75))
33+
count = self.getCount()
34+
35+
self.assertTrue(count == initial, 'Visibility off')
36+
37+
self.runScript('window.geo_feature.visible(true)')
38+
initial = self.getCount()
39+
self.hover('#map', offset=(100, 100))
40+
count = self.getCount()
41+
42+
self.assertTrue(count > initial, 'Visibility on')
43+
44+
45+
class FirefoxVis(Visibility, FirefoxTest):
46+
testCase = Visibility.testCase + ('firefox',)
47+
48+
49+
class ChromeVis(Visibility, ChromeTest):
50+
testCase = Visibility.testCase + ('chrome',)
51+
52+
53+
if __name__ == '__main__':
54+
import unittest
55+
unittest.main()

0 commit comments

Comments
 (0)