Browse Source

fixed bodies scaling

bach 1 year ago
parent
commit
4727333dd6
2 changed files with 10 additions and 3 deletions
  1. 4 0
      src/components/ConcernementMapItem.vue
  2. 6 3
      src/components/MapConcernements.vue

+ 4 - 0
src/components/ConcernementMapItem.vue

@@ -201,6 +201,10 @@ export default {
     this.scale = this.concernement.opened ? 5 : 1;
 
     if (this.scale !== this.oldScale) {
+      // https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
+      // revert to the original size (by reverting the previous scale)
+      Matter.Body.scale(this.body, 1 / this.oldScale, 1 / this.oldScale)
+      // then scale again
       Matter.Body.scale(this.body, this.scale, this.scale)
     }
 

+ 6 - 3
src/components/MapConcernements.vue

@@ -108,11 +108,14 @@ export default {
       const query = Matter.Query.point(Matter.Composite.allBodies(this.world), this.mouse.position)
       // console.log(this.mouse.position);
       // console.log(query);
+      let clickedIDs = [];
       query.forEach(elmt => {
         // console.log('body id:', elmt.id);
-        this.concernements.forEach((concernement, index) => {
-          this.openCloseConcernement(concernement.id, elmt.id === concernement.id)
-        });
+        clickedIDs.push(elmt.id);
+      });
+      let opend
+      this.concernements.forEach((concernement, index) => {
+        this.openCloseConcernement(concernement.id, clickedIDs.indexOf(concernement.id) !== -1)
       });
     }
   },