简体   繁体   English

Openlayers中的缩放事件

[英]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. 我正在图像上使用openlayers,并希望具有它,以便如果我一直缩小并稍微偏向一侧,它将自动居中。 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? 看起来好像没有在紧急情况下调用“ zoomEnd”,但是会触发什么事件?

Is there a list of all the possible events to listen for in Openayers? 是否有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. 我相信您最好使用moveend事件。 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 另外,这是事件列表: 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 您可能还想在最近的Map()函数中使用map.setCenter()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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