|
|
@ -2,12 +2,19 @@ var util = require('../../util'); |
|
|
|
var Hammer = require('../../module/hammer'); |
|
|
|
|
|
|
|
exports._cleanNavigation = function() { |
|
|
|
// clean hammer bindings
|
|
|
|
if (this.navigationHammers.existing.length != 0) { |
|
|
|
for (var i = 0; i < this.navigationHammers.existing.length; i++) { |
|
|
|
this.navigationHammers.existing[i].dispose(); |
|
|
|
} |
|
|
|
this.navigationHammers.existing = []; |
|
|
|
} |
|
|
|
|
|
|
|
// clean up previous navigation items
|
|
|
|
var wrapper = document.getElementById('network-navigation_wrapper'); |
|
|
|
if (wrapper && wrapper.parentNode) { |
|
|
|
wrapper.parentNode.removeChild(wrapper); |
|
|
|
} |
|
|
|
document.onmouseup = null; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -23,23 +30,43 @@ exports._loadNavigationElements = function() { |
|
|
|
|
|
|
|
this.navigationDivs = {}; |
|
|
|
var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends']; |
|
|
|
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','zoomExtent']; |
|
|
|
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','_zoomExtent']; |
|
|
|
|
|
|
|
this.navigationDivs['wrapper'] = document.createElement('div'); |
|
|
|
this.navigationDivs['wrapper'].id = 'network-navigation_wrapper'; |
|
|
|
this.frame.appendChild(this.navigationDivs['wrapper']); |
|
|
|
|
|
|
|
var me = this; |
|
|
|
for (var i = 0; i < navigationDivs.length; i++) { |
|
|
|
this.navigationDivs[navigationDivs[i]] = document.createElement('div'); |
|
|
|
this.navigationDivs[navigationDivs[i]].id = 'network-navigation_' + navigationDivs[i]; |
|
|
|
this.navigationDivs[navigationDivs[i]].className = 'network-navigation ' + navigationDivs[i]; |
|
|
|
this.navigationDivs['wrapper'].appendChild(this.navigationDivs[navigationDivs[i]]); |
|
|
|
|
|
|
|
var hammer = Hammer(this.navigationDivs[navigationDivs[i]], {prevent_default: true}); |
|
|
|
hammer.on('touch', me[navigationDivActions[i]].bind(me)); |
|
|
|
hammer.on('touch', this[navigationDivActions[i]].bind(this)); |
|
|
|
this.navigationHammers.new.push(hammer); |
|
|
|
} |
|
|
|
|
|
|
|
var hammerDoc = Hammer(document, {prevent_default: false}); |
|
|
|
hammerDoc.on('release', this._stopMovement.bind(this)); |
|
|
|
this.navigationHammers.new.push(hammerDoc); |
|
|
|
|
|
|
|
this.navigationHammers.existing = this.navigationHammers.new; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* this stops all movement induced by the navigation buttons |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
exports._zoomExtent = function(event) { |
|
|
|
// FIXME: this is a workaround because the binding of Hammer on Document makes this fire twice
|
|
|
|
if (this._zoomExtentLastTime === undefined || new Date() - this._zoomExtentLastTime > 50) { |
|
|
|
this._zoomExtentLastTime = new Date(); |
|
|
|
this.zoomExtent({duration:800}); |
|
|
|
event.stopPropagation(); |
|
|
|
} |
|
|
|
var hammer = Hammer(document, {prevent_default: false}); |
|
|
|
hammer.on('release', me._stopMovement.bind(me)); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|