Problems panning large svg in PaperJS











up vote
1
down vote

favorite















var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>





I can't actually get my example to work anywhere except for on localhost but I have a large SVG inside of my paperJS canvas which extends out past the canvas bounds.



When I try to pan it by pressing shift and dragging the mouse the svg moves but ultimately snaps to a specific position and responds but always pings back to this place after that










share|improve this question
























  • Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
    – Ismael Miguel
    Nov 9 at 12:10










  • I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
    – Keith
    Nov 9 at 12:10










  • Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
    – Nino Filiu
    Nov 9 at 12:11










  • @NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
    – Keith
    Nov 9 at 12:12










  • @Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
    – Nino Filiu
    Nov 9 at 12:15















up vote
1
down vote

favorite















var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>





I can't actually get my example to work anywhere except for on localhost but I have a large SVG inside of my paperJS canvas which extends out past the canvas bounds.



When I try to pan it by pressing shift and dragging the mouse the svg moves but ultimately snaps to a specific position and responds but always pings back to this place after that










share|improve this question
























  • Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
    – Ismael Miguel
    Nov 9 at 12:10










  • I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
    – Keith
    Nov 9 at 12:10










  • Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
    – Nino Filiu
    Nov 9 at 12:11










  • @NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
    – Keith
    Nov 9 at 12:12










  • @Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
    – Nino Filiu
    Nov 9 at 12:15













up vote
1
down vote

favorite









up vote
1
down vote

favorite














var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>





I can't actually get my example to work anywhere except for on localhost but I have a large SVG inside of my paperJS canvas which extends out past the canvas bounds.



When I try to pan it by pressing shift and dragging the mouse the svg moves but ultimately snaps to a specific position and responds but always pings back to this place after that










share|improve this question


















var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>





I can't actually get my example to work anywhere except for on localhost but I have a large SVG inside of my paperJS canvas which extends out past the canvas bounds.



When I try to pan it by pressing shift and dragging the mouse the svg moves but ultimately snaps to a specific position and responds but always pings back to this place after that






var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>





var path = new Path.Circle({
center: view.center,
radius: 10,
strokeColor: 'red',
strokeWidth: 3,
applyMatrix: false,
strokeScaling: false
});

var svgItem;

project.importSVG("https://svgshare.com/getbyhash/sha1-yxefOEotn9oAUgg+1qfc5gNw4Bs=", {
onLoad : function (item) {
item.center = view.center;
svgItem = item;
}
});

console.log(svgItem);

tool.onMouseMove = function(event) {
//on mouse move the position of 'path' var changes to underneath cursor again
path.position = event.point;
//console.log(event.point); //debug
}

var toolSize = document.getElementById("tool");

console.log(toolSize);
toolSize.addEventListener("change", function(event) {
console.log("Radius slider change detected! " + event.target.value + ". path.radius is: " + path.bounds.width);
//path.radius = event.target.value;
path.scaling = this.value;
});

tool.onMouseDrag = function(event) {
//test to see of the shift key was held whilst a mouse drag action was peformed
if (event.modifiers.shift)
{
//move the image the distance of the mouse drag
svgItem.position = view.center + event.delta;
}
}

body,
html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
min-height: 100%;
}

main {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

canvas {
width: 90vw;
height: 90vh;
border: 1px solid;
}

#opts {
position: absolute;
right: 10vw;
bottom: 10vh;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.8/paper-full.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link href="svg_style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="opts">
<input id="tool" type="range" name="tool" min="1" max="10" value="1" step="1" id="toolSize" />
<input id="smooth" type="range" name="flatten" min="1" max="10" value="1" step="1" id="smooth" />
<input id="flatten" type="range" name="flatten" min="1" max="10" value="1" step="1" id="flatten" />
</div>
<main>
<canvas id="canvas" resize></canvas>
</main>
<script type="text/paperscript" src="paper_script.js" canvas="canvas">
</script>
</body>

</html>






javascript html css svg paperjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 18:41

























asked Nov 9 at 12:06









Scott Anderson

879




879












  • Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
    – Ismael Miguel
    Nov 9 at 12:10










  • I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
    – Keith
    Nov 9 at 12:10










  • Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
    – Nino Filiu
    Nov 9 at 12:11










  • @NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
    – Keith
    Nov 9 at 12:12










  • @Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
    – Nino Filiu
    Nov 9 at 12:15


















  • Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
    – Ismael Miguel
    Nov 9 at 12:10










  • I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
    – Keith
    Nov 9 at 12:10










  • Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
    – Nino Filiu
    Nov 9 at 12:11










  • @NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
    – Keith
    Nov 9 at 12:12










  • @Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
    – Nino Filiu
    Nov 9 at 12:15
















Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
– Ismael Miguel
Nov 9 at 12:10




Please, replace http://localhost:8080/PCB-trace.svg with a path to the file you intend to use. You can try using a service like svgur.com to host the file.
– Ismael Miguel
Nov 9 at 12:10












I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
– Keith
Nov 9 at 12:10




I can't actually get my example to work Looks like SO snippets are down atm. For me I'm getting a 503 (service unavailable).
– Keith
Nov 9 at 12:10












Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
– Nino Filiu
Nov 9 at 12:11




Snippet can't work, since you make a call to http://localhost:8080/. Please refactor your code so as to make it reproducible.
– Nino Filiu
Nov 9 at 12:11












@NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
– Keith
Nov 9 at 12:12




@NinoFiliu Snippets are down full stop, the http://localhost:8080/ is of course a problem when snippets are up an running.
– Keith
Nov 9 at 12:12












@Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
– Nino Filiu
Nov 9 at 12:15




@Keith indeed, thanks for the info. Your comment was not yet available when i made mine.
– Nino Filiu
Nov 9 at 12:15












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Your error is in this line:



svgItem.position = view.center + event.delta;


Inside of a mousedrag event handler function, event.delta is actually representing the vector between the last point and the current point. You were wrongly calculating the desired position by simply adding this vector to view center point.



What you want to do instead, is add this vector to item current position.



svgItem.position += event.delta;


Here is a sketch demonstrating the solution.



// draw a circle
var item = new Path.Circle({
center: view.center,
radius: 50,
fillColor: 'orange'
});

// on mouse drag...
function onMouseDrag(event) {
// ...if shift is pressed...
if (event.modifiers.shift) {
// ...move item
item.position += event.delta;
}
}

// display instructions
new PointText({
content: 'press shift and drag to move the circle',
point: view.center + [0, -50],
justification: 'center'
});





share|improve this answer





















  • I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
    – Scott Anderson
    Nov 9 at 20:07











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225436%2fproblems-panning-large-svg-in-paperjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Your error is in this line:



svgItem.position = view.center + event.delta;


Inside of a mousedrag event handler function, event.delta is actually representing the vector between the last point and the current point. You were wrongly calculating the desired position by simply adding this vector to view center point.



What you want to do instead, is add this vector to item current position.



svgItem.position += event.delta;


Here is a sketch demonstrating the solution.



// draw a circle
var item = new Path.Circle({
center: view.center,
radius: 50,
fillColor: 'orange'
});

// on mouse drag...
function onMouseDrag(event) {
// ...if shift is pressed...
if (event.modifiers.shift) {
// ...move item
item.position += event.delta;
}
}

// display instructions
new PointText({
content: 'press shift and drag to move the circle',
point: view.center + [0, -50],
justification: 'center'
});





share|improve this answer





















  • I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
    – Scott Anderson
    Nov 9 at 20:07















up vote
2
down vote



accepted










Your error is in this line:



svgItem.position = view.center + event.delta;


Inside of a mousedrag event handler function, event.delta is actually representing the vector between the last point and the current point. You were wrongly calculating the desired position by simply adding this vector to view center point.



What you want to do instead, is add this vector to item current position.



svgItem.position += event.delta;


Here is a sketch demonstrating the solution.



// draw a circle
var item = new Path.Circle({
center: view.center,
radius: 50,
fillColor: 'orange'
});

// on mouse drag...
function onMouseDrag(event) {
// ...if shift is pressed...
if (event.modifiers.shift) {
// ...move item
item.position += event.delta;
}
}

// display instructions
new PointText({
content: 'press shift and drag to move the circle',
point: view.center + [0, -50],
justification: 'center'
});





share|improve this answer





















  • I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
    – Scott Anderson
    Nov 9 at 20:07













up vote
2
down vote



accepted







up vote
2
down vote



accepted






Your error is in this line:



svgItem.position = view.center + event.delta;


Inside of a mousedrag event handler function, event.delta is actually representing the vector between the last point and the current point. You were wrongly calculating the desired position by simply adding this vector to view center point.



What you want to do instead, is add this vector to item current position.



svgItem.position += event.delta;


Here is a sketch demonstrating the solution.



// draw a circle
var item = new Path.Circle({
center: view.center,
radius: 50,
fillColor: 'orange'
});

// on mouse drag...
function onMouseDrag(event) {
// ...if shift is pressed...
if (event.modifiers.shift) {
// ...move item
item.position += event.delta;
}
}

// display instructions
new PointText({
content: 'press shift and drag to move the circle',
point: view.center + [0, -50],
justification: 'center'
});





share|improve this answer












Your error is in this line:



svgItem.position = view.center + event.delta;


Inside of a mousedrag event handler function, event.delta is actually representing the vector between the last point and the current point. You were wrongly calculating the desired position by simply adding this vector to view center point.



What you want to do instead, is add this vector to item current position.



svgItem.position += event.delta;


Here is a sketch demonstrating the solution.



// draw a circle
var item = new Path.Circle({
center: view.center,
radius: 50,
fillColor: 'orange'
});

// on mouse drag...
function onMouseDrag(event) {
// ...if shift is pressed...
if (event.modifiers.shift) {
// ...move item
item.position += event.delta;
}
}

// display instructions
new PointText({
content: 'press shift and drag to move the circle',
point: view.center + [0, -50],
justification: 'center'
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 12:46









sasensi

685114




685114












  • I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
    – Scott Anderson
    Nov 9 at 20:07


















  • I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
    – Scott Anderson
    Nov 9 at 20:07
















I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
– Scott Anderson
Nov 9 at 20:07




I am not sure exactly why it was giving me the behaviour it did but thankyou nonetheless!
– Scott Anderson
Nov 9 at 20:07


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225436%2fproblems-panning-large-svg-in-paperjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?