summaryrefslogtreecommitdiff
path: root/public/assets/test/ortho2.html
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-04-28 17:54:30 -0400
committerJules Laplace <jules@okfoc.us>2015-04-28 19:05:13 -0400
commitaaa81d4b52659f991e38994f8fff56ba43baa419 (patch)
treee2b70802cc85ca1b11b09cba29383989c6333686 /public/assets/test/ortho2.html
parent53695472cfb20b730d04b2d6a6a16c6d281e9180 (diff)
abstract out map tools
Diffstat (limited to 'public/assets/test/ortho2.html')
-rw-r--r--public/assets/test/ortho2.html156
1 files changed, 76 insertions, 80 deletions
diff --git a/public/assets/test/ortho2.html b/public/assets/test/ortho2.html
index 2c600f5..49e0308 100644
--- a/public/assets/test/ortho2.html
+++ b/public/assets/test/ortho2.html
@@ -41,6 +41,7 @@ body {
<script src="/assets/javascripts/vendor/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/assets/javascripts/vendor/bower_components/lodash/lodash.min.js"></script>
<script src="/assets/javascripts/vendor/bower_components/hidpi-canvas/dist/hidpi-canvas.js"></script>
+<script src="/assets/javascripts/vendor/bower_components/fiber/src/fiber.min.js"></script>
<script src="/assets/javascripts/vendor/polyfill.js"></script>
<script src="/assets/javascripts/vendor/tube.js"></script>
<script src="/assets/javascripts/mx/mx.js"></script>
@@ -66,92 +67,87 @@ app.tube = new Tube ()
app.on = function(){ app.tube.on.apply(app.tube, arguments) }
app.off = function(){ app.tube.off.apply(app.tube, arguments) }
-Map.UI = Map.UI || {}
-Map.UI.Ortho = function(map){
-
- var base = this
+var MapTool = Fiber.extend(function(base){
+ var exports = {
+ down: function(e, cursor){},
+ move: function(e, cursor){},
+ drag: function(e, cursor){},
+ up: function(e, cursor, new_cursor){},
+ }
+ return exports
+})
- base.creating = base.dragging = base.resizing = false
+var PositionTool = MapTool.extend(function(base){
+ var exports = {
+ down: function(e, cursor){
+ cursor.quantize(1/map.zoom)
+ map.center.a = cursor.x.a
+ map.center.b = -cursor.y.a
+ cursor.x.b = cursor.x.a
+ cursor.y.b = cursor.y.a
+ map.ui.mouse.down = false
+ },
+ }
+ return exports
+})
- 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)
+var PolylineTool = MapTool.extend(function (base) {
+ var exports = {}
+ exports.down = function(e, cursor){
- if (e.ctrlKey || e.which === 3) {
- if (placing) {
- // close polyline or cancel
- placing = false
- add_mx_polyline(points)
- return
+ // rightclick?
+ if (e.ctrlKey || e.which === 3) {
+ e.preventDefault()
+ e.stopPropagation()
+ if (placing) {
+ // close polyline or cancel
+ placing = false
+ if (points.length > 2) {
+ add_mx_polyline(points)
+ }
+ else {
+ points.length = 0
}
- cursor.quantize(1/map.zoom)
- map.center.a = cursor.x.a
- map.center.b = -cursor.y.a
- cursor.x.b = cursor.x.a
- cursor.y.b = cursor.y.a
- base.mouse.down = false
- e.preventDefault()
- e.stopPropagation()
return
}
+ map.ui.tools.position.down(e, cursor)
+ return
+ }
- // compare to initial point
- var p = new vec2( cursor.x.a, cursor.y.a )
- if (placing) {
- if (points.length > 2 && points[0].distanceTo( p ) < 10/map.zoom) {
- points.push( points[0].clone() )
- placing = false
- add_mx_polyline(points)
- }
- else {
- points.push( p )
- mx_points.push( add_mx_point(p) )
- }
- }
- else {
- placing = true
- points = []
- points.push( p )
+ // compare to initial point
+ var p = new vec2( cursor.x.a, cursor.y.a )
+ if (placing) {
+ if (points.length > 2 && points[0].distanceTo( p ) < 10/map.zoom) {
+ points.push( points[0].clone() )
+ placing = false
+ add_mx_polyline(points)
+ }
+ else {
+ points.push( p )
mx_points.push( add_mx_point(p) )
- }
- },
- 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)
-
- last_point = new vec2( cursor.x.a, cursor.y.a )
- if (placing && points.length > 1 && points[0].distanceTo( last_point ) < 10/map.zoom) {
- document.body.style.cursor = "pointer"
- last_point.assign(points[0])
- cursor.x.a = cursor.x.b = last_point.a
- cursor.y.a = cursor.y.b = last_point.b
- }
- else {
- document.body.style.cursor = "crosshair"
- }
- },
- 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
- },
- 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.wheel = new wheel({
- el: map.el,
- update: mousewheel,
- })
-
- function mousewheel (e, deltaY, deltaX){
- map.set_zoom(map.zoom_exponent - deltaY/20)
- }
-}
-
+ }
+ }
+ else {
+ placing = true
+ points = []
+ points.push( p )
+ mx_points.push( add_mx_point(p) )
+ }
+ }
+ exports.move = function(e, cursor){
+ last_point = new vec2( cursor.x.a, cursor.y.a )
+ if (placing && points.length > 1 && points[0].distanceTo( last_point ) < 10/map.zoom) {
+ document.body.style.cursor = "pointer"
+ last_point.assign(points[0])
+ cursor.x.a = cursor.x.b = last_point.a
+ cursor.y.a = cursor.y.b = last_point.b
+ }
+ else {
+ document.body.style.cursor = "crosshair"
+ }
+ }
+ return exports
+})
var scene, map, controls
@@ -302,8 +298,8 @@ function build () {
floorplan.el.addEventListener("contextmenu", function(e){
e.preventDefault()
var offset = offsetFromPoint(e, this)
- var x = (offset.left - 0.5) * floorplan.width
- var z = (offset.top - 0.5) * floorplan.height
+ var x = (offset.left - 0.5) * floorplan.width * floorplan.scale
+ var z = (offset.top - 0.5) * floorplan.height * floorplan.scale
controls.opt.center.x = -x
controls.opt.center.y = 0
controls.opt.center.z = -z