From bb79fba0978f5a60453826893e34a1bc6a9269c1 Mon Sep 17 00:00:00 2001 From: Christoph Oberhofer Date: Sun, 4 Jun 2017 22:19:46 +0200 Subject: [PATCH] Added fake zoom to live-example --- example/live_w_locator.html | 8 ++++++++ example/live_w_locator.js | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/example/live_w_locator.html b/example/live_w_locator.html index 3844e8b..9806e56 100644 --- a/example/live_w_locator.html +++ b/example/live_w_locator.html @@ -88,6 +88,14 @@ +
diff --git a/example/live_w_locator.js b/example/live_w_locator.js index 5ae880e..b9797bb 100644 --- a/example/live_w_locator.js +++ b/example/live_w_locator.js @@ -116,7 +116,7 @@ $(function() { }, setState: function(path, value) { if (typeof this._accessByPath(this.inputMapper, path) === "function") { - value = this._accessByPath(this.inputMapper, path)(value); + value = this._accessByPath(this.inputMapper, path)(value, this.state); } this._accessByPath(this.state, path, value); @@ -134,24 +134,30 @@ $(function() { }, inputMapper: { inputStream: { - constraints: function(value){ + constraints: function(value, state){ if (/^(\d+)x(\d+)$/.test(value)) { var values = value.split('x'); return { - landscape: { + landscape: Object.assign({}, state.inputStream.constraints.landscape, { width: {ideal: parseInt(values[0])}, height: {ideal: parseInt(values[1])}, - zoom: 1.5, - }, - portrait: { + }), + portrait: Object.assign({}, state.inputStream.constraints.portrait, { width: {ideal: parseInt(values[0])}, height: {ideal: parseInt(values[0])}, - zoom: 1.5, - aspectRatio: 1, - }, + }), width: {ideal: parseInt(values[0])}, height: {ideal: parseInt(values[1])} }; + } else if (/^(\d+)\.?(\d+)?$/.test(value)) { + return Object.assign({}, state.inputStream.constraints, { + landscape: Object.assign({}, state.inputStream.constraints.landscape, { + zoom: {ideal: parseFloat(value)}, + }), + portrait: Object.assign({}, state.inputStream.constraints.portrait, { + zoom: {ideal: parseFloat(value)}, + }), + }); } return { deviceId: value @@ -190,12 +196,10 @@ $(function() { landscape: { width: {ideal: 640}, height: {ideal: 480}, - zoom: 1.5, }, portrait: { width: {ideal: 640}, height: {ideal: 640}, - zoom: 1.5, aspectRatio: 1, } }