0

I have two canvas the first one is working good, but when I initialize the second one the paper.Tool does not work properly, sometimes the event onMouseMove works others not.

var dataLoad;
var mypapers = []
$(document).ready(function () {
    dataLoad = new DataLoad();
    mypapers[0] = new paper.PaperScope();
    mypapers[1] = new paper.PaperScope();
    mypapers[0].setup(document.getElementById('dataCanvas'));
    dataLoad.Init();
});


  // "returnedData" THIS ARRAY COMES FROM AN AJAX CALL
  DataLoad.prototype = {
      Init: function () {
         var self = this;
         var paperData = new 
         DataReader(document.getElementById('dataCanvas'));
         paperData.Init(returnedData[i],mypapers[0]);
         paperData.Draw(true);
         self.datas.push(paperData);
      }
   });

Till here everything is good the first canvas is populated with the graphics I setted.

DataReader.prototype = {
  Init: function (data,mypaper) {
    var self = this;
    paper = mypaper;
    self.paper = paper;
    self.toolPan = new self.paper.Tool()
    self.toolPan.activate();
    self.toolPan.onMouseDrag = function (event) {
       var delta = event.downPoint.subtract(event.point)
       self.paper.view.scrollBy(delta)
    };

    self.toolPan.onMouseMove = function (event) {
        self.OnMouseMove(event);
    };
     self.toolPan.onMouseUp = function (event) {
        // AFTER MAKE A SELECTION OF ITEMS IN THE CANVAS CALLING THE SECOND CANVAS
        var core = self.HighlightElementsInBox();
        self.dc = new DefineComponent();
        self.dc.Init(core);
        $('#DCCanvas').modal('toggle'); // THE CANVAS IS INSIDE THIS  BOOTSTRAP MODAL
    }
  }

});

/* this initialize the second canvas that basically creates another instance of the same prototype i use to manipulate paperjs in the first canvas */

DefineComponent.prototype = {
  Init: function (dataCore) {
    var self = this;
    mypapers[1].setup(document.getElementById('DCCanvas')); // setting second canvas
    var paperDataDC = new DataReader(document.getElementById('DCCanvas'));
    paperDataDC.Init(dataCore,mypapers[1]);
    paperDataDC.Draw(true);
    self.datas.push(paperDatasDC);
  }

});

In this second canvas all is drawn correctly, but the events onmousedrag and onmousemove does not works properly the first one move the canvas in another position where the mouse is not and mousemove works only in some places of the canvas not in all.

Phix
  • 9,364
  • 4
  • 35
  • 62
user3442776
  • 162
  • 2
  • 4
  • 13
  • No experts in paperjs?????? – user3442776 Feb 01 '18 at 16:53
  • i think its good if you try and create a minimal example - showing your question - here at stackoverflow as 'code snippet' or externally as [jsfiddle (link to a simple paper.js example)](https://jsfiddle.net/s_light/5ubkj3yd/) or something similar - so that others can easily build up or debug your code.. – Stefan Krüger s-light Mar 02 '18 at 17:01

1 Answers1

0

As you are creating two different paperScopes you will need to toggle between them when working with one or the other.

You are saving both paperScopes inside "mypapers" array

mypapers[0] = new paper.PaperScope();
mypapers[1] = new paper.PaperScope();

So to use any of those you should do

mypapers[0].activate();
// or
mypapers[1].activate();

Check out this (min setup) example of what I mean above.

Also, follow stefan's suggestion if you want more help on this since it's hard for people to try to help without a minimal working example

Oxcarga
  • 260
  • 3
  • 9