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