Map.UI = Map.UI || {} Map.UI.Ortho = function(map){ var base = this base.creating = base.dragging = base.resizing = false base.mouse = new mouse({ el: map.el, down: function(e, cursor){ cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) base.tools[currentTool].down(e, cursor) }, move: function(e, cursor){ cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) base.tools[currentTool].move(e, cursor) }, drag: function(e, cursor){ cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + map.center.a cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom - map.center.b base.tools[currentTool].drag(e, cursor) }, up: function(e, cursor, new_cursor){ new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) base.tools[currentTool].up(e, cursor, new_cursor) } }) var currentTool = "polyline" base.add_tool = function(name, tool){ base.tools[name] = tool } base.set_tool = function(s){ currentTool = s } base.tools = {} base.wheel = new wheel({ el: map.el, update: mousewheel, }) function mousewheel (e, deltaY, deltaX){ map.set_zoom(map.zoom_exponent - deltaY/20) } }