简体   繁体   中英

Pinch zoom event in openlayers

I'm using openlayers on an image and looking to have it so that if I zoom all the way out and it's off to the side a bit, that it will be automatically centered. I have the following code, but it is not working. It doesn't look like 'zoomEnd' is called on pinch, but what event is fired?

Is there a list of all the possible events to listen for in Openayers? I can't find something like that anywhere in the documentation..

map = new OpenLayers.Map('detailsdiv', {
    projection : 'EPSG:3785',
    units : 'm',
    fractionalZoom : true,
    eventListeners: {
        "zoomend": recenterMap
    },
    maxResolution: Math.pow(2, graphic.numberOfTiers - 1),
    numZoomLevels : graphic.numberOfTiers,
    controls: [
         new OpenLayers.Control.TouchNavigation({
                dragPanOptions: {
                    enableKinetic: true
                }
         })
    ]
});

==============================

function recenterMap(){
    if (!map.centered){
        if (map.getZoom() == 0){
            map.centered = true;
            map.zoomToMaxExtent();
            map.zoomTo(0);
        } else {

        }
    }
}

I believe you are better off using the moveend event. It gets fired when a drag, pan, or zoom ends...which is better. Also, here is a list of events: http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events

You also might want to use map.setCenter() in your recenterMap() function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM