blob: 559aea8790477dd35be49513f62f67448425af51 (
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
|
var PolylineTool = MapTool.extend(function (base) {
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 (line.points.length > 2) {
line.build()
}
else {
line.reset()
}
return
}
map.ui.tools.position.rightclick(e, cursor)
return
}
// compare to initial point
var p = last_point.clone()
if (map.ui.placing) {
if (line.canCloseWith(p)) {
line.close()
line.build()
map.ui.placing = false
}
else {
line.add(p)
}
}
else {
map.ui.placing = true
line = new Polyline ()
line.add(p)
}
}
exports.move = function(e, cursor){
last_point.a = cursor.x.a
last_point.b = cursor.y.a
if (map.ui.placing && line.canCloseWith(last_point)) {
document.body.style.cursor = "pointer"
last_point.assign(line.points[0])
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) { line.reset() }
map.ui.placing = false
}
return exports
})
|