在特定位置缩放GWT上的图像

时间:2019-01-09 16:04:18

标签: java gwt zoom gxt image-zoom

是否可以在特定位置放大GWT图像。就像在Google地图上一样。如果在鼠标指针所在的部分上滚动,图像将在该位置放大。 非常感谢你!

1 个答案:

答案 0 :(得分:0)

这可以解决问题。基于this JS response。完整的源代码here

EventType.bind(document, wheel, new EventCallbackFn<WheelEvent>() {
    double[] pos = {0, 0};
    double scale = 1;
    @Override
    public void onEvent(WheelEvent ev) {
        ev.preventDefault();
        // cap the delta to [-1,1] for cross browser consistency
        double delta = Math.max(-1, Math.min(1, ev.deltaY / 200.));
        // determine the point on where the img is zoomed in
        double[] zoomTarget = {(ev.pageX - pos[0]) / scale, (ev.pageY - pos[1]) / scale};
        // calculate zoom and x and y based on it
        scale = Math.max(.1, Math.min(10, scale + delta * scale));
        pos[0] = -zoomTarget[0] * scale + ev.pageX;
        pos[1] = -zoomTarget[1] * scale + ev.pageY;
        target.style.transform = "translate(" + pos[0] + "px ," + pos[1] + "px) scale(" + scale + ")";
    }
});