blob: 6ced728c09d5ac47b1b2eaa82a8fb143fa7df210 (
plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Tool to make a polyline where all walls are orthogonal
var OrthoPolylineTool = MapTool.extend(function (base) {
var prev_point, horizontal = false, first_edge_is_horizontal = false
var exports = {}
exports.down = function(e, cursor){
// rightclick?
if (e.ctrlKey || e.which === 3) {
e.preventDefault()
e.stopPropagation()
if (map.ui.placing) {
// close polyline or cancel
map.ui.placing = false
if (shapes.workline.points.length > 2) {
shapes.workline.build()
shapes.add(shapes.workline)
}
else {
shapes.workline.reset()
}
return
}
else {
map.ui.tools.position.rightclick(e, cursor)
}
return
}
// compare to initial point
var p = last_point.clone()
if (map.ui.placing) {
if (shapes.workline.lastPoint().eq(p)) {
return
}
else if (shapes.workline.canCloseWith(p)) {
shapes.workline.close()
shapes.workline.build()
shapes.add(shapes.workline)
map.ui.placing = false
}
else {
shapes.workline.add(p)
prev_point = p
horizontal = ! horizontal
}
}
else {
map.ui.placing = true
shapes.workline = new Polyline ()
shapes.workline.add(p)
first_point = prev_point = p
horizontal = false
}
}
exports.move = function(e, cursor){
last_point.a = cursor.x.a
last_point.b = cursor.y.a
if (map.ui.placing) {
if (shapes.workline.points.length == 1) {
var x = abs(prev_point.a - last_point.a)
var y = abs(prev_point.b - last_point.b)
if (x > y) {
last_point.b = prev_point.b
first_edge_is_horizontal = horizontal = true
}
else {
last_point.a = prev_point.a
first_edge_is_horizontal = horizontal = false
}
}
else {
if (horizontal) {
last_point.b = prev_point.b
}
else {
last_point.a = prev_point.a
}
if (horizontal == first_edge_is_horizontal) {
// check if this point is within N pixels of the normal
// and lock it into place if so
if (horizontal && abs( first_point.a - last_point.a ) < 10/map.zoom) {
last_point.a = first_point.a
}
else if (! horizontal && abs( first_point.b - last_point.b ) < 10/map.zoom) {
last_point.b = first_point.b
}
}
}
if (shapes.workline.canCloseWith(last_point)) {
document.body.style.cursor = "pointer"
last_point.assign(first_point)
cursor.x.a = cursor.x.b = last_point.a
cursor.y.a = cursor.y.b = last_point.b
}
return
}
var end_point = shapes.findClosestEndPoint(last_point)
if (end_point) {
document.body.style.cursor = "pointer"
last_point.assign(end_point.point)
cursor.x.a = cursor.x.b = last_point.a
cursor.y.a = cursor.y.b = last_point.b
return
}
else {
document.body.style.cursor = "crosshair"
}
}
exports.cancel = function(){
if (map.ui.placing) { shapes.workline.reset() }
first_point = null
map.ui.placing = false
}
return exports
})
|