Correct calculation of anchor for zooming
Correct calculation of anchor for zooming

Quick explanation:

Let targetCenterPx be described by PX and PY.  Let oldRes and newRes be R0 and R1 respectively.  Let centerPx (center after zoom) be described by CX and CY.  And assume there is some anchored pixel point out there that represents the same map location before and after zoom.  Let this be the origin OX and OY.

We want to recenter the map on the provided box.  This means the map distance between the origin and box center at R0 is the same as the map distance between the origin and the map center at R1.

That is,

    R0 * (OX - PX) = R1 * (OX - CX), and
    R1 * (OY - PY) = R1 * (OY - CY)

Or, solving for OX and OY:

    OX = (R0 * PX - R1 * CX) / (R0 - R1), and
    OY = (R0 * PY - R1 * CY) / (R0 - R1)

sbrunner/openlayers,tschaub/openlayers-raster,adh1365/openlayers,altamiracorp/openlayers,wet-boew/openlayers,avinet/openlayers,wet-boew/openlayers,Gnafu/openlayers,altamiracorp/openlayers,kartverket/openlayers,ahocevar/ol2,elbakai/openlayers,owenmead/openlayers,shevawen/openlayers,Gnafu/openlayers,boundlessgeo/openlayers,sanak/ol2,pvalsecc/openlayers,openlayers/ol2,openlayers/ol2,shevawen/openlayers,PetrDlouhy/openlayers,kartverket/openlayers,adh1365/openlayers,kartverket/openlayers,elbakai/openlayers,sbrunner/openlayers,ahocevar/ol2,v5analytics/openlayers,v5analytics/openlayers,colllin/openlayers,ahocevar/ol2,adh1365/openlayers,dracic/openlayers,Gnafu/openlayers,pvalsecc/openlayers,colllin/openlayers,avinet/openlayers,tschaub/openlayers-raster,pgiraud/openlayers,shevawen/openlayers,colllin/openlayers,boundlessgeo/openlayers,owenmead/openlayers,wet-boew/openlayers,georchestra/openlayers,dracic/openlayers,avinet/openlayers,boundlessgeo/openlayers,wet-boew/openlayers,dracic/openlayers,openlayers/ol2,boundlessgeo/openlayers,pgiraud/openlayers,PublicStuff/openlayers,elbakai/openlayers,Gnafu/openlayers,avinet/openlayers,georchestra/openlayers,owenmead/openlayers,altamiracorp/openlayers,pgiraud/openlayers,v5analytics/openlayers,sbrunner/openlayers,elbakai/openlayers,PublicStuff/openlayers,shevawen/openlayers,PetrDlouhy/openlayers,georchestra/openlayers,v5analytics/openlayers,dracic/openlayers,sanak/ol2,PetrDlouhy/openlayers,sanak/ol2,pgiraud/openlayers,owenmead/openlayers,tschaub/openlayers-raster,pvalsecc/openlayers,altamiracorp/openlayers,PublicStuff/openlayers,sanak/ol2,colllin/openlayers,openlayers/ol2,adh1365/openlayers,kartverket/openlayers,PetrDlouhy/openlayers,sbrunner/openlayers,pvalsecc/openlayers,PublicStuff/openlayers