@@ -225,10 +225,37 @@ export class NgMagnizoomComponent implements OnInit, OnChanges {
225
225
226
226
calculateMousePosition ( clientX : number , clientY : number ) {
227
227
const boundingRect = this . canvas . getBoundingClientRect ( ) ;
228
- const viewToModelX = this . canvasWidth / boundingRect . width ;
229
- const viewToModelY = this . canvasHeight / boundingRect . height ;
230
- const x = ( clientX - boundingRect . left ) * viewToModelX ;
231
- const y = ( clientY - boundingRect . top ) * viewToModelY ;
228
+
229
+ const boundingRectX = ( clientX - boundingRect . left ) ;
230
+ const boundingRectY = ( clientY - boundingRect . top ) ;
231
+
232
+ let elementX = boundingRectX , elementY = boundingRectY ;
233
+ let elementWidth = boundingRect . width , elementHeight = boundingRect . height ;
234
+
235
+ const computedStyle = window . getComputedStyle ( this . canvas , null ) ;
236
+ const domMatrix = new DOMMatrix ( computedStyle . transform ) ;
237
+ if ( ! domMatrix . isIdentity ) {
238
+ const { a, b } = domMatrix ;
239
+ const transformRot = Math . atan2 ( b , a ) ;
240
+ const transformScale = Math . round ( Math . sqrt ( a * a + b * b ) * 100 ) / 100 ;
241
+ if ( transformRot ) {
242
+ const boundingRectCenterX = boundingRect . width / 2 ;
243
+ const boundingRectCenterY = boundingRect . height / 2 ;
244
+ const dx = ( boundingRectX - boundingRectCenterX ) ;
245
+ const dy = ( boundingRectY - boundingRectCenterY ) ;
246
+ const d = Math . sqrt ( dx * dx + dy * dy ) ;
247
+ const r = Math . atan2 ( dy , dx ) ;
248
+ elementWidth = this . canvas . clientWidth * transformScale ;
249
+ elementHeight = this . canvas . clientHeight * transformScale ;
250
+ elementX = ( elementWidth / 2 ) + ( d * Math . cos ( r - transformRot ) ) ;
251
+ elementY = ( elementHeight / 2 ) + ( d * Math . sin ( r - transformRot ) ) ;
252
+ }
253
+ }
254
+
255
+ const viewToModelX = this . canvasWidth / elementWidth ;
256
+ const viewToModelY = this . canvasHeight / elementHeight ;
257
+ const x = elementX * viewToModelX ;
258
+ const y = elementY * viewToModelY ;
232
259
this . _centerPosition = { x, y } ;
233
260
}
234
261
0 commit comments