2017-08-26 193 views
0

我有一個地圖,在createjs中設置了一個響應式畫布。我想要做的是使地圖可縮放但也可拖動。拖動地圖時,我想讓它從特定中心點放大。createjs中心縮放點localtoglobal

我認爲我需要做的是計算中心點相對於地圖的位置,然後設置地圖regX/regY到那一點(然後我想我需要重置爲x/y的地圖以彌補regX/Y偏移量

由於舞臺已縮放,因此即使計算出中心位置也很難,因爲全局座標似乎與縮放比例有關。在支架點:

exportRoot.pointHolder.tmpPt

和地圖包含於:

exportRoot.map_main_sym

什麼,我需要搞清楚的是什麼是map_main_sym本地X/Y值relativie(即直屬(exportRoot.pointHolder.tmpPt.x,exportRoot.pointHolder.tmpPt.y)

回答

0

我不建議在縮放時更改註冊點。更好的方法是確定與鼠標的距離,並確定在縮放容器/對象時翻譯多少。

這裏是從地圖工具我有方便的一個片段:

// Find the mouse point INSIDE the mapView 
var point = new createjs.Point(this.stage.mouseX, this.stage.mouseY); 
var localPoint = this.mapView.globalToLocal(point.x, point.y); 

// Scale the Map View 
if(event.wheelDeltaY > 0){ // This is part of a mousewheel event 
    // zoom in 
    this.mapView.scaleX = this.mapView.scaleY *= 1.3; 
} else { 
    this.mapView.scaleX = this.mapView.scaleY /= 1.3; 
} 

// Find where the original point is now 
var globalPoint = this.mapView.localToGlobal(localPoint.x, localPoint.y); 
// Move the map by the difference 
this.mapView.x -= (globalPoint.x - point.x); 
this.mapView.y -= (globalPoint.y - point.y); 

這只是一個例子,我相信還有一種更純粹的數學方法。

乾杯。