diff --git a/frontend/src/Metamaps/AutoLayout.js b/frontend/src/Metamaps/AutoLayout.js index ee9dc33c..e0835473 100644 --- a/frontend/src/Metamaps/AutoLayout.js +++ b/frontend/src/Metamaps/AutoLayout.js @@ -1,3 +1,5 @@ +import Active from './Active' + const AutoLayout = { nextX: 0, nextY: 0, @@ -7,7 +9,7 @@ const AutoLayout = { nextYshift: 0, timeToTurn: 0, - getNextCoord: function () { + getNextCoord: function (opts = {}) { var self = AutoLayout var nextX = self.nextX var nextY = self.nextY @@ -49,9 +51,22 @@ const AutoLayout = { } } - return { - x: nextX, - y: nextY + if (opts.map && self.coordsTaken(nextX, nextY, opts.map)) { + // check if the coordinate is already taken on the current map + return self.getNextCoord(opts) + } else { + return { + x: nextX, + y: nextY + } + } + }, + coordsTaken: function(x, y, map) { + const mappings = map.getMappings() + if (mappings.findWhere({ xloc: x, yloc: y })) { + return true + } else { + return false } }, resetSpiral: function () { diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 2de7ca02..5d5f91a7 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -227,7 +227,7 @@ const Import = { parsedTopics.forEach(function (topic) { let coords = { x: topic.x, y: topic.y } if (!coords.x || !coords.y) { - coords = AutoLayout.getNextCoord() + coords = AutoLayout.getNextCoord({ map: Active.Map }) } if (!topic.name && topic.link || @@ -349,7 +349,7 @@ const Import = { handleURL: function (url, opts = {}) { let coords = opts.coords if (!coords || coords.x === undefined || coords.y === undefined) { - coords = AutoLayout.getNextCoord() + coords = AutoLayout.getNextCoord({ map: Active.Map }) } const name = opts.name || 'Link'