diff options
Diffstat (limited to 'public/assets/javascripts/ui/blueprint/BlueprintScaler.js')
| -rw-r--r-- | public/assets/javascripts/ui/blueprint/BlueprintScaler.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintScaler.js b/public/assets/javascripts/ui/blueprint/BlueprintScaler.js index ff26c8e..0f2fdcd 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintScaler.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintScaler.js @@ -2,7 +2,7 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ el: ".blueprintScaler", - action: "/api/media/scale", + action: "/api/blueprint/scale", events: { "change [name=blueprint-dimensions]": "changeDimensions", @@ -26,8 +26,8 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ width: window.innerWidth, height: window.innerHeight, zoom: -2, - zoom_min: -6.2, - zoom_max: 1, + zoom_min: -7.0, + zoom_max: 2, }) this.lineTool = new LineTool this.map.ui.add_tool("line", this.lineTool) @@ -42,17 +42,27 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ this.parent.uploader.show() }, - pick: function(media){ + pick: function(media, shouldEdit){ this.media = media - - if (!! media.units) { + + this.floorplan.load({ media: media, scale: 1, keepImage: true }) + + if (!! media.units && ! shouldEdit) { this.parent.useFloorplan(media) this.hide() this.stopAnimating() return } - this.floorplan.load({ media: media, keepImage: true }) + if (media.units && media.line && media.scale) { + var points = media.line.split(",") + this.lineTool.line[0] = new vec2( +points[0], +points[1] ) + this.lineTool.line[1] = new vec2( +points[2], +points[3] ) + + app.units = media.units + this.$units.val( media.units ) + this.$dimensions.unitVal( media.scale * this.lineLength() ) + } this.startAnimating() }, @@ -65,8 +75,9 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ this.floorplan.draw(this.map.draw.ctx, true) + this.map.draw.ctx.save() this.map.draw.ctx.strokeStyle = "#f00" - this.map.draw.ctx.lineWidth = 2/map.zoom + this.map.draw.ctx.lineWidth = 1/map.zoom switch (this.lineTool.line.length) { case 1: this.map.draw.line( @@ -85,6 +96,7 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ ) break } + this.map.draw.ctx.restore() this.map.draw.coords() @@ -125,15 +137,17 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ showErrors: function(){}, serialize: function(){ - var fd = new FormData() + var fd = new FormData(), line = this.lineTool.line fd.append( "_id", this.media._id) fd.append( "units", this.$units.val() ) fd.append( "scale", this.$dimensions.unitVal() / this.lineLength() ) + fd.append( "line", [line[0].a,line[0].b,line[1].a,line[1].b].join(",") ) fd.append( "_csrf", $("[name=_csrf]").val()) return fd }, success: function(){ + this.media.scale = this.$dimensions.unitVal() / this.lineLength() this.stopAnimating() this.parent.useFloorplan(this.media) this.hide() |
