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
97
98
99
100
101
102
103
104
105
|
Map.UI = Map.UI || {}
Map.UI.Ortho = function(map){
var base = this
var last_event = null
base.creating = base.dragging = base.resizing = false
base.mouse = new mouse({
el: map.el,
down: function(e, cursor){
last_event = e
cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom)
cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom)
if (tool.recenterCursor) {
cursor.x.add(map.center.a)
cursor.y.sub(map.center.b)
base.tools[currentTool].down(e, cursor)
}
else {
base.tools[currentTool].down(e, cursor)
cursor.x.add(map.center.a)
cursor.y.sub(map.center.b)
}
},
move: function(e, cursor){
last_event = e
cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom)
cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom)
if (tool.recenterCursor) {
cursor.x.add(map.center.a)
cursor.y.sub(map.center.b)
base.tools[currentTool].move(e, cursor)
}
else {
base.tools[currentTool].move(e, cursor)
cursor.x.add(map.center.a)
cursor.y.sub(map.center.b)
}
},
drag: function(e, cursor){
last_event = e
cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom
cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom
if (tool.recenterCursor) {
cursor.x.b += map.center.a
cursor.y.b -= map.center.b
base.tools[currentTool].drag(e, cursor)
}
else {
base.tools[currentTool].drag(e, cursor)
cursor.x.b += map.center.a
cursor.y.b -= map.center.b
}
},
up: function(e, cursor, new_cursor){
last_event = e
new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom)
new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom)
if (tool.recenterCursor) {
new_cursor.x.add(map.center.a)
new_cursor.y.sub(map.center.b)
base.tools[currentTool].up(e, cursor, new_cursor)
}
else {
base.tools[currentTool].up(e, cursor, new_cursor)
new_cursor.x.add(map.center.a)
new_cursor.y.sub(map.center.b)
}
if (nextTool) {
console.log('found nextTool')
base.set_tool(nextTool)
nextTool = null
}
}
})
var currentTool = "polyline", nextTool, tool
base.add_tool = function(name, tool){
base.tools[name] = tool
}
base.set_tool = function(s){
console.log("set tool to", s)
base.tools[currentTool].cancel()
currentTool = s
tool = base.tools[currentTool]
}
base.set_drag_tool = function(s){
console.log('set drag tool to', s)
nextTool = currentTool
currentTool = s
tool = base.tools[currentTool]
base.tools[currentTool].down(last_event, base.mouse.cursor)
}
base.tools = {}
base.wheel = new wheel({
el: map.el,
update: mousewheel,
})
function mousewheel (e, deltaY, deltaX){
map.set_zoom(map.zoom_exponent - deltaY/20)
}
}
|